TDengine icon indicating copy to clipboard operation
TDengine copied to clipboard

相同sql语句执行, jdbc:TAOS-RS 正常, jdbc:TAOS-WS 异常

Open shadiniao opened this issue 6 months ago • 2 comments

Bug Description SELECT entity_id, LAST_ROW(*) FROM s1 WHERE entity_id IN ( ?, ?, ? ) AND tenant_id = ? GROUP BY entity_id

相同sql语句执行 , jdbc:TAOS-RS 下执行正常, jdbc:TAOS-WS 则异常

To Reproduce 建表和测试sql

`

    CREATE STABLE s1 (
        ts TIMESTAMP,
        a FLOAT
    ) TAGS (
        company_id BIGINT,
        tenant_id BIGINT,
        entity_id BIGINT,
        model_id  BIGINT
    );
    
    CREATE TABLE d1 USING s1 TAGS(100, 200, 1, 10);
    CREATE TABLE d2 USING s1 TAGS(100, 200, 2, 10);
    CREATE TABLE d3 USING s1 TAGS(100, 300, 3, 10);
    
    INSERT INTO d1 (ts, a) VALUES
           (NOW + 1s, 12.3),
           (NOW + 2s, 15.7),
           (NOW + 3s, 9.8),
           (NOW + 4s, 20.1),
           (NOW + 5s, 13.6);
           
    INSERT INTO d2 (ts, a) VALUES
           (NOW + 1s, 33),
           (NOW + 2s, 5),
           (NOW + 3s, 7.8),
           (NOW + 4s, 8.1),
           (NOW + 5s, 12.4);
           
    INSERT INTO d3 (ts, a) VALUES
           (NOW + 1s, 22),
           (NOW + 2s, 15),
           (NOW + 3s, 17.8),
           (NOW + 4s, 18.1),
           (NOW + 5s, 2.4);

`

测试用 java 代码 `

public static void main(String[] args) throws Exception {
    String jdbcUrl = "jdbc:TAOS-WS://192.168.1.249:6041/mg?user=root&password=taosdata";
    // 如果换成这个就能执行成功 String jdbcUrl = "jdbc:TAOS-RS://192.168.1.249:6041/mg?user=root&password=taosdata";
    Properties connProps = new Properties();
    connProps.setProperty(TSDBDriver.PROPERTY_KEY_ENABLE_AUTO_RECONNECT, "true");
    connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
    connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");

    String sql = "SELECT entity_id, LAST_ROW(*) FROM s1 WHERE entity_id IN ( ?, ?, ? ) AND tenant_id = ? GROUP BY entity_id";
    try (Connection connection = DriverManager.getConnection(jdbcUrl, connProps)) {
        System.out.println("Connected to " + jdbcUrl + " successfully.");
        PreparedStatement stmt = connection.prepareStatement(sql);
        stmt.setLong(1, 1L); // Set tenant_id to 200L
        stmt.setLong(2, 2); // Set tenant_id to 200L
        stmt.setLong(3, 3); // Set tenant_id to 200L
        stmt.setObject(4, 200L); // Set tenant_id to 200L
        ResultSet resultSet = stmt.executeQuery();
        Timestamp ts;
        float current;
        Long deviceId;
        while (resultSet.next()) {
            // we recommend using the column index to get the value for better performance
            deviceId = resultSet.getLong("entity_id");
            ts = resultSet.getTimestamp("last_row(ts)");
            current = resultSet.getFloat("last_row(a)");

            // you can check data here
            System.out.printf("ts: %s, current: %f, deviceId: %s %n", ts, current, deviceId);
        }

    } catch (Exception ex) {
        ex.printStackTrace();
        throw ex;
    }
}

` 上面代码中如果换成这个就能执行成功 String jdbcUrl = "jdbc:TAOS-RS://192.168.1.249:6041/mg?user=root&password=taosdata";

Expected Behavior 执行正常输出类似 ts: 2025-05-30 09:14:06.419, current: 12.400000, deviceId: 2 ts: 2025-05-30 09:14:06.404, current: 13.600000, deviceId: 1

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information): tdengine运行在docker中

docker-compose.yml

`

  version: '3'
  
  services:
    tdengine:
      image: tdengine/tdengine:3.3.3.0
      container_name: tdengine
      ports:
        - "6030:6030"    # 客户端连接端口
        - "6041:6041"    # REST API 端口
        - "6043:6043"    # 内部通信端口
        - "6044-6049:6044-6049"  # 集群通信端口
        - "6044-6045:6044-6045/udp"  # 集群通信 UDP 端口
        - "6060:6060"    # 监控端口
      restart: always
      volumes:
        - /opt/data/taos/data:/var/lib/taos  # 数据持久化目录
        - /opt/data/taos/logs:/var/log/taos  # 日志持久化目录
      networks:
        - tdengine-net
  
  networks:
    tdengine-net:
      driver: bridge

`

Additional Context 报错异常信息

java.sql.SQLException: TDengine ERROR (0xffff): FETCH DATA ERROR at com.taosdata.jdbc.TSDBError.createSQLException(TSDBError.java:95) at com.taosdata.jdbc.ws.AbstractWSResultSet.next(AbstractWSResultSet.java:173) at com.hnjme.iot.service.impl.RealtimeDataServiceImpl.main(RealtimeDataServiceImpl.java:76) Exception in thread "main" java.sql.SQLException: TDengine ERROR (0xffff): FETCH DATA ERROR at com.taosdata.jdbc.TSDBError.createSQLException(TSDBError.java:95) at com.taosdata.jdbc.ws.AbstractWSResultSet.next(AbstractWSResultSet.java:173) at com.hnjme.iot.service.impl.RealtimeDataServiceImpl.main(RealtimeDataServiceImpl.java:76)

shadiniao avatar May 30 '25 01:05 shadiniao

驱动版本是?

yu285 avatar Jun 09 '25 01:06 yu285

https://docs.taosdata.com/reference/connector/java/

jdbcUrl 以“jdbc:TAOS-WS://”开头是较新版本驱动支持的。

yu285 avatar Jun 09 '25 01:06 yu285