influxdata / influxdata/influxdb-client-java

About the failure of the query method-----query(@Nonnull String var1, @Nonnull Class<M> var2)

Offen
#598 7 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Java
Sterne
477
Forks
129
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

__The issue:__
There is a problem with the data when using this method-----client.getQueryApi().query(statFlux.toString(), Stat.class);
However, when using this method, the data is obtained normally-----client.getQueryApi().query(statFlux.toString());
This indicates that the database is working correctly, but there may be problems converting the data.
The following is the relevant information.
__The dependency:__
```xml
3.1.0
17
UTF-8

com.influxdb
influxdb-client-java
6.9.0


com.influxdb
flux-dsl
6.9.0

```
__The model:__
```java

import com.influxdb.annotations.Column;
import com.influxdb.annotations.Measurement;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.Instant;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Measurement(name = "Stat")//influxDB注解
public class Stat {
@Column
private String intr;
@Column
private long ctxt;
@Column
private long btime;
@Column
private long processes;
@Column
private long procs_running;
@Column
private String procs_blocked;
@Column
private long softirq;
@Column(timestamp = true)
Instant time;
}

```
__The code:__
```java
import com.cabin.empty.influxDB.Stat;
import com.cabin.influxDB.util.InfluxDBTemplate;
import com.cabin.utils.dateUtil.DateUtil;
import com.influxdb.client.InfluxDBClient;
import com.influxdb.query.FluxTable;
import com.influxdb.query.dsl.Flux;
import com.influxdb.query.dsl.functions.restriction.Restrictions;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.Duration;
import java.time.Instant;
import java.util.List;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
public class InfluxDBTest {
@Resource(name = "influxByToken")
private InfluxDBClient client;
@Resource(name = "InfluxDBTemplate")
private InfluxDBTemplate template;

@Test
void testAPI() {
String bucket = "bucket";
String measurement = "Stat";
Instant stop = DateUtil.getNowInstant();
Instant start = stop.minus(Duration.ofSeconds(1));

Flux statFlux = Flux.from(bucket)
.range(start, stop)
.filter(Restrictions.and(
Restrictions.measurement().equal(measurement)));

List queryList = client.getQueryApi().query(statFlux.toString(), Stat.class);
queryList.forEach(l -> {
System.out.println(l.toString());
});

List query = client.getQueryApi().query(statFlux.toString());
query.forEach(l -> {
l.getRecords()
.forEach(r -> System.out.println(r.getTime() + ": " + r.getValueByKey("_value")));
});
}

}

```
__The result:__
```
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
Stat(intr=null, ctxt=0, btime=0, processes=0, procs_running=0, procs_blocked=null, softirq=0, time=2023-07-04T06:36:23.005Z)
Stat(intr=null, ctxt=0, btime=0, processes=0, procs_running=0, procs_blocked=null, softirq=0, time=2023-07-04T06:36:23.005Z)
Stat(intr=null, ctxt=0, btime=0, processes=0, procs_running=0, procs_blocked=null, softirq=0, time=2023-07-04T06:36:23.005Z)
Stat(intr=null, ctxt=0, btime=0, processes=0, procs_running=0, procs_blocked=null, softirq=0, time=2023-07-04T06:36:23.005Z)
Stat(intr=null, ctxt=0, btime=0, processes=0, procs_running=0, procs_blocked=null, softirq=0, time=2023-07-04T06:36:23.005Z)
Stat(intr=null, ctxt=0, btime=0, processes=0, procs_running=0, procs_blocked=null, softirq=0, time=2023-07-04T06:36:23.005Z)
2023-07-04T06:36:23.005Z: 1685014131
2023-07-04T06:36:23.005Z: 15002073429
2023-07-04T06:36:23.005Z: 6140525
2023-07-04T06:36:23.005Z: 0
2023-07-04T06:36:23.005Z: 7
2023-07-04T06:36:23.005Z: 0
```
__The information:__
![image](https://github.com/influxdata/influxdb-client-java/assets/74083801/774f1419-70a1-42ec-9476-26a631eac3d4)

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne bei QueryApi.query(String, Class) und vergleiche dessen Verhalten mit query(String), wobei du das bereitgestellte Stat-Modell und die Flux-Abfrage verwendest, um das Mapping-Ergebnis zu reproduzieren. Als erledigt gilt die Aufgabe, wenn die klassenbasierte Abfrage die ausgefüllten Feldwerte zurückgibt, die in den rohen FluxTable-Datensätzen angezeigt werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java, spring-boot
Bereich
databases
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.