Skip to content

Commit 2e11e72

Browse files
committed
AJ-706: add test case about combine
1 parent 810a5e9 commit 2e11e72

File tree

5 files changed

+141
-2
lines changed

5 files changed

+141
-2
lines changed

test/com/xxdb/DBConnectionTest.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.stream.DoubleStream;
2626
import java.util.stream.IntStream;
2727

28+
import static com.xxdb.Prepare.*;
2829
import static com.xxdb.comm.SqlStdEnum.*;
2930
import static org.junit.Assert.*;
3031

@@ -4046,9 +4047,8 @@ public void test_tableInsert_decimal_arrayvector() throws Exception {
40464047
assertEquals("[[1.0000,3.0000,100000.0000],[-1.0000,0.0000,0.1235],[1.0000,3.0000,100000.0000],[-1.0000,0.0000,0.1235]]",res.getColumn(5).getString());
40474048
assertEquals("[[1.00000000,3.00001000,100000.00000000],[-1.00000000,0.00000000,0.12345679],[1.00000000,3.00001000,100000.00000000],[-1.00000000,0.00000000,0.12345679]]",res.getColumn(6).getString());
40484049
System.out.println(res.getColumn(0).getString());
4049-
40504050
}
4051-
4051+
40524052
@Test
40534053
public void test_tableInsert_decimal128_arrayvector() throws Exception {
40544054
DBConnection connection = new DBConnection(false, false, false);
@@ -4900,4 +4900,37 @@ public void test_exception_Function() throws IOException {
49004900
}
49014901
assertEquals(true, re.contains("Can't recognize function name C. function: C"));
49024902
}
4903+
@Test
4904+
public void test_allDateType_combine() throws IOException {
4905+
conn = new DBConnection();
4906+
conn.connect(HOST,PORT,"admin","123456");
4907+
Preparedata1(10000);
4908+
EntityBlockReader blockReader = (EntityBlockReader) conn.run("select * from data;", (ProgressListener) null,4,4,9999);
4909+
BasicTable data = (BasicTable) blockReader.read();
4910+
assertEquals(9999, data.rows());
4911+
while (blockReader.hasNext()) {
4912+
System.out.println(data.rows());
4913+
BasicTable t = (BasicTable) blockReader.read();
4914+
data = data.combine(t);
4915+
}
4916+
System.out.println(data.rows());
4917+
assertEquals(10000, data.rows());
4918+
}
4919+
4920+
@Test
4921+
public void test_allDateTyp_array_combine() throws IOException {
4922+
conn = new DBConnection();
4923+
conn.connect(HOST,PORT,"admin","123456");
4924+
Preparedata_array(100000,10);
4925+
EntityBlockReader blockReader = (EntityBlockReader) conn.run("select * from data;", (ProgressListener) null,4,4,9999);
4926+
BasicTable data = (BasicTable) blockReader.read();
4927+
assertEquals(9999, data.rows());
4928+
while (blockReader.hasNext()) {
4929+
System.out.println(data.rows());
4930+
BasicTable t = (BasicTable) blockReader.read();
4931+
data = data.combine(t);
4932+
}
4933+
System.out.println(data.rows());
4934+
assertEquals(10000, data.rows());
4935+
}
49034936
}

test/com/xxdb/Prepare.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,46 @@ public static void Preparedata(long count) throws IOException {
107107
conn.run(script);
108108
}
109109

