I am reading a sensor value through JDBC in a tree-model query. The returned label is reading, but using the same label in uppercase with a ResultSet getter fails.
The minimal data on Apache IoTDB 2.0.10 is:
CREATE DATABASE root.calibration_cards;
CREATE TIMESERIES root.calibration_cards.sensor_a.pressure
WITH DATATYPE=DOUBLE,ENCODING=PLAIN;
INSERT INTO root.calibration_cards.sensor_a(time,pressure) VALUES (1000,1.6);
I ran this query with the 2.0.10 JDBC driver:
SELECT pressure AS reading
FROM root.calibration_cards.sensor_a
LIMIT 1;
The query result itself is:
+-----------------------------+-------+
| Time|reading|
+-----------------------------+-------+
|1970-01-01T08:00:01.000+08:00| 1.6|
+-----------------------------+-------+
ResultSetMetaData.getColumnLabel(2) returns reading. However, resultSet.getDouble("READING") throws IllegalArgumentException: Unknown column name: READING, while getDouble("reading") and getDouble(2) both return 1.6.
Here is the client reproduction. The connection variables refer to the same server used for the SQL setup:
import java.sql.*;
public class ReadingLabels {
public static void main(String[] args) throws Exception {
Class.forName("org.apache.iotdb.jdbc.IoTDBDriver");
try (Connection c = DriverManager.getConnection(
System.getenv("IOTDB_JDBC_URL"), System.getenv("IOTDB_USER"),
System.getenv("IOTDB_PASSWORD"));
Statement s = c.createStatement()) {
System.out.println("JDBC driver: " + c.getMetaData().getDriverVersion());
try (ResultSet r = s.executeQuery(
"SELECT pressure AS reading FROM root.calibration_cards.sensor_a LIMIT 1")) {
System.out.println("columnLabel(2)=" + r.getMetaData().getColumnLabel(2));
r.next();
try { System.out.println("getDouble(READING)=" + r.getDouble("READING")); }
catch (IllegalArgumentException e) {
System.out.println("getDouble(READING) -> " + e.getClass().getName()
+ ": " + e.getMessage());
}
System.out.println("getDouble(reading)=" + r.getDouble("reading"));
System.out.println("getDouble(2)=" + r.getDouble(2));
}
try (ResultSet r = s.executeQuery(
"SELECT pressure AS READING FROM root.calibration_cards.sensor_a LIMIT 1")) {
r.next();
System.out.println("uppercase alias: getDouble(READING)=" + r.getDouble("READING"));
}
}
}
}
The output is:
JDBC driver: 2.0.10
columnLabel(2)=reading
getDouble(READING) -> java.lang.IllegalArgumentException: Unknown column name: READING
getDouble(reading)=1.6
getDouble(2)=1.6
uppercase alias: getDouble(READING)=1.6
Changing only the alias spelling to uppercase makes the uppercase getter succeed:
SELECT pressure AS READING
FROM root.calibration_cards.sensor_a
LIMIT 1;
+-----------------------------+-------+
| Time|READING|
+-----------------------------+-------+
|1970-01-01T08:00:01.000+08:00| 1.6|
+-----------------------------+-------+
The JDBC ResultSet contract says column names supplied to getter methods are case-insensitive. Why does the IoTDB JDBC driver resolve the label returned by metadata case-sensitively for this query?