提交 68c14bb6 编写于 作者: P plum-lihui

Merge branch 'develop' of https://github.com/taosdata/TDengine into develop

package com.taosdata.jdbc; package com.taosdata.jdbc;
import com.google.common.collect.Lists; import com.taosdata.jdbc.annotation.CatalogRunner;
import org.checkerframework.checker.units.qual.A; import com.taosdata.jdbc.annotation.Description;
import com.taosdata.jdbc.annotation.TestTarget;
import org.junit.*; import org.junit.*;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
import java.sql.*; import java.sql.*;
import java.util.List;
/**
* test json tag
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
@RunWith(CatalogRunner.class)
@TestTarget(alias = "JsonTag", author = "huolibo", version = "2.0.36")
public class JsonTagTest { public class JsonTagTest {
private static String dbname = "json_tag_test"; private static final String dbName = "json_tag_test";
private static Connection connection; private static Connection connection;
private static Statement statement; 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 superSql = "create table if not exists jsons1(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)";
...@@ -74,6 +74,7 @@ public class JsonTagTest { ...@@ -74,6 +74,7 @@ public class JsonTagTest {
}; };
@Test @Test
@Description("insert json tag")
public void case01_InsertTest() throws SQLException { public void case01_InsertTest() throws SQLException {
for (String sql : sql) { for (String sql : sql) {
statement.execute(sql); statement.execute(sql);
...@@ -87,7 +88,8 @@ public class JsonTagTest { ...@@ -87,7 +88,8 @@ public class JsonTagTest {
} }
@Test @Test
public void case02_InvalidJsonInsertTest() { @Description("error json tag insert")
public void case02_ErrorJsonInsertTest() {
int count = 0; int count = 0;
for (String sql : errorJsonInsertSql) { for (String sql : errorJsonInsertSql) {
try { try {
...@@ -99,59 +101,62 @@ public class JsonTagTest { ...@@ -99,59 +101,62 @@ public class JsonTagTest {
Assert.assertEquals(errorJsonInsertSql.length, count); Assert.assertEquals(errorJsonInsertSql.length, count);
} }
// test invalidate json key, key must can be printed assic char
@Test(expected = SQLException.class) @Test(expected = SQLException.class)
@Description("exception will throw when json value is array")
public void case02_ArrayErrorTest() throws SQLException { public void case02_ArrayErrorTest() throws SQLException {
statement.execute("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"tag1\":[1,true]}')"); statement.execute("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"tag1\":[1,true]}')");
} }
@Test(expected = SQLException.class) @Test(expected = SQLException.class)
public void case02_EmptyKeyErrorTest() throws SQLException { @Description("exception will throw when json value is empty")
statement.execute("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"\":\"fff\"}')");
}
@Test(expected = SQLException.class)
public void case02_EmptyValueErrorTest() throws SQLException { public void case02_EmptyValueErrorTest() throws SQLException {
statement.execute("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"tag1\":{}}')"); statement.execute("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"tag1\":{}}')");
} }
@Test(expected = SQLException.class) @Test(expected = SQLException.class)
@Description("exception will throw when json key is not ASCII")
public void case02_AbnormalKeyErrorTest1() throws SQLException { public void case02_AbnormalKeyErrorTest1() throws SQLException {
statement.execute("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"。loc\":\"fff\"}')"); statement.execute("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"。loc\":\"fff\"}')");
} }
@Test(expected = SQLException.class) @Test(expected = SQLException.class)
@Description("exception will throw when json key is '\\t'")
public void case02_AbnormalKeyErrorTest2() throws SQLException { public void case02_AbnormalKeyErrorTest2() throws SQLException {
statement.execute("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"\t\":\"fff\"}')"); statement.execute("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"\t\":\"fff\"}')");
} }
@Test(expected = SQLException.class) @Test(expected = SQLException.class)
@Description("exception will throw when json key is chinese")
public void case02_AbnormalKeyErrorTest3() throws SQLException { public void case02_AbnormalKeyErrorTest3() throws SQLException {
statement.execute("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"试试\":\"fff\"}')"); statement.execute("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"试试\":\"fff\"}')");
} }
@Test @Test
@Description("alter json tag")
public void case03_AlterTag() throws SQLException { public void case03_AlterTag() throws SQLException {
statement.execute("ALTER TABLE jsons1_1 SET TAG jtag='{\"tag1\":\"femail\",\"tag2\":35,\"tag3\":true}'"); statement.execute("ALTER TABLE jsons1_1 SET TAG jtag='{\"tag1\":\"femail\",\"tag2\":35,\"tag3\":true}'");
} }
@Test(expected = SQLException.class) @Test(expected = SQLException.class)
@Description("exception will throw when add json tag")
public void case03_AddTagErrorTest() throws SQLException { public void case03_AddTagErrorTest() throws SQLException {
statement.execute("ALTER STABLE jsons1 add tag tag2 nchar(20)"); statement.execute("ALTER STABLE jsons1 add tag tag2 nchar(20)");
} }
@Test(expected = SQLException.class) @Test(expected = SQLException.class)
@Description("exception will throw when delete json tag")
public void case03_dropTagErrorTest() throws SQLException { public void case03_dropTagErrorTest() throws SQLException {
statement.execute("ALTER STABLE jsons1 drop tag jtag"); statement.execute("ALTER STABLE jsons1 drop tag jtag");
} }
@Test(expected = SQLException.class) @Test(expected = SQLException.class)
@Description("exception will throw when set some json tag value")
public void case03_AlterTagErrorTest() throws SQLException { public void case03_AlterTagErrorTest() throws SQLException {
statement.execute("ALTER TABLE jsons1_1 SET TAG jtag=4"); statement.execute("ALTER TABLE jsons1_1 SET TAG jtag=4");
} }
// test error syntax
@Test @Test
@Description("exception will throw when select syntax error")
public void case04_SelectErrorTest() { public void case04_SelectErrorTest() {
int count = 0; int count = 0;
for (String sql : errorSelectSql) { for (String sql : errorSelectSql) {
...@@ -164,8 +169,8 @@ public class JsonTagTest { ...@@ -164,8 +169,8 @@ public class JsonTagTest {
Assert.assertEquals(errorSelectSql.length, count); Assert.assertEquals(errorSelectSql.length, count);
} }
// test select normal column
@Test @Test
@Description("normal select stable")
public void case04_select01() throws SQLException { public void case04_select01() throws SQLException {
ResultSet resultSet = statement.executeQuery("select dataint from jsons1"); ResultSet resultSet = statement.executeQuery("select dataint from jsons1");
int count = 0; int count = 0;
...@@ -176,8 +181,8 @@ public class JsonTagTest { ...@@ -176,8 +181,8 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// test select json tag
@Test @Test
@Description("select all column from stable")
public void case04_select02() throws SQLException { public void case04_select02() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1"); ResultSet resultSet = statement.executeQuery("select * from jsons1");
int count = 0; int count = 0;
...@@ -189,6 +194,7 @@ public class JsonTagTest { ...@@ -189,6 +194,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("select json tag from stable")
public void case04_select03() throws SQLException { public void case04_select03() throws SQLException {
ResultSet resultSet = statement.executeQuery("select jtag from jsons1"); ResultSet resultSet = statement.executeQuery("select jtag from jsons1");
int count = 0; int count = 0;
...@@ -200,6 +206,7 @@ public class JsonTagTest { ...@@ -200,6 +206,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition tag is null")
public void case04_select04() throws SQLException { public void case04_select04() throws SQLException {
ResultSet resultSet = statement.executeQuery("select jtag from jsons1 where jtag is null"); ResultSet resultSet = statement.executeQuery("select jtag from jsons1 where jtag is null");
int count = 0; int count = 0;
...@@ -211,6 +218,7 @@ public class JsonTagTest { ...@@ -211,6 +218,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition tag is not null")
public void case04_select05() throws SQLException { public void case04_select05() throws SQLException {
ResultSet resultSet = statement.executeQuery("select jtag from jsons1 where jtag is not null"); ResultSet resultSet = statement.executeQuery("select jtag from jsons1 where jtag is not null");
int count = 0; int count = 0;
...@@ -222,6 +230,7 @@ public class JsonTagTest { ...@@ -222,6 +230,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("select json tag")
public void case04_select06() throws SQLException { public void case04_select06() throws SQLException {
ResultSet resultSet = statement.executeQuery("select jtag from jsons1_8"); ResultSet resultSet = statement.executeQuery("select jtag from jsons1_8");
resultSet.next(); resultSet.next();
...@@ -231,6 +240,7 @@ public class JsonTagTest { ...@@ -231,6 +240,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("select json tag")
public void case04_select07() throws SQLException { public void case04_select07() throws SQLException {
ResultSet resultSet = statement.executeQuery("select jtag from jsons1_1"); ResultSet resultSet = statement.executeQuery("select jtag from jsons1_1");
resultSet.next(); resultSet.next();
...@@ -239,8 +249,8 @@ public class JsonTagTest { ...@@ -239,8 +249,8 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// test jtag is NULL
@Test @Test
@Description("select not exist json tag")
public void case04_select08() throws SQLException { public void case04_select08() throws SQLException {
ResultSet resultSet = statement.executeQuery("select jtag from jsons1_9"); ResultSet resultSet = statement.executeQuery("select jtag from jsons1_9");
resultSet.next(); resultSet.next();
...@@ -249,8 +259,8 @@ public class JsonTagTest { ...@@ -249,8 +259,8 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// test select json tag->'key', value is string
@Test @Test
@Description("select a json tag")
public void case04_select09() throws SQLException { public void case04_select09() throws SQLException {
ResultSet resultSet = statement.executeQuery("select jtag->'tag1' from jsons1_1"); ResultSet resultSet = statement.executeQuery("select jtag->'tag1' from jsons1_1");
resultSet.next(); resultSet.next();
...@@ -260,6 +270,7 @@ public class JsonTagTest { ...@@ -260,6 +270,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("select a json tag, the value is empty")
public void case04_select10() throws SQLException { public void case04_select10() throws SQLException {
ResultSet resultSet = statement.executeQuery("select jtag->'tag2' from jsons1_6"); ResultSet resultSet = statement.executeQuery("select jtag->'tag2' from jsons1_6");
resultSet.next(); resultSet.next();
...@@ -268,8 +279,8 @@ public class JsonTagTest { ...@@ -268,8 +279,8 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// test select json tag->'key', value is int
@Test @Test
@Description("select a json tag, the value is int")
public void case04_select11() throws SQLException { public void case04_select11() throws SQLException {
ResultSet resultSet = statement.executeQuery("select jtag->'tag2' from jsons1_1"); ResultSet resultSet = statement.executeQuery("select jtag->'tag2' from jsons1_1");
resultSet.next(); resultSet.next();
...@@ -278,8 +289,8 @@ public class JsonTagTest { ...@@ -278,8 +289,8 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// test select json tag->'key', value is bool
@Test @Test
@Description("select a json tag, the value is boolean")
public void case04_select12() throws SQLException { public void case04_select12() throws SQLException {
ResultSet resultSet = statement.executeQuery("select jtag->'tag3' from jsons1_1"); ResultSet resultSet = statement.executeQuery("select jtag->'tag3' from jsons1_1");
resultSet.next(); resultSet.next();
...@@ -288,8 +299,8 @@ public class JsonTagTest { ...@@ -288,8 +299,8 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// test select json tag->'key', value is null
@Test @Test
@Description("select a json tag, the value is null")
public void case04_select13() throws SQLException { public void case04_select13() throws SQLException {
ResultSet resultSet = statement.executeQuery("select jtag->'tag1' from jsons1_4"); ResultSet resultSet = statement.executeQuery("select jtag->'tag1' from jsons1_4");
resultSet.next(); resultSet.next();
...@@ -298,8 +309,8 @@ public class JsonTagTest { ...@@ -298,8 +309,8 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// test select json tag->'key', value is double
@Test @Test
@Description("select a json tag, the value is double")
public void case04_select14() throws SQLException { public void case04_select14() throws SQLException {
ResultSet resultSet = statement.executeQuery("select jtag->'tag1' from jsons1_5"); ResultSet resultSet = statement.executeQuery("select jtag->'tag1' from jsons1_5");
resultSet.next(); resultSet.next();
...@@ -308,8 +319,8 @@ public class JsonTagTest { ...@@ -308,8 +319,8 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// test select json tag->'key', key is not exist
@Test @Test
@Description("select a json tag, the key is not exist")
public void case04_select15() throws SQLException { public void case04_select15() throws SQLException {
ResultSet resultSet = statement.executeQuery("select jtag->'tag10' from jsons1_4"); ResultSet resultSet = statement.executeQuery("select jtag->'tag10' from jsons1_4");
resultSet.next(); resultSet.next();
...@@ -319,6 +330,7 @@ public class JsonTagTest { ...@@ -319,6 +330,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("select a json tag, the result number equals tables number")
public void case04_select16() throws SQLException { public void case04_select16() throws SQLException {
ResultSet resultSet = statement.executeQuery("select jtag->'tag1' from jsons1"); ResultSet resultSet = statement.executeQuery("select jtag->'tag1' from jsons1");
int count = 0; int count = 0;
...@@ -330,18 +342,7 @@ public class JsonTagTest { ...@@ -330,18 +342,7 @@ public class JsonTagTest {
} }
@Test @Test
public void case04_select17() throws SQLException { @Description("where condition '=' for string")
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);
}
// where json value is string
@Test
public void case04_select19() throws SQLException { public void case04_select19() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag2'='beijing'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag2'='beijing'");
int count = 0; int count = 0;
...@@ -353,6 +354,7 @@ public class JsonTagTest { ...@@ -353,6 +354,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("select and where conditon '=' for string")
public void case04_select20() throws SQLException { public void case04_select20() throws SQLException {
ResultSet resultSet = statement.executeQuery("select dataint,tbname,jtag->'tag1',jtag from jsons1 where jtag->'tag2'='beijing'"); ResultSet resultSet = statement.executeQuery("select dataint,tbname,jtag->'tag1',jtag from jsons1 where jtag->'tag2'='beijing'");
int count = 0; int count = 0;
...@@ -364,6 +366,7 @@ public class JsonTagTest { ...@@ -364,6 +366,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition result is null")
public void case04_select21() throws SQLException { public void case04_select21() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'='beijing'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'='beijing'");
int count = 0; int count = 0;
...@@ -375,6 +378,7 @@ public class JsonTagTest { ...@@ -375,6 +378,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition equation has chinese")
public void case04_select23() throws SQLException { public void case04_select23() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'='收到货'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'='收到货'");
int count = 0; int count = 0;
...@@ -386,6 +390,7 @@ public class JsonTagTest { ...@@ -386,6 +390,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support '>' for character")
public void case05_symbolOperation01() throws SQLException { public void case05_symbolOperation01() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag2'>'beijing'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag2'>'beijing'");
int count = 0; int count = 0;
...@@ -397,6 +402,7 @@ public class JsonTagTest { ...@@ -397,6 +402,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support '>=' for character")
public void case05_symbolOperation02() throws SQLException { public void case05_symbolOperation02() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag2'>='beijing'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag2'>='beijing'");
int count = 0; int count = 0;
...@@ -408,6 +414,7 @@ public class JsonTagTest { ...@@ -408,6 +414,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support '<' for character")
public void case05_symbolOperation03() throws SQLException { public void case05_symbolOperation03() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag2'<'beijing'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag2'<'beijing'");
int count = 0; int count = 0;
...@@ -419,6 +426,7 @@ public class JsonTagTest { ...@@ -419,6 +426,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support '<=' in character")
public void case05_symbolOperation04() throws SQLException { public void case05_symbolOperation04() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag2'<='beijing'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag2'<='beijing'");
int count = 0; int count = 0;
...@@ -430,6 +438,7 @@ public class JsonTagTest { ...@@ -430,6 +438,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support '!=' in character")
public void case05_symbolOperation05() throws SQLException { public void case05_symbolOperation05() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag2'!='beijing'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag2'!='beijing'");
int count = 0; int count = 0;
...@@ -441,6 +450,7 @@ public class JsonTagTest { ...@@ -441,6 +450,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support '=' empty")
public void case05_symbolOperation06() throws SQLException { public void case05_symbolOperation06() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag2'=''"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag2'=''");
int count = 0; int count = 0;
...@@ -453,11 +463,11 @@ public class JsonTagTest { ...@@ -453,11 +463,11 @@ public class JsonTagTest {
// where json value is int // where json value is int
@Test @Test
@Description("where condition support '=' for int")
public void case06_selectValue01() throws SQLException { public void case06_selectValue01() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=5"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=5");
int count = 0; int count = 0;
while (resultSet.next()) { while (resultSet.next()) {
System.out.println(resultSet.getString(1));
count++; count++;
} }
Assert.assertEquals(1, count); Assert.assertEquals(1, count);
...@@ -465,6 +475,7 @@ public class JsonTagTest { ...@@ -465,6 +475,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where conditional support '<' for int")
public void case06_selectValue02() throws SQLException { public void case06_selectValue02() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'<54"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'<54");
int count = 0; int count = 0;
...@@ -476,6 +487,7 @@ public class JsonTagTest { ...@@ -476,6 +487,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support '<=' for int")
public void case06_selectValue03() throws SQLException { public void case06_selectValue03() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'<=11"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'<=11");
int count = 0; int count = 0;
...@@ -487,6 +499,7 @@ public class JsonTagTest { ...@@ -487,6 +499,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where conditional support '>' for int")
public void case06_selectValue04() throws SQLException { public void case06_selectValue04() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'>4"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'>4");
int count = 0; int count = 0;
...@@ -498,6 +511,7 @@ public class JsonTagTest { ...@@ -498,6 +511,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support '>=' for int")
public void case06_selectValue05() throws SQLException { public void case06_selectValue05() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'>=5"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'>=5");
int count = 0; int count = 0;
...@@ -509,6 +523,7 @@ public class JsonTagTest { ...@@ -509,6 +523,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where conditional support '!=' for int")
public void case06_selectValue06() throws SQLException { public void case06_selectValue06() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'!=5"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'!=5");
int count = 0; int count = 0;
...@@ -520,6 +535,7 @@ public class JsonTagTest { ...@@ -520,6 +535,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where conditional support '!=' for int")
public void case06_selectValue07() throws SQLException { public void case06_selectValue07() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'!=55"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'!=55");
int count = 0; int count = 0;
...@@ -531,6 +547,7 @@ public class JsonTagTest { ...@@ -531,6 +547,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where conditional support '!=' for int and result is nothing")
public void case06_selectValue08() throws SQLException { public void case06_selectValue08() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=10"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=10");
int count = 0; int count = 0;
...@@ -541,8 +558,8 @@ public class JsonTagTest { ...@@ -541,8 +558,8 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// where json value is double
@Test @Test
@Description("where condition support '=' for double")
public void case07_selectValue01() throws SQLException { public void case07_selectValue01() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=1.232"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=1.232");
int count = 0; int count = 0;
...@@ -554,6 +571,7 @@ public class JsonTagTest { ...@@ -554,6 +571,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support '<' for double")
public void case07_doubleOperation01() throws SQLException { public void case07_doubleOperation01() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'<1.232"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'<1.232");
int count = 0; int count = 0;
...@@ -565,6 +583,7 @@ public class JsonTagTest { ...@@ -565,6 +583,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support '<=' for double")
public void case07_doubleOperation02() throws SQLException { public void case07_doubleOperation02() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'<=1.232"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'<=1.232");
int count = 0; int count = 0;
...@@ -576,6 +595,7 @@ public class JsonTagTest { ...@@ -576,6 +595,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support '>' for double")
public void case07_doubleOperation03() throws SQLException { public void case07_doubleOperation03() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'>1.23"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'>1.23");
int count = 0; int count = 0;
...@@ -587,6 +607,7 @@ public class JsonTagTest { ...@@ -587,6 +607,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support '>=' for double")
public void case07_doubleOperation04() throws SQLException { public void case07_doubleOperation04() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'>=1.232"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'>=1.232");
int count = 0; int count = 0;
...@@ -598,6 +619,7 @@ public class JsonTagTest { ...@@ -598,6 +619,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support '!=' for double")
public void case07_doubleOperation05() throws SQLException { public void case07_doubleOperation05() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'!=1.232"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'!=1.232");
int count = 0; int count = 0;
...@@ -609,6 +631,7 @@ public class JsonTagTest { ...@@ -609,6 +631,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support '!=' for double")
public void case07_doubleOperation06() throws SQLException { public void case07_doubleOperation06() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'!=3.232"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'!=3.232");
int count = 0; int count = 0;
...@@ -620,16 +643,19 @@ public class JsonTagTest { ...@@ -620,16 +643,19 @@ public class JsonTagTest {
} }
@Test(expected = SQLException.class) @Test(expected = SQLException.class)
@Description("exception will throw when denominator is zero")
public void case07_doubleOperation07() throws SQLException { public void case07_doubleOperation07() throws SQLException {
statement.executeQuery("select * from jsons1 where jtag->'tag1'/0=3"); statement.executeQuery("select * from jsons1 where jtag->'tag1'/0=3");
} }
@Test(expected = SQLException.class) @Test(expected = SQLException.class)
@Description("exception will throw when invalid operation")
public void case07_doubleOperation08() throws SQLException { public void case07_doubleOperation08() throws SQLException {
statement.executeQuery("select * from jsons1 where jtag->'tag1'/5=1"); statement.executeQuery("select * from jsons1 where jtag->'tag1'/5=1");
} }
@Test @Test
@Description("where condition support '=' for boolean")
public void case08_boolOperation01() throws SQLException { public void case08_boolOperation01() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=true"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=true");
int count = 0; int count = 0;
...@@ -641,6 +667,7 @@ public class JsonTagTest { ...@@ -641,6 +667,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support '=' for boolean")
public void case08_boolOperation02() throws SQLException { public void case08_boolOperation02() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=false"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=false");
int count = 0; int count = 0;
...@@ -652,6 +679,7 @@ public class JsonTagTest { ...@@ -652,6 +679,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support '!=' for boolean")
public void case08_boolOperation03() throws SQLException { public void case08_boolOperation03() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'!=false"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'!=false");
int count = 0; int count = 0;
...@@ -663,12 +691,13 @@ public class JsonTagTest { ...@@ -663,12 +691,13 @@ public class JsonTagTest {
} }
@Test(expected = SQLException.class) @Test(expected = SQLException.class)
@Description("exception will throw when '>' operation for boolean")
public void case08_boolOperation04() throws SQLException { public void case08_boolOperation04() throws SQLException {
statement.executeQuery("select * from jsons1 where jtag->'tag1'>false"); statement.executeQuery("select * from jsons1 where jtag->'tag1'>false");
} }
// where json value is null
@Test @Test
@Description("where conditional support '=null'")
public void case09_select01() throws SQLException { public void case09_select01() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=null"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=null");
int count = 0; int count = 0;
...@@ -680,6 +709,7 @@ public class JsonTagTest { ...@@ -680,6 +709,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where conditional support 'is null'")
public void case09_select02() throws SQLException { public void case09_select02() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag is null"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag is null");
int count = 0; int count = 0;
...@@ -691,6 +721,7 @@ public class JsonTagTest { ...@@ -691,6 +721,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support 'is not null'")
public void case09_select03() throws SQLException { public void case09_select03() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag is not null"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag is not null");
int count = 0; int count = 0;
...@@ -702,6 +733,7 @@ public class JsonTagTest { ...@@ -702,6 +733,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support one tag '='")
public void case09_select04() throws SQLException { public void case09_select04() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag_no_exist'=3"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag_no_exist'=3");
int count = 0; int count = 0;
...@@ -713,6 +745,7 @@ public class JsonTagTest { ...@@ -713,6 +745,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support one tag 'is null'")
public void case09_select05() throws SQLException { public void case09_select05() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1' is null"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1' is null");
int count = 0; int count = 0;
...@@ -724,6 +757,7 @@ public class JsonTagTest { ...@@ -724,6 +757,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support one tag 'is null'")
public void case09_select06() throws SQLException { public void case09_select06() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag4' is null"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag4' is null");
int count = 0; int count = 0;
...@@ -735,6 +769,7 @@ public class JsonTagTest { ...@@ -735,6 +769,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition support one tag 'is not null'")
public void case09_select07() throws SQLException { public void case09_select07() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag3' is not null"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag3' is not null");
int count = 0; int count = 0;
...@@ -745,8 +780,8 @@ public class JsonTagTest { ...@@ -745,8 +780,8 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// test ?
@Test @Test
@Description("contains")
public void case09_select10() throws SQLException { public void case09_select10() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag contains 'tag1'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag contains 'tag1'");
int count = 0; int count = 0;
...@@ -758,6 +793,7 @@ public class JsonTagTest { ...@@ -758,6 +793,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("contains")
public void case09_select11() throws SQLException { public void case09_select11() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag contains 'tag3'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag contains 'tag3'");
int count = 0; int count = 0;
...@@ -769,6 +805,7 @@ public class JsonTagTest { ...@@ -769,6 +805,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("contains with no exist tag")
public void case09_select12() throws SQLException { public void case09_select12() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag contains 'tag_no_exist'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag contains 'tag_no_exist'");
int count = 0; int count = 0;
...@@ -779,8 +816,8 @@ public class JsonTagTest { ...@@ -779,8 +816,8 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// test json tag in where condition with and/or
@Test @Test
@Description("where condition with and")
public void case10_selectAndOr01() throws SQLException { public void case10_selectAndOr01() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='beijing'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='beijing'");
int count = 0; int count = 0;
...@@ -792,6 +829,7 @@ public class JsonTagTest { ...@@ -792,6 +829,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition with 'or'")
public void case10_selectAndOr02() throws SQLException { public void case10_selectAndOr02() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=false or jtag->'tag2'='beijing'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=false or jtag->'tag2'='beijing'");
int count = 0; int count = 0;
...@@ -803,6 +841,7 @@ public class JsonTagTest { ...@@ -803,6 +841,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition with 'and'")
public void case10_selectAndOr03() throws SQLException { public void case10_selectAndOr03() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='shanghai'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='shanghai'");
int count = 0; int count = 0;
...@@ -814,6 +853,7 @@ public class JsonTagTest { ...@@ -814,6 +853,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition with 'or'")
public void case10_selectAndOr04() throws SQLException { public void case10_selectAndOr04() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=13 or jtag->'tag2'>35"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'=13 or jtag->'tag2'>35");
int count = 0; int count = 0;
...@@ -825,6 +865,7 @@ public class JsonTagTest { ...@@ -825,6 +865,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition with 'or' and contains")
public void case10_selectAndOr05() throws SQLException { public void case10_selectAndOr05() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1' is not null and jtag contains 'tag3'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1' is not null and jtag contains 'tag3'");
int count = 0; int count = 0;
...@@ -836,6 +877,7 @@ public class JsonTagTest { ...@@ -836,6 +877,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition with 'and' and contains")
public void case10_selectAndOr06() throws SQLException { public void case10_selectAndOr06() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'='femail' and jtag contains 'tag3'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1'='femail' and jtag contains 'tag3'");
int count = 0; int count = 0;
...@@ -846,8 +888,8 @@ public class JsonTagTest { ...@@ -846,8 +888,8 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// test with tbname/normal column
@Test @Test
@Description("test with tbname/normal column")
public void case11_selectTbName01() throws SQLException { public void case11_selectTbName01() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where tbname = 'jsons1_1'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where tbname = 'jsons1_1'");
int count = 0; int count = 0;
...@@ -859,6 +901,7 @@ public class JsonTagTest { ...@@ -859,6 +901,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("test with tbname/normal column")
public void case11_selectTbName02() throws SQLException { public void case11_selectTbName02() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3'");
int count = 0; int count = 0;
...@@ -870,6 +913,7 @@ public class JsonTagTest { ...@@ -870,6 +913,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("test with tbname/normal column")
public void case11_selectTbName03() throws SQLException { public void case11_selectTbName03() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3' and dataint=3"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3' and dataint=3");
int count = 0; int count = 0;
...@@ -881,6 +925,7 @@ public class JsonTagTest { ...@@ -881,6 +925,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("test with tbname/normal column")
public void case11_selectTbName04() throws SQLException { public void case11_selectTbName04() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3' and dataint=23"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3' and dataint=23");
int count = 0; int count = 0;
...@@ -891,8 +936,8 @@ public class JsonTagTest { ...@@ -891,8 +936,8 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// test where condition like
@Test @Test
@Description("where condition like")
public void case12_selectWhere01() throws SQLException { public void case12_selectWhere01() throws SQLException {
ResultSet resultSet = statement.executeQuery("select *,tbname from jsons1 where jtag->'tag2' like 'bei%'"); ResultSet resultSet = statement.executeQuery("select *,tbname from jsons1 where jtag->'tag2' like 'bei%'");
int count = 0; int count = 0;
...@@ -904,6 +949,7 @@ public class JsonTagTest { ...@@ -904,6 +949,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition like")
public void case12_selectWhere02() throws SQLException { 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"); ResultSet resultSet = statement.executeQuery("select *,tbname from jsons1 where jtag->'tag1' like 'fe%' and jtag->'tag2' is not null");
int count = 0; int count = 0;
...@@ -914,14 +960,14 @@ public class JsonTagTest { ...@@ -914,14 +960,14 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// test where condition in no support in
@Test(expected = SQLException.class) @Test(expected = SQLException.class)
@Description("where condition in no support in")
public void case12_selectWhere03() throws SQLException { public void case12_selectWhere03() throws SQLException {
statement.executeQuery("select * from jsons1 where jtag->'tag1' in ('beijing')"); statement.executeQuery("select * from jsons1 where jtag->'tag1' in ('beijing')");
} }
// test where condition match
@Test @Test
@Description("where condition match")
public void case12_selectWhere04() throws SQLException { public void case12_selectWhere04() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1' match 'ma'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1' match 'ma'");
int count = 0; int count = 0;
...@@ -933,6 +979,7 @@ public class JsonTagTest { ...@@ -933,6 +979,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition match")
public void case12_selectWhere05() throws SQLException { public void case12_selectWhere05() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1' match 'ma$'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1' match 'ma$'");
int count = 0; int count = 0;
...@@ -944,6 +991,7 @@ public class JsonTagTest { ...@@ -944,6 +991,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition match")
public void case12_selectWhere06() throws SQLException { public void case12_selectWhere06() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag2' match 'jing$'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag2' match 'jing$'");
int count = 0; int count = 0;
...@@ -955,6 +1003,7 @@ public class JsonTagTest { ...@@ -955,6 +1003,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("where condition match")
public void case12_selectWhere07() throws SQLException { public void case12_selectWhere07() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1' match '收到'"); ResultSet resultSet = statement.executeQuery("select * from jsons1 where jtag->'tag1' match '收到'");
int count = 0; int count = 0;
...@@ -965,13 +1014,14 @@ public class JsonTagTest { ...@@ -965,13 +1014,14 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// test distinct
@Test @Test
@Description("insert distinct")
public void case13_selectDistinct01() throws SQLException { public void case13_selectDistinct01() throws SQLException {
statement.execute("insert into jsons1_14 using jsons1 tags('{\"tag1\":\"收到货\",\"tag2\":\"\",\"tag3\":null}') values(1591062628000, 2, NULL, '你就会', 'dws')"); statement.execute("insert into jsons1_14 using jsons1 tags('{\"tag1\":\"收到货\",\"tag2\":\"\",\"tag3\":null}') values(1591062628000, 2, NULL, '你就会', 'dws')");
} }
@Test @Test
@Description("distinct json tag")
public void case13_selectDistinct02() throws SQLException { public void case13_selectDistinct02() throws SQLException {
ResultSet resultSet = statement.executeQuery("select distinct jtag->'tag1' from jsons1"); ResultSet resultSet = statement.executeQuery("select distinct jtag->'tag1' from jsons1");
int count = 0; int count = 0;
...@@ -983,6 +1033,7 @@ public class JsonTagTest { ...@@ -983,6 +1033,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("distinct json tag")
public void case13_selectDistinct03() throws SQLException { public void case13_selectDistinct03() throws SQLException {
ResultSet resultSet = statement.executeQuery("select distinct jtag from jsons1"); ResultSet resultSet = statement.executeQuery("select distinct jtag from jsons1");
int count = 0; int count = 0;
...@@ -993,13 +1044,14 @@ public class JsonTagTest { ...@@ -993,13 +1044,14 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// test dumplicate key with normal colomn
@Test @Test
@Description("insert json tag")
public void case14_selectDump01() throws SQLException { 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', \"你就会\")"); statement.execute("INSERT INTO jsons1_15 using jsons1 tags('{\"tbname\":\"tt\",\"databool\":true,\"datastr\":\"是是是\"}') values(1591060828000, 4, false, 'jjsf', \"你就会\")");
} }
@Test @Test
@Description("test duplicate key with normal column")
public void case14_selectDump02() throws SQLException { public void case14_selectDump02() throws SQLException {
ResultSet resultSet = statement.executeQuery("select *,tbname,jtag from jsons1 where jtag->'datastr' match '是' and datastr match 'js'"); ResultSet resultSet = statement.executeQuery("select *,tbname,jtag from jsons1 where jtag->'datastr' match '是' and datastr match 'js'");
int count = 0; int count = 0;
...@@ -1011,6 +1063,7 @@ public class JsonTagTest { ...@@ -1011,6 +1063,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("test duplicate key with normal column")
public void case14_selectDump03() throws SQLException { public void case14_selectDump03() throws SQLException {
ResultSet resultSet = statement.executeQuery("select tbname,jtag->'tbname' from jsons1 where jtag->'tbname'='tt' and tbname='jsons1_14'"); ResultSet resultSet = statement.executeQuery("select tbname,jtag->'tbname' from jsons1 where jtag->'tbname'='tt' and tbname='jsons1_14'");
int count = 0; int count = 0;
...@@ -1021,8 +1074,8 @@ public class JsonTagTest { ...@@ -1021,8 +1074,8 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// test join
@Test @Test
@Description("insert json tag for join test")
public void case15_selectJoin01() throws SQLException { 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("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_1 using jsons2 tags('{\"tag1\":\"fff\",\"tag2\":5, \"tag3\":true}') values(1591060618000, 2, false, 'json2', '你是2')");
...@@ -1033,17 +1086,17 @@ public class JsonTagTest { ...@@ -1033,17 +1086,17 @@ public class JsonTagTest {
statement.execute("insert into jsons3_2 using jsons3 tags('{\"tag1\":5,\"tag2\":\"beijing\"}') values (1591060638000, 2, true, 'json3', 'sss')"); statement.execute("insert into jsons3_2 using jsons3 tags('{\"tag1\":5,\"tag2\":\"beijing\"}') values (1591060638000, 2, true, 'json3', 'sss')");
} }
// TODO check result
@Test @Test
@Description("select json tag from join")
public void case15_selectJoin02() throws SQLException { 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 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); close(resultSet);
} }
// test group by & order by json tag
// TODO check other result
@Test @Test
@Description("group by and order by json tag desc")
public void case16_selectGroupOrder01() throws SQLException { public void case16_selectGroupOrder01() throws SQLException {
ResultSet resultSet = statement.executeQuery("select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag1' desc"); ResultSet resultSet = statement.executeQuery("select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag1' desc");
int count = 0; int count = 0;
...@@ -1055,6 +1108,7 @@ public class JsonTagTest { ...@@ -1055,6 +1108,7 @@ public class JsonTagTest {
} }
@Test @Test
@Description("group by and order by json tag asc")
public void case16_selectGroupOrder02() throws SQLException { public void case16_selectGroupOrder02() throws SQLException {
ResultSet resultSet = statement.executeQuery("select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag1' asc"); ResultSet resultSet = statement.executeQuery("select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag1' asc");
int count = 0; int count = 0;
...@@ -1065,9 +1119,8 @@ public class JsonTagTest { ...@@ -1065,9 +1119,8 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// test stddev with group by json tag
// TODO check result
@Test @Test
@Description("stddev with group by json tag")
public void case17_selectStddev01() throws SQLException { public void case17_selectStddev01() throws SQLException {
ResultSet resultSet = statement.executeQuery("select stddev(dataint) from jsons1 group by jtag->'tag1'"); ResultSet resultSet = statement.executeQuery("select stddev(dataint) from jsons1 group by jtag->'tag1'");
String s = ""; String s = "";
...@@ -1082,8 +1135,8 @@ public class JsonTagTest { ...@@ -1082,8 +1135,8 @@ public class JsonTagTest {
close(resultSet); close(resultSet);
} }
// subquery with json tag
@Test @Test
@Description("subquery json tag")
public void case18_selectSubquery01() throws SQLException { public void case18_selectSubquery01() throws SQLException {
ResultSet resultSet = statement.executeQuery("select * from (select jtag, dataint from jsons1)"); ResultSet resultSet = statement.executeQuery("select * from (select jtag, dataint from jsons1)");
int count = 0; int count = 0;
...@@ -1095,8 +1148,14 @@ public class JsonTagTest { ...@@ -1095,8 +1148,14 @@ public class JsonTagTest {
} }
@Test @Test
@Description("subquery some json tags")
public void case18_selectSubquery02() throws SQLException { public void case18_selectSubquery02() throws SQLException {
ResultSet resultSet = statement.executeQuery("select jtag->'tag1' from (select jtag->'tag1', dataint from jsons1)"); 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; int count = 0;
while (resultSet.next()) { while (resultSet.next()) {
count++; count++;
...@@ -1106,15 +1165,7 @@ public class JsonTagTest { ...@@ -1106,15 +1165,7 @@ public class JsonTagTest {
} }
@Test @Test
public void case18_selectSubquery03() throws SQLException { @Description("query some json tags from subquery")
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);
close(resultSet);
}
@Test
public void case18_selectSubquery04() throws SQLException { 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)"); ResultSet resultSet = statement.executeQuery("select ts,tbname,jtag->'tag1' from (select jtag->'tag1',tbname,ts from jsons1 order by ts)");
int count = 0; int count = 0;
...@@ -1142,9 +1193,9 @@ public class JsonTagTest { ...@@ -1142,9 +1193,9 @@ public class JsonTagTest {
try { try {
connection = DriverManager.getConnection(url); connection = DriverManager.getConnection(url);
statement = connection.createStatement(); statement = connection.createStatement();
statement.execute("drop database if exists " + dbname); statement.execute("drop database if exists " + dbName);
statement.execute("create database if not exists " + dbname); statement.execute("create database if not exists " + dbName);
statement.execute("use " + dbname); statement.execute("use " + dbName);
statement.execute(superSql); statement.execute(superSql);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -1155,7 +1206,7 @@ public class JsonTagTest { ...@@ -1155,7 +1206,7 @@ public class JsonTagTest {
public static void afterClass() { public static void afterClass() {
try { try {
if (null != statement) { if (null != statement) {
statement.execute("drop database " + dbname); statement.execute("drop database " + dbName);
statement.close(); statement.close();
} }
if (null != connection) { if (null != connection) {
......
...@@ -2,17 +2,23 @@ package com.taosdata.jdbc; ...@@ -2,17 +2,23 @@ package com.taosdata.jdbc;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.taosdata.jdbc.annotation.CatalogRunner;
import com.taosdata.jdbc.annotation.Description;
import com.taosdata.jdbc.annotation.TestTarget;
import com.taosdata.jdbc.enums.SchemalessProtocolType; import com.taosdata.jdbc.enums.SchemalessProtocolType;
import com.taosdata.jdbc.enums.SchemalessTimestampType; import com.taosdata.jdbc.enums.SchemalessTimestampType;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import java.sql.*; import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@RunWith(CatalogRunner.class)
@TestTarget(alias = "Schemaless",author = "huolibo", version = "2.0.36")
public class SchemalessInsertTest { public class SchemalessInsertTest {
private final String dbname = "test_schemaless_insert"; private final String dbname = "test_schemaless_insert";
private Connection conn; private Connection conn;
...@@ -23,6 +29,7 @@ public class SchemalessInsertTest { ...@@ -23,6 +29,7 @@ public class SchemalessInsertTest {
* @throws SQLException execute error * @throws SQLException execute error
*/ */
@Test @Test
@Description("line insert")
public void schemalessInsert() throws SQLException { public void schemalessInsert() throws SQLException {
// given // given
String[] lines = new String[]{ String[] lines = new String[]{
...@@ -53,6 +60,7 @@ public class SchemalessInsertTest { ...@@ -53,6 +60,7 @@ public class SchemalessInsertTest {
* @throws SQLException execute error * @throws SQLException execute error
*/ */
@Test @Test
@Description("telnet insert")
public void telnetInsert() throws SQLException { public void telnetInsert() throws SQLException {
// given // given
String[] lines = new String[]{ String[] lines = new String[]{
...@@ -87,6 +95,7 @@ public class SchemalessInsertTest { ...@@ -87,6 +95,7 @@ public class SchemalessInsertTest {
* @throws SQLException execute error * @throws SQLException execute error
*/ */
@Test @Test
@Description("json insert")
public void jsonInsert() throws SQLException { public void jsonInsert() throws SQLException {
// given // given
String json = "[\n" + String json = "[\n" +
......
package com.taosdata.jdbc.annotation;
import java.util.ArrayList;
import java.util.List;
/**
* Test class
*/
public class CatalogClass {
private String name;
private String alias;
private String author;
private String version;
private List<CatalogMethod> methods = new ArrayList<>();
private int total;
private int failure;
public void setTotal(int total) {
this.total = total;
}
public void setFailure(int failure) {
this.failure = failure;
}
public void setAuthor(String author) {
this.author = author;
}
public void setVersion(String version) {
this.version = version;
}
public void setName(String name) {
this.name = name;
}
public void setAlias(String alias) {
this.alias = alias;
}
public void setMethods(List<CatalogMethod> methods) {
this.methods = methods;
}
@Override
public String toString() {
if (methods.size() < 1)
return null;
StringBuilder sb = new StringBuilder();
sb.append("ClassName: ").append(name);
String msg = trim(alias);
if (null != msg)
sb.append("\tAlias:").append(alias);
sb.append("\tTotal:").append(total)
.append("\tFailure:").append(failure).append("\n");
for (CatalogMethod method : methods) {
sb.append("\t").append(method.getName());
sb.append("\t").append(method.isSuccess());
sb.append("\t").append(method.getMessage());
String mAuthor = trim(method.getAuthor());
if (null == mAuthor) {
sb.append("\t").append(author);
} else {
sb.append("\t").append(method.getAuthor());
}
String mVersion = trim(method.getVersion());
if (null == mVersion) {
sb.append("\t").append(version);
} else {
sb.append("\t").append(mVersion);
}
sb.append("\n");
}
return sb.toString();
}
private String trim(String s) {
if (null == s || s.trim().equals("")) {
return null;
} else {
return s.trim();
}
}
}
package com.taosdata.jdbc.annotation;
import org.junit.runner.Description;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;
import java.io.File;
import java.io.FileWriter;
import java.util.LinkedList;
public class CatalogListener extends RunListener {
public static final String CATALOG_FILE = "target/TestCaseCatalog.txt";
CatalogClass catalogClass = null;
private final LinkedList<CatalogMethod> methods = new LinkedList<>();
@Override
public void testRunStarted(Description description) throws Exception {
catalogClass = new CatalogClass();
TestTarget target = description.getAnnotation(TestTarget.class);
if (target != null) {
catalogClass.setAlias(target.alias());
catalogClass.setAuthor(target.author());
catalogClass.setVersion(target.version());
}
catalogClass.setName(getClassName(description.getClassName()));
}
private String getClassName(String name) {
if (null == name || name.trim().equals("")) {
return null;
}
name = name.trim();
int pos = name.lastIndexOf(".");
if (-1 == pos) {
return name;
}
return name.substring(pos + 1);
}
@Override
public void testRunFinished(Result result) throws Exception {
catalogClass.setMethods(methods);
catalogClass.setTotal(result.getRunCount());
catalogClass.setFailure(result.getFailureCount());
File file = new File(CATALOG_FILE);
if (!file.exists()) {
synchronized (CatalogListener.class) {
if (!file.exists()) {
file.createNewFile();
try (FileWriter writer = new FileWriter(file, true)) {
writer.write("\tName\tPass\tMessage\tAuthor\tVersion\n");
writer.write(catalogClass.toString());
}
}
}
} else {
try (FileWriter writer = new FileWriter(file, true)) {
writer.write(catalogClass.toString());
}
}
}
@Override
public void testStarted(Description description) throws Exception {
}
@Override
public void testFinished(Description description) throws Exception {
com.taosdata.jdbc.annotation.Description annotation
= description.getAnnotation(com.taosdata.jdbc.annotation.Description.class);
if (annotation != null) {
CatalogMethod method = new CatalogMethod();
method.setMessage(annotation.value());
method.setAuthor(annotation.author());
method.setVersion(annotation.version());
method.setSuccess(true);
method.setName(description.getMethodName());
methods.addLast(method);
}
}
@Override
public void testFailure(Failure failure) throws Exception {
com.taosdata.jdbc.annotation.Description annotation
= failure.getDescription().getAnnotation(com.taosdata.jdbc.annotation.Description.class);
CatalogMethod method = new CatalogMethod();
method.setMessage(annotation.value());
method.setAuthor(annotation.author());
method.setVersion(annotation.version());
method.setSuccess(false);
method.setName(failure.getDescription().getMethodName());
methods.addFirst(method);
}
@Override
public void testAssumptionFailure(Failure failure) {
}
@Override
public void testIgnored(Description description) throws Exception {
super.testIgnored(description);
}
}
\ No newline at end of file
package com.taosdata.jdbc.annotation;
/**
* Test method
*/
public class CatalogMethod {
private String name;
private boolean success;
private String message;
private String author;
private String version;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
}
package com.taosdata.jdbc.annotation;
import org.junit.internal.AssumptionViolatedException;
import org.junit.internal.runners.model.EachTestNotifier;
import org.junit.runner.notification.RunNotifier;
import org.junit.runner.notification.StoppedByUserException;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
public class CatalogRunner extends BlockJUnit4ClassRunner {
public CatalogRunner(Class<?> testClass) throws InitializationError {
super(testClass);
}
@Override
public void run(RunNotifier notifier) {
//add user-defined listener
notifier.addListener(new CatalogListener());
EachTestNotifier testNotifier = new EachTestNotifier(notifier, getDescription());
notifier.fireTestRunStarted(getDescription());
try {
Statement statement = classBlock(notifier);
statement.evaluate();
} catch (AssumptionViolatedException av) {
testNotifier.addFailedAssumption(av);
} catch (StoppedByUserException exception) {
throw exception;
} catch (Throwable e) {
testNotifier.addFailure(e);
}
}
}
\ No newline at end of file
package com.taosdata.jdbc.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface Description {
String value();
// git blame author
String author() default "";
// since which version;
String version() default "";
}
package com.taosdata.jdbc.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface TestTarget {
String alias() default "";
String author();
String version() default "";
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册