Skip to content

Commit b7906f2

Browse files
committed
Merge branch 'main' of github.com:taosdata/taos-connector-jdbc into perf/TD-37355
2 parents d4c83e5 + 180ba59 commit b7906f2

19 files changed

Lines changed: 539 additions & 423 deletions

deploy-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.taosdata.jdbc</groupId>
77
<artifactId>taos-jdbcdriver</artifactId>
8-
<version>3.7.2</version>
8+
<version>3.7.3</version>
99
<packaging>jar</packaging>
1010

1111
<name>JDBCDriver</name>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.taosdata.jdbc</groupId>
55
<artifactId>taos-jdbcdriver</artifactId>
6-
<version>3.7.2</version>
6+
<version>3.7.3</version>
77

88
<packaging>jar</packaging>
99
<name>JDBCDriver</name>

src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,6 @@ public ResultSet getProcedureColumns(String catalog, String schemaPattern, Strin
553553
return null;
554554
}
555555

556-
public abstract ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException;
557-
558556
private List<ColumnMetaData> buildGetTablesColumnMetaDataList() {
559557
List<ColumnMetaData> columnMetaDataList = new ArrayList<>();
560558
columnMetaDataList.add(buildTableCatalogMeta(1)); // 1. TABLE_CAT
@@ -720,15 +718,18 @@ public ResultSet getSchemas() {
720718
return getEmptyResultSet();
721719
}
722720

723-
public abstract ResultSet getCatalogs() throws SQLException;
724-
725721
private List<ColumnMetaData> buildTableTypesColumnMetadataList() {
726722
List<ColumnMetaData> columnMetaDataList = new ArrayList<>();
727723
columnMetaDataList.add(buildTableTypeMeta(1));
728724
return columnMetaDataList;
729725
}
730726

731727
public ResultSet getTableTypes() throws SQLException {
728+
Connection connection = getConnection();
729+
if (connection == null || connection.isClosed()) {
730+
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
731+
}
732+
732733
DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
733734
// set up ColumnMetaDataList
734735
resultSet.setColumnMetaDataList(buildTableTypesColumnMetadataList());
@@ -745,8 +746,6 @@ public ResultSet getTableTypes() throws SQLException {
745746
return resultSet;
746747
}
747748

748-
public abstract ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException;
749-
750749
private Map<String, String> getCatalogMate(Connection connection, String catalog) throws SQLException {
751750
Map<String, String> result = new HashMap<>();
752751
try (Statement stmt = connection.createStatement();
@@ -1382,8 +1381,6 @@ public ResultSet getVersionColumns(String catalog, String schema, String table)
13821381
return getEmptyResultSet();
13831382
}
13841383

1385-
public abstract ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException;
1386-
13871384
public ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException {
13881385
return getEmptyResultSet();
13891386
}
@@ -1449,7 +1446,7 @@ public boolean insertsAreDetected(int type) throws SQLException {
14491446
}
14501447

14511448
public boolean supportsBatchUpdates() throws SQLException {
1452-
return false;
1449+
return true;
14531450
}
14541451

14551452
public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException {
@@ -1477,9 +1474,6 @@ public boolean supportsGetGeneratedKeys() throws SQLException {
14771474
public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) throws SQLException {
14781475
return getEmptyResultSet();
14791476
}
1480-
1481-
public abstract ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException;
1482-
14831477
public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) throws SQLException {
14841478
return getEmptyResultSet();
14851479
}
@@ -1710,4 +1704,46 @@ private ColumnMetaData buildSuperTableNameMeta(int colIndex) {
17101704
private String generateDescribeSql(String dbName, String tableName) throws SQLException {
17111705
return "describe " + dbName + "." + getIdentifierQuoteString() + tableName + getIdentifierQuoteString();
17121706
}
1707+
1708+
1709+
@Override
1710+
public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException {
1711+
Connection connection = getConnection();
1712+
if (connection == null || connection.isClosed()) {
1713+
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
1714+
}
1715+
return getTables(catalog, schemaPattern, tableNamePattern, types, connection);
1716+
}
1717+
1718+
@Override
1719+
public ResultSet getCatalogs() throws SQLException {
1720+
Connection connection = getConnection();
1721+
if (connection == null || connection.isClosed())
1722+
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
1723+
return getCatalogs(connection);
1724+
}
1725+
1726+
@Override
1727+
public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException {
1728+
Connection connection = getConnection();
1729+
if (connection == null || connection.isClosed())
1730+
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
1731+
return getColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern, connection);
1732+
}
1733+
1734+
@Override
1735+
public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
1736+
Connection connection = getConnection();
1737+
if (connection == null || connection.isClosed())
1738+
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
1739+
return getPrimaryKeys(catalog, schema, table, connection);
1740+
}
1741+
1742+
@Override
1743+
public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException {
1744+
Connection connection = getConnection();
1745+
if (connection == null || connection.isClosed())
1746+
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
1747+
return getSuperTables(catalog, schemaPattern, tableNamePattern, connection);
1748+
}
17131749
}

src/main/java/com/taosdata/jdbc/AbstractDriver.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
import com.taosdata.jdbc.enums.WSFunction;
88
import com.taosdata.jdbc.rs.ConnectionParam;
99
import com.taosdata.jdbc.utils.*;
10-
import com.taosdata.jdbc.ws.FutureResponse;
11-
import com.taosdata.jdbc.ws.InFlightRequest;
12-
import com.taosdata.jdbc.ws.Transport;
13-
import com.taosdata.jdbc.ws.WSConnection;
10+
import com.taosdata.jdbc.ws.*;
1411
import com.taosdata.jdbc.ws.entity.*;
1512
import org.slf4j.LoggerFactory;
1613

@@ -87,13 +84,26 @@ protected Connection getWSConnection(String url, ConnectionParam param, Properti
8784
long id = byteBuf.readLongLE();
8885
byteBuf.readerIndex(8);
8986

90-
FutureResponse remove = inFlightRequest.remove(Action.FETCH_BLOCK_NEW.getAction(), id);
91-
if (null != remove) {
87+
// only neet to handle fetch block new response
88+
FetchBlockData fetchBlockData = FetchDataUtil.getFetchMap().get(id);
89+
if (null != fetchBlockData) {
9290
Utils.retainByteBuf(byteBuf);
91+
byte[] bytes = new byte[byteBuf.readableBytes()];
92+
byteBuf.getBytes(byteBuf.readerIndex(), bytes);
93+
9394
FetchBlockNewResp fetchBlockResp = new FetchBlockNewResp(byteBuf);
94-
remove.getFuture().complete(fetchBlockResp);
95+
try {
96+
fetchBlockData.handleReceiveBlockData(fetchBlockResp);
97+
} catch (InterruptedException e) {
98+
log.error("Error handling fetch block data", e);
99+
Thread.currentThread().interrupt();
100+
Utils.releaseByteBuf(byteBuf);
101+
} catch (Exception e) {
102+
Utils.releaseByteBuf(byteBuf);
103+
log.error("Unexpected error handling fetch block data, id: {}", id, e);
104+
}
95105
} else {
96-
106+
log.warn("Received fetch block new response, but no fetch data found for id: {}", id);
97107
}
98108
});
99109
Transport transport = new Transport(WSFunction.WS, param, inFlightRequest);

src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,4 @@ public ResultSet getSuperTables(String catalog, String schemaPattern, String tab
7777
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
7878
return super.getSuperTables(catalog, schemaPattern, tableNamePattern, conn);
7979
}
80-
8180
}