110+
public static void Preparedata1(long count) throws IOException {
111+
String script = "login(`admin, `123456); \n" +
112+
"n="+count+";\n" +
113+
"colNames = `boolv`charv`shortv`intv`longv`doublev`floatv`datev`monthv`timev`minutev`secondv`datetimev`timestampv`nanotimev`nanotimestampv`symbolv`stringv`datehourv`uuidv`ippaddrv`int128v`blobv`pointv`complexv`decimal32v`decimal64v`decimal128v ;\n" +
114+
"colTypes=[BOOL,CHAR,SHORT,INT,LONG,DOUBLE,FLOAT,DATE,MONTH,TIME,MINUTE,SECOND,DATETIME,TIMESTAMP,NANOTIME,NANOTIMESTAMP,SYMBOL,STRING,DATEHOUR,UUID,IPADDR,INT128,BLOB,POINT,COMPLEX,DECIMAL32(2),DECIMAL64(7),DECIMAL128(18)]\n" +
115+
"share table(1:0,colNames,colTypes) as data;\n" +
116+
"boolv = bool(rand([true, false, NULL], n));\n" +
117+
"charv = char(rand(rand(-100..100, 1000) join take(char(), 4), n));\n" +
118+
"shortv = short(rand(rand(-100..100, 1000) join take(short(), 4), n));\n" +
119+
"intv = int(rand(rand(-100..100, 1000) join take(int(), 4), n));\n" +
120+
"longv = long(rand(rand(-100..100, 1000) join take(long(), 4), n));\n" +
121+
"doublev = double(rand(rand(-100..100, 1000)*0.23 join take(double(), 4), n));\n" +
122+
"floatv = float(rand(rand(-100..100, 1000)*0.23 join take(float(), 4), n));\n" +
123+
"datev = date(rand(rand(-100..100, 1000) join take(date(), 4), n));\n" +
124+
"monthv = month(rand(1967.12M+rand(-100..100, 1000) join take(month(), 4), n));\n" +
125+
"timev = time(rand(rand(0..100, 1000) join take(time(), 4), n));\n" +
126+
"minutev = minute(rand(12:13m+rand(-100..100, 1000) join take(minute(), 4), n));\n" +
127+
"secondv = second(rand(12:13:12+rand(-100..100, 1000) join take(second(), 4), n));\n" +
128+
"datetimev = datetime(rand(1969.12.23+rand(-100..100, 1000) join take(datetime(), 4), n));\n" +
129+
"timestampv = timestamp(rand(1970.01.01T00:00:00.023+rand(-100..100, 1000) join take(timestamp(), 4), n));\n" +
130+
"nanotimev = nanotime(rand(12:23:45.452623154+rand(-100..100, 1000) join take(nanotime(), 4), n));\n" +
131+
"nanotimestampv = nanotimestamp(rand(rand(-100..100, 1000) join take(nanotimestamp(), 4), n));\n" +
132+
"symbolv = rand((\"syms\"+string(rand(100, 1000))) join take(string(), 4), n);\n" +
133+
"stringv = rand((\"stringv\"+string(rand(100, 1000))) join take(string(), 4), n);\n" +
134+
"uuidv = rand(rand(uuid(), 1000) join take(uuid(), 4), n);\n" +
135+
"datehourv = datehour(rand(datehour(1969.12.31T12:45:12)+rand(-100..100, 1000) join take(datehour(), 4), n));\n" +
136+
"ippaddrv = rand(rand(ipaddr(), 1000) join take(ipaddr(), 4), n);\n" +
137+
"int128v = rand(rand(int128(), 1000) join take(int128(), 4), n);\n" +
138+
"blobv = blob(string(rand((\"blob\"+string(rand(100, 1000))) join take(\"\", 4), n)));\n" +
139+
"complexv = rand(complex(rand(100, 1000), rand(100, 1000)) join NULL, n);\n" +
140+
"pointv = rand(point(rand(100, 1000), rand(100, 1000)) join NULL, n);\n" +
141+
"decimal32v = decimal32(rand(rand(-100..100, 1000)*0.23 join take(double(), 4), n), 3);\n" +
142+
"decimal64v = decimal64(rand(rand(-100..100, 1000)*0.23 join take(double(), 4), n), 8);\n" +
143+
"decimal128v = decimal128(rand(rand(-100..100, 1000)*0.23 join take(double(), 4), n), 10);\n" +
144+
"data.append!(table(boolv, charv, shortv, intv, longv, doublev, floatv, datev, monthv, timev, minutev, secondv, datetimev, timestampv, nanotimev, nanotimestampv, symbolv, stringv, datehourv, uuidv, ippaddrv, int128v, blobv, pointv, complexv, decimal32v, decimal64v,decimal128v)) ;\n";
145+
DBConnection conn = new DBConnection();
146+
conn.connect(HOST,PORT,"admin","123456");
147+
conn.run(script);
148+
}
149+
110150
public static void Preparedata_array(long count1,long count2) throws IOException {
111151
String script1 = "login(`admin, `123456); \n"+
112152
"n="+count1+";\n" +

test/com/xxdb/data/BasicDecimal128VectorTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,4 +535,27 @@ public void test_BasicDecimal128Vector_asof() throws Exception {
535535
Scalar sc = new BasicDecimal128("1",2);
536536
assertEquals(0,tmp_128_v.asof(sc));
537537
}
538+
@Test
539+
public void test_BasicDecimal128Vector_combine() throws Exception {
540+
String[] tmp_string_v = {"0.0","-123.004128","1128.204234","100.0"};
541+
BasicDecimal128Vector tmp_128_v = new BasicDecimal128Vector(tmp_string_v,4);
542+
BasicDecimal128Vector tmp_128_v1 = new BasicDecimal128Vector(0,4);
543+
BasicDecimal128Vector tmp_128_v2 = new BasicDecimal128Vector(0,5);
544+
BigInteger[] tmp_string_v1 = {new BigInteger("17014118346046923173168730371588410")};
545+
BasicDecimal128Vector tmp_128_v3 = new BasicDecimal128Vector(tmp_string_v1,4);
546+
547+
assertEquals("[0.0000,-123.0041,1128.2042,100.0000,0.0000,-123.0041,1128.2042,100.0000]",tmp_128_v.combine(tmp_128_v).getString());
548+
assertEquals("[0.0000,-123.0041,1128.2042,100.0000]",tmp_128_v.combine(tmp_128_v1).getString());
549+
assertEquals("[0.0000,-123.0041,1128.2042,100.0000]",tmp_128_v1.combine(tmp_128_v).getString());
550+
assertEquals("[0.0000,-123.0041,1128.2042,100.0000,1701411834604692317316873037158.8410]",tmp_128_v.combine(tmp_128_v3).getString());
551+
tmp_128_v.setNull(0);
552+
assertEquals("[,-123.0041,1128.2042,100.0000,,-123.0041,1128.2042,100.0000]",tmp_128_v.combine(tmp_128_v).getString());
553+
String re = null;
554+
try{
555+
tmp_128_v.combine(tmp_128_v2);
556+
}catch(Exception ex){
557+
re = ex.getMessage();
558+
}
559+
assertEquals("The scale of the vector to be combine does not match the scale of the current vector.",re);
560+
}
538561
}

