influxdata / influxdata/influxdb-client-java
About the failure of the query method-----query(@Nonnull String var1, @Nonnull Class<M> var2)
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Java
- Star
- 477
- Fork
- 129
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
__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:__

Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu từ QueryApi.query(String, Class) và so sánh hành vi của nó với query(String), sử dụng mô hình Stat và truy vấn Flux được cung cấp để tái hiện kết quả ánh xạ. Hoàn tất khi truy vấn dựa trên lớp trả về các giá trị trường đã được điền như được hiển thị trong các bản ghi FluxTable thô.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- java, spring-boot
- Lĩnh vực
- databases
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 35/100