提交 acee6a73 编写于 作者: S shenglian zhou

Merge remote-tracking branch 'origin/develop' into szhou/feature/support-math-functions

......@@ -181,6 +181,76 @@ def pre_test_noinstall(){
'''
return 1
}
def pre_test_mac(){
sh'hostname'
sh'''
cd ${WKC}
git reset --hard HEAD~10 >/dev/null
'''
script {
if (env.CHANGE_TARGET == 'master') {
sh '''
cd ${WKC}
git checkout master
'''
}
else if(env.CHANGE_TARGET == '2.0'){
sh '''
cd ${WKC}
git checkout 2.0
'''
}
else{
sh '''
cd ${WKC}
git checkout develop
'''
}
}
sh'''
cd ${WKC}
git pull >/dev/null
git fetch origin +refs/pull/${CHANGE_ID}/merge
git checkout -qf FETCH_HEAD
git clean -dfx
git submodule update --init --recursive
cd ${WK}
git reset --hard HEAD~10
'''
script {
if (env.CHANGE_TARGET == 'master') {
sh '''
cd ${WK}
git checkout master
'''
}
else if(env.CHANGE_TARGET == '2.0'){
sh '''
cd ${WK}
git checkout 2.0
'''
}
else{
sh '''
cd ${WK}
git checkout develop
'''
}
}
sh '''
cd ${WK}
git pull >/dev/null
export TZ=Asia/Harbin
date
git clean -dfx
mkdir debug
cd debug
cmake .. > /dev/null
cmake --build .
'''
return 1
}
def pre_test_win(){
bat '''
taskkill /f /t /im python.exe
......@@ -385,17 +455,18 @@ pipeline {
npm install td2.0-connector > /dev/null 2>&1
node nodejsChecker.js host=localhost
node test1970.js
cd ${WKC}/tests/connectorTest/nodejsTest/nanosupport
npm install td2.0-connector > /dev/null 2>&1
cd ${WKC}/tests/connectorTest/nodejsTest/nanosupport
npm install td2.0-connector > /dev/null 2>&1
node nanosecondTest.js
'''
sh '''
cd ${WKC}/tests/examples/C#/taosdemo
mcs -out:taosdemo *.cs > /dev/null 2>&1
echo '' |./taosdemo -c /etc/taos
'''
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh '''
cd ${WKC}/tests/examples/C#/taosdemo
mcs -out:taosdemo *.cs > /dev/null 2>&1
echo '' |./taosdemo -c /etc/taos
'''
}
sh '''
cd ${WKC}/tests/gotest
bash batchtest.sh
......@@ -581,6 +652,12 @@ pipeline {
pre_test_noinstall()
}
}
stage('Mac_build') {
agent{label " catalina "}
steps {
pre_test_mac()
}
}
stage('build'){
agent{label " wintest "}
......
......@@ -121,7 +121,7 @@ IF (TD_MIPS_32)
SET(COMMON_FLAGS "-Wall -Werror -fPIC -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
ENDIF ()
IF (TD_APLHINE)
IF (TD_ALPINE)
SET(COMMON_FLAGS "${COMMON_FLAGS} -largp")
link_libraries(/usr/lib/libargp.a)
ADD_DEFINITIONS(-D_ALPINE)
......@@ -172,11 +172,14 @@ IF (TD_LINUX)
ENDIF ()
IF (TD_MEMORY_SANITIZER)
SET(DEBUG_FLAGS "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -O0 -g3 -DDEBUG")
MESSAGE(STATUS "memory sanitizer detected as true")
IF (TD_ARCHLINUX)
SET(DEBUG_FLAGS "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -O0 -g3 -DDEBUG")
ELSE ()
SET(DEBUG_FLAGS "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -O0 -g3 -DDEBUG")
ENDIF ()
MESSAGE(STATUS "${BoldRed}Will compile with memory sanitizer! ${ColourReset}")
ELSE ()
SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG")
MESSAGE(STATUS "memory sanitizer detected as false")
ENDIF ()
SET(RELEASE_FLAGS "-O3 -Wno-error")
......
......@@ -21,7 +21,7 @@ SET(TD_LINUX FALSE)
SET(TD_ARM_32 FALSE)
SET(TD_MIPS_64 FALSE)
SET(TD_MIPS_32 FALSE)
SET(TD_APLHINE FALSE)
SET(TD_ALPINE FALSE)
SET(TD_NINGSI FALSE)
SET(TD_NINGSI_60 FALSE)
SET(TD_NINGSI_80 FALSE)
......@@ -36,7 +36,7 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# Get OS information and store in variable TD_OS_INFO.
#
execute_process(COMMAND chmod 777 ${TD_COMMUNITY_DIR}/packaging/tools/get_os.sh)
execute_process(COMMAND ${TD_COMMUNITY_DIR}/packaging/tools/get_os.sh "" OUTPUT_VARIABLE TD_OS_INFO)
execute_process(COMMAND sh ${TD_COMMUNITY_DIR}/packaging/tools/get_os.sh "" OUTPUT_VARIABLE TD_OS_INFO)
MESSAGE(STATUS "The current os is " ${TD_OS_INFO})
SET(TD_LINUX TRUE)
......@@ -52,8 +52,13 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
ENDIF ()
IF (${TD_OS_INFO} MATCHES "Alpine")
SET(TD_APLHINE TRUE)
MESSAGE(STATUS "The current OS is Alpine, append extra flags")
SET(TD_ALPINE TRUE)
MESSAGE(STATUS "The current OS is Alpine Linux, append extra flags")
ELSEIF (${TD_OS_INFO} MATCHES "Arch")
SET(TD_ARCHLINUX TRUE)
MESSAGE(STATUS "The current OS is Arch Linux")
ELSE ()
MESSAGE(STATUS "Ths distro is " ${TD_OS_INFO})
ENDIF()
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
SET(TD_DARWIN TRUE)
......@@ -155,7 +160,7 @@ ELSEIF (${OSTYPE} MATCHES "Linux")
MESSAGE(STATUS "input osType: Linux")
ELSEIF (${OSTYPE} MATCHES "Alpine")
MESSAGE(STATUS "input osType: Alpine")
SET(TD_APLHINE TRUE)
SET(TD_ALPINE TRUE)
ELSE ()
MESSAGE(STATUS "The user specified osType is unknown: " ${OSTYPE})
ENDIF ()
......@@ -121,10 +121,11 @@ TDengine是一个高效的存储、查询、分析时序大数据的平台,专
* [数据复制](/architecture/replica):支持实时同步、异步复制,保证系统的High Availibility
* [技术博客](https://www.taosdata.com/cn/blog/?categories=3):更多的技术分析和架构设计文章
## [应用 TDengine 快速搭建 IT 运维系统](/devops)
## 应用 TDengine 快速搭建 IT 运维系统
* [devops](/devops/telegraf):使用 TDengine + Telegraf + Grafana 快速搭建 IT 运维系统
* [devops](/devops/collectd):使用 TDengine + collectd_statsd + Grafana 快速搭建 IT 运维系统
* [最佳实践](/devops/immigrate):OpenTSDB 应用迁移到 TDengine 的最佳实践
## 常用工具
......
......@@ -145,7 +145,7 @@ insert delay, avg: 8.31ms, max: 860.12ms, min: 2.00ms
```
$ taosdemo --help
-f, --file=FILE The meta file to the execution procedure.
-f, --file=FILE The meta file to the execution procedure. Currently, we support standard UTF-8 (without BOM) encoded files only.
-u, --user=USER The user name to use when connecting to the server.
-p, --password The password to use when connecting to the server.
-c, --config-dir=CONFIG_DIR Configuration directory.
......@@ -442,7 +442,7 @@ TDengine是涛思数据专为物联网、车联网、工业互联网、IT运维
taosdemo支持两种配置参数的模式,一种是命令行参数,一种是使用json格式的配置文件。
一、命令行参数
-f:指定taosdemo所需参数的meta文件。当使用该参数时,其他所有命令行参数都失效。可选项,缺省是NULL。
-f:指定taosdemo所需参数的meta文件。当使用该参数时,其他所有命令行参数都失效。可选项,缺省是NULL。目前仅支持不含 BOM(byte-order mark)的标准 UTF-8 编码文件。
-u: 用户名。可选项,缺省是“root“。
......
......@@ -30,7 +30,7 @@ INSERT INTO d1001 VALUES (1538548685000, 10.3, 219, 0.31) (1538548695000, 12.6,
## <a class="anchor" id="schemaless"></a>无模式(Schemaless)写入
**前言**
<br/>在物联网应用中,常会采集比较多的数据项,用于实现智能控制、业务分析、设备监控等。由于应用逻辑的版本升级,或者设备自身的硬件调整等原因,数据采集项就有可能比较频繁地出现变动。为了在这种情况下方便地完成数据记录工作,TDengine 从 2.2.0.0 版本开始,提供调用 Schemaless 写入方式,可以免于预先创建超级表/子表的步骤,随着数据写入写入接口能够自动创建与数据对应的存储结构。并且在必要时,Schemaless 将自动增加必要的数据列,保证用户写入的数据可以被正确存储。
<br/>目前,TDengine 的 C/C++ Connector 提供支持 Schemaless 的操作接口,详情请参见 Schemaless 方式写入接口 章节。这里对 Schemaless 的数据表达格式进行了描述。
<br/>目前,TDengine 的 C/C++ Connector 提供支持 Schemaless 的操作接口,详情请参见 [Schemaless 方式写入接口](https://www.taosdata.com/cn/documentation/connector#schemaless)章节。这里对 Schemaless 的数据表达格式进行了描述。
<br/>无模式写入方式建立的超级表及其对应的子表与通过 SQL 直接建立的超级表和子表完全没有区别,您也可以通过 SQL 语句直接向其中写入数据。需要注意的是,通过无模式写入方式建立的表,其表名是基于标签值按照固定的映射规则生成,所以无法明确地进行表意,缺乏可读性。
**无模式写入行协议**
......@@ -56,14 +56,14 @@ tag_set 中的所有的数据自动转化为 nchar 数据类型,并不需要
* 对空格、等号(=)、逗号(,)、双引号("),前面需要使用反斜杠(\)进行转义。(都指的是英文半角符号)
* 数值类型将通过后缀来区分数据类型:
| **序号** | **后缀** | **映射类型** | **大小(字节)** |
| ---- | ------------------- | ------------ | -------- |
| 1 | 无或f64 | double | 8 |
| 2 | f32 | float | 4 |
| 3 | i8 | TinyInt | 1 |
| 4 | i16 | SmallInt | 2 |
| 5 | i32 | Int | 4 |
| 6 | i64或i | Bigint | 8 |
| **序号** | **后缀** | **映射类型** | **大小(字节)** |
| -- | ------- | ---------| ------ |
| 1 | 无或f64 | double | 8 |
| 2 | f32 | float | 4 |
| 3 | i8 | TinyInt | 1 |
| 4 | i16 | SmallInt | 2 |
| 5 | i32 | Int | 4 |
| 6 | i64或i | Bigint | 8 |
* t, T, true, True, TRUE, f, F, false, False 将直接作为 BOOL 型来处理。
<br/>例如如下数据行表示:向名为 st 的超级表下的 t1 标签为 "3"(NCHAR)、t2 标签为 "4"(NCHAR)、t3 标签为 "t3"(NCHAR)的数据子表,写入 c1 列为 3(BIGINT)、c2 列为 false(BOOL)、c3 列为 "passit"(BINARY)、c4 列为 4(DOUBLE)、主键时间戳为 1626006833639000000 的一行数据。
```json
......@@ -102,7 +102,8 @@ st,t1=3,t2=4,t3=t3 c1=3i64,c3="passit",c2=false,c4=4f64 1626006833639000000
| 2 | SML_TELNET_PROTOCOL | OpenTSDB文本行协议 |
| 3 | SML_JSON_PROTOCOL | Json协议格式 |
在 SML_LINE_PROTOCOL 解析模式下,需要用户指定输入的时间戳的时间分辨率。可用的时间分辨率如下表所示:
<br/>在 SML_LINE_PROTOCOL 解析模式下,需要用户指定输入的时间戳的时间分辨率。可用的时间分辨率如下表所示:<br/>
| **序号** | **时间分辨率定义** | **含义** |
| ---- | ----------------------------- | --------- |
| 1 | TSDB_SML_TIMESTAMP_NOT_CONFIGURED | 未定义(无效) |
......@@ -144,27 +145,27 @@ st,t1=3,t2=4,t3=t3 c1=3i64,c6="passit" 1626006833640000000
<br/>如果是无模式写入过程中的数据本身错误,应用会得到 TSDB_CODE_TSC_LINE_SYNTAX_ERROR 错误信息,该错误信息表明错误发生在写入文本中。其他的错误码与原系统一致,可以通过 taos_errstr 获取具体的错误原因。
**后续升级计划**
<br/>当前版本只提供了 C 版本的 API,后续将提供 其他高级语言的 API,例如 Java/Go/Python/C# 等。此外,在TDengine v2.3及后续版本中,您还可以通过 BLM v3 采用 REST 的方式直接写入无模式数据。
<br/>当前版本只提供了 C 版本的 API,后续将提供 其他高级语言的 API,例如 Java/Go/Python/C# 等。此外,在TDengine v2.3及后续版本中,您还可以通过 Taos Adapter 采用 REST 的方式直接写入无模式数据。
## <a class="anchor" id="prometheus"></a>Prometheus 直接写入
[Prometheus](https://www.prometheus.io/)作为Cloud Native Computing Fundation毕业的项目,在性能监控以及K8S性能监控领域有着非常广泛的应用。TDengine提供一个小工具[Bailongma](https://github.com/taosdata/Bailongma),只需对Prometheus做简单配置,无需任何代码,就可将Prometheus采集的数据直接写入TDengine,并按规则在TDengine自动创建库和相关表项。博文[用Docker容器快速搭建一个Devops监控Demo](https://www.taosdata.com/blog/2020/02/03/1189.html)即是采用Bailongma将Prometheus和Telegraf的数据写入TDengine中的示例,可以参考。
### 从源代码编译 taosadapter_prometheus
### 从源代码编译 blm_prometheus
用户需要从github下载[Bailongma](https://github.com/taosdata/Bailongma)的源码,使用Golang语言编译器编译生成可执行文件。在开始编译前,需要准备好以下条件:
- Linux操作系统的服务器
- 安装好Golang,1.14版本以上
- 对应的TDengine版本。因为用到了TDengine的客户端动态链接库,因此需要安装好和服务端相同版本的TDengine程序;比如服务端版本是TDengine 2.0.0, 则在Bailongma所在的Linux服务器(可以与TDengine在同一台服务器,或者不同服务器)
Bailongma项目中有一个文件夹taosadapter_prometheus,存放了prometheus的写入API程序。编译过程如下:
Bailongma项目中有一个文件夹blm_prometheus,存放了prometheus的写入API程序。编译过程如下:
```bash
cd taosadapter_prometheus
cd blm_prometheus
go build
```
一切正常的情况下,就会在对应的目录下生成一个taosadapter_prometheus的可执行程序。
一切正常的情况下,就会在对应的目录下生成一个blm_prometheus的可执行程序。
### 安装 Prometheus
......@@ -175,23 +176,23 @@ go build
参考Prometheus的[配置文档](https://prometheus.io/docs/prometheus/latest/configuration/configuration/),在Prometheus的配置文件中的<remote_write>部分,增加以下配置:
```
- url: "bailongma API服务提供的URL"(参考下面的taosadapter_prometheus启动示例章节)
- url: "bailongma API服务提供的URL"(参考下面的blm_prometheus启动示例章节)
```
启动Prometheus后,可以通过taos客户端查询确认数据是否成功写入。
### 启动 taosadapter_prometheus 程序
### 启动 blm_prometheus 程序
taosadapter_prometheus程序有以下选项,在启动taosadapter_prometheus程序时可以通过设定这些选项来设定taosadapter_prometheus的配置。
blm_prometheus程序有以下选项,在启动blm_prometheus程序时可以通过设定这些选项来设定blm_prometheus的配置。
```bash
--tdengine-name
如果TDengine安装在一台具备域名的服务器上,也可以通过配置TDengine的域名来访问TDengine。在K8S环境下,可以配置成TDengine所运行的service name。
--batch-size
taosadapter_prometheus会将收到的prometheus的数据拼装成TDengine的写入请求,这个参数控制一次发给TDengine的写入请求中携带的数据条数。
blm_prometheus会将收到的prometheus的数据拼装成TDengine的写入请求,这个参数控制一次发给TDengine的写入请求中携带的数据条数。
--dbname
设置在TDengine中创建的数据库名称,taosadapter_prometheus会自动在TDengine中创建一个以dbname为名称的数据库,缺省值是prometheus。
设置在TDengine中创建的数据库名称,blm_prometheus会自动在TDengine中创建一个以dbname为名称的数据库,缺省值是prometheus。
--dbuser
设置访问TDengine的用户名,缺省值是'root'
......@@ -200,16 +201,16 @@ taosadapter_prometheus会将收到的prometheus的数据拼装成TDengine的写
设置访问TDengine的密码,缺省值是'taosdata'
--port
taosadapter_prometheus对prometheus提供服务的端口号。
blm_prometheus对prometheus提供服务的端口号。
```
### 启动示例
通过以下命令启动一个taosadapter_prometheus的API服务
通过以下命令启动一个blm_prometheus的API服务
```bash
./taosadapter_prometheus -port 8088
./blm_prometheus -port 8088
```
假设taosadapter_prometheus所在服务器的IP地址为"10.1.2.3",则在prometheus的配置文件中<remote_write>部分增加url为
假设blm_prometheus所在服务器的IP地址为"10.1.2.3",则在prometheus的配置文件中<remote_write>部分增加url为
```yaml
remote_write:
- url: "http://10.1.2.3:8088/receive"
......@@ -234,7 +235,7 @@ prometheus产生的数据格式如下:
}
}
```
其中,apiserver_request_latencies_bucket为prometheus采集的时序数据的名称,后面{}中的为该时序数据的标签。taosadapter_prometheus会以时序数据的名称在TDengine中自动创建一个超级表,并将{}中的标签转换成TDengine的tag值,Timestamp作为时间戳,value作为该时序数据的值。因此在TDengine的客户端中,可以通过以下指令查到这个数据是否成功写入。
其中,apiserver_request_latencies_bucket为prometheus采集的时序数据的名称,后面{}中的为该时序数据的标签。blm_prometheus会以时序数据的名称在TDengine中自动创建一个超级表,并将{}中的标签转换成TDengine的tag值,Timestamp作为时间戳,value作为该时序数据的值。因此在TDengine的客户端中,可以通过以下指令查到这个数据是否成功写入。
```mysql
use prometheus;
select * from apiserver_request_latencies_bucket;
......@@ -313,7 +314,7 @@ taosadapter 相关配置参数请参考 taosadapter --help 命令输出以及相
[Telegraf](https://www.influxdata.com/time-series-platform/telegraf/)是一流行的IT运维数据采集开源工具,TDengine提供一个小工具[Bailongma](https://github.com/taosdata/Bailongma),只需在Telegraf做简单配置,无需任何代码,就可将Telegraf采集的数据直接写入TDengine,并按规则在TDengine自动创建库和相关表项。博文[用Docker容器快速搭建一个Devops监控Demo](https://www.taosdata.com/blog/2020/02/03/1189.html)即是采用bailongma将Prometheus和Telegraf的数据写入TDengine中的示例,可以参考。
### 从源代码编译 taosadapter_telegraf
### 从源代码编译 blm_telegraf
用户需要从github下载[Bailongma](https://github.com/taosdata/Bailongma)的源码,使用Golang语言编译器编译生成可执行文件。在开始编译前,需要准备好以下条件:
......@@ -321,14 +322,14 @@ taosadapter 相关配置参数请参考 taosadapter --help 命令输出以及相
- 安装好Golang,1.10版本以上
- 对应的TDengine版本。因为用到了TDengine的客户端动态链接库,因此需要安装好和服务端相同版本的TDengine程序;比如服务端版本是TDengine 2.0.0, 则在Bailongma所在的Linux服务器(可以与TDengine在同一台服务器,或者不同服务器)
Bailongma项目中有一个文件夹taosadapter_telegraf,存放了Telegraf的写入API程序。编译过程如下:
Bailongma项目中有一个文件夹blm_telegraf,存放了Telegraf的写入API程序。编译过程如下:
```bash
cd taosadapter_telegraf
cd blm_telegraf
go build
```
一切正常的情况下,就会在对应的目录下生成一个taosadapter_telegraf的可执行程序。
一切正常的情况下,就会在对应的目录下生成一个blm_telegraf的可执行程序。
### 安装 Telegraf
......@@ -351,19 +352,19 @@ go build
关于如何使用Telegraf采集数据以及更多有关使用Telegraf的信息,请参考Telegraf官方的[文档](https://docs.influxdata.com/telegraf/v1.11/)
### 启动 taosadapter_telegraf 程序
### 启动 blm_telegraf 程序
taosadapter_telegraf程序有以下选项,在启动taosadapter_telegraf程序时可以通过设定这些选项来设定taosadapter_telegraf的配置。
blm_telegraf程序有以下选项,在启动blm_telegraf程序时可以通过设定这些选项来设定blm_telegraf的配置。
```bash
--host
TDengine服务端的IP地址,缺省值为空。
--batch-size
taosadapter_telegraf会将收到的telegraf的数据拼装成TDengine的写入请求,这个参数控制一次发给TDengine的写入请求中携带的数据条数。
blm_telegraf会将收到的telegraf的数据拼装成TDengine的写入请求,这个参数控制一次发给TDengine的写入请求中携带的数据条数。
--dbname
设置在TDengine中创建的数据库名称,taosadapter_telegraf会自动在TDengine中创建一个以dbname为名称的数据库,缺省值是prometheus。
设置在TDengine中创建的数据库名称,blm_telegraf会自动在TDengine中创建一个以dbname为名称的数据库,缺省值是prometheus。
--dbuser
设置访问TDengine的用户名,缺省值是'root'
......@@ -372,17 +373,17 @@ taosadapter_telegraf会将收到的telegraf的数据拼装成TDengine的写入
设置访问TDengine的密码,缺省值是'taosdata'
--port
taosadapter_telegraf对telegraf提供服务的端口号。
blm_telegraf对telegraf提供服务的端口号。
```
### 启动示例
通过以下命令启动一个taosadapter_telegraf的API服务:
通过以下命令启动一个blm_telegraf的API服务:
```bash
./taosadapter_telegraf -host 127.0.0.1 -port 8089
./blm_telegraf -host 127.0.0.1 -port 8089
```
假设taosadapter_telegraf所在服务器的IP地址为"10.1.2.3",则在telegraf的配置文件中, 在output plugins部分,增加[[outputs.http]]配置项:
假设blm_telegraf所在服务器的IP地址为"10.1.2.3",则在telegraf的配置文件中, 在output plugins部分,增加[[outputs.http]]配置项:
```yaml
url = "http://10.1.2.3:8089/telegraf"
......@@ -415,7 +416,7 @@ telegraf产生的数据格式如下:
}
```
其中,name字段为telegraf采集的时序数据的名称,tags字段为该时序数据的标签。taosadapter_telegraf会以时序数据的名称在TDengine中自动创建一个超级表,并将tags字段中的标签转换成TDengine的tag值,timestamp作为时间戳,fields字段中的值作为该时序数据的值。因此在TDengine的客户端中,可以通过以下指令查到这个数据是否成功写入。
其中,name字段为telegraf采集的时序数据的名称,tags字段为该时序数据的标签。blm_telegraf会以时序数据的名称在TDengine中自动创建一个超级表,并将tags字段中的标签转换成TDengine的tag值,timestamp作为时间戳,fields字段中的值作为该时序数据的值。因此在TDengine的客户端中,可以通过以下指令查到这个数据是否成功写入。
```mysql
use telegraf;
......
# TDengine的运营与运维
# TDengine的运营与维护
## <a class="anchor" id="planning"></a>容量规划
......@@ -157,7 +157,7 @@ taosd -C
| 39 | keep | | **S** | 天 | 数据保留的天数 | | 3650 | |
| 40 | minRows | | **S** | | 文件块中记录的最小条数 | | 100 | |
| 41 | maxRows | | **S** | | 文件块中记录的最大条数 | | 4096 | |
| 42 | quorum | | **S** | | 异步写入成功所需应答之法定数 | 1-3 | 1 | |
| 42 | quorum | | **S** | | 多副本环境下指令执行的确认数要求 | 1,2 | 1 | |
| 43 | comp | | **S** | | 文件压缩标志位 | 0:关闭,1:一阶段压缩,2:两阶段压缩 | 2 | |
| 44 | walLevel | | **S** | | WAL级别 | 1:写wal, 但不执行fsync; 2:写wal, 而且执行fsync | 1 | |
| 45 | fsync | | **S** | 毫秒 | 当wal设置为2时,执行fsync的周期 | 最小为0,表示每次写入,立即执行fsync;最大为180000(三分钟) | 3000 | |
......
......@@ -124,7 +124,7 @@ TDengine 缺省的时间戳是毫秒精度,但通过在 CREATE DATABASE 时传
```mysql
ALTER DATABASE db_name QUORUM 2;
```
QUORUM 参数是指数据写入成功所需要的确认数,取值范围 [1, 2]。对于异步复制,quorum 设为 1,具有 master 角色的虚拟节点自己确认即可。对于同步复制,需要至少大于等于 2。原则上,Quorum >= 1 并且 Quorum <= replica(副本数),这个参数在启动一个同步模块实例时需要提供。
QUORUM 参数是指数据写入成功所需要的确认数,取值范围 [1, 2]。对于异步复制,quorum 设为 1,具有 master 角色的虚拟节点自己确认即可。对于同步复制,quorum 设为 2。原则上,Quorum >= 1 并且 Quorum <= replica(副本数),这个参数在启动一个同步模块实例时需要提供。
```mysql
ALTER DATABASE db_name BLOCKS 100;
......
......@@ -40,7 +40,7 @@ IT 运维监测数据通常都是对时间特性比较敏感的数据,例如
```
### 配置 collectd
在 /etc/collectd/collectd.conf 文件中增加如下内容,其中 host 和 port 请填写 TDengine 和 BLM3 配置的实际值:
在 /etc/collectd/collectd.conf 文件中增加如下内容,其中 host 和 port 请填写 TDengine 和 Taos Adapter 配置的实际值:
```
LoadPlugin network
<Plugin network>
......@@ -51,7 +51,7 @@ sudo systemctl start collectd
```
### 配置 StatsD
在 config.js 文件中增加如下内容后启动 StatsD,其中 host 和 port 请填写 TDengine 和 BLM3 配置的实际值:
在 config.js 文件中增加如下内容后启动 StatsD,其中 host 和 port 请填写 TDengine 和 Taos Adapter 配置的实际值:
```
backends 部分添加 "./backends/repeater"
repeater 部分添加 { host:'<TDengine server/cluster host>', port: <port for StatsD>}
......
此差异已折叠。
......@@ -154,7 +154,7 @@ The complete list of taosdemo command-line arguments can be displayed via taosde
```
$ taosdemo --help
-f, --file=FILE The meta file to the execution procedure.
-f, --file=FILE The meta file to the execution procedure. Currently, we support standard UTF-8 (without BOM) encoded files only.
-u, --user=USER The user name to use when connecting to the server.
-p, --password The password to use when connecting to the server.
-c, --config-dir=CONFIG_DIR Configuration directory.
......
......@@ -45,10 +45,10 @@ mkdir -p ${pkg_dir}${install_home_path}/script
cp ${compile_dir}/../packaging/cfg/taos.cfg ${pkg_dir}${install_home_path}/cfg
if [ -f "${compile_dir}/test/cfg/taosadapter.toml" ]; then
cp ${compile_dir}/test/cfg/taosadapter.toml ${pkg_dir}${install_home_path}/cfg
cp ${compile_dir}/test/cfg/taosadapter.toml ${pkg_dir}${install_home_path}/cfg || :
fi
if [ -f "${compile_dir}/test/cfg/taosadapter.service" ]; then
cp ${compile_dir}/test/cfg/taosadapter.service ${pkg_dir}${install_home_path}/cfg ||:
cp ${compile_dir}/test/cfg/taosadapter.service ${pkg_dir}${install_home_path}/cfg || :
fi
cp ${compile_dir}/../packaging/deb/taosd ${pkg_dir}${install_home_path}/init.d
......
......@@ -757,8 +757,12 @@ function install_service_on_systemd() {
}
function install_taosadapter_service() {
[ -f ${script_dir}/cfg/taosadapter.service ] &&\
${csudo} cp ${script_dir}/cfg/taosadapter.service ${service_config_dir}/
if ((${service_mod}==0)); then
[ -f ${script_dir}/cfg/taosadapter.service ] &&\
${csudo} cp ${script_dir}/cfg/taosadapter.service \
${service_config_dir}/ || :
${csudo} systemctl daemon-reload
fi
}
function install_service() {
......
......@@ -523,9 +523,8 @@ function install_taosadapter_service() {
if ((${service_mod}==0)); then
[ -f ${binary_dir}/test/cfg/taosadapter.service ] &&\
${csudo} cp ${binary_dir}/test/cfg/taosadapter.service\
${service_config_dir}/ || :
else
kill_taosadapter
${service_config_dir}/ || :
${csudo} systemctl daemon-reload
fi
}
......
......@@ -78,7 +78,13 @@ mkdir -p ${install_dir}
mkdir -p ${install_dir}/inc && cp ${header_files} ${install_dir}/inc
mkdir -p ${install_dir}/cfg && cp ${cfg_dir}/taos.cfg ${install_dir}/cfg/taos.cfg
[ -f ${cfg_dir}/taosadapter.toml ] && cp ${cfg_dir}/taosadapter.toml ${install_dir}/cfg/taosadapter.toml
if [ -f "${compile_dir}/test/cfg/taosadapter.toml" ]; then
cp ${compile_dir}/test/cfg/taosadapter.toml ${install_dir}/cfg || :
fi
if [ -f "${compile_dir}/test/cfg/taosadapter.service" ]; then
cp ${compile_dir}/test/cfg/taosadapter.service ${install_dir}/cfg || :
fi
mkdir -p ${install_dir}/bin && cp ${bin_files} ${install_dir}/bin && chmod a+x ${install_dir}/bin/* || :
mkdir -p ${install_dir}/init.d && cp ${init_file_deb} ${install_dir}/init.d/taosd.deb
......
......@@ -467,7 +467,12 @@ function install_service_on_systemd() {
}
function install_taosadapter_service() {
[ -f ${cfg_dir}/taosadapter.service ] && ${csudo} cp ${cfg_dir}/taosadapter.service ${service_config_dir}
if ((${service_mod}==0)); then
[ -f ${script_dir}/cfg/taosadapter.service ] &&\
${csudo} cp ${script_dir}/cfg/taosadapter.service \
${service_config_dir}/ || :
${csudo} systemctl daemon-reload
fi
}
function install_service() {
......
......@@ -314,8 +314,6 @@ int32_t tsParseOneColumn(SSchema *pSchema, SStrToken *pToken, char *payload, cha
ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false);
if (ret != TSDB_CODE_SUCCESS) {
return tscInvalidOperationMsg(msg, "invalid unsigned bigint data", pToken->z);
} else if (!IS_VALID_UBIGINT((uint64_t)iv)) {
return tscInvalidOperationMsg(msg, "unsigned bigint data overflow", pToken->z);
}
*((uint64_t *)payload) = iv;
......
......@@ -1513,9 +1513,9 @@ static bool convertStrToNumber(TAOS_SML_KV *pVal, char *str, SSmlLinesInfo* info
errno = 0;
uint8_t type = pVal->type;
int16_t length = pVal->length;
int64_t val_s;
uint64_t val_u;
double val_d;
int64_t val_s = 0;
uint64_t val_u = 0;
double val_d = 0.0;
strntolower_s(str, str, (int32_t)strlen(str));
if (IS_FLOAT_TYPE(type)) {
......@@ -1815,7 +1815,7 @@ static int32_t getTimeStampValue(char *value, uint16_t len,
int32_t convertSmlTimeStamp(TAOS_SML_KV *pVal, char *value,
uint16_t len, SSmlLinesInfo* info) {
int32_t ret;
SMLTimeStampType type;
SMLTimeStampType type = SML_TIME_STAMP_NOW;
int64_t tsVal;
ret = isTimeStamp(value, len, &type, info);
......@@ -2414,7 +2414,7 @@ static SSqlObj* createSmlQueryObj(TAOS* taos, int32_t affected_rows, int32_t cod
TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int protocol, int precision) {
int code = TSDB_CODE_SUCCESS;
int affected_rows = 0;
SMLTimeStampType tsType;
SMLTimeStampType tsType = SML_TIME_STAMP_NOW;
if (protocol == TSDB_SML_LINE_PROTOCOL) {
code = convertPrecisionType(precision, &tsType);
......
......@@ -2955,7 +2955,8 @@ int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool
// in case of child table, here only get the
if (pMeta->tableType == TSDB_CHILD_TABLE) {
int32_t code = tscCreateTableMetaFromSTableMeta(pSql, &pTableMetaInfo->pTableMeta, name, &pTableMetaInfo->tableMetaCapacity, (STableMeta **)(&pSTMeta));
pSql->pBuf = (void *)(pSTMeta);
pSql->pBuf = (void *)(pSTMeta);
pMeta = pTableMetaInfo->pTableMeta;
if (code != TSDB_CODE_SUCCESS) {
return getTableMetaFromMnode(pSql, pTableMetaInfo, autocreate);
}
......
......@@ -413,8 +413,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti
status = future.get();
else
status = future.get(timeout, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
} catch (InterruptedException | ExecutionException ignored) {
} catch (TimeoutException e) {
future.cancel(true);
status = false;
......
......@@ -597,7 +597,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
return col4;
}
public ResultSet getSchemas() throws SQLException {
public ResultSet getSchemas() {
return getEmptyResultSet();
}
......@@ -629,7 +629,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
public abstract ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException;
protected ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern, Connection conn) {
protected ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern, Connection conn) throws SQLException {
if (catalog == null || catalog.isEmpty())
return null;
if (!isAvailableCatalog(conn, catalog))
......@@ -682,8 +682,6 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
rowIndex++;
}
resultSet.setRowDataList(rowDataList);
} catch (SQLException e) {
e.printStackTrace();
}
return resultSet;
}
......@@ -1220,7 +1218,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
return col6;
}
private boolean isAvailableCatalog(Connection connection, String catalog) {
private boolean isAvailableCatalog(Connection connection, String catalog) throws SQLException {
try (Statement stmt = connection.createStatement();
ResultSet databases = stmt.executeQuery("show databases")) {
while (databases.next()) {
......@@ -1229,8 +1227,6 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
if (dbname.equalsIgnoreCase(catalog))
return true;
}
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
......
......@@ -8,16 +8,35 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
/**
* @author huolibo@qq.com
* @version v1.0.0
* @JDK: 1.8
* @description: this class is an extension of {@link Statement}. use like:
* Statement statement = conn.createStatement();
* SchemalessStatement schemalessStatement = new SchemalessStatement(statement);
* schemalessStatement.execute(sql);
* schemalessStatement.executeSchemaless(lines, SchemalessProtocolType, SchemalessTimestampType);
* @since 2021-11-03 17:10
*/
public class SchemalessStatement extends AbstractStatementWrapper {
public SchemalessStatement(Statement statement) {
super(statement);
}
public void executeSchemaless(String[] strings, SchemalessProtocolType protocolType, SchemalessTimestampType timestampType) throws SQLException {
/**
* batch insert schemaless lines
*
* @param lines schemaless data
* @param protocolType schemaless type {@link SchemalessProtocolType}
* @param timestampType Time precision {@link SchemalessTimestampType}
* @throws SQLException execute insert exception
*/
public void executeSchemaless(String[] lines, SchemalessProtocolType protocolType, SchemalessTimestampType timestampType) throws SQLException {
Connection connection = this.getConnection();
if (connection instanceof TSDBConnection) {
TSDBConnection tsdbConnection = (TSDBConnection) connection;
tsdbConnection.getConnector().insertLines(strings, protocolType, timestampType);
tsdbConnection.getConnector().insertLines(lines, protocolType, timestampType);
} else if (connection instanceof RestfulConnection) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD, "restful connection is not supported currently");
} else {
......@@ -25,7 +44,15 @@ public class SchemalessStatement extends AbstractStatementWrapper {
}
}
public void executeSchemaless(String sql, SchemalessProtocolType protocolType, SchemalessTimestampType timestampType) throws SQLException {
executeSchemaless(new String[]{sql}, protocolType, timestampType);
/**
* only one insert
*
* @param line schemaless line
* @param protocolType schemaless type {@link SchemalessProtocolType}
* @param timestampType Time precision {@link SchemalessTimestampType}
* @throws SQLException execute insert exception
*/
public void executeSchemaless(String line, SchemalessProtocolType protocolType, SchemalessTimestampType timestampType) throws SQLException {
executeSchemaless(new String[]{line}, protocolType, timestampType);
}
}
......@@ -21,6 +21,7 @@ import com.taosdata.jdbc.enums.SchemalessProtocolType;
import com.taosdata.jdbc.enums.SchemalessTimestampType;
import com.taosdata.jdbc.utils.TaosInfo;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.sql.SQLException;
import java.sql.SQLWarning;
......@@ -107,8 +108,7 @@ public class TSDBJNIConnector {
try {
pSql = this.executeQueryImp(sql.getBytes(TaosGlobalConfig.getCharset()), this.taos);
taosInfo.stmt_count_increment();
} catch (Exception e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
this.freeResultSetImp(this.taos, pSql);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_ENCODING);
}
......
......@@ -611,7 +611,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
try {
this.tagValueLength += value.getBytes(charset).length;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}
......@@ -786,7 +786,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
b = val.getBytes(charset);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
tagDataList.put(b);
......@@ -921,7 +921,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
b = val.getBytes(charset);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
if (val.length() > col1.bytes) {
......@@ -980,8 +980,10 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
@Override
public void close() throws SQLException {
this.columnDataClearBatchInternal();
this.columnDataCloseBatch();
if (this.nativeStmtHandle != 0L) {
this.columnDataClearBatchInternal();
this.columnDataCloseBatch();
}
super.close();
}
}
......@@ -92,75 +92,71 @@ public class TSDBResultSetBlockData {
}
public void setByteArray(int col, int length, byte[] value) {
try {
switch (this.columnMetaDataList.get(col).getColType()) {
case TSDBConstants.TSDB_DATA_TYPE_BOOL: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
buf.order(ByteOrder.LITTLE_ENDIAN).asCharBuffer();
this.colData.set(col, buf);
break;
}
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT:
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
buf.order(ByteOrder.LITTLE_ENDIAN);
this.colData.set(col, buf);
break;
}
case TSDBConstants.TSDB_DATA_TYPE_USMALLINT:
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
ShortBuffer sb = buf.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
this.colData.set(col, sb);
break;
}
case TSDBConstants.TSDB_DATA_TYPE_UINT:
case TSDBConstants.TSDB_DATA_TYPE_INT: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
IntBuffer ib = buf.order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
this.colData.set(col, ib);
break;
}
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT:
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
LongBuffer lb = buf.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
this.colData.set(col, lb);
break;
}
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
FloatBuffer fb = buf.order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer();
this.colData.set(col, fb);
break;
}
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
DoubleBuffer db = buf.order(ByteOrder.LITTLE_ENDIAN).asDoubleBuffer();
this.colData.set(col, db);
break;
}
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
buf.order(ByteOrder.LITTLE_ENDIAN);
this.colData.set(col, buf);
break;
}
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
LongBuffer lb = buf.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
this.colData.set(col, lb);
break;
}
case TSDBConstants.TSDB_DATA_TYPE_NCHAR: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
buf.order(ByteOrder.LITTLE_ENDIAN);
this.colData.set(col, buf);
break;
}
switch (this.columnMetaDataList.get(col).getColType()) {
case TSDBConstants.TSDB_DATA_TYPE_BOOL: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
buf.order(ByteOrder.LITTLE_ENDIAN).asCharBuffer();
this.colData.set(col, buf);
break;
}
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT:
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
buf.order(ByteOrder.LITTLE_ENDIAN);
this.colData.set(col, buf);
break;
}
case TSDBConstants.TSDB_DATA_TYPE_USMALLINT:
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
ShortBuffer sb = buf.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
this.colData.set(col, sb);
break;
}
case TSDBConstants.TSDB_DATA_TYPE_UINT:
case TSDBConstants.TSDB_DATA_TYPE_INT: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
IntBuffer ib = buf.order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
this.colData.set(col, ib);
break;
}
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT:
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
LongBuffer lb = buf.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
this.colData.set(col, lb);
break;
}
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
FloatBuffer fb = buf.order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer();
this.colData.set(col, fb);
break;
}
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
DoubleBuffer db = buf.order(ByteOrder.LITTLE_ENDIAN).asDoubleBuffer();
this.colData.set(col, db);
break;
}
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
buf.order(ByteOrder.LITTLE_ENDIAN);
this.colData.set(col, buf);
break;
}
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
LongBuffer lb = buf.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
this.colData.set(col, lb);
break;
}
case TSDBConstants.TSDB_DATA_TYPE_NCHAR: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
buf.order(ByteOrder.LITTLE_ENDIAN);
this.colData.set(col, buf);
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
......@@ -283,14 +279,8 @@ public class TSDBResultSetBlockData {
return 0;
}
public Timestamp getTimestamp(int col) {
try {
return new Timestamp(getLong(col));
} catch (SQLException e) {
e.printStackTrace();
}
return null;
public Timestamp getTimestamp(int col) throws SQLException {
return new Timestamp(getLong(col));
}
public double getDouble(int col) {
......@@ -429,7 +419,7 @@ public class TSDBResultSetBlockData {
String charset = TaosGlobalConfig.getCharset();
return new String(dest, charset);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}
}
......
......@@ -16,6 +16,7 @@ package com.taosdata.jdbc;
import com.taosdata.jdbc.utils.NullType;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.sql.Timestamp;
......@@ -378,8 +379,8 @@ public class TSDBResultSetRowData {
// this setByteArr(int, byte[]) to handle NCHAR value, we need to build a String with charsetEncoding by TaosGlobalConfig
try {
data.set(col, new String(value, TaosGlobalConfig.getCharset()));
} catch (Exception e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e.getMessage());
}
}
......
package com.taosdata.jdbc.enums;
import java.util.Arrays;
public enum SchemalessProtocolType {
UNKNOWN,
LINE,
......@@ -7,4 +9,10 @@ public enum SchemalessProtocolType {
JSON,
;
public static SchemalessProtocolType parse(String type) {
return Arrays.stream(SchemalessProtocolType.values())
.filter(protocol -> type.equalsIgnoreCase(protocol.name()))
.findFirst().orElse(UNKNOWN);
}
}
package com.taosdata.jdbc.enums;
public enum SchemalessTimestampType {
// Let the database decide
NOT_CONFIGURED,
HOURS,
MINUTES,
......
......@@ -16,8 +16,8 @@ public class TaosInfo implements TaosInfoMBean {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName("TaosInfoMBean:name=TaosInfo");
server.registerMBean(TaosInfo.getInstance(), name);
} catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
e.printStackTrace();
} catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException ignored) {
throw new RuntimeException("registerMBean failed");
}
}
......
package com.taosdata.jdbc;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.taosdata.jdbc.enums.SchemalessProtocolType;
import com.taosdata.jdbc.enums.SchemalessTimestampType;
import org.junit.After;
......@@ -10,10 +12,14 @@ import org.junit.Test;
import java.sql.*;
public class SchemalessInsertTest {
private String host = "127.0.0.1";
private String dbname = "test_schemaless_insert";
private final String dbname = "test_schemaless_insert";
private Connection conn;
/**
* schemaless insert compatible with influxdb
*
* @throws SQLException execute error
*/
@Test
public void schemalessInsert() throws SQLException {
// given
......@@ -41,6 +47,11 @@ public class SchemalessInsertTest {
statement.close();
}
/**
* telnet insert compatible with opentsdb
*
* @throws SQLException execute error
*/
@Test
public void telnetInsert() throws SQLException {
// given
......@@ -71,6 +82,11 @@ public class SchemalessInsertTest {
statement.close();
}
/**
* json insert compatible with opentsdb json format
*
* @throws SQLException execute error
*/
@Test
public void jsonInsert() throws SQLException {
// given
......@@ -113,13 +129,15 @@ public class SchemalessInsertTest {
while (rs.next()) {
rowCnt++;
}
// Assert.assertEquals(json.length, rowCnt);
Assert.assertEquals(((JSONArray) JSONObject.parse(json)).size(), rowCnt);
rs.close();
statement.close();
}
@Before
public void before() {
String host = "127.0.0.1";
final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
try {
conn = DriverManager.getConnection(url);
......
......@@ -30,42 +30,6 @@ public class TSDBConnectionTest {
}
}
@Test
public void runSubscribe() {
try {
// given
TSDBConnection unwrap = conn.unwrap(TSDBConnection.class);
TSDBSubscribe subscribe = unwrap.subscribe("topic1", "select * from log.log", false);
// when
TSDBResultSet rs = subscribe.consume();
ResultSetMetaData metaData = rs.getMetaData();
// then
Assert.assertNotNull(rs);
Assert.assertEquals(4, metaData.getColumnCount());
Assert.assertEquals("ts", metaData.getColumnLabel(1));
Assert.assertEquals("level", metaData.getColumnLabel(2));
Assert.assertEquals("content", metaData.getColumnLabel(3));
Assert.assertEquals("ipaddr", metaData.getColumnLabel(4));
rs.next();
// row 1
{
Assert.assertNotNull(rs.getTimestamp(1));
Assert.assertNotNull(rs.getTimestamp("ts"));
Assert.assertNotNull(rs.getByte(2));
Assert.assertNotNull(rs.getByte("level"));
Assert.assertNotNull(rs.getString(3));
Assert.assertNotNull(rs.getString("content"));
Assert.assertNotNull(rs.getString(4));
Assert.assertNotNull(rs.getString("ipaddr"));
}
subscribe.close(false);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
public void prepareStatement() throws SQLException {
PreparedStatement pstmt = conn.prepareStatement("select server_status()");
......@@ -391,13 +355,9 @@ public class TSDBConnectionTest {
}
@Test
public void unwrap() {
try {
TSDBConnection tsdbConnection = conn.unwrap(TSDBConnection.class);
Assert.assertNotNull(tsdbConnection);
} catch (SQLException e) {
e.printStackTrace();
}
public void unwrap() throws SQLException {
TSDBConnection tsdbConnection = conn.unwrap(TSDBConnection.class);
Assert.assertNotNull(tsdbConnection);
}
@Test
......@@ -406,32 +366,22 @@ public class TSDBConnectionTest {
}
@BeforeClass
public static void beforeClass() {
try {
Class.forName("com.taosdata.jdbc.TSDBDriver");
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/log?user=root&password=taosdata", properties);
// create test database for test cases
try (Statement stmt = conn.createStatement()) {
stmt.execute("create database if not exists test");
}
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
public static void beforeClass() throws SQLException {
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/log?user=root&password=taosdata", properties);
// create test database for test cases
try (Statement stmt = conn.createStatement()) {
stmt.execute("create database if not exists test");
}
}
@AfterClass
public static void afterClass() {
try {
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
public static void afterClass() throws SQLException {
if (conn != null)
conn.close();
}
}
\ No newline at end of file
......@@ -33,7 +33,6 @@ public class TSDBDriverTest {
conn = DriverManager.getConnection(url);
assertNotNull("failure - connection should not be null", conn);
} catch (SQLException e) {
e.printStackTrace();
fail("failure - should not throw Exception");
}
}
......@@ -49,7 +48,6 @@ public class TSDBDriverTest {
conn = DriverManager.getConnection(jdbcUrl, connProps);
assertNotNull("failure - connection should not be null", conn);
} catch (SQLException e) {
e.printStackTrace();
fail("failure - should not throw Exception");
}
}
......@@ -65,7 +63,6 @@ public class TSDBDriverTest {
conn = DriverManager.getConnection(jdbcUrl, connProps);
assertNotNull("failure - connection should not be null", conn);
} catch (SQLException e) {
e.printStackTrace();
fail("failure - should not throw Exception");
}
}
......@@ -157,16 +154,8 @@ public class TSDBDriverTest {
}
@Test
public void getParentLogger() throws SQLFeatureNotSupportedException {
public void getParentLogger() {
assertNull(new TSDBDriver().getParentLogger());
}
@BeforeClass
public static void before() {
try {
Class.forName("com.taosdata.jdbc.TSDBDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
......@@ -57,44 +57,31 @@ public class AuthenticationTest {
@Ignore
@Test
public void test() {
public void test() throws SQLException {
// change password
try {
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=taosdata");
Statement stmt = conn.createStatement();
String url = "jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=taosdata";
try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();) {
stmt.execute("alter user " + user + " pass '" + password + "'");
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
// use new to login and execute query
try {
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password);
Statement stmt = conn.createStatement();
url = "jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password;
try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
stmt.execute("show databases");
ResultSet rs = stmt.getResultSet();
ResultSetMetaData meta = rs.getMetaData();
while (rs.next()) {
for (int i = 1; i <= meta.getColumnCount(); i++) {
System.out.print(meta.getColumnLabel(i) + ":" + rs.getString(i) + "\t");
}
System.out.println();
}
} catch (SQLException e) {
e.printStackTrace();
}
// change password back
try {
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password);
Statement stmt = conn.createStatement();
url = "jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password;
try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
stmt.execute("alter user " + user + " pass 'taosdata'");
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
@Before
......
......@@ -19,16 +19,14 @@ public class BatchErrorIgnoreTest {
IntStream.range(1, 6).mapToObj(i -> "insert into test.t" + i + " values(now, " + i + ")").forEach(sql -> {
try {
stmt.addBatch(sql);
} catch (SQLException e) {
e.printStackTrace();
} catch (SQLException ignored) {
}
});
stmt.addBatch("insert into t11 values(now, 11)");
IntStream.range(6, 11).mapToObj(i -> "insert into test.t" + i + " values(now, " + i + "),(now + 1s, " + (10 * i) + ")").forEach(sql -> {
try {
stmt.addBatch(sql);
} catch (SQLException e) {
e.printStackTrace();
} catch (SQLException ignored) {
}
});
stmt.addBatch("select count(*) from test.weather");
......@@ -57,23 +55,19 @@ public class BatchErrorIgnoreTest {
IntStream.range(1, 6).mapToObj(i -> "insert into test.t" + i + " values(now, " + i + ")").forEach(sql -> {
try {
stmt.addBatch(sql);
} catch (SQLException e) {
e.printStackTrace();
} catch (SQLException ignored) {
}
});
stmt.addBatch("insert into t11 values(now, 11)");
IntStream.range(6, 11).mapToObj(i -> "insert into test.t" + i + " values(now, " + i + "),(now + 1s, " + (10 * i) + ")").forEach(sql -> {
try {
stmt.addBatch(sql);
} catch (SQLException e) {
e.printStackTrace();
} catch (SQLException ignored) {
}
});
stmt.addBatch("select count(*) from test.weather");
results = stmt.executeBatch();
} catch (SQLException e) {
e.printStackTrace();
}
// then
......@@ -94,10 +88,10 @@ public class BatchErrorIgnoreTest {
}
@Before
public void before() {
try {
Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata");
Statement stmt = conn.createStatement();
public void before() throws SQLException {
try (Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata");
Statement stmt = conn.createStatement();) {
stmt.execute("use test");
stmt.execute("drop table if exists weather");
stmt.execute("create table weather (ts timestamp, f1 float) tags(t1 int)");
......@@ -108,37 +102,25 @@ public class BatchErrorIgnoreTest {
e.printStackTrace();
}
});
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
@BeforeClass
public static void beforeClass() {
try {
Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata");
Statement stmt = conn.createStatement();
public static void beforeClass() throws SQLException {
try (Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata");
Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists test");
stmt.execute("create database if not exists test");
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
@AfterClass
public static void afterClass() {
try {
Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata");
Statement stmt = conn.createStatement();
public static void afterClass() throws SQLException {
try (Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata");
Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists test");
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
......@@ -20,22 +20,20 @@ public class ConnectMultiTaosdByRestfulWithDifferentTokenTest {
private Connection conn2;
@Test
public void test() {
public void test() throws SQLException {
//when
executeSelectStatus(conn1);
executeSelectStatus(conn2);
executeSelectStatus(conn1);
}
private void executeSelectStatus(Connection connection) {
private void executeSelectStatus(Connection connection) throws SQLException {
try (Statement stmt = connection.createStatement()) {
ResultSet rs = stmt.executeQuery("select server_status()");
ResultSetMetaData meta = rs.getMetaData();
Assert.assertNotNull(meta);
while (rs.next()) {
}
} catch (SQLException e) {
e.printStackTrace();
}
}
......
package com.taosdata.jdbc.cases;
import com.taosdata.jdbc.TSDBErrorNumbers;
import org.junit.Assert;
import org.junit.Test;
import java.sql.DriverManager;
......@@ -9,16 +7,9 @@ import java.sql.SQLException;
public class ConnectWrongDatabaseTest {
@Test
public void connect() {
try {
Class.forName("com.taosdata.jdbc.TSDBDriver");
DriverManager.getConnection("jdbc:TAOS://localhost:6030/wrong_db?user=root&password=taosdata");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
Assert.assertEquals(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL, e.getErrorCode());
}
@Test(expected = SQLException.class)
public void connect() throws SQLException {
DriverManager.getConnection("jdbc:TAOS://localhost:6030/wrong_db?user=root&password=taosdata");
}
}
......@@ -11,7 +11,7 @@ public class DatetimeBefore1970Test {
private Connection conn;
@Test
public void test() {
public void test() throws SQLException {
try (Statement stmt = conn.createStatement()) {
// given
stmt.executeUpdate("insert into weather(ts) values('1969-12-31 23:59:59.999')");
......@@ -45,36 +45,25 @@ public class DatetimeBefore1970Test {
// then
ts = rs.getTimestamp("ts");
Assert.assertEquals("1970-01-01 07:59:59.999", TimestampUtil.longToDatetime(ts.getTime()));
} catch (SQLException e) {
e.printStackTrace();
}
}
@Before
public void before() {
try {
conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata");
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test_timestamp");
stmt.execute("create database if not exists test_timestamp keep 36500");
stmt.execute("use test_timestamp");
stmt.execute("create table weather(ts timestamp,f1 float)");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
public void before() throws SQLException {
conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata");
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test_timestamp");
stmt.execute("create database if not exists test_timestamp keep 36500");
stmt.execute("use test_timestamp");
stmt.execute("create table weather(ts timestamp,f1 float)");
stmt.close();
}
@After
public void after() {
try {
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test_timestamp");
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
public void after() throws SQLException {
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test_timestamp");
if (conn != null)
conn.close();
}
}
......@@ -17,29 +17,6 @@ public class ImportTest {
static String host = "127.0.0.1";
private static long ts;
@BeforeClass
public static void before() {
try {
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root");
properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata");
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
Statement stmt = connection.createStatement();
stmt.execute("create database if not exists " + dbName);
stmt.execute("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)");
stmt.close();
ts = System.currentTimeMillis();
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
public void case001_insertData() throws Exception {
try (Statement stmt = connection.createStatement()) {
......@@ -52,28 +29,25 @@ public class ImportTest {
}
@Test
public void case002_checkSum() {
public void case002_checkSum() throws SQLException {
Assert.assertEquals(50, select());
}
private int select() {
private int select() throws SQLException {
int count = 0;
try (Statement stmt = connection.createStatement()) {
String sql = "select * from " + dbName + "." + tName;
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
count++;
}
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
return count;
}
@Test
public void case003_importData() {
public void case003_importData() throws SQLException {
// 避免时间重复
try (Statement stmt = connection.createStatement()) {
StringBuilder sqlBuilder = new StringBuilder("import into ").append(dbName).append(".").append(tName).append(" values ");
......@@ -84,27 +58,40 @@ public class ImportTest {
}
int rows = stmt.executeUpdate(sqlBuilder.toString());
assertEquals(50, rows);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
public void case004_checkSum() {
public void case004_checkSum() throws SQLException {
Assert.assertEquals(100, select());
}
@BeforeClass
public static void before() throws SQLException {
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root");
properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata");
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
Statement stmt = connection.createStatement();
stmt.execute("create database if not exists " + dbName);
stmt.execute("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)");
stmt.close();
ts = System.currentTimeMillis();
}
@AfterClass
public static void close() {
try {
if (connection != null) {
Statement statement = connection.createStatement();
statement.executeUpdate("drop database " + dbName);
statement.close();
connection.close();
}
} catch (SQLException e) {
e.printStackTrace();
public static void close() throws SQLException {
if (connection != null) {
Statement statement = connection.createStatement();
statement.executeUpdate("drop database " + dbName);
statement.close();
connection.close();
}
}
}
......@@ -23,7 +23,7 @@ public class MicroSecondPrecisionRestfulTest {
private static Connection conn3;
@Test
public void testCase1() {
public void testCase1() throws SQLException {
try (Statement stmt = conn1.createStatement()) {
ResultSet rs = stmt.executeQuery("select last_row(ts) from " + ms_timestamp_db + ".weather");
rs.next();
......@@ -31,13 +31,11 @@ public class MicroSecondPrecisionRestfulTest {
Assert.assertEquals(timestamp1, ts);
ts = rs.getLong(1);
Assert.assertEquals(timestamp1, ts);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
public void testCase2() {
public void testCase2() throws SQLException {
try (Statement stmt = conn1.createStatement()) {
ResultSet rs = stmt.executeQuery("select last_row(ts) from " + us_timestamp_db + ".weather");
rs.next();
......@@ -50,13 +48,11 @@ public class MicroSecondPrecisionRestfulTest {
ts = rs.getLong(1);
Assert.assertEquals(timestamp1, ts);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
public void testCase3() {
public void testCase3() throws SQLException {
try (Statement stmt = conn2.createStatement()) {
ResultSet rs = stmt.executeQuery("select last_row(ts) from " + ms_timestamp_db + ".weather");
rs.next();
......@@ -65,13 +61,11 @@ public class MicroSecondPrecisionRestfulTest {
Assert.assertEquals(timestamp1, ts);
ts = rs.getLong(1);
Assert.assertEquals(timestamp1, ts);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
public void testCase4() {
public void testCase4() throws SQLException {
try (Statement stmt = conn2.createStatement()) {
ResultSet rs = stmt.executeQuery("select last_row(ts) from " + us_timestamp_db + ".weather");
rs.next();
......@@ -84,13 +78,11 @@ public class MicroSecondPrecisionRestfulTest {
ts = rs.getLong(1);
Assert.assertEquals(timestamp1, ts);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
public void testCase5() {
public void testCase5() throws SQLException {
try (Statement stmt = conn3.createStatement()) {
ResultSet rs = stmt.executeQuery("select last_row(ts) from " + ms_timestamp_db + ".weather");
rs.next();
......@@ -99,13 +91,11 @@ public class MicroSecondPrecisionRestfulTest {
Assert.assertEquals(timestamp1, ts);
ts = rs.getLong(1);
Assert.assertEquals(timestamp1, ts);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
public void testCase6() {
public void testCase6() throws SQLException {
try (Statement stmt = conn3.createStatement()) {
ResultSet rs = stmt.executeQuery("select last_row(ts) from " + us_timestamp_db + ".weather");
rs.next();
......@@ -118,8 +108,6 @@ public class MicroSecondPrecisionRestfulTest {
ts = rs.getLong(1);
Assert.assertEquals(timestamp1, ts);
} catch (SQLException e) {
e.printStackTrace();
}
}
......@@ -154,16 +142,12 @@ public class MicroSecondPrecisionRestfulTest {
}
@AfterClass
public static void afterClass() {
try {
if (conn1 != null)
conn1.close();
if (conn2 != null)
conn2.close();
if (conn3 != null)
conn3.close();
} catch (SQLException e) {
e.printStackTrace();
}
public static void afterClass() throws SQLException {
if (conn1 != null)
conn1.close();
if (conn2 != null)
conn2.close();
if (conn3 != null)
conn3.close();
}
}
......@@ -9,8 +9,7 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;
public class MultiConnectionWithDifferentDbTest {
......@@ -26,16 +25,17 @@ public class MultiConnectionWithDifferentDbTest {
@Override
public void run() {
for (int j = 0; j < 10; j++) {
queryDb();
try {
queryDb();
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (InterruptedException ignored) {
} catch (SQLException throwables) {
fail();
}
}
}
private void queryDb() {
private void queryDb() throws SQLException {
String url = "jdbc:TAOS-RS://" + host + ":6041/db" + i + "?user=root&password=taosdata";
try (Connection connection = DriverManager.getConnection(url)) {
Statement stmt = connection.createStatement();
......@@ -54,8 +54,6 @@ public class MultiConnectionWithDifferentDbTest {
assertEquals(loc, loc_actual);
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}, "thread-" + i)).collect(Collectors.toList());
......@@ -73,12 +71,10 @@ public class MultiConnectionWithDifferentDbTest {
}
@Before
public void before() {
public void before() throws SQLException {
ts = System.currentTimeMillis();
try {
Connection conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata");
try (Connection conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata")) {
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + db1);
stmt.execute("create database if not exists " + db1);
......@@ -91,10 +87,6 @@ public class MultiConnectionWithDifferentDbTest {
stmt.execute("use " + db2);
stmt.execute("create table weather(ts timestamp, f1 int) tags(loc nchar(10))");
stmt.execute("insert into t1 using weather tags('shanghai') values(" + ts + ", 2)");
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
......
package com.taosdata.jdbc.cases;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.sql.*;
import java.util.concurrent.TimeUnit;
public class MultiThreadsWithSameStatementTest {
private static class Service {
public Connection conn;
public Statement stmt;
public Service() {
try {
conn = DriverManager.getConnection("jdbc:TAOS://localhost:6030/?user=root&password=taosdata");
stmt = conn.createStatement();
stmt.execute("create database if not exists jdbctest");
stmt.executeUpdate("create table if not exists jdbctest.weather (ts timestamp, f1 int)");
} catch (SQLException e) {
e.printStackTrace();
}
}
public void release() {
try {
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
@Before
public void before() {
}
@Test
public void test() {
Thread t1 = new Thread(() -> {
try {
Service service = new Service();
ResultSet resultSet = service.stmt.executeQuery("select * from jdbctest.weather");
while (resultSet.next()) {
ResultSetMetaData metaData = resultSet.getMetaData();
}
resultSet.close();
service.release();
} catch (SQLException e) {
e.printStackTrace();
}
});
Thread t2 = new Thread(() -> {
while (true) {
try {
Service service = new Service();
service.stmt.executeUpdate("insert into jdbctest.weather values(now,1)");
service.release();
} catch (SQLException e) {
e.printStackTrace();
}
}
});
t1.start();
sleep(1000);
t2.start();
}
private void sleep(long mills) {
try {
TimeUnit.MILLISECONDS.sleep(mills);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@After
public void after() {
}
}
......@@ -17,7 +17,7 @@ public class NanoSecondTimestampJNITest {
private static Connection conn;
@Test
public void insertUsingLongValue() {
public void insertUsingLongValue() throws SQLException {
// given
long ms = System.currentTimeMillis();
long ns = ms * 1000_000 + random.nextInt(1000_000);
......@@ -26,8 +26,6 @@ public class NanoSecondTimestampJNITest {
int ret = 0;
try (Statement stmt = conn.createStatement()) {
ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)");
} catch (SQLException e) {
e.printStackTrace();
}
// then
......@@ -35,15 +33,13 @@ public class NanoSecondTimestampJNITest {
}
@Test
public void insertUsingStringValue() {
public void insertUsingStringValue() throws SQLException {
// given
// when
int ret = 0;
try (Statement stmt = conn.createStatement()) {
ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('2021-01-01 12:00:00.123456789', 12.3, 4)");
} catch (SQLException e) {
e.printStackTrace();
}
// then
......@@ -51,7 +47,7 @@ public class NanoSecondTimestampJNITest {
}
@Test
public void insertUsingTimestampValue() {
public void insertUsingTimestampValue() throws SQLException {
// given
long epochSec = System.currentTimeMillis() / 1000;
long nanoAdjustment = random.nextInt(1000_000_000);
......@@ -65,8 +61,6 @@ public class NanoSecondTimestampJNITest {
pstmt.setFloat(2, 12.34f);
pstmt.setInt(3, 55);
ret = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
// then
......@@ -85,8 +79,6 @@ public class NanoSecondTimestampJNITest {
stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)");
rs = stmt.executeQuery("select * from weather");
rs.next();
} catch (SQLException e) {
e.printStackTrace();
}
// then
......@@ -102,13 +94,11 @@ public class NanoSecondTimestampJNITest {
String timestampStr = "2021-01-01 12:00:00.123456789";
// when
ResultSet rs = null;
ResultSet rs;
try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('" + timestampStr + "', 12.3, 4)");
rs = stmt.executeQuery("select * from weather");
rs.next();
} catch (SQLException e) {
e.printStackTrace();
}
// then
......@@ -133,8 +123,6 @@ public class NanoSecondTimestampJNITest {
pstmt.setFloat(2, 12.34f);
pstmt.setInt(3, 55);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
// when
......@@ -142,8 +130,6 @@ public class NanoSecondTimestampJNITest {
try (Statement stmt = conn.createStatement()) {
rs = stmt.executeQuery("select * from weather");
rs.next();
} catch (SQLException e) {
e.printStackTrace();
}
// then
......@@ -156,26 +142,21 @@ public class NanoSecondTimestampJNITest {
}
@Before
public void before() {
public void before() throws SQLException {
try (Statement stmt = conn.createStatement()) {
stmt.execute("drop table if exists weather");
stmt.execute("create table weather(ts timestamp, temperature float, humidity int)");
} catch (SQLException e) {
e.printStackTrace();
}
}
@BeforeClass
public static void beforeClass() {
public static void beforeClass() throws SQLException {
final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
try {
conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
conn = DriverManager.getConnection(url);
try (Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname + " precision 'ns'");
stmt.execute("use " + dbname);
} catch (SQLException e) {
e.printStackTrace();
}
}
......
......@@ -17,7 +17,7 @@ public class NanoSecondTimestampRestfulTest {
private static Connection conn;
@Test
public void insertUsingLongValue() {
public void insertUsingLongValue() throws SQLException {
// given
long ms = System.currentTimeMillis();
long ns = ms * 1000_000 + random.nextInt(1000_000);
......@@ -26,8 +26,6 @@ public class NanoSecondTimestampRestfulTest {
int ret = 0;
try (Statement stmt = conn.createStatement()) {
ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)");
} catch (SQLException e) {
e.printStackTrace();
}
// then
......@@ -35,15 +33,13 @@ public class NanoSecondTimestampRestfulTest {
}
@Test
public void insertUsingStringValue() {
public void insertUsingStringValue() throws SQLException {
// given
// when
int ret = 0;
try (Statement stmt = conn.createStatement()) {
ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('2021-01-01 12:00:00.123456789', 12.3, 4)");
} catch (SQLException e) {
e.printStackTrace();
}
// then
......@@ -51,7 +47,7 @@ public class NanoSecondTimestampRestfulTest {
}
@Test
public void insertUsingTimestampValue() {
public void insertUsingTimestampValue() throws SQLException {
// given
long epochSec = System.currentTimeMillis() / 1000;
long nanoAdjustment = random.nextInt(1000_000_000);
......@@ -65,8 +61,6 @@ public class NanoSecondTimestampRestfulTest {
pstmt.setFloat(2, 12.34f);
pstmt.setInt(3, 55);
ret = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
// then
......@@ -80,13 +74,11 @@ public class NanoSecondTimestampRestfulTest {
long ns = ms * 1000_000L + random.nextInt(1000_000);
// when
ResultSet rs = null;
ResultSet rs;
try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)");
rs = stmt.executeQuery("select * from weather");
rs.next();
} catch (SQLException e) {
e.printStackTrace();
}
// then
......@@ -102,13 +94,11 @@ public class NanoSecondTimestampRestfulTest {
String timestampStr = "2021-01-01 12:00:00.123456789";
// when
ResultSet rs = null;
ResultSet rs;
try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('" + timestampStr + "', 12.3, 4)");
rs = stmt.executeQuery("select * from weather");
rs.next();
} catch (SQLException e) {
e.printStackTrace();
}
// then
......@@ -133,8 +123,6 @@ public class NanoSecondTimestampRestfulTest {
pstmt.setFloat(2, 12.34f);
pstmt.setInt(3, 55);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
// when
......@@ -142,8 +130,6 @@ public class NanoSecondTimestampRestfulTest {
try (Statement stmt = conn.createStatement()) {
rs = stmt.executeQuery("select * from weather");
rs.next();
} catch (SQLException e) {
e.printStackTrace();
}
// then
......@@ -156,26 +142,21 @@ public class NanoSecondTimestampRestfulTest {
}
@Before
public void before() {
public void before() throws SQLException {
try (Statement stmt = conn.createStatement()) {
stmt.execute("drop table if exists weather");
stmt.execute("create table weather(ts timestamp, temperature float, humidity int)");
} catch (SQLException e) {
e.printStackTrace();
}
}
@BeforeClass
public static void beforeClass() {
public static void beforeClass() throws SQLException {
final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
try {
conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
conn = DriverManager.getConnection(url);
try (Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname + " precision 'ns'");
stmt.execute("use " + dbname);
} catch (SQLException e) {
e.printStackTrace();
}
}
......
......@@ -12,15 +12,13 @@ public class NullValueInResultSetJNITest {
Connection conn;
@Test
public void test() {
public void test() throws SQLException {
try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select * from weather");
ResultSetMetaData meta = rs.getMetaData();
while (rs.next()) {
}
} catch (SQLException e) {
e.printStackTrace();
}
}
......@@ -42,18 +40,12 @@ public class NullValueInResultSetJNITest {
stmt.executeUpdate("insert into weather(ts, f7) values(now+7s, true)");
stmt.executeUpdate("insert into weather(ts, f8) values(now+8s, 'hello')");
stmt.executeUpdate("insert into weather(ts, f9) values(now+9s, '涛思数据')");
} catch (SQLException e) {
e.printStackTrace();
}
}
@After
public void after() {
try {
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
public void after() throws SQLException {
if (conn != null)
conn.close();
}
}
......@@ -12,7 +12,7 @@ public class NullValueInResultSetRestfulTest {
Connection conn;
@Test
public void test() {
public void test() throws SQLException {
try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select * from weather");
ResultSetMetaData meta = rs.getMetaData();
......@@ -21,9 +21,6 @@ public class NullValueInResultSetRestfulTest {
Object value = rs.getObject(i);
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
......@@ -45,18 +42,12 @@ public class NullValueInResultSetRestfulTest {
stmt.executeUpdate("insert into weather(ts, f7) values(now+7s, true)");
stmt.executeUpdate("insert into weather(ts, f8) values(now+8s, 'hello')");
stmt.executeUpdate("insert into weather(ts, f9) values(now+9s, '涛思数据')");
} catch (SQLException e) {
e.printStackTrace();
}
}
@After
public void after() {
try {
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
public void after() throws SQLException {
if (conn != null)
conn.close();
}
}
......@@ -20,7 +20,7 @@ public class PreparedStatementBatchInsertRestfulTest {
private Connection conn;
@Test
public void test() {
public void test() throws SQLException {
// given
long ts = System.currentTimeMillis();
List<Object[]> rows = IntStream.range(0, 10).mapToObj(i -> {
......@@ -52,7 +52,6 @@ public class PreparedStatementBatchInsertRestfulTest {
}
pstmt.executeBatch();
} catch (SQLException e) {
e.printStackTrace();
Assert.fail();
}
......@@ -64,35 +63,25 @@ public class PreparedStatementBatchInsertRestfulTest {
count++;
}
Assert.assertEquals(10, count);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Before
public void before() {
try {
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata");
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table meters(ts timestamp, current float, voltage int, phase int) tags(groupId int)");
} catch (SQLException e) {
e.printStackTrace();
}
public void before() throws SQLException {
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata");
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table meters(ts timestamp, current float, voltage int, phase int) tags(groupId int)");
}
@After
public void after() {
try {
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
public void after() throws SQLException {
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.close();
conn.close();
}
}
......@@ -19,26 +19,22 @@ public class QueryDataTest {
static String host = "127.0.0.1";
@Before
public void createDatabase() {
try {
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root");
properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata");
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
statement = connection.createStatement();
statement.executeUpdate("drop database if exists " + dbName);
statement.executeUpdate("create database if not exists " + dbName);
statement.executeUpdate("use " + dbName);
String createTableSql = "create table " + stbName + "(ts timestamp, name binary(64))";
statement.executeUpdate(createTableSql);
} catch (SQLException e) {
e.printStackTrace();
}
public void createDatabase() throws SQLException {
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root");
properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata");
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
statement = connection.createStatement();
statement.executeUpdate("drop database if exists " + dbName);
statement.executeUpdate("create database if not exists " + dbName);
statement.executeUpdate("use " + dbName);
String createTableSql = "create table " + stbName + "(ts timestamp, name binary(64))";
statement.executeUpdate(createTableSql);
}
@Test
......@@ -57,15 +53,11 @@ public class QueryDataTest {
}
@After
public void close() {
try {
if (statement != null)
statement.close();
if (connection != null)
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
public void close() throws SQLException {
if (statement != null)
statement.close();
if (connection != null)
connection.close();
}
}
\ No newline at end of file
......@@ -15,19 +15,15 @@ public class ResultSetMetaShouldNotBeNullRestfulTest {
private Connection connection;
@Test
public void testExecuteQuery() {
public void testExecuteQuery() throws SQLException {
// given
ResultSetMetaData metaData = null;
int columnCount = -1;
ResultSetMetaData metaData;
int columnCount;
// when
try {
Statement statement = connection.createStatement();
metaData = statement.executeQuery("select * from weather").getMetaData();
columnCount = metaData.getColumnCount();
} catch (SQLException e) {
e.printStackTrace();
}
Statement statement = connection.createStatement();
metaData = statement.executeQuery("select * from weather").getMetaData();
columnCount = metaData.getColumnCount();
// then
Assert.assertNotNull(metaData);
......@@ -35,20 +31,17 @@ public class ResultSetMetaShouldNotBeNullRestfulTest {
}
@Test
public void testExecute() {
public void testExecute() throws SQLException {
// given
ResultSetMetaData metaData = null;
int columnCount = -1;
boolean execute = false;
ResultSetMetaData metaData;
int columnCount;
boolean execute;
// when
try {
Statement statement = connection.createStatement();
execute = statement.execute("select * from weather");
metaData = statement.getResultSet().getMetaData();
columnCount = metaData.getColumnCount();
} catch (SQLException e) {
e.printStackTrace();
}
Statement statement = connection.createStatement();
execute = statement.execute("select * from weather");
metaData = statement.getResultSet().getMetaData();
columnCount = metaData.getColumnCount();
// then
Assert.assertEquals(true, execute);
......@@ -57,30 +50,22 @@ public class ResultSetMetaShouldNotBeNullRestfulTest {
}
@Before
public void before() {
try {
connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata");
Statement stmt = connection.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table weather (ts timestamp, temperature float)");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
public void before() throws SQLException {
connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata");
Statement stmt = connection.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table weather (ts timestamp, temperature float)");
stmt.close();
}
@After
public void after() {
try {
Statement stmt = connection.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.close();
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
public void after() throws SQLException {
Statement stmt = connection.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.close();
connection.close();
}
}
......@@ -17,25 +17,20 @@ public class SelectTest {
String host = "127.0.0.1";
@Before
public void createDatabaseAndTable() {
try {
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root");
properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata");
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
Statement stmt = connection.createStatement();
stmt.execute("drop database if exists " + dbName);
stmt.execute("create database if not exists " + dbName);
stmt.execute("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
public void createDatabaseAndTable() throws SQLException {
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root");
properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata");
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
Statement stmt = connection.createStatement();
stmt.execute("drop database if exists " + dbName);
stmt.execute("create database if not exists " + dbName);
stmt.execute("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)");
stmt.close();
}
@Test
......@@ -65,16 +60,12 @@ public class SelectTest {
}
@After
public void close() {
try {
if (connection != null) {
Statement stmt = connection.createStatement();
stmt.executeUpdate("drop database " + dbName);
stmt.close();
connection.close();
}
} catch (SQLException e) {
e.printStackTrace();
public void close() throws SQLException {
if (connection != null) {
Statement stmt = connection.createStatement();
stmt.executeUpdate("drop database " + dbName);
stmt.close();
connection.close();
}
}
}
package com.taosdata.jdbc.cases;
import org.junit.Test;
import java.sql.*;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class TaosInfoMonitorTest {
@Test
public void testCreateTooManyConnection() throws ClassNotFoundException {
Class.forName("com.taosdata.jdbc.TSDBDriver");
final String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata";
List<Connection> connectionList = IntStream.range(0, 100).mapToObj(i -> {
try {
TimeUnit.MILLISECONDS.sleep(100);
return DriverManager.getConnection(url);
} catch (SQLException | InterruptedException e) {
e.printStackTrace();
}
return null;
}).collect(Collectors.toList());
connectionList.forEach(conn -> {
try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("show databases");
while (rs.next()) {
}
TimeUnit.MILLISECONDS.sleep(100);
} catch (SQLException | InterruptedException e) {
e.printStackTrace();
}
});
connectionList.forEach(conn -> {
try {
conn.close();
TimeUnit.MILLISECONDS.sleep(100);
} catch (SQLException | InterruptedException e) {
e.printStackTrace();
}
});
}
}
......@@ -15,7 +15,7 @@ public class UnsignedNumberJniTest {
private static long ts;
@Test
public void testCase001() {
public void testCase001() throws SQLException {
try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select * from us_table");
ResultSetMetaData meta = rs.getMetaData();
......@@ -27,13 +27,11 @@ public class UnsignedNumberJniTest {
Assert.assertEquals("2147483647", rs.getString(4));
Assert.assertEquals("9223372036854775807", rs.getString(5));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
public void testCase002() {
public void testCase002() throws SQLException {
try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select * from us_table");
ResultSetMetaData meta = rs.getMetaData();
......@@ -46,8 +44,6 @@ public class UnsignedNumberJniTest {
Assert.assertEquals(2147483647, rs.getInt(4));
Assert.assertEquals(9223372036854775807L, rs.getLong(5));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
......@@ -140,36 +136,28 @@ public class UnsignedNumberJniTest {
}
@BeforeClass
public static void beforeClass() {
public static void beforeClass() throws SQLException {
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
ts = System.currentTimeMillis();
try {
final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
conn = DriverManager.getConnection(url, properties);
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists unsign_jni");
stmt.execute("create database if not exists unsign_jni");
stmt.execute("use unsign_jni");
stmt.execute("create table us_table(ts timestamp, f1 tinyint unsigned, f2 smallint unsigned, f3 int unsigned, f4 bigint unsigned)");
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + ts + ", 127, 32767,2147483647, 9223372036854775807)");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
conn = DriverManager.getConnection(url, properties);
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists unsign_jni");
stmt.execute("create database if not exists unsign_jni");
stmt.execute("use unsign_jni");
stmt.execute("create table us_table(ts timestamp, f1 tinyint unsigned, f2 smallint unsigned, f3 int unsigned, f4 bigint unsigned)");
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + ts + ", 127, 32767,2147483647, 9223372036854775807)");
stmt.close();
}
@AfterClass
public static void afterClass() {
try {
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
public static void afterClass() throws SQLException {
if (conn != null)
conn.close();
}
}
......@@ -16,7 +16,7 @@ public class UnsignedNumberRestfulTest {
private static long ts;
@Test
public void testCase001() {
public void testCase001() throws SQLException {
try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select * from us_table");
ResultSetMetaData meta = rs.getMetaData();
......@@ -28,13 +28,11 @@ public class UnsignedNumberRestfulTest {
Assert.assertEquals("2147483647", rs.getString(4));
Assert.assertEquals("9223372036854775807", rs.getString(5));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
public void testCase002() {
public void testCase002() throws SQLException {
try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select * from us_table");
ResultSetMetaData meta = rs.getMetaData();
......@@ -47,8 +45,6 @@ public class UnsignedNumberRestfulTest {
Assert.assertEquals(2147483647, rs.getInt(4));
Assert.assertEquals(9223372036854775807L, rs.getLong(5));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
......
package com.taosdata.jdbc.cases;
import org.junit.Before;
import org.junit.Test;
import java.sql.*;
......@@ -12,7 +11,7 @@ public class UseNowInsertTimestampTest {
String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata";
@Test
public void millisec() {
public void millisec() throws SQLException {
try (Connection conn = DriverManager.getConnection(url)) {
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test");
......@@ -30,13 +29,11 @@ public class UseNowInsertTimestampTest {
assertEquals(0, nanos % 1000_000);
stmt.execute("drop database if exists test");
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
public void microsec() {
public void microsec() throws SQLException {
try (Connection conn = DriverManager.getConnection(url)) {
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test");
......@@ -53,13 +50,11 @@ public class UseNowInsertTimestampTest {
assertEquals(0, nanos % 1000);
stmt.execute("drop database if exists test");
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
public void nanosec() {
public void nanosec() throws SQLException {
try (Connection conn = DriverManager.getConnection(url)) {
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test");
......@@ -77,8 +72,6 @@ public class UseNowInsertTimestampTest {
assertTrue(nanos % 1000 != 0);
stmt.execute("drop database if exists test");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
package com.taosdata.jdbc.cases;
package com.taosdata.jdbc.confprops;
import com.taosdata.jdbc.TSDBDriver;
......@@ -19,26 +19,22 @@ public class BadLocaleSettingTest {
private static Connection conn;
@Test
public void canSetLocale() {
try {
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
conn = DriverManager.getConnection(url, properties);
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbName);
stmt.execute("create database if not exists " + dbName);
stmt.execute("use " + dbName);
stmt.execute("drop table if exists weather");
stmt.execute("create table weather(ts timestamp, temperature float, humidity int)");
stmt.executeUpdate("insert into weather values(1624071506435, 12.3, 4)");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
public void canSetLocale() throws SQLException {
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
conn = DriverManager.getConnection(url, properties);
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbName);
stmt.execute("create database if not exists " + dbName);
stmt.execute("use " + dbName);
stmt.execute("drop table if exists weather");
stmt.execute("create table weather(ts timestamp, temperature float, humidity int)");
stmt.executeUpdate("insert into weather values(1624071506435, 12.3, 4)");
stmt.close();
}
@BeforeClass
......@@ -48,12 +44,8 @@ public class BadLocaleSettingTest {
}
@AfterClass
public static void afterClass() {
try {
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
public static void afterClass() throws SQLException {
if (conn != null)
conn.close();
}
}
\ No newline at end of file
package com.taosdata.jdbc.confprops;
import org.junit.*;
import org.junit.runners.MethodSorters;
import java.sql.*;
import java.util.Random;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class BatchFetchTest {
private static String host = "127.0.0.1";
private long rowFetchCost, batchFetchCost;
@Test
public void case01_rowFetch() throws SQLException {
String url = "jdbc:TAOS://" + host + ":6030/test?user=root&password=taosdata";
try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
boolean batchfetch = Boolean.parseBoolean(conn.getClientInfo("batchfetch"));
Assert.assertFalse(batchfetch);
long start = System.currentTimeMillis();
ResultSet rs = stmt.executeQuery("select * from weather");
while (rs.next()) {
}
long end = System.currentTimeMillis();
rowFetchCost = end - start;
}
}
@Test
public void case02_batchFetch() throws SQLException {
String url = "jdbc:TAOS://" + host + ":6030/test?user=root&password=taosdata&batchfetch=true";
try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
boolean batchfetch = Boolean.parseBoolean(conn.getClientInfo("batchfetch"));
Assert.assertTrue(batchfetch);
long start = System.currentTimeMillis();
ResultSet rs = stmt.executeQuery("select * from weather");
while (rs.next()) {
}
long end = System.currentTimeMillis();
batchFetchCost = end - start;
}
}
@Test
public void case03_batchFetchFastThanRowFetch() {
Assert.assertTrue(rowFetchCost - batchFetchCost >= 0);
}
@BeforeClass
public static void beforeClass() throws SQLException {
String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists test");
stmt.execute("create database if not exists test");
stmt.execute("use test");
stmt.execute("create table weather(ts timestamp, f int) tags(t int)");
for (int i = 0; i < 1000; i++) {
stmt.execute(generateSql(100, 100));
}
}
}
private static String generateSql(int tableSize, int valueSize) {
Random random = new Random(System.currentTimeMillis());
StringBuilder builder = new StringBuilder("insert into ");
for (int i = 0; i < tableSize; i++) {
builder.append("t" + i).append(" using weather tags(").append(random.nextInt(100)).append(") values");
for (int j = 0; j < valueSize; j++) {
builder.append(" (now + ").append(i).append("s, ").append(random.nextInt(100)).append(")");
}
}
return builder.toString();
}
}
package com.taosdata.jdbc.confprops;
import com.taosdata.jdbc.TSDBDriver;
import org.junit.Assert;
import org.junit.Test;
import java.sql.*;
import java.util.Properties;
public class CharsetTest {
private static final String host = "127.0.0.1";
@Test
public void test() throws SQLException {
// given
String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
Properties props = new Properties();
props.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
try (Connection conn = DriverManager.getConnection(url, props);
Statement stmt = conn.createStatement()) {
// when
stmt.execute("drop database if exists test");
stmt.execute("create database if not exists test");
stmt.execute("use test");
stmt.execute("create table weather(ts timestamp, temperature nchar(10))");
stmt.execute("insert into weather values(now, '北京')");
// then
ResultSet rs = stmt.executeQuery("select * from weather");
while (rs.next()) {
Object value = rs.getObject("temperature");
Assert.assertTrue(value instanceof String);
Assert.assertEquals("北京", value.toString());
}
}
}
}
package com.taosdata.jdbc.confprops;
import org.junit.Assert;
import org.junit.Test;
import java.sql.*;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class TaosInfoMonitorTest {
private static final String host = "127.0.0.1";
private Random random = new Random(System.currentTimeMillis());
@Test
public void testCreateTooManyConnection() throws InterruptedException {
List<Thread> threads = IntStream.range(1, 11).mapToObj(i -> new Thread(() -> {
final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
int connSize = random.nextInt(10);
for (int j = 0; j < connSize; j++) {
try {
Connection conn = DriverManager.getConnection(url);
TimeUnit.MILLISECONDS.sleep(random.nextInt(3000));
int stmtSize = random.nextInt(100);
for (int k = 0; k < stmtSize; k++) {
Statement stmt = conn.createStatement();
TimeUnit.MILLISECONDS.sleep(random.nextInt(3000));
ResultSet rs = stmt.executeQuery("show databases");
while (rs.next()) {
}
rs.close();
stmt.close();
}
} catch (SQLException | InterruptedException throwables) {
Assert.fail();
}
}
}, "thread-" + i)).collect(Collectors.toList());
threads.forEach(Thread::start);
for (Thread thread : threads) {
thread.join();
}
}
}
package com.taosdata.jdbc.cases;
package com.taosdata.jdbc.confprops;
import com.taosdata.jdbc.TSDBDriver;
import org.junit.Test;
......
package com.taosdata.jdbc.confprops;
import com.taosdata.jdbc.TSDBDriver;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.sql.*;
import java.time.Instant;
import java.util.Properties;
public class TimestampFormatTest {
private static final String host = "127.0.0.1";
private long ts = Instant.now().toEpochMilli();
@Test
public void string() throws SQLException {
// given
String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
// when
try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
// then
String actual = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT);
Assert.assertEquals("STRING", actual);
ResultSet rs = stmt.executeQuery("select * from test.weather");
while (rs.next()) {
String value = rs.getString("ts");
String expect = new Timestamp(ts).toString();
Assert.assertEquals(expect, value);
}
}
}
@Test
public void stringInProperties() throws SQLException {
// given
String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
// when
String timestampFormat = "STRING";
Properties props = new Properties();
props.setProperty(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT, timestampFormat);
try (Connection conn = DriverManager.getConnection(url, props);
Statement stmt = conn.createStatement()) {
// then
String actual = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT);
Assert.assertEquals(timestampFormat, actual);
ResultSet rs = stmt.executeQuery("select * from test.weather");
while (rs.next()) {
String value = rs.getString("ts");
String expect = new Timestamp(ts).toString();
Assert.assertEquals(expect, value);
}
}
}
@Test
public void timestampInUrl() throws SQLException {
// given
String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata&timestampFormat=";
String timestampFormat = "TIMESTAMP";
// when
try (Connection conn = DriverManager.getConnection(url + timestampFormat);
Statement stmt = conn.createStatement()) {
// then
String actual = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT);
Assert.assertEquals(timestampFormat, actual);
ResultSet rs = stmt.executeQuery("select * from test.weather");
while (rs.next()) {
Object value = rs.getObject("ts");
String expect = new Timestamp(ts).toString();
Assert.assertEquals(expect, value.toString());
}
}
}
@Test
public void timestampInProperties() throws SQLException {
// given
String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
String timestampFormat = "TIMESTAMP";
// when
Properties props = new Properties();
props.setProperty(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT, timestampFormat);
try (Connection conn = DriverManager.getConnection(url, props);
Statement stmt = conn.createStatement()) {
// then
String actual = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT);
Assert.assertEquals(timestampFormat, actual);
ResultSet rs = stmt.executeQuery("select * from test.weather");
while (rs.next()) {
Object value = rs.getObject("ts");
String expect = new Timestamp(ts).toString();
Assert.assertEquals(expect, value.toString());
}
}
}
@Test
public void utcInUrl() throws SQLException {
// given
String timestampFormat = "UTC";
String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata&timestampFormat=" + timestampFormat;
// when & then
try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
String actual = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT);
Assert.assertEquals(timestampFormat, actual);
ResultSet rs = stmt.executeQuery("select * from test.weather");
while (rs.next()) {
Object value = rs.getObject("ts");
Assert.assertTrue(value instanceof Timestamp);
String expect = new Timestamp(ts).toString();
Assert.assertEquals(expect, value.toString());
}
}
}
@Test
public void utcInProperties() throws SQLException {
// given
String timestampFormat = "UTC";
String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
// when
Properties props = new Properties();
props.setProperty(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT, timestampFormat);
try (Connection conn = DriverManager.getConnection(url, props);
Statement stmt = conn.createStatement()) {
// then
String actual = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT);
Assert.assertEquals(timestampFormat, actual);
ResultSet rs = stmt.executeQuery("select * from test.weather");
while (rs.next()) {
Object value = rs.getObject("ts");
Assert.assertTrue(value instanceof Timestamp);
String expect = new Timestamp(ts).toString();
Assert.assertEquals(expect, value.toString());
}
}
}
@Before
public void before() throws SQLException {
String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists test");
stmt.execute("create database if not exists test");
stmt.execute("use test");
stmt.execute("create table weather(ts timestamp, temperature nchar(10))");
stmt.execute("insert into weather values(" + ts + ", '北京')");
}
}
}
......@@ -23,14 +23,12 @@ public class RestfulConnectionTest {
}
@Test
public void createStatement() {
public void createStatement() throws SQLException {
try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select server_status()");
rs.next();
int status = rs.getInt("server_status()");
assertEquals(1, status);
} catch (SQLException e) {
e.printStackTrace();
}
}
......@@ -359,13 +357,9 @@ public class RestfulConnectionTest {
}
@Test
public void unwrap() {
try {
RestfulConnection restfulConnection = conn.unwrap(RestfulConnection.class);
Assert.assertNotNull(restfulConnection);
} catch (SQLException e) {
e.printStackTrace();
}
public void unwrap() throws SQLException {
RestfulConnection restfulConnection = conn.unwrap(RestfulConnection.class);
Assert.assertNotNull(restfulConnection);
}
@Test
......@@ -374,32 +368,22 @@ public class RestfulConnectionTest {
}
@BeforeClass
public static void beforeClass() {
try {
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/log?user=root&password=taosdata", properties);
// create test database for test cases
try (Statement stmt = conn.createStatement()) {
stmt.execute("create database if not exists test");
}
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
public static void beforeClass() throws SQLException {
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/log?user=root&password=taosdata", properties);
// create test database for test cases
try (Statement stmt = conn.createStatement()) {
stmt.execute("create database if not exists test");
}
}
@AfterClass
public static void afterClass() {
try {
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
public static void afterClass() throws SQLException {
if (conn != null)
conn.close();
}
}
\ No newline at end of file
......@@ -1085,30 +1085,26 @@ public class RestfulDatabaseMetaDataTest {
}
@BeforeClass
public static void beforeClass() {
try {
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
connection = DriverManager.getConnection(url, properties);
metaData = connection.getMetaData().unwrap(RestfulDatabaseMetaData.class);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
public static void beforeClass() throws SQLException {
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
connection = DriverManager.getConnection(url, properties);
Statement stmt = connection.createStatement();
stmt.execute("drop database if exists log");
stmt.execute("create database if not exists log precision 'us'");
stmt.execute("use log");
stmt.execute("create table `dn` (ts TIMESTAMP,cpu_taosd FLOAT,cpu_system FLOAT,cpu_cores INT,mem_taosd FLOAT,mem_system FLOAT,mem_total INT,disk_used FLOAT,disk_total INT,band_speed FLOAT,io_read FLOAT,io_write FLOAT,req_http INT,req_select INT,req_insert INT) TAGS (dnodeid INT,fqdn BINARY(128))");
stmt.execute("insert into dn1 using dn tags(1,'a') (ts) values(now)");
metaData = connection.getMetaData().unwrap(RestfulDatabaseMetaData.class);
}
@AfterClass
public static void afterClass() {
try {
if (connection != null)
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
public static void afterClass() throws SQLException {
if (connection != null)
connection.close();
}
}
\ No newline at end of file
......@@ -14,7 +14,7 @@ public class RestfulJDBCTest {
private Connection connection;
@Test
public void testCase001() {
public void testCase001() throws SQLException {
// given
String sql = "drop database if exists restful_test";
// when
......@@ -38,7 +38,7 @@ public class RestfulJDBCTest {
}
@Test
public void testCase002() {
public void testCase002() throws SQLException {
// given
String sql = "create table weather(ts timestamp, temperature float, humidity int) tags(location nchar(64), groupId int)";
// when
......@@ -48,7 +48,7 @@ public class RestfulJDBCTest {
}
@Test
public void testCase004() {
public void testCase004() throws SQLException {
for (int i = 1; i <= 100; i++) {
// given
String sql = "create table t" + i + " using weather tags('beijing', '" + i + "')";
......@@ -60,7 +60,7 @@ public class RestfulJDBCTest {
}
@Test
public void testCase005() {
public void testCase005() throws SQLException {
int rows = 0;
for (int i = 0; i < 10; i++) {
for (int j = 1; j <= 100; j++) {
......@@ -99,7 +99,7 @@ public class RestfulJDBCTest {
}
@Test
public void testCase007() {
public void testCase007() throws SQLException {
// given
String sql = "drop database restful_test";
......@@ -110,51 +110,34 @@ public class RestfulJDBCTest {
Assert.assertFalse(execute);
}
private int executeUpdate(Connection connection, String sql) {
private int executeUpdate(Connection connection, String sql) throws SQLException {
try (Statement stmt = connection.createStatement()) {
return stmt.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return 0;
}
private boolean execute(Connection connection, String sql) {
private boolean execute(Connection connection, String sql) throws SQLException {
try (Statement stmt = connection.createStatement()) {
return stmt.execute(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
private ResultSet executeQuery(Connection connection, String sql) {
private ResultSet executeQuery(Connection connection, String sql) throws SQLException {
try (Statement statement = connection.createStatement()) {
return statement.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
@Before
public void before() {
try {
connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata");
} catch (SQLException e) {
e.printStackTrace();
}
public void before() throws SQLException {
connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata&httpKeepAlive=false");
}
@After
public void after() {
try {
if (connection != null)
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
public void after() throws SQLException {
if (connection != null)
connection.close();
}
}
......@@ -17,46 +17,32 @@ public class RestfulStatementTest {
private static Statement stmt;
@Test
public void executeQuery() {
try {
ResultSet rs = stmt.executeQuery("show databases");
Assert.assertNotNull(rs);
ResultSetMetaData meta = rs.getMetaData();
int columnCount = meta.getColumnCount();
Assert.assertTrue(columnCount > 1);
while (rs.next()) {
Assert.assertEquals("name", meta.getColumnLabel(1));
Assert.assertNotNull(rs.getString("name"));
}
rs.close();
} catch (SQLException e) {
e.printStackTrace();
public void executeQuery() throws SQLException {
ResultSet rs = stmt.executeQuery("show databases");
Assert.assertNotNull(rs);
ResultSetMetaData meta = rs.getMetaData();
int columnCount = meta.getColumnCount();
Assert.assertTrue(columnCount > 1);
while (rs.next()) {
Assert.assertEquals("name", meta.getColumnLabel(1));
Assert.assertNotNull(rs.getString("name"));
}
rs.close();
}
@Test
public void executeUpdate() {
public void executeUpdate() throws SQLException {
final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32);
try {
int affectRows = stmt.executeUpdate("create database " + dbName);
Assert.assertEquals(0, affectRows);
affectRows = stmt.executeUpdate("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
Assert.assertEquals(0, affectRows);
affectRows = stmt.executeUpdate("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
Assert.assertEquals(1, affectRows);
affectRows = stmt.executeUpdate("drop database " + dbName);
Assert.assertEquals(0, affectRows);
} catch (SQLException e) {
e.printStackTrace();
}
int affectRows = stmt.executeUpdate("create database " + dbName);
Assert.assertEquals(0, affectRows);
affectRows = stmt.executeUpdate("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
Assert.assertEquals(0, affectRows);
affectRows = stmt.executeUpdate("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
Assert.assertEquals(1, affectRows);
affectRows = stmt.executeUpdate("drop database " + dbName);
Assert.assertEquals(0, affectRows);
}
@Test
public void close() {
// test in AfterClass method
}
@Test
public void getMaxFieldSize() throws SQLException {
Assert.assertEquals(16 * 1024, stmt.getMaxFieldSize());
......@@ -64,7 +50,6 @@ public class RestfulStatementTest {
@Test(expected = SQLException.class)
public void setMaxFieldSize() throws SQLException {
stmt.setMaxFieldSize(0);
stmt.setMaxFieldSize(-1);
}
......@@ -118,83 +103,70 @@ public class RestfulStatementTest {
}
@Test
public void execute() {
public void execute() throws SQLException {
final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32);
try {
boolean isSelect = stmt.execute("create database if not exists " + dbName);
Assert.assertEquals(false, isSelect);
int affectedRows = stmt.getUpdateCount();
Assert.assertEquals(0, affectedRows);
isSelect = stmt.execute("create table if not exists " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
Assert.assertEquals(false, isSelect);
affectedRows = stmt.getUpdateCount();
Assert.assertEquals(0, affectedRows);
isSelect = stmt.execute("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
Assert.assertEquals(false, isSelect);
affectedRows = stmt.getUpdateCount();
Assert.assertEquals(1, affectedRows);
isSelect = stmt.execute("select * from " + dbName + ".weather");
Assert.assertEquals(true, isSelect);
isSelect = stmt.execute("drop database " + dbName);
Assert.assertEquals(false, isSelect);
affectedRows = stmt.getUpdateCount();
Assert.assertEquals(0, affectedRows);
} catch (SQLException e) {
e.printStackTrace();
}
boolean isSelect = stmt.execute("create database if not exists " + dbName);
Assert.assertEquals(false, isSelect);
int affectedRows = stmt.getUpdateCount();
Assert.assertEquals(0, affectedRows);
isSelect = stmt.execute("create table if not exists " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
Assert.assertEquals(false, isSelect);
affectedRows = stmt.getUpdateCount();
Assert.assertEquals(0, affectedRows);
isSelect = stmt.execute("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
Assert.assertEquals(false, isSelect);
affectedRows = stmt.getUpdateCount();
Assert.assertEquals(1, affectedRows);
isSelect = stmt.execute("select * from " + dbName + ".weather");
Assert.assertEquals(true, isSelect);
isSelect = stmt.execute("drop database " + dbName);
Assert.assertEquals(false, isSelect);
affectedRows = stmt.getUpdateCount();
Assert.assertEquals(0, affectedRows);
}
@Test
public void getResultSet() {
public void getResultSet() throws SQLException {
final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32);
try {
boolean isSelect = stmt.execute("create database if not exists " + dbName);
Assert.assertEquals(false, isSelect);
int affectedRows = stmt.getUpdateCount();
Assert.assertEquals(0, affectedRows);
isSelect = stmt.execute("create table if not exists " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
Assert.assertEquals(false, isSelect);
affectedRows = stmt.getUpdateCount();
Assert.assertEquals(0, affectedRows);
isSelect = stmt.execute("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
Assert.assertEquals(false, isSelect);
affectedRows = stmt.getUpdateCount();
Assert.assertEquals(1, affectedRows);
isSelect = stmt.execute("select * from " + dbName + ".weather");
Assert.assertEquals(true, isSelect);
ResultSet rs = stmt.getResultSet();
Assert.assertNotNull(rs);
ResultSetMetaData meta = rs.getMetaData();
Assert.assertEquals(3, meta.getColumnCount());
int count = 0;
while (rs.next()) {
Assert.assertEquals("ts", meta.getColumnLabel(1));
Assert.assertNotNull(rs.getTimestamp(1));
Assert.assertEquals("temperature", meta.getColumnLabel(2));
Assert.assertEquals(22.33, rs.getFloat(2), 0.001f);
count++;
}
Assert.assertEquals(1, count);
isSelect = stmt.execute("drop database " + dbName);
Assert.assertEquals(false, isSelect);
affectedRows = stmt.getUpdateCount();
Assert.assertEquals(0, affectedRows);
} catch (SQLException e) {
e.printStackTrace();
boolean isSelect = stmt.execute("create database if not exists " + dbName);
Assert.assertEquals(false, isSelect);
int affectedRows = stmt.getUpdateCount();
Assert.assertEquals(0, affectedRows);
isSelect = stmt.execute("create table if not exists " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
Assert.assertEquals(false, isSelect);
affectedRows = stmt.getUpdateCount();
Assert.assertEquals(0, affectedRows);
isSelect = stmt.execute("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
Assert.assertEquals(false, isSelect);
affectedRows = stmt.getUpdateCount();
Assert.assertEquals(1, affectedRows);
isSelect = stmt.execute("select * from " + dbName + ".weather");
Assert.assertEquals(true, isSelect);
ResultSet rs = stmt.getResultSet();
Assert.assertNotNull(rs);
ResultSetMetaData meta = rs.getMetaData();
Assert.assertEquals(3, meta.getColumnCount());
int count = 0;
while (rs.next()) {
Assert.assertEquals("ts", meta.getColumnLabel(1));
Assert.assertNotNull(rs.getTimestamp(1));
Assert.assertEquals("temperature", meta.getColumnLabel(2));
Assert.assertEquals(22.33, rs.getFloat(2), 0.001f);
count++;
}
}
Assert.assertEquals(1, count);
@Test
public void getUpdateCount() {
// already test in execute method
isSelect = stmt.execute("drop database " + dbName);
Assert.assertEquals(false, isSelect);
affectedRows = stmt.getUpdateCount();
Assert.assertEquals(0, affectedRows);
}
@Test
......@@ -239,64 +211,48 @@ public class RestfulStatementTest {
}
@Test
public void addBatch() {
public void addBatch() throws SQLException {
final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32);
try {
stmt.addBatch("create database " + dbName);
stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
stmt.addBatch("select * from " + dbName + ".weather");
stmt.addBatch("drop database " + dbName);
} catch (SQLException e) {
e.printStackTrace();
}
stmt.addBatch("create database " + dbName);
stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
stmt.addBatch("select * from " + dbName + ".weather");
stmt.addBatch("drop database " + dbName);
}
@Test
public void clearBatch() {
public void clearBatch() throws SQLException {
final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32);
try {
stmt.clearBatch();
stmt.addBatch("create database " + dbName);
stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
stmt.addBatch("select * from " + dbName + ".weather");
stmt.addBatch("drop database " + dbName);
stmt.clearBatch();
} catch (SQLException e) {
e.printStackTrace();
}
stmt.clearBatch();
stmt.addBatch("create database " + dbName);
stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
stmt.addBatch("select * from " + dbName + ".weather");
stmt.addBatch("drop database " + dbName);
stmt.clearBatch();
}
@Test
public void executeBatch() {
public void executeBatch() throws SQLException {
final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32);
try {
stmt.addBatch("create database " + dbName);
stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
stmt.addBatch("select * from " + dbName + ".weather");
stmt.addBatch("drop database " + dbName);
int[] results = stmt.executeBatch();
Assert.assertEquals(0, results[0]);
Assert.assertEquals(0, results[1]);
Assert.assertEquals(1, results[2]);
Assert.assertEquals(Statement.SUCCESS_NO_INFO, results[3]);
Assert.assertEquals(0, results[4]);
} catch (SQLException e) {
e.printStackTrace();
}
stmt.addBatch("create database " + dbName);
stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
stmt.addBatch("select * from " + dbName + ".weather");
stmt.addBatch("drop database " + dbName);
int[] results = stmt.executeBatch();
Assert.assertEquals(0, results[0]);
Assert.assertEquals(0, results[1]);
Assert.assertEquals(1, results[2]);
Assert.assertEquals(Statement.SUCCESS_NO_INFO, results[3]);
Assert.assertEquals(0, results[4]);
}
@Test
public void getConnection() {
try {
Connection connection = stmt.getConnection();
Assert.assertNotNull(connection);
Assert.assertTrue(this.conn == connection);
} catch (SQLException e) {
e.printStackTrace();
}
public void getConnection() throws SQLException {
Connection connection = stmt.getConnection();
Assert.assertNotNull(connection);
Assert.assertTrue(this.conn == connection);
}
@Test(expected = SQLFeatureNotSupportedException.class)
......@@ -346,12 +302,8 @@ public class RestfulStatementTest {
}
@Test
public void isClosed() {
try {
Assert.assertEquals(false, stmt.isClosed());
} catch (SQLException e) {
e.printStackTrace();
}
public void isClosed() throws SQLException {
Assert.assertEquals(false, stmt.isClosed());
}
@Test
......@@ -387,29 +339,21 @@ public class RestfulStatementTest {
}
@BeforeClass
public static void beforeClass() {
try {
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata", properties);
stmt = conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
public static void beforeClass() throws SQLException {
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata", properties);
stmt = conn.createStatement();
}
@AfterClass
public static void afterClass() {
try {
if (stmt != null)
stmt.close();
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
public static void afterClass() throws SQLException {
if (stmt != null)
stmt.close();
if (conn != null)
conn.close();
}
}
......@@ -543,15 +543,6 @@ public class SQLTest {
Assert.assertNotNull(rs);
}
@Test
public void testCase053() {
String sql = "select avg(cpu_taosd), avg(cpu_system), max(cpu_cores), avg(mem_taosd), avg(mem_system), max(mem_total), avg(disk_used), max(disk_total), avg(band_speed), avg(io_read), avg(io_write), sum(req_http), sum(req_select), sum(req_insert) from log.dn1 where ts> now - 60m and ts<= now interval(1m) fill(value, 0)";
// when
ResultSet rs = executeQuery(connection, sql);
// then
Assert.assertNotNull(rs);
}
private boolean execute(Connection connection, String sql) {
try (Statement statement = connection.createStatement()) {
return statement.execute(sql);
......
......@@ -17,7 +17,6 @@ public class HttpClientPoolUtilTest {
String user = "root";
String password = "taosdata";
String host = "127.0.0.1";
// String host = "master";
@Test
public void useLog() {
......
......@@ -400,7 +400,7 @@ typedef struct SColIndex {
int16_t colId; // column id
int16_t colIndex; // column index in colList if it is a normal column or index in tagColList if a tag
uint16_t flag; // denote if it is a tag or a normal column
char name[TSDB_COL_NAME_LEN + TSDB_DB_NAME_LEN + 1];
char name[TSDB_COL_NAME_LEN + TSDB_TABLE_NAME_LEN + 1];
} SColIndex;
typedef struct SColumnFilterInfo {
......
......@@ -25,7 +25,7 @@
static char **shellSQLFiles = NULL;
static int32_t shellSQLFileNum = 0;
static char shellTablesSQLFile[TSDB_FILENAME_LEN] = {0};
static char shellTablesSQLFile[4096] = {0};
typedef struct {
pthread_t threadID;
......
......@@ -10969,7 +10969,7 @@ static void startMultiThreadInsertData(int threads, char* db_name,
}
int64_t ntables = 0;
uint64_t tableFrom;
uint64_t tableFrom = 0;
if (stbInfo) {
if (stbInfo->iface != SML_IFACE) {
......
......@@ -1293,7 +1293,7 @@ static int getTableDes(
length[0], tbuf, COL_VALUEBUF_LEN-2);
sprintf(tableDes->cols[i].value, "%s", tbuf);
} else {
tableDes->cols[i].var_value = calloc(1, len * 4);
tableDes->cols[i].var_value = calloc(1, nlen * 4);
if (tableDes->cols[i].var_value == NULL) {
errorPrint("%s() LN%d, memory alalocation failed!\n",
__func__, __LINE__);
......@@ -1303,7 +1303,7 @@ static int getTableDes(
converStringToReadable(
(char *)row[TSDB_SHOW_TABLES_NAME_INDEX],
length[0],
(char *)(tableDes->cols[i].var_value), len);
(char *)(tableDes->cols[i].var_value), nlen);
}
break;
case TSDB_DATA_TYPE_TIMESTAMP:
......
......@@ -41,7 +41,7 @@ ELSE ()
COMMAND git clean -f -d
BUILD_COMMAND CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../inc CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib go build -ldflags "-s -w -X github.com/taosdata/taosadapter/version.CommitID=${taosadapter_commit_sha1}"
INSTALL_COMMAND
COMMAND curl -sL https://github.com/upx/upx/releases/download/v3.96/upx-3.96-amd64_linux.tar.xz -o upx.tar.xz && tar xvJf upx.tar.xz --strip-components 1 && ./upx taosadapter
COMMAND curl -sL https://github.com/upx/upx/releases/download/v3.96/upx-3.96-amd64_linux.tar.xz -o upx.tar.xz && tar xvJf upx.tar.xz --strip-components 1 > /dev/null && ./upx taosadapter || :
COMMAND cmake -E copy taosadapter ${CMAKE_BINARY_DIR}/build/bin
COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/test/cfg/
COMMAND cmake -E copy ./example/config/taosadapter.toml ${CMAKE_BINARY_DIR}/test/cfg/
......
......@@ -296,7 +296,7 @@ double tdigestQuantile(TDigest *t, double q) {
a = b;
right = t->max;
if (idx < weight_so_far + a->weight) {
if (idx < weight_so_far + a->weight && a->weight != 0) {
double p = (idx - weight_so_far) / a->weight;
return left * (1 - p) + right * p;
}
......
......@@ -233,7 +233,7 @@ static int64_t syncProcessLastWal(SSyncPeer *pPeer, char *wname, int64_t index)
int32_t once = 0; // last WAL has once ever been processed
int64_t offset = 0;
uint64_t fversion = 0;
char fname[TSDB_FILENAME_LEN * 2] = {0}; // full path to wal file
char fname[TSDB_FILENAME_LEN * 3] = {0}; // full path to wal file
// get full path to wal file
snprintf(fname, sizeof(fname), "%s/%s", pNode->path, wname);
......
......@@ -229,7 +229,7 @@ int tsdbWriteBlockIdx(SDFile *pHeadf, SArray *pIdxA, void **ppBuf) {
SBlockIdx *pBlkIdx;
size_t nidx = taosArrayGetSize(pIdxA);
int tlen = 0, size;
int64_t offset;
int64_t offset = 0;
if (nidx <= 0) {
// All data are deleted
......@@ -1186,7 +1186,7 @@ int tsdbWriteBlockImpl(STsdbRepo *pRepo, STable *pTable, SDFile *pDFile, SDFile
return -1;
}
uint32_t aggrStatus = ((nColsNotAllNull > 0) && (rowsToWrite > 8)) ? 1 : 0; // TODO: How to make the decision?
uint32_t aggrStatus = nColsNotAllNull > 0 ? 1 : 0;
if (aggrStatus > 0) {
taosCalcChecksumAppend(0, (uint8_t *)pAggrBlkData, tsizeAggr);
......
......@@ -79,7 +79,7 @@ void *tsdbDecodeSMFileEx(void *buf, SMFile *pMFile) {
char *aname;
buf = tsdbDecodeMFInfo(buf, &(pMFile->info));
buf = taosDecodeString(buf, &aname);
strncpy(TSDB_FILE_FULL_NAME(pMFile), aname, TSDB_FILENAME_LEN);
tstrncpy(TSDB_FILE_FULL_NAME(pMFile), aname, TSDB_FILENAME_LEN);
TSDB_FILE_SET_CLOSED(pMFile);
tfree(aname);
......@@ -345,7 +345,7 @@ static void *tsdbDecodeSDFileEx(void *buf, SDFile *pDFile) {
// The sync module would send DFileSet with latest verion.
buf = tsdbDecodeDFInfo(buf, &(pDFile->info), TSDB_LATEST_SFS_VER);
buf = taosDecodeString(buf, &aname);
strncpy(TSDB_FILE_FULL_NAME(pDFile), aname, TSDB_FILENAME_LEN);
tstrncpy(TSDB_FILE_FULL_NAME(pDFile), aname, TSDB_FILENAME_LEN);
TSDB_FILE_SET_CLOSED(pDFile);
tfree(aname);
......@@ -716,4 +716,4 @@ static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, c
snprintf(fname, TSDB_FILENAME_LEN, "vnode/vnode%d/tsdb/%s-ver%" PRIu32, vid, TSDB_FNAME_SUFFIX[ftype], ver);
}
}
}
\ No newline at end of file
}
......@@ -1544,7 +1544,7 @@ static void mergeTwoRowFromMem(STsdbQueryHandle* pQueryHandle, int32_t capacity,
int16_t offset;
bool isRow1DataRow = isDataRow(row1);
bool isRow2DataRow;
bool isRow2DataRow = false;
bool isChosenRowDataRow;
int32_t chosen_itr;
void *value;
......
......@@ -230,7 +230,7 @@ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const
{
int32_t parent;
int32_t child;
char *buf;
char *buf = NULL;
if (base && size > 0 && compar) {
parent = start;
......
......@@ -566,7 +566,7 @@ static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, char *msg, int32_t msgLen)
int32_t end = 0;
int32_t remainSize = 0;
static int64_t lostLine = 0;
char tmpBuf[40] = {0};
char tmpBuf[60] = {0};
int32_t tmpBufLen = 0;
if (tLogBuff == NULL || tLogBuff->stop) return -1;
......
......@@ -258,9 +258,9 @@ void taosCloseQset(taos_qset param) {
pthread_mutex_unlock(&qset->mutex);
pthread_mutex_destroy(&qset->mutex);
uTrace("qset:%p is closed", qset);
tsem_destroy(&qset->sem);
free(qset);
uTrace("qset:%p is closed", qset);
}
// tsem_post 'qset->sem', so that reader threads waiting for it
......
......@@ -91,6 +91,6 @@ void *tWorkerAllocQueue(SWorkerPool *pPool, void *ahandle) {
}
void tWorkerFreeQueue(SWorkerPool *pPool, void *pQueue) {
taosCloseQueue(pQueue);
uDebug("worker:%s, queue:%p is freed", pPool->name, pQueue);
taosCloseQueue(pQueue);
}
......@@ -17,7 +17,7 @@
<dependency>
<groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId>
<version>2.0.34</version>
<version>2.0.35</version>
</dependency>
</dependencies>
......
package com.taosdata.example;
import java.sql.*;
import java.util.*;
public class BatchInsert {
private static final String host = "127.0.0.1";
private static final String user = "root";
private static final String password = "taosdata";
private static final String dbname = "test";
private static final String stbname = "stb";
private static final int tables= 100;
private static final int rows = 500;
private static final long ts = 1604877767000l;
private Connection conn;
private void init() {
// final String url = "jdbc:TAOS://" + host + ":6030/?user=" + user + "&password=" + password;
final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=" + user + "&password=" + password;
// get connection
try {
Properties properties = new Properties();
properties.setProperty("charset", "UTF-8");
properties.setProperty("locale", "en_US.UTF-8");
properties.setProperty("timezone", "UTC-8");
System.out.println("get connection starting...");
conn = DriverManager.getConnection(url, properties);
if (conn != null){
System.out.println("[ OK ] Connection established.");
}
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table " + dbname + "." + stbname + "(ts timestamp, col int) tags(id int)");
} catch (SQLException e) {
e.printStackTrace();
}
}
private String generateSql() {
StringBuilder sb = new StringBuilder();
Random rand = new Random();
sb.append("insert into ");
for (int i = 0; i < tables; i++) {
sb.append(dbname + ".tb" + i + " using " + dbname + "." + stbname + " tags(" + i + ") values");
for (int j = 0; j < rows; j++) {
sb.append("(");
sb.append(ts + j);
sb.append(",");
sb.append(rand.nextInt(1000));
sb.append(") ");
}
}
return sb.toString();
}
private void executeQuery(String sql) {
try (Statement stmt = conn.createStatement()) {
long start = System.currentTimeMillis();
stmt.execute(sql);
long end = System.currentTimeMillis();
System.out.println("insert " + tables * rows + " records, cost " + (end - start)+ "ms");
} catch (SQLException ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
BatchInsert bi = new BatchInsert();
String sql = bi.generateSql();
bi.init();
bi.executeQuery(sql);
}
}
......@@ -23,43 +23,31 @@ var conn = taos.connect({host:"127.0.0.1", user:"root", password:"taosdata", con
// Initialize our TDengineCursor, which we use to interact with TDengine
var c1 = conn.cursor();
//execute the sql
function execute(sql){
try {
c1.execute(sql);
}
catch(err) {
conn.close();
throw err;
}
}
// c1.execute(query) will execute the query
// Let's create a database named db
try {
c1.execute('create database if not exists db;');
}
catch(err) {
conn.close();
throw err;
}
execute('create database if not exists db;')
// Now we will use database db
try {
c1.execute('use db;');
}
catch (err) {
conn.close();
throw err;
}
execute('use db;')
// Let's create a table called weather
// which stores some weather data like humidity, AQI (air quality index), temperature, and some notes as text
try {
c1.execute('create table if not exists weather (ts timestamp, humidity smallint, aqi int, temperature float, notes binary(30));');
}
catch (err) {
conn.close();
throw err;
}
execute('create table if not exists weather (ts timestamp, humidity smallint, aqi int, temperature float, notes binary(30));');
// Let's get the description of the table weather
try {
c1.execute('describe db.weather');
}
catch (err) {
conn.close();
throw err;
}
execute('describe db.weather');
// To get results, we run the function c1.fetchall()
// It only returns the query results as an array of result rows, but also stores the latest results in c1.data
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -25,8 +25,7 @@ class TDTestCase:
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
now = time.time()
self.ts = int(round(now * 1000))
self.ts = 1633333333000.
self.num = 10
def run(self):
......@@ -534,4 +533,4 @@ class TDTestCase:
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
\ No newline at end of file
tdCases.addLinux(__file__, TDTestCase())
......@@ -135,7 +135,7 @@ typedef struct _script_t {
int32_t numOfLines; // number of lines in the script
int32_t bgScriptLen;
char fileName[MAX_FILE_NAME_LEN]; // script file name
char error[MAX_ERROR_LEN];
char error[TSDB_MAX_BINARY_LEN + 100];
char * optionBuffer;
SCmdLine *lines; // command list
SVariable variables[MAX_VAR_LEN];
......@@ -178,4 +178,4 @@ bool simExecuteLineInsertCmd(SScript *script, char *option);
bool simExecuteLineInsertErrorCmd(SScript *script, char *option);
void simVisuallizeOption(SScript *script, char *src, char *dst);
#endif
\ No newline at end of file
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册