Skip to content

Commit

Permalink
Merge pull request #208 from taosdata/feat/TS-5161
Browse files Browse the repository at this point in the history
add ws timezone and app info support
  • Loading branch information
zitsen authored Dec 27, 2024
2 parents 243bb35 + 738f3a0 commit c5cf46d
Show file tree
Hide file tree
Showing 48 changed files with 1,031 additions and 524 deletions.
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
14 changes: 0 additions & 14 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
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
14 changes: 0 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 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
37 changes: 10 additions & 27 deletions src/main/java/com/taosdata/jdbc/TSDBResultSetBlockData.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
/***************************************************************************
* 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 com.taosdata.jdbc.enums.TimestampPrecision;
import com.taosdata.jdbc.utils.DataTypeConverUtil;
import com.taosdata.jdbc.utils.DateTimeUtils;
import com.taosdata.jdbc.utils.Utils;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.sql.SQLDataException;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;

import static com.taosdata.jdbc.TSDBConstants.*;
import static com.taosdata.jdbc.utils.UnsignedDataUtils.*;
Expand Down Expand Up @@ -193,7 +174,7 @@ public void doSetByteArray() {
if (isNull(tmp, j)) {
col.add(null);
} else {
col.add(DataTypeConverUtil.parseTimestampColumnData(l, this.timestampPrecision));
col.add(DateTimeUtils.parseTimestampColumnData(l, this.timestampPrecision));
}
}
break;
Expand Down Expand Up @@ -378,16 +359,18 @@ public Timestamp getTimestamp(int col) throws SQLException {
}
wasNull = false;
int type = this.columnMetaDataList.get(col).getColType();
if (type == TSDB_DATA_TYPE_BIGINT)
return DataTypeConverUtil.parseTimestampColumnData((long) obj, this.timestampPrecision);
if (type == TSDB_DATA_TYPE_BIGINT) {
Instant instant = DateTimeUtils.parseTimestampColumnData((long) obj, this.timestampPrecision);
return DateTimeUtils.getTimestamp(instant, null);
}
if (type == TSDB_DATA_TYPE_TIMESTAMP)
return (Timestamp) obj;
return DateTimeUtils.getTimestamp((Instant) obj, null);
if (obj instanceof byte[]) {
String tmp = "";
String charset = TaosGlobalConfig.getCharset();
try {
tmp = new String((byte[]) obj, charset);
return Utils.parseTimestamp(tmp);
return DateTimeUtils.parseTimestamp(tmp, null);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e.getMessage());
}
Expand Down
Loading

0 comments on commit c5cf46d

Please sign in to comment.