influxdata / influxdb-client-java

InfluxDB 2 JVM Based Clients
https://influxdata.github.io/influxdb-client-java/
MIT License
445 stars 128 forks source link

When i try to query the data from influxdb using queryApi.query(flux), i am getting exceptions #338

Closed anil123lalam closed 2 years ago

anil123lalam commented 2 years ago

package com.unitedrentals.dto;

import java.time.Instant;

import com.influxdb.annotations.Column; import com.influxdb.annotations.Measurement;

@Measurement(name = "series") public class InfluxSeriesDto { @Column String shardId; @Column String equipmentId; @Column String datatimestamp; @Column String tagname; @Column String uom; @Column String datavalue; @Column(timestamp = true) Instant time;

public String getShardId() {
    return shardId;
}

public void setShardId(String shardId) {
    this.shardId = shardId;
}

public String getEquipmentId() {
    return equipmentId;
}

public void setEquipmentId(String equipmentId) {
    this.equipmentId = equipmentId;
}

public String getDatatimestamp() {
    return datatimestamp;
}

public void setDatatimestamp(String datatimestamp) {
    this.datatimestamp = datatimestamp;
}

public String getTagname() {
    return tagname;
}

public void setTagname(String tagname) {
    this.tagname = tagname;
}

public String getUom() {
    return uom;
}

public void setUom(String uom) {
    this.uom = uom;
}

public String getDatavalue() {
    return datavalue;
}

public void setDatavalue(String datavalue) {
    this.datavalue = datavalue;
}

public Instant getTime() {
    return time;
}

public void setTime(Instant time) {
    this.time = time;
}

}

public class InfluxDBClientSample {

private static String bucket = "unitedrentals";
private static String org = "unitedrentals";
private static String token = "85pZyGiyloQRyXpaEypv4ErrHMKveOkGfle2JXRFBPU9Uh7rI8uvKkyLPGumq_TUO_gZhTWZ6O5hRnCf3HEA1w==";

public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub

    InfluxDBClientOptions build = InfluxDBClientOptions.builder().bucket(bucket).org(org)
            .url("http://localhost:8086").authenticateToken(token.toCharArray()).build();

    InfluxDBClient client = InfluxDBClientFactory.create(build);

    System.out.println("*** Query Points ***");
    String flux = "from(bucket:\"unitedrentals\") |> range(start: 0) |> filter(fn: (r) => r._measurement == \"series\")";

    // client.getDeleteApi().delete(OffsetDateTime.of(2022,04,19,0,0,0,0,ZoneOffset.UTC),
    // OffsetDateTime.now(),"_measurement=\"series\"",
    // "unitedrentals","unitedrentals");
    List<InfluxSeriesDto> list = client.getQueryApi().query(flux, InfluxSeriesDto.class);
    client.close();
}

}

Steps to reproduce: List the minimal actions needed to reproduce the behavior.

  1. After executing the above program , i am getting below exceptions