test/com/xxdb/data/BasicDecimal32VectorTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,4 +514,29 @@ public void test_BasicDecimal32Vector_asof() throws Exception {
514514
Scalar sc = new BasicDecimal32("1",2);
515515
assertEquals(0,tmp_32_v.asof(sc));
516516
}
517+
@Test
518+
public void test_BasicDecimal32Vector_combine() throws Exception {
519+
String[] tmp_string_v = {"0.0","-123.00432","132.204234","100.0"};
520+
BasicDecimal32Vector tmp_32_v = new BasicDecimal32Vector(tmp_string_v,4);
521+
BasicDecimal32Vector tmp_32_v1 = new BasicDecimal32Vector(0,4);
522+
BasicDecimal32Vector tmp_32_v2 = new BasicDecimal32Vector(0,5);
523+
BasicDecimal64Vector tmp_64_v = new BasicDecimal64Vector(0,4);
524+
525+
assertEquals("[0.0000,-123.0043,132.2042,100.0000,0.0000,-123.0043,132.2042,100.0000]",tmp_32_v.combine(tmp_32_v).getString());
526+
assertEquals("[0.0000,-123.0043,132.2042,100.0000]",tmp_32_v.combine(tmp_32_v1).getString());
527+
String re = null;
528+
try{
529+
tmp_32_v.combine(tmp_32_v2);
530+
}catch(Exception ex){
531+
re = ex.getMessage();
532+
}
533+
assertEquals("The scale of the vector to be combine does not match the scale of the current vector.",re);
534+
String re1 = null;
535+
try{
536+
tmp_32_v.combine(tmp_64_v);
537+
}catch(Exception ex){
538+
re1 = ex.getMessage();
539+
}
540+
assertEquals("com.xxdb.data.BasicDecimal64Vector cannot be cast to com.xxdb.data.BasicDecimal32Vector",re1);
541+
}
517542
}

test/com/xxdb/data/BasicDecimal64VectorTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,4 +459,22 @@ public void testBasicDecimal64Vector_getValue() throws IOException {
459459
System.out.println(Arrays.toString(re));
460460
assertEquals("[0, -1230043, 1322042, 1000000]",Arrays.toString(re));
461461
}
462+
463+
@Test
464+
public void test_BasicDecimal64Vector_combine() throws Exception {
465+
String[] tmp_string_v = {"0.0","-123.00464","164.204234","100.0"};
466+
BasicDecimal64Vector tmp_64_v = new BasicDecimal64Vector(tmp_string_v,4);
467+
BasicDecimal64Vector tmp_64_v1 = new BasicDecimal64Vector(0,4);
468+
BasicDecimal64Vector tmp_64_v2 = new BasicDecimal64Vector(0,5);
469+
470+
assertEquals("[0.0000,-123.0046,164.2042,100.0000,0.0000,-123.0046,164.2042,100.0000]",tmp_64_v.combine(tmp_64_v).getString());
471+
assertEquals("[0.0000,-123.0046,164.2042,100.0000]",tmp_64_v.combine(tmp_64_v1).getString());
472+
String re = null;
473+
try{
474+
tmp_64_v.combine(tmp_64_v2);
475+
}catch(Exception ex){
476+
re = ex.getMessage();
477+
}
478+
assertEquals("The scale of the vector to be combine does not match the scale of the current vector.",re);
479+
}
462480
}

0 commit comments

Comments
 (0)