opensearch-project / sql-jdbc

This is the driver for JDBC connectivity to a cluster running with OpenSearch SQL support.
Apache License 2.0
14 stars 25 forks source link

[BUG] `getColumnTypeName` for timestamp depends on cursor on/off #90

Open Yury-Fridlyand opened 1 year ago

Yury-Fridlyand commented 1 year ago

What is the bug?

getColumnTypeName for timestamp depends whether cursor feature is active

How can one reproduce the bug?

Steps to reproduce the behavior:

  1. Create an index and a doc:
    curl -s -H 'Content-Type: application/json' -XPUT "http://localhost:9200/date_type_index?pretty" -d '{"mappings": {"properties": {"release_date": {"type": "date" }}}}'
    curl -s -H 'Content-Type: application/json' -XPOST "http://localhost:9200/date_type_index/_doc?pretty" -d '{"release_date": "2022-11-16"}'
  2. Query it without cursor:
    Connection conn = driver.connect(connStr, properties);
    Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = stmt.executeQuery("select * from date_type_index");
    ResultSetMetaData rsmd = rs.getMetaData();
    String typeName = rsmd.getColumnTypeName("release_date");
  3. typeName is TIMESTAMP
  4. Query it with cursor:
    Connection conn = driver.connect(connStr, properties);
    Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    stmt.setFetchSize(5);
    ResultSet rs = stmt.executeQuery("select * from date_type_index");
    ResultSetMetaData rsmd = rs.getMetaData();
    String typeName = rsmd.getColumnTypeName("release_date");
  5. typeName is DATE

What is the expected behavior?

It should be always timestamp since SQL plugin reports this type:

{
  "schema": [
    {
      "name": "release_date",
      "type": "timestamp"
    }
  ],
  "datarows": [
    [
      "2022-11-16 00:00:00"
    ]
  ],
  "total": 1,
  "size": 1,
  "status": 200
}

What is your host/environment?

Do you have any screenshots?

N/A

Do you have any additional context?

Thanks @akuzin1 for reporting that