Skip to content

Commit

Permalink
Merge pull request #216 from taosdata/main
Browse files Browse the repository at this point in the history
merge from main
  • Loading branch information
sheyanjie-qq authored Jan 22, 2025
2 parents 95dac34 + 0aae4e4 commit fcc4fbb
Show file tree
Hide file tree
Showing 62 changed files with 1,691 additions and 632 deletions.
2 changes: 1 addition & 1 deletion deploy-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId>
<version>3.5.0</version>
<version>3.5.3</version>
<packaging>jar</packaging>

<name>JDBCDriver</name>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId>
<version>3.5.0</version>
<version>3.5.3</version>

<packaging>jar</packaging>
<name>JDBCDriver</name>
Expand Down
14 changes: 3 additions & 11 deletions src/main/java/com/taosdata/jdbc/AbstractDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.taosdata.jdbc.enums.WSFunction;
import com.taosdata.jdbc.rs.ConnectionParam;
import com.taosdata.jdbc.utils.JsonUtil;
import com.taosdata.jdbc.utils.ReqId;
import com.taosdata.jdbc.utils.StringUtils;
import com.taosdata.jdbc.utils.Utils;
import com.taosdata.jdbc.ws.*;
import com.taosdata.jdbc.ws.entity.*;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -101,17 +103,7 @@ protected Connection getWSConnection(String url, ConnectionParam param, Properti

transport.checkConnection(param.getConnectTimeout());

ConnectReq connectReq = new ConnectReq();
connectReq.setReqId(1);
connectReq.setUser(param.getUser());
connectReq.setPassword(param.getPassword());
connectReq.setDb(param.getDatabase());

// Currently, only BI mode is supported. The downstream interface value is 0, so a conversion is performed here.
if(param.getConnectMode() == ConnectionParam.CONNECT_MODE_BI){
connectReq.setMode(0);
}

ConnectReq connectReq = new ConnectReq(param);
ConnectResp auth = (ConnectResp) transport.send(new Request(Action.CONN.getAction(), connectReq));

if (Code.SUCCESS.getCode() != auth.getCode()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.time.Instant;

public abstract class AbstractParameterMetaData extends WrapperImpl implements ParameterMetaData {

Expand Down Expand Up @@ -91,6 +92,8 @@ public int getParameterType(int param) throws SQLException {

if (parameters[param - 1] instanceof Timestamp)
return Types.TIMESTAMP;
if (parameters[param - 1] instanceof Instant)
return Types.TIMESTAMP;
if (parameters[param - 1] instanceof Byte)
return Types.TINYINT;
if (parameters[param - 1] instanceof Short)
Expand All @@ -117,6 +120,8 @@ public String getParameterTypeName(int param) throws SQLException {
if (param < 1 && param >= parameters.length)
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE);

if (parameters[param - 1] instanceof Instant)
return TSDBConstants.jdbcType2TaosTypeName(Types.TIMESTAMP);
if (parameters[param - 1] instanceof Timestamp)
return TSDBConstants.jdbcType2TaosTypeName(Types.TIMESTAMP);
if (parameters[param - 1] instanceof Byte)
Expand Down
36 changes: 30 additions & 6 deletions src/main/java/com/taosdata/jdbc/BlockData.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.taosdata.jdbc;

import com.taosdata.jdbc.rs.RestfulResultSet;
import com.taosdata.jdbc.utils.DataTypeConverUtil;
import com.taosdata.jdbc.utils.DateTimeUtils;

import java.nio.ByteBuffer;
import java.sql.SQLException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Semaphore;
Expand All @@ -19,20 +22,27 @@ public class BlockData {
private int numOfRows;
private ByteBuffer buffer;
private List<RestfulResultSet.Field> fields;
Semaphore semaphore;
private final Semaphore semaphore;
private int precision;

public BlockData(List<List<Object>> data, int returnCode, int numOfRows, ByteBuffer buffer, List<RestfulResultSet.Field> fields) {
public BlockData(List<List<Object>> data,
int returnCode,
int numOfRows,
ByteBuffer buffer,
List<RestfulResultSet.Field> fields,
int precision) {
this.data = data;
this.returnCode = returnCode;
this.numOfRows = numOfRows;
this.buffer = buffer;
this.fields = fields;
this.semaphore = new Semaphore(0);
this.isCompleted = false;
this.precision = precision;
}

public static BlockData getEmptyBlockData(List<RestfulResultSet.Field> fields) {
return new BlockData(null, 0, 0, null, fields);
public static BlockData getEmptyBlockData(List<RestfulResultSet.Field> fields, int precision) {
return new BlockData(null, 0, 0, null, fields, precision);
}

public void handleData() {
Expand Down Expand Up @@ -106,8 +116,7 @@ public void handleData() {
break;
}
case TSDB_DATA_TYPE_BIGINT:
case TSDB_DATA_TYPE_UBIGINT:
case TSDB_DATA_TYPE_TIMESTAMP: {
case TSDB_DATA_TYPE_UBIGINT: {
length = bitMapOffset;
byte[] tmp = new byte[bitMapOffset];
buffer.get(tmp);
Expand All @@ -121,6 +130,21 @@ public void handleData() {
}
break;
}
case TSDB_DATA_TYPE_TIMESTAMP: {
length = bitMapOffset;
byte[] tmp = new byte[bitMapOffset];
buffer.get(tmp);
for (int j = 0; j < numOfRows; j++) {
long l = buffer.getLong();
if (isNull(tmp, j)) {
col.add(null);
} else {
Instant instant = DateTimeUtils.parseTimestampColumnData(l, precision);
col.add(instant);
}
}
break;
}
case TSDB_DATA_TYPE_FLOAT: {
length = bitMapOffset;
byte[] tmp = new byte[bitMapOffset];
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/com/taosdata/jdbc/ColumnMetaData.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
/***************************************************************************
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
package com.taosdata.jdbc;

public class ColumnMetaData {
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
/***************************************************************************
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
package com.taosdata.jdbc;

import java.math.BigDecimal;
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/com/taosdata/jdbc/EmptyResultSet.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
/***************************************************************************
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
package com.taosdata.jdbc;

import java.io.InputStream;
Expand Down
41 changes: 19 additions & 22 deletions src/main/java/com/taosdata/jdbc/TSDBConstants.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
/***************************************************************************
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
package com.taosdata.jdbc;

import java.sql.SQLException;
Expand Down Expand Up @@ -58,10 +44,10 @@ public abstract class TSDBConstants {
public static final int TSDB_DATA_TYPE_NCHAR = 10;
/**
* 系统增加新的无符号数据类型,分别是:
* unsigned tinyint, 数值范围:0-254, NULL 为255
* unsigned smallint,数值范围: 0-65534, NULL 为65535
* unsigned int,数值范围:0-4294967294,NULL 为4294967295u
* unsigned bigint,数值范围:0-18446744073709551614u,NULL 为18446744073709551615u
* unsigned tinyint, 数值范围:0-255
* unsigned smallint,数值范围: 0-65535
* unsigned int,数值范围:0-4294967295
* unsigned bigint,数值范围:0-18446744073709551615u
* example:
* create table tb(ts timestamp, a tinyint unsigned, b smallint unsigned, c int unsigned, d bigint unsigned);
*/
Expand All @@ -78,10 +64,15 @@ public abstract class TSDBConstants {

// precision for data types, this is used for metadata
public static final int BOOLEAN_PRECISION = 1;
public static final int TINYINT_PRECISION = 4;
public static final int SMALLINT_PRECISION = 6;
public static final int INT_PRECISION = 11;
public static final int BIGINT_PRECISION = 20;
public static final int TINYINT_PRECISION = 3;
public static final int UNSIGNED_TINYINT_PRECISION = 3;
public static final int SMALLINT_PRECISION = 5;
public static final int UNSIGNED_SMALLINT_PRECISION = 5;

public static final int INT_PRECISION = 10;
public static final int UNSIGNED_INT_PRECISION = 10;
public static final int BIGINT_PRECISION = 19;
public static final int UNSIGNED_BIGINT_PRECISION = 20;
public static final int FLOAT_PRECISION = 12;
public static final int DOUBLE_PRECISION = 22;
public static final int TIMESTAMP_MS_PRECISION = 23;
Expand All @@ -94,6 +85,12 @@ public abstract class TSDBConstants {

public static final boolean DEFAULT_BATCH_ERROR_IGNORE = false;


public static final short MAX_UNSIGNED_BYTE = 255;
public static final int MAX_UNSIGNED_SHORT = 65535;
public static final long MAX_UNSIGNED_INT = 4294967295L;
public static final String MAX_UNSIGNED_LONG = "18446744073709551615";

public static String jdbcType2TaosTypeName(int jdbcType) throws SQLException {
switch (jdbcType) {
case Types.BOOLEAN:
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
/***************************************************************************
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
package com.taosdata.jdbc;

import java.sql.Connection;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/taosdata/jdbc/TSDBDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public class TSDBDriver extends AbstractDriver {
public static final String PROPERTY_KEY_RECONNECT_RETRY_COUNT = "reconnectRetryCount";

public static final String PROPERTY_KEY_DISABLE_SSL_CERT_VALIDATION = "disableSSLCertValidation";
public static final String PROPERTY_KEY_APP_IP = "app_ip";
public static final String PROPERTY_KEY_APP_NAME = "app_name";


/**
* max message number send to server concurrently
Expand All @@ -145,8 +148,6 @@ public class TSDBDriver extends AbstractDriver {
*/
public static final String HTTP_SOCKET_TIMEOUT = "httpSocketTimeout";

public static final String HTTP_TIME_ZONE= "tz";

private TSDBDatabaseMetaData dbMetaData = null;

static {
Expand Down
25 changes: 11 additions & 14 deletions src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
/***************************************************************************
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
package com.taosdata.jdbc;

import com.taosdata.jdbc.utils.Utils;
Expand All @@ -20,6 +6,7 @@
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
Expand Down Expand Up @@ -478,6 +465,11 @@ public void setTagLong(int index, long value) {
this.tagValueLength += Long.BYTES;
}

@Override
public void setTagBigInteger(int index, BigInteger value) throws SQLException {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}

@Override
public void setTagTimestamp(int index, long value) {
ensureTagCapacity(index);
Expand Down Expand Up @@ -578,6 +570,11 @@ public void setLong(int columnIndex, List<Long> list) throws SQLException {
setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BIGINT, Long.BYTES);
}

@Override
public void setBigInteger(int columnIndex, List<BigInteger> list) throws SQLException{
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}

@Override
public void setDouble(int columnIndex, List<Double> list) throws SQLException {
setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_DOUBLE, Double.BYTES);
Expand Down
25 changes: 6 additions & 19 deletions src/main/java/com/taosdata/jdbc/TSDBResultSet.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
/***************************************************************************
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
package com.taosdata.jdbc;

import com.google.common.primitives.Ints;
import com.google.common.primitives.Longs;
import com.google.common.primitives.Shorts;

import java.math.BigDecimal;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
Expand Down Expand Up @@ -210,7 +193,11 @@ public ResultSetMetaData getMetaData() throws SQLException {
@Override
public Object getObject(int columnIndex) throws SQLException {
checkAvailability(columnIndex, this.columnMetaDataList.size());
return this.blockData.get(columnIndex - 1);
Object o = this.blockData.get(columnIndex - 1);
if (o instanceof Instant){
return Timestamp.from((Instant) o);
}
return o;
}

public int findColumn(String columnLabel) throws SQLException {
Expand Down
Loading

0 comments on commit fcc4fbb

Please sign in to comment.