Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
63f5190d
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1193
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
63f5190d
编写于
3月 22, 2022
作者:
H
huolibo
提交者:
GitHub
3月 22, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-14055]<fix>: adjust the method of obtaining values (#10884)
上级
7f0394fd
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
2031 addition
and
10 deletion
+2031
-10
src/client/src/TSDBJNIConnector.c
src/client/src/TSDBJNIConnector.c
+4
-9
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetBlockData.java
...c/main/java/com/taosdata/jdbc/TSDBResultSetBlockData.java
+2
-1
src/connector/jdbc/src/test/java/com/taosdata/jdbc/block/TSDBBlockJsonTagTest.java
...st/java/com/taosdata/jdbc/block/TSDBBlockJsonTagTest.java
+1338
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/block/TSDBBlockResultSetTest.java
.../java/com/taosdata/jdbc/block/TSDBBlockResultSetTest.java
+687
-0
未找到文件。
src/client/src/TSDBJNIConnector.c
浏览文件 @
63f5190d
...
@@ -574,7 +574,6 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchBlockImp(JNI
...
@@ -574,7 +574,6 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchBlockImp(JNI
}
}
TAOS_RES
*
tres
=
(
TAOS_RES
*
)
res
;
TAOS_RES
*
tres
=
(
TAOS_RES
*
)
res
;
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
tres
);
int32_t
numOfFields
=
taos_num_fields
(
tres
);
int32_t
numOfFields
=
taos_num_fields
(
tres
);
assert
(
numOfFields
>
0
);
assert
(
numOfFields
>
0
);
...
@@ -596,14 +595,10 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchBlockImp(JNI
...
@@ -596,14 +595,10 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchBlockImp(JNI
(
*
env
)
->
CallVoidMethod
(
env
,
rowobj
,
g_blockdataSetNumOfRowsFp
,
(
jint
)
numOfRows
);
(
*
env
)
->
CallVoidMethod
(
env
,
rowobj
,
g_blockdataSetNumOfRowsFp
,
(
jint
)
numOfRows
);
(
*
env
)
->
CallVoidMethod
(
env
,
rowobj
,
g_blockdataSetNumOfColsFp
,
(
jint
)
numOfFields
);
(
*
env
)
->
CallVoidMethod
(
env
,
rowobj
,
g_blockdataSetNumOfColsFp
,
(
jint
)
numOfFields
);
int32_t
*
field
=
taos_fetch_lengths
(
tres
);
for
(
int
i
=
0
;
i
<
numOfFields
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numOfFields
;
i
++
)
{
int
bytes
=
fields
[
i
].
bytes
;
(
*
env
)
->
CallVoidMethod
(
env
,
rowobj
,
g_blockdataSetByteArrayFp
,
i
,
field
[
i
]
*
numOfRows
,
jniFromNCharToByteArray
(
env
,
(
char
*
)
row
[
i
],
field
[
i
]
*
numOfRows
));
if
(
fields
[
i
].
type
==
TSDB_DATA_TYPE_BINARY
||
fields
[
i
].
type
==
TSDB_DATA_TYPE_NCHAR
)
{
bytes
+=
2
;
}
(
*
env
)
->
CallVoidMethod
(
env
,
rowobj
,
g_blockdataSetByteArrayFp
,
i
,
bytes
*
numOfRows
,
jniFromNCharToByteArray
(
env
,
(
char
*
)
row
[
i
],
bytes
*
numOfRows
));
}
}
return
JNI_SUCCESS
;
return
JNI_SUCCESS
;
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetBlockData.java
浏览文件 @
63f5190d
...
@@ -513,7 +513,8 @@ public class TSDBResultSetBlockData {
...
@@ -513,7 +513,8 @@ public class TSDBResultSetBlockData {
case
TSDBConstants
.
TSDB_DATA_TYPE_JSON
:
case
TSDBConstants
.
TSDB_DATA_TYPE_JSON
:
case
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
:
{
case
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
:
{
ByteBuffer
bb
=
(
ByteBuffer
)
this
.
colData
.
get
(
col
);
ByteBuffer
bb
=
(
ByteBuffer
)
this
.
colData
.
get
(
col
);
bb
.
position
((
fieldSize
+
BINARY_LENGTH_OFFSET
)
*
this
.
rowIndex
);
// bb.position((fieldSize * 4 + 2 + 1) * this.rowIndex);
bb
.
position
(
bb
.
capacity
()
/
numOfRows
*
this
.
rowIndex
);
int
length
=
bb
.
getShort
();
int
length
=
bb
.
getShort
();
byte
[]
dest
=
new
byte
[
length
];
byte
[]
dest
=
new
byte
[
length
];
bb
.
get
(
dest
,
0
,
length
);
bb
.
get
(
dest
,
0
,
length
);
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/block/TSDBBlockJsonTagTest.java
0 → 100644
浏览文件 @
63f5190d
package
com.taosdata.jdbc.block
;
import
com.taosdata.jdbc.TSDBDriver
;
import
com.taosdata.jdbc.TSDBPreparedStatement
;
import
com.taosdata.jdbc.annotation.CatalogRunner
;
import
com.taosdata.jdbc.annotation.Description
;
import
com.taosdata.jdbc.annotation.TestTarget
;
import
org.junit.*
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.MethodSorters
;
import
java.sql.*
;
import
java.util.*
;
/**
* fetch_block for json tag test
*/
@FixMethodOrder
(
MethodSorters
.
NAME_ASCENDING
)
@RunWith
(
CatalogRunner
.
class
)
@TestTarget
(
alias
=
"JsonTag"
,
author
=
"huolibo"
,
version
=
"2.0.38"
)
public
class
TSDBBlockJsonTagTest
{
private
static
final
String
dbName
=
"json_tag_test"
;
private
static
Connection
connection
;
private
static
Statement
statement
;
private
static
final
String
superSql
=
"create table if not exists jsons1(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)"
;
private
static
final
String
[]
sql
=
{
"insert into jsons1_1 using jsons1 tags('{\"tag1\":\"fff\",\"tag2\":5, \"tag3\":true}') values(now, 1, false, 'json1', '你是') (1591060608000, 23, true, '等等', 'json')"
,
"insert into jsons1_2 using jsons1 tags('{\"tag1\":5,\"tag2\":\"beijing\"}') values (1591060628000, 2, true, 'json2', 'sss')"
,
"insert into jsons1_3 using jsons1 tags('{\"tag1\":false,\"tag2\":\"beijing\"}') values (1591060668000, 3, false, 'json3', 'efwe')"
,
"insert into jsons1_4 using jsons1 tags('{\"tag1\":null,\"tag2\":\"shanghai\",\"tag3\":\"hello\"}') values (1591060728000, 4, true, 'json4', '323sd')"
,
"insert into jsons1_5 using jsons1 tags('{\"tag1\":1.232, \"tag2\":null}') values(1591060928000, 1, false, '你就会', 'ewe')"
,
"insert into jsons1_6 using jsons1 tags('{\"tag1\":11,\"tag2\":\"\",\"tag2\":null}') values(1591061628000, 11, false, '你就会','')"
,
"insert into jsons1_7 using jsons1 tags('{\"tag1\":\"收到货\",\"tag2\":\"\",\"tag3\":null}') values(1591062628000, 2, NULL, '你就会', 'dws')"
,
// test duplicate key using the first one.
"CREATE TABLE if not exists jsons1_8 using jsons1 tags('{\"tag1\":null, \"tag1\":true, \"tag1\":45, \"1tag$\":2, \" \":90}')"
,
};
private
static
final
String
[]
invalidJsonInsertSql
=
{
// test empty json string, save as tag is NULL
"insert into jsons1_9 using jsons1 tags('\t') values (1591062328000, 24, NULL, '你就会', '2sdw')"
,
};
private
static
final
String
[]
invalidJsonCreateSql
=
{
"CREATE TABLE if not exists jsons1_10 using jsons1 tags('')"
,
"CREATE TABLE if not exists jsons1_11 using jsons1 tags(' ')"
,
"CREATE TABLE if not exists jsons1_12 using jsons1 tags('{}')"
,
"CREATE TABLE if not exists jsons1_13 using jsons1 tags('null')"
,
};
// test invalidate json
private
static
final
String
[]
errorJsonInsertSql
=
{
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('\"efwewf\"')"
,
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('3333')"
,
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('33.33')"
,
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('false')"
,
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('[1,true]')"
,
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('{222}')"
,
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"fe\"}')"
,
};
private
static
final
String
[]
errorSelectSql
=
{
"select * from jsons1 where jtag->tag1='beijing'"
,
"select * from jsons1 where jtag->'location'"
,
"select * from jsons1 where jtag->''"
,
"select * from jsons1 where jtag->''=9"
,
"select -> from jsons1"
,
"select ? from jsons1"
,
"select * from jsons1 where contains"
,
"select * from jsons1 where jtag->"
,
"select jtag->location from jsons1"
,
"select jtag contains location from jsons1"
,
"select * from jsons1 where jtag contains location"
,
"select * from jsons1 where jtag contains ''"
,
"select * from jsons1 where jtag contains 'location'='beijing'"
,
// test where with json tag
"select * from jsons1_1 where jtag is not null"
,
"select * from jsons1 where jtag='{\"tag1\":11,\"tag2\":\"\"}'"
,
"select * from jsons1 where jtag->'tag1'={}"
};
@Test
@Description
(
"insert json tag"
)
public
void
case01_InsertTest
()
throws
SQLException
{
for
(
String
sql
:
sql
)
{
statement
.
execute
(
sql
);
}
for
(
String
sql
:
invalidJsonInsertSql
)
{
statement
.
execute
(
sql
);
}
for
(
String
sql
:
invalidJsonCreateSql
)
{
statement
.
execute
(
sql
);
}
}
@Test
@Description
(
"error json tag insert"
)
public
void
case02_ErrorJsonInsertTest
()
{
int
count
=
0
;
for
(
String
sql
:
errorJsonInsertSql
)
{
try
{
statement
.
execute
(
sql
);
}
catch
(
SQLException
e
)
{
count
++;
}
}
Assert
.
assertEquals
(
errorJsonInsertSql
.
length
,
count
);
}
@Test
(
expected
=
SQLException
.
class
)
@Description
(
"exception will throw when json value is array"
)
public
void
case02_ArrayErrorTest
()
throws
SQLException
{
statement
.
execute
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"tag1\":[1,true]}')"
);
}
@Test
(
expected
=
SQLException
.
class
)
@Description
(
"exception will throw when json value is empty"
)
public
void
case02_EmptyValueErrorTest
()
throws
SQLException
{
statement
.
execute
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"tag1\":{}}')"
);
}
@Test
(
expected
=
SQLException
.
class
)
@Description
(
"exception will throw when json key is not ASCII"
)
public
void
case02_AbnormalKeyErrorTest1
()
throws
SQLException
{
statement
.
execute
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"。loc\":\"fff\"}')"
);
}
@Test
(
expected
=
SQLException
.
class
)
@Description
(
"exception will throw when json key is '\\t'"
)
public
void
case02_AbnormalKeyErrorTest2
()
throws
SQLException
{
statement
.
execute
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"\t\":\"fff\"}')"
);
}
@Test
(
expected
=
SQLException
.
class
)
@Description
(
"exception will throw when json key is chinese"
)
public
void
case02_AbnormalKeyErrorTest3
()
throws
SQLException
{
statement
.
execute
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"试试\":\"fff\"}')"
);
}
@Test
@Description
(
"alter json tag"
)
public
void
case03_AlterTag
()
throws
SQLException
{
statement
.
execute
(
"ALTER TABLE jsons1_1 SET TAG jtag='{\"tag1\":\"femail\",\"tag2\":35,\"tag3\":true}'"
);
}
@Test
(
expected
=
SQLException
.
class
)
@Description
(
"exception will throw when add json tag"
)
public
void
case03_AddTagErrorTest
()
throws
SQLException
{
statement
.
execute
(
"ALTER STABLE jsons1 add tag tag2 nchar(20)"
);
}
@Test
(
expected
=
SQLException
.
class
)
@Description
(
"exception will throw when delete json tag"
)
public
void
case03_dropTagErrorTest
()
throws
SQLException
{
statement
.
execute
(
"ALTER STABLE jsons1 drop tag jtag"
);
}
@Test
(
expected
=
SQLException
.
class
)
@Description
(
"exception will throw when set some json tag value"
)
public
void
case03_AlterTagErrorTest
()
throws
SQLException
{
statement
.
execute
(
"ALTER TABLE jsons1_1 SET TAG jtag=4"
);
}
@Test
@Description
(
"exception will throw when select syntax error"
)
public
void
case04_SelectErrorTest
()
{
int
count
=
0
;
for
(
String
sql
:
errorSelectSql
)
{
try
{
statement
.
execute
(
sql
);
}
catch
(
SQLException
e
)
{
count
++;
}
}
Assert
.
assertEquals
(
errorSelectSql
.
length
,
count
);
}
@Test
@Description
(
"normal select stable"
)
public
void
case04_select01
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select dataint from jsons1"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
sql
.
length
+
invalidJsonInsertSql
.
length
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"select all column from stable"
)
public
void
case04_select02
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
sql
.
length
+
invalidJsonInsertSql
.
length
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"select json tag from stable"
)
public
void
case04_select03
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select jtag from jsons1"
);
ResultSetMetaData
metaData
=
resultSet
.
getMetaData
();
metaData
.
getColumnTypeName
(
1
);
int
count
=
0
;
Set
<
String
>
set
=
new
HashSet
<>();
while
(
resultSet
.
next
())
{
count
++;
set
.
add
(
resultSet
.
getString
(
1
));
}
Assert
.
assertTrue
(
set
.
contains
(
"{\"tag1\":null,\"1tag$\":2,\" \":90}"
));
Assert
.
assertTrue
(
set
.
contains
(
"{\"tag1\":\"收到货\",\"tag2\":\"\",\"tag3\":null}"
));
Assert
.
assertEquals
(
sql
.
length
+
invalidJsonInsertSql
.
length
+
invalidJsonCreateSql
.
length
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition tag is null"
)
public
void
case04_select04
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select jtag from jsons1 where jtag is null"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
invalidJsonInsertSql
.
length
+
invalidJsonCreateSql
.
length
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition tag is not null"
)
public
void
case04_select05
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select jtag from jsons1 where jtag is not null"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
sql
.
length
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"select json tag"
)
public
void
case04_select06
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select jtag from jsons1_8"
);
resultSet
.
next
();
String
result
=
resultSet
.
getString
(
1
);
Assert
.
assertEquals
(
"{\"tag1\":null,\"1tag$\":2,\" \":90}"
,
result
);
close
(
resultSet
);
}
@Test
@Description
(
"select json tag"
)
public
void
case04_select07
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select jtag from jsons1_1"
);
resultSet
.
next
();
String
result
=
resultSet
.
getString
(
1
);
Assert
.
assertEquals
(
"{\"tag1\":\"femail\",\"tag2\":35,\"tag3\":true}"
,
result
);
close
(
resultSet
);
}
@Test
@Description
(
"select not exist json tag"
)
public
void
case04_select08
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select jtag from jsons1_9"
);
resultSet
.
next
();
String
result
=
resultSet
.
getString
(
1
);
Assert
.
assertNull
(
result
);
close
(
resultSet
);
}
@Test
@Description
(
"select a json tag"
)
public
void
case04_select09
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select jtag->'tag1' from jsons1_1"
);
resultSet
.
next
();
String
result
=
resultSet
.
getString
(
1
);
Assert
.
assertEquals
(
"\"femail\""
,
result
);
close
(
resultSet
);
}
@Test
@Description
(
"select a json tag, the value is empty"
)
public
void
case04_select10
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select jtag->'tag2' from jsons1_6"
);
resultSet
.
next
();
String
result
=
resultSet
.
getString
(
1
);
Assert
.
assertEquals
(
"\"\""
,
result
);
close
(
resultSet
);
}
@Test
@Description
(
"select a json tag, the value is int"
)
public
void
case04_select11
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select jtag->'tag2' from jsons1_1"
);
resultSet
.
next
();
String
string
=
resultSet
.
getString
(
1
);
Assert
.
assertEquals
(
"35"
,
string
);
close
(
resultSet
);
}
@Test
@Description
(
"select a json tag, the value is boolean"
)
public
void
case04_select12
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select jtag->'tag3' from jsons1_1"
);
resultSet
.
next
();
String
string
=
resultSet
.
getString
(
1
);
Assert
.
assertEquals
(
"true"
,
string
);
close
(
resultSet
);
}
@Test
@Description
(
"select a json tag, the value is null"
)
public
void
case04_select13
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select jtag->'tag1' from jsons1_4"
);
resultSet
.
next
();
String
string
=
resultSet
.
getString
(
1
);
Assert
.
assertEquals
(
"null"
,
string
);
close
(
resultSet
);
}
@Test
@Description
(
"select a json tag, the value is double"
)
public
void
case04_select14
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select jtag->'tag1' from jsons1_5"
);
resultSet
.
next
();
String
string
=
resultSet
.
getString
(
1
);
Assert
.
assertEquals
(
"1.232000000"
,
string
);
close
(
resultSet
);
}
@Test
@Description
(
"select a json tag, the key is not exist"
)
public
void
case04_select15
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select jtag->'tag10' from jsons1_4"
);
resultSet
.
next
();
String
string
=
resultSet
.
getString
(
1
);
Assert
.
assertNull
(
string
);
close
(
resultSet
);
}
@Test
@Description
(
"select a json tag, the result number equals tables number"
)
public
void
case04_select16
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select jtag->'tag1' from jsons1"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
sql
.
length
+
invalidJsonCreateSql
.
length
+
invalidJsonInsertSql
.
length
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition '=' for string"
)
public
void
case04_select19
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag2'='beijing'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
2
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"select and where conditon '=' for string"
)
public
void
case04_select20
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select dataint,tbname,jtag->'tag1',jtag from jsons1 where jtag->'tag2'='beijing'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
2
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition result is null"
)
public
void
case04_select21
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'='beijing'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
0
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition equation has chinese"
)
public
void
case04_select23
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'='收到货'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
1
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support '>' for character"
)
public
void
case05_symbolOperation01
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag2'>'beijing'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
1
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support '>=' for character"
)
public
void
case05_symbolOperation02
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag2'>='beijing'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
3
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support '<' for character"
)
public
void
case05_symbolOperation03
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag2'<'beijing'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
2
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support '<=' in character"
)
public
void
case05_symbolOperation04
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag2'<='beijing'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
4
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support '!=' in character"
)
public
void
case05_symbolOperation05
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag2'!='beijing'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
3
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support '=' empty"
)
public
void
case05_symbolOperation06
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag2'=''"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
2
,
count
);
close
(
resultSet
);
}
// where json value is int
@Test
@Description
(
"where condition support '=' for int"
)
public
void
case06_selectValue01
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'=5"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
1
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where conditional support '<' for int"
)
public
void
case06_selectValue02
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'<54"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
3
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support '<=' for int"
)
public
void
case06_selectValue03
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'<=11"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
3
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where conditional support '>' for int"
)
public
void
case06_selectValue04
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'>4"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
2
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support '>=' for int"
)
public
void
case06_selectValue05
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'>=5"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
2
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where conditional support '!=' for int"
)
public
void
case06_selectValue06
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'!=5"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
2
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where conditional support '!=' for int"
)
public
void
case06_selectValue07
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'!=55"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
3
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where conditional support '!=' for int and result is nothing"
)
public
void
case06_selectValue08
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'=10"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
0
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support '=' for double"
)
public
void
case07_selectValue01
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'=1.232"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
1
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support '<' for double"
)
public
void
case07_doubleOperation01
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'<1.232"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
0
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support '<=' for double"
)
public
void
case07_doubleOperation02
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'<=1.232"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
1
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support '>' for double"
)
public
void
case07_doubleOperation03
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'>1.23"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
3
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support '>=' for double"
)
public
void
case07_doubleOperation04
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'>=1.232"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
3
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support '!=' for double"
)
public
void
case07_doubleOperation05
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'!=1.232"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
2
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support '!=' for double"
)
public
void
case07_doubleOperation06
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'!=3.232"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
3
,
count
);
close
(
resultSet
);
}
@Test
(
expected
=
SQLException
.
class
)
@Description
(
"exception will throw when denominator is zero"
)
public
void
case07_doubleOperation07
()
throws
SQLException
{
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'/0=3"
);
}
@Test
(
expected
=
SQLException
.
class
)
@Description
(
"exception will throw when invalid operation"
)
public
void
case07_doubleOperation08
()
throws
SQLException
{
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'/5=1"
);
}
@Test
@Description
(
"where condition support '=' for boolean"
)
public
void
case08_boolOperation01
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'=true"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
0
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support '=' for boolean"
)
public
void
case08_boolOperation02
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'=false"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
1
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support '!=' for boolean"
)
public
void
case08_boolOperation03
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'!=false"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
0
,
count
);
close
(
resultSet
);
}
@Test
(
expected
=
SQLException
.
class
)
@Description
(
"exception will throw when '>' operation for boolean"
)
public
void
case08_boolOperation04
()
throws
SQLException
{
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'>false"
);
}
@Test
@Description
(
"where conditional support '=null'"
)
public
void
case09_select01
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'=null"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
1
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where conditional support 'is null'"
)
public
void
case09_select02
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag is null"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
1
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support 'is not null'"
)
public
void
case09_select03
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag is not null"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
8
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support one tag '='"
)
public
void
case09_select04
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag_no_exist'=3"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
0
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support one tag 'is null'"
)
public
void
case09_select05
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1' is null"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
invalidJsonInsertSql
.
length
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support one tag 'is null'"
)
public
void
case09_select06
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag4' is null"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
sql
.
length
+
invalidJsonInsertSql
.
length
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition support one tag 'is not null'"
)
public
void
case09_select07
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag3' is not null"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
4
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"contains"
)
public
void
case09_select10
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag contains 'tag1'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
8
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"contains"
)
public
void
case09_select11
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag contains 'tag3'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
4
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"contains with no exist tag"
)
public
void
case09_select12
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag contains 'tag_no_exist'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
0
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition with and"
)
public
void
case10_selectAndOr01
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='beijing'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
1
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition with 'or'"
)
public
void
case10_selectAndOr02
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'=false or jtag->'tag2'='beijing'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
2
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition with 'and'"
)
public
void
case10_selectAndOr03
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='shanghai'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
0
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition with 'or'"
)
public
void
case10_selectAndOr04
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'=13 or jtag->'tag2'>35"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
0
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition with 'or' and contains"
)
public
void
case10_selectAndOr05
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1' is not null and jtag contains 'tag3'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
4
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition with 'and' and contains"
)
public
void
case10_selectAndOr06
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1'='femail' and jtag contains 'tag3'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
2
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"test with tbname/normal column"
)
public
void
case11_selectTbName01
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where tbname = 'jsons1_1'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
2
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"test with tbname/normal column"
)
public
void
case11_selectTbName02
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
2
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"test with tbname/normal column"
)
public
void
case11_selectTbName03
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3' and dataint=3"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
0
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"test with tbname/normal column"
)
public
void
case11_selectTbName04
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3' and dataint=23"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
1
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition like"
)
public
void
case12_selectWhere01
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select *,tbname from jsons1 where jtag->'tag2' like 'bei%'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
2
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition like"
)
public
void
case12_selectWhere02
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select *,tbname from jsons1 where jtag->'tag1' like 'fe%' and jtag->'tag2' is not null"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
2
,
count
);
close
(
resultSet
);
}
@Test
(
expected
=
SQLException
.
class
)
@Description
(
"where condition in no support in"
)
public
void
case12_selectWhere03
()
throws
SQLException
{
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1' in ('beijing')"
);
}
@Test
@Description
(
"where condition match"
)
public
void
case12_selectWhere04
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1' match 'ma'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
2
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition match"
)
public
void
case12_selectWhere05
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1' match 'ma$'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
0
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition match"
)
public
void
case12_selectWhere06
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag2' match 'jing$'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
2
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"where condition match"
)
public
void
case12_selectWhere07
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from jsons1 where jtag->'tag1' match '收到'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
1
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"insert distinct"
)
public
void
case13_selectDistinct01
()
throws
SQLException
{
statement
.
execute
(
"insert into jsons1_14 using jsons1 tags('{\"tag1\":\"收到货\",\"tag2\":\"\",\"tag3\":null}') values(1591062628000, 2, NULL, '你就会', 'dws')"
);
}
@Test
@Description
(
"distinct json tag"
)
public
void
case13_selectDistinct02
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select distinct jtag->'tag1' from jsons1"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
8
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"distinct json tag"
)
public
void
case13_selectDistinct03
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select distinct jtag from jsons1"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
9
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"insert json tag"
)
public
void
case14_selectDump01
()
throws
SQLException
{
statement
.
execute
(
"INSERT INTO jsons1_15 using jsons1 tags('{\"tbname\":\"tt\",\"databool\":true,\"datastr\":\"是是是\"}') values(1591060828000, 4, false, 'jjsf', \"你就会\")"
);
}
@Test
@Description
(
"test duplicate key with normal column"
)
public
void
case14_selectDump02
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select *,tbname,jtag from jsons1 where jtag->'datastr' match '是' and datastr match 'js'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
1
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"test duplicate key with normal column"
)
public
void
case14_selectDump03
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select tbname,jtag->'tbname' from jsons1 where jtag->'tbname'='tt' and tbname='jsons1_14'"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
0
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"insert json tag for join test"
)
public
void
case15_selectJoin01
()
throws
SQLException
{
statement
.
execute
(
"create table if not exists jsons2(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)"
);
statement
.
execute
(
"insert into jsons2_1 using jsons2 tags('{\"tag1\":\"fff\",\"tag2\":5, \"tag3\":true}') values(1591060618000, 2, false, 'json2', '你是2')"
);
statement
.
execute
(
"insert into jsons2_2 using jsons2 tags('{\"tag1\":5,\"tag2\":null}') values (1591060628000, 2, true, 'json2', 'sss')"
);
statement
.
execute
(
"create table if not exists jsons3(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)"
);
statement
.
execute
(
"insert into jsons3_1 using jsons3 tags('{\"tag1\":\"fff\",\"tag2\":5, \"tag3\":true}') values(1591060618000, 3, false, 'json3', '你是3')"
);
statement
.
execute
(
"insert into jsons3_2 using jsons3 tags('{\"tag1\":5,\"tag2\":\"beijing\"}') values (1591060638000, 2, true, 'json3', 'sss')"
);
}
@Test
@Description
(
"select json tag from join"
)
public
void
case15_selectJoin02
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select 'sss',33,a.jtag->'tag3' from jsons2 a,jsons3 b where a.ts=b.ts and a.jtag->'tag1'=b.jtag->'tag1'"
);
resultSet
.
next
();
Assert
.
assertEquals
(
"sss"
,
resultSet
.
getString
(
1
));
close
(
resultSet
);
}
@Test
@Description
(
"group by and order by json tag desc"
)
public
void
case16_selectGroupOrder01
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag1' desc"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
8
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"group by and order by json tag asc"
)
public
void
case16_selectGroupOrder02
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag1' asc"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
8
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"stddev with group by json tag"
)
public
void
case17_selectStddev01
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select stddev(dataint) from jsons1 group by jtag->'tag1'"
);
String
s
=
""
;
int
count
=
0
;
Set
<
String
>
set
=
new
HashSet
<>();
while
(
resultSet
.
next
())
{
count
++;
set
.
add
(
resultSet
.
getString
(
2
));
}
Assert
.
assertEquals
(
8
,
count
);
Assert
.
assertTrue
(
set
.
contains
(
"\"femail\""
));
Assert
.
assertTrue
(
set
.
contains
(
"\"收到货\""
));
}
@Test
@Description
(
"subquery json tag"
)
public
void
case18_selectSubquery01
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from (select jtag, dataint from jsons1)"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
11
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"subquery some json tags"
)
public
void
case18_selectSubquery02
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select jtag->'tag1' from (select jtag->'tag1', dataint from jsons1)"
);
ResultSetMetaData
metaData
=
resultSet
.
getMetaData
();
String
columnName
=
metaData
.
getColumnName
(
1
);
Assert
.
assertEquals
(
"jtag->'tag1'"
,
columnName
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
11
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"query some json tags from subquery"
)
public
void
case18_selectSubquery04
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select ts,tbname,jtag->'tag1' from (select jtag->'tag1',tbname,ts from jsons1 order by ts)"
);
int
count
=
0
;
while
(
resultSet
.
next
())
{
count
++;
}
Assert
.
assertEquals
(
11
,
count
);
close
(
resultSet
);
}
@Test
@Description
(
"query metadata for json"
)
public
void
case19_selectMetadata01
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select jtag from jsons1"
);
ResultSetMetaData
metaData
=
resultSet
.
getMetaData
();
int
columnType
=
metaData
.
getColumnType
(
1
);
String
columnTypeName
=
metaData
.
getColumnTypeName
(
1
);
Assert
.
assertEquals
(
Types
.
OTHER
,
columnType
);
Assert
.
assertEquals
(
"JSON"
,
columnTypeName
);
close
(
resultSet
);
}
@Test
@Description
(
"query metadata for json"
)
public
void
case19_selectMetadata02
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select *,jtag from jsons1"
);
ResultSetMetaData
metaData
=
resultSet
.
getMetaData
();
int
columnType
=
metaData
.
getColumnType
(
6
);
String
columnTypeName
=
metaData
.
getColumnTypeName
(
6
);
Assert
.
assertEquals
(
Types
.
OTHER
,
columnType
);
Assert
.
assertEquals
(
"JSON"
,
columnTypeName
);
close
(
resultSet
);
}
@Test
@Description
(
"query metadata for one json result"
)
public
void
case19_selectMetadata03
()
throws
SQLException
{
ResultSet
resultSet
=
statement
.
executeQuery
(
"select jtag->'tag1' from jsons1_6"
);
ResultSetMetaData
metaData
=
resultSet
.
getMetaData
();
int
columnType
=
metaData
.
getColumnType
(
1
);
String
columnTypeName
=
metaData
.
getColumnTypeName
(
1
);
Assert
.
assertEquals
(
Types
.
OTHER
,
columnType
);
Assert
.
assertEquals
(
"JSON"
,
columnTypeName
);
resultSet
.
next
();
String
string
=
resultSet
.
getString
(
1
);
Assert
.
assertEquals
(
"11"
,
string
);
close
(
resultSet
);
}
@Test
@Description
(
"stmt batch insert with json tag"
)
public
void
case20_batchInsert
()
throws
SQLException
{
String
jsonTag
=
"{\"tag1\":\"fff\",\"tag2\":5,\"tag3\":true}"
;
statement
.
execute
(
"drop table if exists jsons5"
);
statement
.
execute
(
"CREATE STABLE IF NOT EXISTS jsons5 (ts timestamp, dataInt int, dataStr nchar(20)) TAGS(jtag json)"
);
String
sql
=
"INSERT INTO ? USING jsons5 TAGS (?) VALUES ( ?,?,? )"
;
try
(
PreparedStatement
pst
=
connection
.
prepareStatement
(
sql
))
{
TSDBPreparedStatement
ps
=
pst
.
unwrap
(
TSDBPreparedStatement
.
class
);
// 设定数据表名:
ps
.
setTableName
(
"batch_test"
);
// 设定 TAGS 取值 setTagNString or setTagJson:
// ps.setTagNString(0, jsonTag);
ps
.
setTagJson
(
0
,
jsonTag
);
// VALUES 部分以逐列的方式进行设置:
int
numOfRows
=
4
;
ArrayList
<
Long
>
ts
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
ts
.
add
(
System
.
currentTimeMillis
()
+
i
);
}
ps
.
setTimestamp
(
0
,
ts
);
Random
r
=
new
Random
();
int
random
=
10
+
r
.
nextInt
(
5
);
ArrayList
<
Integer
>
c1
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
if
(
i
%
random
==
0
)
{
c1
.
add
(
null
);
}
else
{
c1
.
add
(
r
.
nextInt
());
}
}
ps
.
setInt
(
1
,
c1
);
ArrayList
<
String
>
c2
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
c2
.
add
(
"分支"
+
i
%
4
);
}
ps
.
setNString
(
2
,
c2
,
10
);
// AddBatch 之后,缓存并未清空。为避免混乱,并不推荐在 ExecuteBatch 之前再次绑定新一批的数据:
ps
.
columnDataAddBatch
();
// 执行绑定数据后的语句:
ps
.
columnDataExecuteBatch
();
}
ResultSet
resultSet
=
statement
.
executeQuery
(
"select jtag from batch_test"
);
ResultSetMetaData
metaData
=
resultSet
.
getMetaData
();
String
columnName
=
metaData
.
getColumnName
(
1
);
Assert
.
assertEquals
(
"jtag"
,
columnName
);
Assert
.
assertEquals
(
"JSON"
,
metaData
.
getColumnTypeName
(
1
));
resultSet
.
next
();
String
string
=
resultSet
.
getString
(
1
);
Assert
.
assertEquals
(
jsonTag
,
string
);
resultSet
.
close
();
resultSet
=
statement
.
executeQuery
(
"select jtag->'tag2' from batch_test"
);
resultSet
.
next
();
long
l
=
resultSet
.
getLong
(
1
);
Assert
.
assertEquals
(
5
,
l
);
resultSet
.
close
();
}
private
void
close
(
ResultSet
resultSet
)
{
try
{
if
(
null
!=
resultSet
)
{
resultSet
.
close
();
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@BeforeClass
public
static
void
beforeClass
()
{
String
host
=
"127.0.0.1"
;
final
String
url
=
"jdbc:TAOS://"
+
host
+
":6030/?user=root&password=taosdata"
;
try
{
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_BATCH_LOAD
,
"true"
);
connection
=
DriverManager
.
getConnection
(
url
,
properties
);
statement
=
connection
.
createStatement
();
statement
.
execute
(
"drop database if exists "
+
dbName
);
statement
.
execute
(
"create database if not exists "
+
dbName
);
statement
.
execute
(
"use "
+
dbName
);
statement
.
execute
(
superSql
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@AfterClass
public
static
void
afterClass
()
{
try
{
if
(
null
!=
statement
)
{
statement
.
execute
(
"drop database "
+
dbName
);
statement
.
close
();
}
if
(
null
!=
connection
)
{
connection
.
close
();
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
src/connector/jdbc/src/test/java/com/taosdata/jdbc/block/TSDBBlockResultSetTest.java
0 → 100644
浏览文件 @
63f5190d
package
com.taosdata.jdbc.block
;
import
com.google.common.primitives.Ints
;
import
com.google.common.primitives.Longs
;
import
com.google.common.primitives.Shorts
;
import
com.taosdata.jdbc.TSDBDriver
;
import
com.taosdata.jdbc.TSDBResultSet
;
import
org.junit.AfterClass
;
import
org.junit.Assert
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.io.InputStream
;
import
java.io.Reader
;
import
java.math.BigDecimal
;
import
java.sql.*
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Arrays
;
import
java.util.Properties
;
public
class
TSDBBlockResultSetTest
{
private
static
final
String
host
=
"127.0.0.1"
;
private
static
Connection
conn
;
private
static
Statement
stmt
;
private
static
ResultSet
rs
;
@Test
public
void
wasNull
()
throws
SQLException
{
Assert
.
assertFalse
(
rs
.
wasNull
());
}
@Test
public
void
getString
()
throws
SQLException
{
String
f10
=
rs
.
getString
(
"f10"
);
Assert
.
assertEquals
(
"涛思数据"
,
f10
);
f10
=
rs
.
getString
(
10
);
Assert
.
assertEquals
(
"涛思数据"
,
f10
);
}
@Test
public
void
getBoolean
()
throws
SQLException
{
Boolean
f9
=
rs
.
getBoolean
(
"f9"
);
Assert
.
assertEquals
(
true
,
f9
);
f9
=
rs
.
getBoolean
(
9
);
Assert
.
assertEquals
(
true
,
f9
);
}
@Test
public
void
getByte
()
throws
SQLException
{
byte
f8
=
rs
.
getByte
(
"f8"
);
Assert
.
assertEquals
(
10
,
f8
);
f8
=
rs
.
getByte
(
8
);
Assert
.
assertEquals
(
10
,
f8
);
}
@Test
public
void
getShort
()
throws
SQLException
{
short
f7
=
rs
.
getShort
(
"f7"
);
Assert
.
assertEquals
(
10
,
f7
);
f7
=
rs
.
getShort
(
7
);
Assert
.
assertEquals
(
10
,
f7
);
}
@Test
public
void
getInt
()
throws
SQLException
{
int
f2
=
rs
.
getInt
(
"f2"
);
Assert
.
assertEquals
(
1
,
f2
);
f2
=
rs
.
getInt
(
2
);
Assert
.
assertEquals
(
1
,
f2
);
}
@Test
public
void
getLong
()
throws
SQLException
{
long
f3
=
rs
.
getLong
(
"f3"
);
Assert
.
assertEquals
(
100
,
f3
);
f3
=
rs
.
getLong
(
3
);
Assert
.
assertEquals
(
100
,
f3
);
}
@Test
public
void
getFloat
()
throws
SQLException
{
float
f4
=
rs
.
getFloat
(
"f4"
);
Assert
.
assertEquals
(
3.1415f
,
f4
,
0
f
);
f4
=
rs
.
getFloat
(
4
);
Assert
.
assertEquals
(
3.1415f
,
f4
,
0
f
);
}
@Test
public
void
getDouble
()
throws
SQLException
{
double
f5
=
rs
.
getDouble
(
"f5"
);
Assert
.
assertEquals
(
3.1415926
,
f5
,
0.0
);
f5
=
rs
.
getDouble
(
5
);
Assert
.
assertEquals
(
3.1415926
,
f5
,
0.0
);
}
@Test
public
void
getBigDecimal
()
throws
SQLException
{
BigDecimal
f1
=
rs
.
getBigDecimal
(
"f1"
);
Assert
.
assertEquals
(
1609430400000L
,
f1
.
longValue
());
BigDecimal
f2
=
rs
.
getBigDecimal
(
"f2"
);
Assert
.
assertEquals
(
1
,
f2
.
intValue
());
BigDecimal
f3
=
rs
.
getBigDecimal
(
"f3"
);
Assert
.
assertEquals
(
100L
,
f3
.
longValue
());
BigDecimal
f4
=
rs
.
getBigDecimal
(
"f4"
);
Assert
.
assertEquals
(
3.1415f
,
f4
.
floatValue
(),
0.00000f
);
BigDecimal
f5
=
rs
.
getBigDecimal
(
"f5"
);
Assert
.
assertEquals
(
3.1415926
,
f5
.
doubleValue
(),
0.0000000
);
BigDecimal
f7
=
rs
.
getBigDecimal
(
"f7"
);
Assert
.
assertEquals
(
10
,
f7
.
intValue
());
BigDecimal
f8
=
rs
.
getBigDecimal
(
"f8"
);
Assert
.
assertEquals
(
10
,
f8
.
intValue
());
}
@Test
public
void
getBytes
()
throws
SQLException
{
byte
[]
f1
=
rs
.
getBytes
(
"f1"
);
Assert
.
assertEquals
(
"2021-01-01 00:00:00.0"
,
new
String
(
f1
));
byte
[]
f2
=
rs
.
getBytes
(
"f2"
);
Assert
.
assertEquals
(
1
,
Ints
.
fromByteArray
(
f2
));
byte
[]
f3
=
rs
.
getBytes
(
"f3"
);
Assert
.
assertEquals
(
100L
,
Longs
.
fromByteArray
(
f3
));
byte
[]
f4
=
rs
.
getBytes
(
"f4"
);
Assert
.
assertEquals
(
3.1415f
,
Float
.
parseFloat
(
new
String
(
f4
)),
0.000000f
);
byte
[]
f5
=
rs
.
getBytes
(
"f5"
);
Assert
.
assertEquals
(
3.1415926
,
Double
.
parseDouble
(
new
String
(
f5
)),
0.000000f
);
byte
[]
f6
=
rs
.
getBytes
(
"f6"
);
Assert
.
assertTrue
(
Arrays
.
equals
(
"abc"
.
getBytes
(),
f6
));
byte
[]
f7
=
rs
.
getBytes
(
"f7"
);
Assert
.
assertEquals
((
short
)
10
,
Shorts
.
fromByteArray
(
f7
));
byte
[]
f8
=
rs
.
getBytes
(
"f8"
);
Assert
.
assertEquals
(
1
,
f8
.
length
);
Assert
.
assertEquals
((
byte
)
10
,
f8
[
0
]);
byte
[]
f9
=
rs
.
getBytes
(
"f9"
);
Assert
.
assertEquals
(
"true"
,
new
String
(
f9
));
byte
[]
f10
=
rs
.
getBytes
(
"f10"
);
Assert
.
assertEquals
(
"涛思数据"
,
new
String
(
f10
));
}
@Test
public
void
getDate
()
throws
SQLException
,
ParseException
{
Date
f1
=
rs
.
getDate
(
"f1"
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
Assert
.
assertEquals
(
sdf
.
parse
(
"2021-01-01"
),
f1
);
}
@Test
public
void
getTime
()
throws
SQLException
{
Time
f1
=
rs
.
getTime
(
"f1"
);
Assert
.
assertNotNull
(
f1
);
Assert
.
assertEquals
(
"00:00:00"
,
f1
.
toString
());
}
@Test
public
void
getTimestamp
()
throws
SQLException
{
Timestamp
f1
=
rs
.
getTimestamp
(
"f1"
);
Assert
.
assertEquals
(
"2021-01-01 00:00:00.0"
,
f1
.
toString
());
f1
=
rs
.
getTimestamp
(
1
);
Assert
.
assertEquals
(
"2021-01-01 00:00:00.0"
,
f1
.
toString
());
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getAsciiStream
()
throws
SQLException
{
rs
.
getAsciiStream
(
"f1"
);
}
@SuppressWarnings
(
"deprecation"
)
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getUnicodeStream
()
throws
SQLException
{
rs
.
getUnicodeStream
(
"f1"
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getBinaryStream
()
throws
SQLException
{
rs
.
getBinaryStream
(
"f1"
);
}
@Test
public
void
getWarnings
()
throws
SQLException
{
Assert
.
assertNull
(
rs
.
getWarnings
());
}
@Test
public
void
clearWarnings
()
throws
SQLException
{
rs
.
clearWarnings
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getCursorName
()
throws
SQLException
{
rs
.
getCursorName
();
}
@Test
public
void
getMetaData
()
throws
SQLException
{
ResultSetMetaData
meta
=
rs
.
getMetaData
();
Assert
.
assertNotNull
(
meta
);
}
@Test
public
void
getObject
()
throws
SQLException
,
ParseException
{
Object
f1
=
rs
.
getObject
(
"f1"
);
Assert
.
assertEquals
(
Timestamp
.
class
,
f1
.
getClass
());
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd hh:mm:ss.sss"
);
java
.
util
.
Date
date
=
sdf
.
parse
(
"2021-01-01 00:00:00.000"
);
Assert
.
assertEquals
(
new
Timestamp
(
date
.
getTime
()),
f1
);
Object
f2
=
rs
.
getObject
(
"f2"
);
Assert
.
assertEquals
(
Integer
.
class
,
f2
.
getClass
());
Assert
.
assertEquals
(
1
,
f2
);
Object
f3
=
rs
.
getObject
(
"f3"
);
Assert
.
assertEquals
(
Long
.
class
,
f3
.
getClass
());
Assert
.
assertEquals
(
100L
,
f3
);
Object
f4
=
rs
.
getObject
(
"f4"
);
Assert
.
assertEquals
(
Float
.
class
,
f4
.
getClass
());
Assert
.
assertEquals
(
3.1415f
,
f4
);
Object
f5
=
rs
.
getObject
(
"f5"
);
Assert
.
assertEquals
(
Double
.
class
,
f5
.
getClass
());
Assert
.
assertEquals
(
3.1415926
,
f5
);
Object
f6
=
rs
.
getObject
(
"f6"
);
Assert
.
assertEquals
(
byte
[].
class
,
f6
.
getClass
());
Assert
.
assertEquals
(
"abc"
,
new
String
((
byte
[])
f6
));
Object
f7
=
rs
.
getObject
(
"f7"
);
Assert
.
assertEquals
(
Short
.
class
,
f7
.
getClass
());
Assert
.
assertEquals
((
short
)
10
,
f7
);
Object
f8
=
rs
.
getObject
(
"f8"
);
Assert
.
assertEquals
(
Byte
.
class
,
f8
.
getClass
());
Assert
.
assertEquals
((
byte
)
10
,
f8
);
Object
f9
=
rs
.
getObject
(
"f9"
);
Assert
.
assertEquals
(
Boolean
.
class
,
f9
.
getClass
());
Assert
.
assertEquals
(
true
,
f9
);
Object
f10
=
rs
.
getObject
(
"f10"
);
Assert
.
assertEquals
(
String
.
class
,
f10
.
getClass
());
Assert
.
assertEquals
(
"涛思数据"
,
f10
);
}
@Test
(
expected
=
SQLException
.
class
)
public
void
findColumn
()
throws
SQLException
{
int
columnIndex
=
rs
.
findColumn
(
"f1"
);
Assert
.
assertEquals
(
1
,
columnIndex
);
columnIndex
=
rs
.
findColumn
(
"f2"
);
Assert
.
assertEquals
(
2
,
columnIndex
);
columnIndex
=
rs
.
findColumn
(
"f3"
);
Assert
.
assertEquals
(
3
,
columnIndex
);
columnIndex
=
rs
.
findColumn
(
"f4"
);
Assert
.
assertEquals
(
4
,
columnIndex
);
columnIndex
=
rs
.
findColumn
(
"f5"
);
Assert
.
assertEquals
(
5
,
columnIndex
);
columnIndex
=
rs
.
findColumn
(
"f6"
);
Assert
.
assertEquals
(
6
,
columnIndex
);
columnIndex
=
rs
.
findColumn
(
"f7"
);
Assert
.
assertEquals
(
7
,
columnIndex
);
columnIndex
=
rs
.
findColumn
(
"f8"
);
Assert
.
assertEquals
(
8
,
columnIndex
);
columnIndex
=
rs
.
findColumn
(
"f9"
);
Assert
.
assertEquals
(
9
,
columnIndex
);
columnIndex
=
rs
.
findColumn
(
"f10"
);
Assert
.
assertEquals
(
10
,
columnIndex
);
rs
.
findColumn
(
"f11"
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getCharacterStream
()
throws
SQLException
{
rs
.
getCharacterStream
(
1
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
isBeforeFirst
()
throws
SQLException
{
rs
.
isBeforeFirst
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
isAfterLast
()
throws
SQLException
{
rs
.
isAfterLast
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
isFirst
()
throws
SQLException
{
rs
.
isFirst
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
isLast
()
throws
SQLException
{
rs
.
isLast
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
beforeFirst
()
throws
SQLException
{
rs
.
beforeFirst
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
afterLast
()
throws
SQLException
{
rs
.
afterLast
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
first
()
throws
SQLException
{
rs
.
first
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
last
()
throws
SQLException
{
rs
.
last
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getRow
()
throws
SQLException
{
rs
.
getRow
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
absolute
()
throws
SQLException
{
rs
.
absolute
(-
1
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
relative
()
throws
SQLException
{
rs
.
relative
(-
1
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
previous
()
throws
SQLException
{
rs
.
previous
();
}
@Test
public
void
setFetchDirection
()
throws
SQLException
{
rs
.
setFetchDirection
(
ResultSet
.
FETCH_FORWARD
);
Assert
.
assertEquals
(
ResultSet
.
FETCH_FORWARD
,
rs
.
getFetchDirection
());
rs
.
setFetchDirection
(
ResultSet
.
FETCH_UNKNOWN
);
Assert
.
assertEquals
(
ResultSet
.
FETCH_FORWARD
,
rs
.
getFetchDirection
());
}
@Test
public
void
getFetchDirection
()
throws
SQLException
{
Assert
.
assertEquals
(
ResultSet
.
FETCH_FORWARD
,
rs
.
getFetchDirection
());
}
@Test
public
void
setFetchSize
()
throws
SQLException
{
rs
.
setFetchSize
(
0
);
Assert
.
assertEquals
(
0
,
rs
.
getFetchSize
());
}
@Test
public
void
getFetchSize
()
throws
SQLException
{
Assert
.
assertEquals
(
0
,
rs
.
getFetchSize
());
}
@Test
public
void
getType
()
throws
SQLException
{
Assert
.
assertEquals
(
ResultSet
.
TYPE_FORWARD_ONLY
,
rs
.
getType
());
}
@Test
public
void
getConcurrency
()
throws
SQLException
{
Assert
.
assertEquals
(
ResultSet
.
CONCUR_READ_ONLY
,
rs
.
getConcurrency
());
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
rowUpdated
()
throws
SQLException
{
rs
.
rowUpdated
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
rowInserted
()
throws
SQLException
{
rs
.
rowInserted
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
rowDeleted
()
throws
SQLException
{
rs
.
rowDeleted
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateNull
()
throws
SQLException
{
rs
.
updateNull
(
"f1"
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateBoolean
()
throws
SQLException
{
rs
.
updateBoolean
(
1
,
false
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateByte
()
throws
SQLException
{
rs
.
updateByte
(
1
,
(
byte
)
0
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateShort
()
throws
SQLException
{
rs
.
updateShort
(
1
,
(
short
)
0
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateInt
()
throws
SQLException
{
rs
.
updateInt
(
1
,
1
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateLong
()
throws
SQLException
{
rs
.
updateLong
(
1
,
1L
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateFloat
()
throws
SQLException
{
rs
.
updateFloat
(
1
,
1
f
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateDouble
()
throws
SQLException
{
rs
.
updateDouble
(
1
,
1.0
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateBigDecimal
()
throws
SQLException
{
rs
.
updateBigDecimal
(
1
,
new
BigDecimal
(
1
));
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateString
()
throws
SQLException
{
rs
.
updateString
(
1
,
"abc"
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateBytes
()
throws
SQLException
{
rs
.
updateBytes
(
1
,
new
byte
[]{});
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateDate
()
throws
SQLException
{
rs
.
updateDate
(
1
,
new
Date
(
System
.
currentTimeMillis
()));
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateTime
()
throws
SQLException
{
rs
.
updateTime
(
1
,
new
Time
(
System
.
currentTimeMillis
()));
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateTimestamp
()
throws
SQLException
{
rs
.
updateTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateAsciiStream
()
throws
SQLException
{
rs
.
updateAsciiStream
(
1
,
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateBinaryStream
()
throws
SQLException
{
rs
.
updateBinaryStream
(
1
,
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateCharacterStream
()
throws
SQLException
{
rs
.
updateCharacterStream
(
1
,
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateObject
()
throws
SQLException
{
rs
.
updateObject
(
1
,
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
insertRow
()
throws
SQLException
{
rs
.
insertRow
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateRow
()
throws
SQLException
{
rs
.
updateRow
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
deleteRow
()
throws
SQLException
{
rs
.
deleteRow
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
refreshRow
()
throws
SQLException
{
rs
.
refreshRow
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
cancelRowUpdates
()
throws
SQLException
{
rs
.
cancelRowUpdates
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
moveToInsertRow
()
throws
SQLException
{
rs
.
moveToInsertRow
();
}
@Test
public
void
getStatement
()
throws
SQLException
{
Statement
stmt
=
rs
.
getStatement
();
Assert
.
assertNotNull
(
stmt
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
moveToCurrentRow
()
throws
SQLException
{
rs
.
moveToCurrentRow
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getRef
()
throws
SQLException
{
rs
.
getRef
(
1
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getBlob
()
throws
SQLException
{
rs
.
getBlob
(
"f1"
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getClob
()
throws
SQLException
{
rs
.
getClob
(
"f1"
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getArray
()
throws
SQLException
{
rs
.
getArray
(
"f1"
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getURL
()
throws
SQLException
{
rs
.
getURL
(
"f1"
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateRef
()
throws
SQLException
{
rs
.
updateRef
(
"f1"
,
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateBlob
()
throws
SQLException
{
rs
.
updateBlob
(
1
,
(
InputStream
)
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateClob
()
throws
SQLException
{
rs
.
updateClob
(
1
,
(
Reader
)
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateArray
()
throws
SQLException
{
rs
.
updateArray
(
1
,
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getRowId
()
throws
SQLException
{
rs
.
getRowId
(
"f1"
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateRowId
()
throws
SQLException
{
rs
.
updateRowId
(
1
,
null
);
}
@Test
public
void
getHoldability
()
throws
SQLException
{
Assert
.
assertEquals
(
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
,
rs
.
getHoldability
());
}
@Test
public
void
isClosed
()
throws
SQLException
{
Assert
.
assertFalse
(
rs
.
isClosed
());
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateNString
()
throws
SQLException
{
rs
.
updateNString
(
1
,
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateNClob
()
throws
SQLException
{
rs
.
updateNClob
(
1
,
(
Reader
)
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getNClob
()
throws
SQLException
{
rs
.
getNClob
(
"f1"
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getSQLXML
()
throws
SQLException
{
rs
.
getSQLXML
(
"f1"
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateSQLXML
()
throws
SQLException
{
rs
.
updateSQLXML
(
1
,
null
);
}
@Test
public
void
getNString
()
throws
SQLException
{
String
f10
=
rs
.
getNString
(
"f10"
);
Assert
.
assertEquals
(
"涛思数据"
,
f10
);
f10
=
rs
.
getNString
(
10
);
Assert
.
assertEquals
(
"涛思数据"
,
f10
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getNCharacterStream
()
throws
SQLException
{
rs
.
getNCharacterStream
(
"f1"
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateNCharacterStream
()
throws
SQLException
{
rs
.
updateNCharacterStream
(
1
,
null
);
}
@Test
public
void
unwrap
()
throws
SQLException
{
TSDBResultSet
unwrap
=
rs
.
unwrap
(
TSDBResultSet
.
class
);
Assert
.
assertNotNull
(
unwrap
);
}
@Test
public
void
isWrapperFor
()
throws
SQLException
{
Assert
.
assertTrue
(
rs
.
isWrapperFor
(
TSDBResultSet
.
class
));
}
@BeforeClass
public
static
void
beforeClass
()
{
try
{
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_BATCH_LOAD
,
"true"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":6030/?user=root&password=taosdata"
,
properties
);
stmt
=
conn
.
createStatement
();
stmt
.
execute
(
"create database if not exists restful_test"
);
stmt
.
execute
(
"use restful_test"
);
stmt
.
execute
(
"drop table if exists weather"
);
stmt
.
execute
(
"create table if not exists weather(f1 timestamp, f2 int, f3 bigint, f4 float, f5 double, f6 binary(64), f7 smallint, f8 tinyint, f9 bool, f10 nchar(64))"
);
stmt
.
execute
(
"insert into restful_test.weather values('2021-01-01 00:00:00.000', 1, 100, 3.1415, 3.1415926, 'abc', 10, 10, true, '涛思数据')"
);
rs
=
stmt
.
executeQuery
(
"select * from restful_test.weather"
);
rs
.
next
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@AfterClass
public
static
void
afterClass
()
{
try
{
if
(
rs
!=
null
)
rs
.
close
();
if
(
stmt
!=
null
)
stmt
.
close
();
if
(
conn
!=
null
)
{
Statement
statement
=
conn
.
createStatement
();
statement
.
execute
(
"drop database if exists restful_test"
);
statement
.
close
();
conn
.
close
();
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录