src/main/java/com/taosdata/jdbc/TSDBResultSet.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@ public boolean next() throws SQLException {
102102

103103
code = this.blockData.returnCode;
104104
} else {
105-
code = this.jniConnector.fetchBlock(this.resultSetPointer, this.blockData);
105+
TSDBResultSetBlockData tsdbResultSetBlockData = new TSDBResultSetBlockData(this.columnMetaDataList, this.columnMetaDataList.size(), timestampPrecision);
106+
107+
code = this.jniConnector.fetchBlock(this.resultSetPointer, tsdbResultSetBlockData);
108+
this.blockData = tsdbResultSetBlockData;
109+
if (code == JNI_SUCCESS) {
110+
this.blockData.doSetByteArray();
111+
}
106112
this.blockData.reset();
107113
}
108114

src/main/java/com/taosdata/jdbc/enums/FetchState.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.taosdata.jdbc.enums;
22

33
public enum FetchState {
4-
PAUSED(1),
4+
STOPPED(1),
55
FETCHING(2),
6-
COMPLETED(3)
6+
FINISHED_ERROR(3),
77
;
88
private final long state;
99

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package com.taosdata.jdbc.rs;
22

33
import com.taosdata.jdbc.AbstractDatabaseMetaData;
4-
import com.taosdata.jdbc.TSDBError;
5-
import com.taosdata.jdbc.TSDBErrorNumbers;
64

75
import java.sql.Connection;
8-
import java.sql.ResultSet;
96
import java.sql.SQLException;
107
@Deprecated
118
public class RestfulDatabaseMetaData extends AbstractDatabaseMetaData {
@@ -35,53 +32,8 @@ public String getDriverName() throws SQLException {
3532
return RestfulDriver.class.getName();
3633
}
3734

38-
@Override
39-
public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException {
40-
if (connection == null || connection.isClosed()) {
41-
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
42-
}
43-
return super.getTables(catalog, schemaPattern, tableNamePattern, types, connection);
44-
}
45-
46-
@Override
47-
public ResultSet getCatalogs() throws SQLException {
48-
if (connection == null || connection.isClosed())
49-
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
50-
return super.getCatalogs(connection);
51-
}
52-
53-
@Override
54-
public ResultSet getTableTypes() throws SQLException {
55-
if (connection == null || connection.isClosed()) {
56-
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
57-
}
58-
return super.getTableTypes();
59-
}
60-
61-
@Override
62-
public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException {
63-
if (connection == null || connection.isClosed())
64-
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
65-
return super.getColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern, connection);
66-
}
67-
68-
@Override
69-
public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
70-
if (connection == null || connection.isClosed())
71-
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
72-
return super.getPrimaryKeys(catalog, schema, table, connection);
73-
}
74-
7535
@Override
7636
public Connection getConnection() throws SQLException {
7737
return this.connection;
7838
}
79-
80-
@Override
81-
public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException {
82-
if (connection == null || connection.isClosed())
83-
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
84-
return super.getSuperTables(catalog, schemaPattern, tableNamePattern, connection);
85-
}
86-
8739
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.taosdata.jdbc.utils;
2+
3+
import com.taosdata.jdbc.ws.FetchBlockData;
4+
5+
import java.util.Map;
6+
import java.util.concurrent.ConcurrentHashMap;
7+
8+
public class FetchDataUtil {
9+
private static final Map<Long, FetchBlockData> INSTANCE = new ConcurrentHashMap<>();
10+
private FetchDataUtil() {}
11+
12+
public static Map<Long, FetchBlockData> getFetchMap() {
13+
return INSTANCE;
14+
}
15+
}

0 commit comments

Comments
 (0)