mmolimar / ksql-jdbc-driver

JDBC driver for Apache Kafka
Apache License 2.0
87 stars 19 forks source link

How to get older data from a table with a self terminating query? #13

Open d-thomson opened 5 years ago

d-thomson commented 5 years ago

Hi Mario,

Thank you for the new release of the driver, I am now able to connect to a KSQL instance. I am able to query metadata (SHOW STREAMS; SHOW TABLES; etc.) however I am having trouble finding a way to query old data from a table where the query wont hang.

The code snippet I'm using:

// query: SELECT * FROM USERS_ORIGINAL LIMIT 3
//rs.beforeFirst(); // <<NOT SUPPORTED  

while (rs.next()) { // << "HANGS" HERE
    for (int colInd = 1; colInd <= rsMetaData.getColumnCount(); colInd++){
        String val = rs.getString(colInd);
                System.out.print(val);
                System.out.print("\t");
    }
    System.out.println();
}

The issue seems to be that the pointer for a table is always at the latest position, so when I run the query the driver seems to hang because there is no data coming in. I see that there is a way to set the offset to the earliest position using the following command

SET 'auto.offset.reset' = 'earliest';

but this doesn't seem to be supported by the driver. Do you know if there is a way to set this globally for the KSQL instance or if there's a way to specify this in the query itself?

Much appreciated. Daniel

mmolimar commented 5 years ago

You can set properties in the driver setting the flag properties=true and adding the properties you like. Besides that, you can also configure the timeout property to end the query if the data is not coming.

d-thomson commented 5 years ago

Thanks for that. I was able to get the timeout working however still having some difficulty working with setting properties. Using the following URL:

jdbc:ksql://<ksql-host>:<port>?timeout=1000&propteries=true&auto.offset.reset=earliest

doesn't seem to set that property for the request. I was able to set this property globally in the KSQL config with the form auto.offset.reset=earliest and in the KSQL shell using SET 'auto.offset.reset' = 'earliest'; however via the JDBC URL it doesn't seem to set. Trying to add quotes, or using SET cant pass the regex check.