Exception in thread "main" java.lang.IllegalArgumentException: Unable to create @Body converter for class com.influxdb.client.domain.Query (parameter #6) for method QueryService.postQueryResponseBody at retrofit2.Utils.methodError(Utils.java:54) at retrofit2.Utils.parameterError(Utils.java:60) at retrofit2.RequestFactory$Builder.parseParameterAnnotation(RequestFactory.java:781) at retrofit2.RequestFactory$Builder.parseParameter(RequestFactory.java:325) at retrofit2.RequestFactory$Builder.build(RequestFactory.java:206) at retrofit2.RequestFactory.parseAnnotations(RequestFactory.java:67) at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:26) at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:202) at retrofit2.Retrofit$1.invoke(Retrofit.java:160) at com.sun.proxy.$Proxy4.postQueryResponseBody(Unknown Source) at com.influxdb.client.internal.QueryApiImpl.query(QueryApiImpl.java:933) at com.influxdb.client.internal.QueryApiImpl.query(QueryApiImpl.java:123) at com.influxdb.client.internal.QueryApiImpl.query(QueryApiImpl.java:85) at com.influxdb.client.internal.QueryApiImpl.query(QueryApiImpl.java:75) at com.influxdb.InfluxDBClientSample.main(InfluxDBClientSample.java:49) Caused by: java.lang.IllegalArgumentException: @JsonAdapter value must be TypeAdapter or TypeAdapterFactory reference. at com.google.gson.internal.bind.JsonAdapterAnnotationTypeAdapterFactory.getTypeAdapter(JsonAdapterAnnotationTypeAdapterFactory.java:65) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:133) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.access$100(ReflectiveTypeAdapterFactory.java:49) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.(ReflectiveTypeAdapterFactory.java:106) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:105) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:161) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:97) at com.google.gson.Gson.getDelegateAdapter(Gson.java:489) at io.gsonfire.gson.WrapTypeAdapterFactory.create(WrapTypeAdapterFactory.java:26) at com.google.gson.Gson.getAdapter(Gson.java:407) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:136) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.access$100(ReflectiveTypeAdapterFactory.java:49) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.(ReflectiveTypeAdapterFactory.java:106) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:105) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:161) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:97) at com.google.gson.Gson.getDelegateAdapter(Gson.java:489) at io.gsonfire.gson.WrapTypeAdapterFactory.create(WrapTypeAdapterFactory.java:26) at com.google.gson.Gson.getAdapter(Gson.java:407) at retrofit2.converter.gson.GsonConverterFactory.requestBodyConverter(GsonConverterFactory.java:74) at retrofit2.Retrofit.nextRequestBodyConverter(Retrofit.java:315) at retrofit2.Retrofit.requestBodyConverter(Retrofit.java:293) at retrofit2.RequestFactory$Builder.parseParameterAnnotation(RequestFactory.java:778) ... 12 more

Expected behavior: Should display records from influxdb

Actual behavior: Exceptions were thrown

Specifications:

bednar commented 2 years ago

Hi @anil123lalam,

thanks for using our client.

Can you share a full stacktrace? How looks like your dependency tree?

Regards

anil123lalam commented 2 years ago

Hi bednar, Thanks for your quick response. Dependency tree: dependencytree

FullStackTrace:

Exception in thread "main" java.lang.IllegalArgumentException: Unable to create @Body converter for class com.influxdb.client.domain.Query (parameter https://github.com/influxdata/influxdb-client-java/pull/6) for method QueryService.postQueryResponseBody at retrofit2.Utils.methodError(Utils.java:54) at retrofit2.Utils.parameterError(Utils.java:60) at retrofit2.RequestFactory$Builder.parseParameterAnnotation(RequestFactory.java:781) at retrofit2.RequestFactory$Builder.parseParameter(RequestFactory.java:325) at retrofit2.RequestFactory$Builder.build(RequestFactory.java:206) at retrofit2.RequestFactory.parseAnnotations(RequestFactory.java:67) at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:26) at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:202) at retrofit2.Retrofit$1.invoke(Retrofit.java:160) at com.sun.proxy.$Proxy4.postQueryResponseBody(Unknown Source) at com.influxdb.client.internal.QueryApiImpl.query(QueryApiImpl.java:933) at com.influxdb.client.internal.QueryApiImpl.query(QueryApiImpl.java:123) at com.influxdb.client.internal.QueryApiImpl.query(QueryApiImpl.java:85) at com.influxdb.client.internal.QueryApiImpl.query(QueryApiImpl.java:75) at com.influxdb.InfluxDBClientSample.main(InfluxDBClientSample.java:49) Caused by: java.lang.IllegalArgumentException: @JsonAdapter value must be TypeAdapter or TypeAdapterFactory reference. at com.google.gson.internal.bind.JsonAdapterAnnotationTypeAdapterFactory.getTypeAdapter(JsonAdapterAnnotationTypeAdapterFactory.java:65) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:133) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.access$100(ReflectiveTypeAdapterFactory.java:49) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.(ReflectiveTypeAdapterFactory.java:106) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:105) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:161) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:97) at com.google.gson.Gson.getDelegateAdapter(Gson.java:489) at io.gsonfire.gson.WrapTypeAdapterFactory.create(WrapTypeAdapterFactory.java:26) at com.google.gson.Gson.getAdapter(Gson.java:407) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:136) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.access$100(ReflectiveTypeAdapterFactory.java:49) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.(ReflectiveTypeAdapterFactory.java:106) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:105) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:161) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:97) at com.google.gson.Gson.getDelegateAdapter(Gson.java:489) at io.gsonfire.gson.WrapTypeAdapterFactory.create(WrapTypeAdapterFactory.java:26) at com.google.gson.Gson.getAdapter(Gson.java:407) at retrofit2.converter.gson.GsonConverterFactory.requestBodyConverter(GsonConverterFactory.java:74) at retrofit2.Retrofit.nextRequestBodyConverter(Retrofit.java:315) at retrofit2.Retrofit.requestBodyConverter(Retrofit.java:293) at retrofit2.RequestFactory$Builder.parseParameterAnnotation(RequestFactory.java:778) ... 12 more

Client Version: com.influxdb influxdb-client-java 5.0.0 InfluxDB Version: 2.2.0 JDK Version: 1.8 Platform:Windows

bednar commented 2 years ago

It looks like problem with gson version. Please try to change gson version to 2.8.8 or remove explicit declaration of gson.

anil123lalam commented 2 years ago

Even after i changed the gson version to 2.8.8 or remove explicit declaration of gson i am seeing the same exceptions.

bednar commented 2 years ago

Can you try the 6.0.0? This version contains PR https://github.com/influxdata/influxdb-client-java/pull/298 with fixed dependency collision.

anil123lalam commented 2 years ago

When i use 6.0.0, i am getting below exceptions

Exception in thread "main" java.lang.NullPointerException: Expecting a not null reference for InfluxDBClientOptions.getOrg at java.base/java.util.Objects.requireNonNull(Objects.java:347) at com.influxdb.utils.Arguments.checkNotNull(Arguments.java:150) at com.influxdb.client.internal.QueryApiImpl.query(QueryApiImpl.java:132) at com.influxdb.InfluxDBClientSample.main(InfluxDBClientSample.java:28)

bednar commented 2 years ago

This is our bug introduced by #335 :(

Please as a workaround change the initialisation of InfluxDBClientOptions to (url as first):

InfluxDBClientOptions build = InfluxDBClientOptions.builder().url("http://localhost:8086").bucket(bucket).org(org)
            .authenticateToken(token.toCharArray()).build();
anil123lalam commented 2 years ago

As per your suggestion i have changed the initialization, now i am getting below exception

Exception in thread "main" java.lang.IllegalArgumentException: Unable to create @Body converter for class com.influxdb.client.domain.Query (parameter #6) for method QueryService.postQueryResponseBody at retrofit2.Utils.methodError(Utils.java:54) at retrofit2.Utils.parameterError(Utils.java:60) at retrofit2.RequestFactory$Builder.parseParameterAnnotation(RequestFactory.java:781) at retrofit2.RequestFactory$Builder.parseParameter(RequestFactory.java:325) at retrofit2.RequestFactory$Builder.build(RequestFactory.java:206) at retrofit2.RequestFactory.parseAnnotations(RequestFactory.java:67) at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:26) at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:202) at retrofit2.Retrofit$1.invoke(Retrofit.java:160) at com.sun.proxy.$Proxy4.postQueryResponseBody(Unknown Source) at com.influxdb.client.internal.QueryApiImpl.query(QueryApiImpl.java:933) at com.influxdb.client.internal.QueryApiImpl.query(QueryApiImpl.java:204) at com.influxdb.client.internal.QueryApiImpl.query(QueryApiImpl.java:147) at com.influxdb.client.internal.QueryApiImpl.query(QueryApiImpl.java:134) at com.influxdb.InfluxDBClientSample.main(InfluxDBClientSample.java:28) Caused by: java.lang.IllegalArgumentException: @JsonAdapter value must be TypeAdapter or TypeAdapterFactory reference. at com.google.gson.internal.bind.JsonAdapterAnnotationTypeAdapterFactory.getTypeAdapter(JsonAdapterAnnotationTypeAdapterFactory.java:65) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:133) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.access$100(ReflectiveTypeAdapterFactory.java:49) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.(ReflectiveTypeAdapterFactory.java:106) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:105) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:161) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:97) at com.google.gson.Gson.getDelegateAdapter(Gson.java:489) at io.gsonfire.gson.WrapTypeAdapterFactory.create(WrapTypeAdapterFactory.java:26) at com.google.gson.Gson.getAdapter(Gson.java:407) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:136) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.access$100(ReflectiveTypeAdapterFactory.java:49) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.(ReflectiveTypeAdapterFactory.java:106) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:105) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:161) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:97) at com.google.gson.Gson.getDelegateAdapter(Gson.java:489) at io.gsonfire.gson.WrapTypeAdapterFactory.create(WrapTypeAdapterFactory.java:26) at com.google.gson.Gson.getAdapter(Gson.java:407) at retrofit2.converter.gson.GsonConverterFactory.requestBodyConverter(GsonConverterFactory.java:74) at retrofit2.Retrofit.nextRequestBodyConverter(Retrofit.java:315) at retrofit2.Retrofit.requestBodyConverter(Retrofit.java:293) at retrofit2.RequestFactory$Builder.parseParameterAnnotation(RequestFactory.java:778) ... 12 more

bednar commented 2 years ago

It looks like gson version problem.

What is an output of:

String version = com.google.gson.internal.GsonBuildConfig.VERSION;
System.out.println("version = " + version);

?

anil123lalam commented 2 years ago

version = 2.8.8

anil123lalam commented 2 years ago

For 6.0.0 what is the suggestable gson version ?

bednar commented 2 years ago

For the client 6.0.0 you have to use 2.9.0.

anil123lalam commented 2 years ago

version = 2.9.0, i am seeing the same exceptions

bednar commented 2 years ago

I've create the following demo project with v6.0.0 client: https://github.com/bednar/java-client-dependency

Can you try the demo project? For me it works correctly.

anil123lalam commented 2 years ago

Thanks, the above demo project works me correctly as well

bednar commented 2 years ago

Can you share your project? Currently I am not able to find a reason of the exception. 😞

anil123lalam commented 2 years ago

Sure, I will share it with you, currently I am out of station. I need to learn influxdb, Could you please help me with resources like videos,books etc. I am not able to find online.

Thanks Anil Lalam ‐‐--------‐------------------------------------------------ Sent From Mobile

On Fri, 22 Apr 2022, 10:09 am Jakub Bednář, @.***> wrote:

Can you share your project? Currently I am not able to find a reason of the exception. 😞

— Reply to this email directly, view it on GitHub https://github.com/influxdata/influxdb-client-java/issues/338#issuecomment-1105998262, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUYMYH2FFXV3VMHAYOEUZJ3VGIUO7ANCNFSM5T3MQDUA . You are receiving this because you were mentioned.Message ID: @.***>

bednar commented 2 years ago

Sure, I will share it with you, currently I am out of station

Thanks

Here are some sources:

bednar commented 2 years ago

Can you test explicitly exclude gson from client dependency and add gson as a new dependency in your project:

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.9.0</version>
</dependency>
<dependency>
    <groupId>com.influxdb</groupId>
    <artifactId>influxdb-client-java</artifactId>
    <version>6.0.0</version>
    <exclusions>
        <exclusion>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </exclusion>
    </exclusions>
</dependency>

?

bednar commented 2 years ago

This issue has been closed because it has not had recent activity. Please reopen if this issue is still important to you and you have additionally information.