4444import org .elasticsearch .test .ESSingleNodeTestCase ;
4545import org .junit .Test ;
4646
47+ import java .math .BigDecimal ;
4748import java .nio .ByteBuffer ;
4849import java .time .Instant ;
4950import java .time .LocalDate ;
@@ -107,7 +108,7 @@ public void testAllTypesTest() throws Exception {
107108 ensureGreen ("ks1" );
108109
109110 process (ConsistencyLevel .ONE ,
110- "CREATE TABLE ks1.natives (c1 text primary key, c2 text, c3 timestamp, c4 int, c5 bigint, c6 double, c7 float, c8 boolean, c9 blob, c10 uuid, c11 timeuuid, c12 smallint, c13 tinyint)" );
111+ "CREATE TABLE ks1.natives (c1 text primary key, c2 text, c3 timestamp, c4 int, c5 bigint, c6 double, c7 float, c8 boolean, c9 blob, c10 uuid, c11 timeuuid, c12 smallint, c13 tinyint, c14 decimal )" );
111112 assertAcked (client ().admin ().indices ()
112113 .preparePutMapping ("ks1" )
113114 .setType ("natives" )
@@ -116,7 +117,7 @@ public void testAllTypesTest() throws Exception {
116117
117118 // {"c2": "toto", "c3" : "2016-10-10", "c4": 1, "c5":44, "c6":1.0, "c7":2.22, "c8": true, "c9":"U29tZSBiaW5hcnkgYmxvYg==" }
118119 assertThat (client ().prepareIndex ("ks1" , "natives" , "1" )
119- .setSource ("{\" c2\" : \" toto\" , \" c3\" : \" 2016-10-10 \" , \" c4\" : 1, \" c5\" :44, \" c6\" :1.0, \" c7\" :2.22, \" c8\" : true, \" c9\" :\" U29tZSBiaW5hcnkgYmxvYg==\" , \" c10\" :\" ae8c9260-dd02-11e6-b9d5-bbfb41c263ba\" ,\" c11\" :\" ae8c9260-dd02-11e6-b9d5-bbfb41c263ba\" , \" c12\" :1, \" c13\" :1 }" , XContentType .JSON )
120+ .setSource ("{\" c2\" : \" toto\" , \" c3\" : \" 2016-10-10T00:00:00.000Z \" , \" c4\" : 1, \" c5\" :44, \" c6\" :1.0, \" c7\" :2.22, \" c8\" : true, \" c9\" :\" U29tZSBiaW5hcnkgYmxvYg==\" , \" c10\" :\" ae8c9260-dd02-11e6-b9d5-bbfb41c263ba\" ,\" c11\" :\" ae8c9260-dd02-11e6-b9d5-bbfb41c263ba\" , \" c12\" :1, \" c13\" :1, \" c14 \" : \" 3.1416 \" }" , XContentType .JSON )
120121 .get ().getResult (), equalTo (DocWriteResponse .Result .CREATED ));
121122 Map <String ,Object > fields = client ().prepareSearch ("ks1" ).setTypes ("natives" ).setQuery (QueryBuilders .queryStringQuery ("c2:toto" ))
122123 .get ().getHits ().getHits ()[0 ]
@@ -131,30 +132,31 @@ public void testAllTypesTest() throws Exception {
131132 assertThat (fields .get ("c9" ),equalTo ("U29tZSBiaW5hcnkgYmxvYg==" ));
132133 assertThat (fields .get ("c12" ),equalTo (1 ));
133134 assertThat (fields .get ("c13" ),equalTo (1 ));
135+ assertThat (fields .get ("c14" ),equalTo ("3.1416" ));
134136
135- process (ConsistencyLevel .ONE ,"insert into ks1.natives (c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13) VALUES ('tutu', 'titi', '2016-11-11 ', 1, 45, 1.0, 2.23, false,textAsBlob('bdb14fbe076f6b94444c660e36a400151f26fc6f'),ae8c9260-dd02-11e6-b9d5-bbfb41c263ba,ae8c9260-dd02-11e6-b9d5-bbfb41c263ba, 1, 1)" );
137+ process (ConsistencyLevel .ONE ,"insert into ks1.natives (c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14 ) VALUES ('tutu', 'titi', '2016-11-11T00:00:00.000Z ', 1, 45, 1.0, 2.23, false,textAsBlob('bdb14fbe076f6b94444c660e36a400151f26fc6f'),ae8c9260-dd02-11e6-b9d5-bbfb41c263ba,ae8c9260-dd02-11e6-b9d5-bbfb41c263ba, 1, 1, 3.1416 )" );
136138 assertThat (client ().prepareSearch ().setIndices ("ks1" ).setTypes ("natives" ).setQuery (QueryBuilders .matchAllQuery ()).get ().getHits ().getTotalHits (), equalTo (2L ));
137139
138140 fields = client ().prepareSearch ().setIndices ("ks1" ).setTypes ("natives" ).setQuery (QueryBuilders .queryStringQuery ("c5:45" )).get ().getHits ().getHits ()[0 ].getSourceAsMap ();
139-
140141 assertThat (fields .get ("c2" ), equalTo ("titi" ));
141- // assertThat(fields.get("c3"), equalTo(new SimpleDateFormat("yyyy-MM-dd").parse(" 2016-11-11").toLocaleString() ));
142+ assertThat (fields .get ("c3" ), equalTo (" 2016-11-11T00:00:00.000Z" ));
142143 assertThat (fields .get ("c4" ),equalTo (1 ));
143144 assertThat (fields .get ("c5" ),equalTo (45 ));
144145 assertThat (fields .get ("c6" ),equalTo (1.0 ));
145146 assertThat (fields .get ("c7" ),equalTo (2.23 ));
146147 assertThat (fields .get ("c8" ),equalTo (false ));
147148 assertThat (fields .get ("c12" ),equalTo (1 ));
148149 assertThat (fields .get ("c13" ),equalTo (1 ));
150+ assertThat (fields .get ("c14" ),equalTo ("3.1416" ));
149151 }
150152
151153 @ Test
152154 public void testSinglePkTypesTest () throws Exception {
153155 createIndex ("ks" );
154156 ensureGreen ("ks" );
155157
156- String [] types = new String [] { "text" ,"int" ,"smallint" ,"tinyint" ,"bigint" ,"double" ,"float" ,"boolean" ,"blob" ,"timestamp" ,"date" ,"inet" ,"uuid" };
157- Object [] values = new Object [] { "foo" , 1 , (short )1 , (byte )1 , 2L , new Double (3.14 ), new Float (3.14 ), true , ByteBuffer .wrap ("toto" .getBytes ("UTF-8" )), new Date (), (int )LocalDate .now ().toEpochDay (), InetAddresses .forString ("127.0.0.1" ), UUID .randomUUID () };
158+ String [] types = new String [] { "text" ,"int" ,"smallint" ,"tinyint" ,"bigint" ,"double" ,"float" ,"boolean" ,"blob" ,"timestamp" ,"date" ,"inet" ,"uuid" , "decimal" };
159+ Object [] values = new Object [] { "foo" , 1 , (short )1 , (byte )1 , 2L , new Double (3.14 ), new Float (3.14 ), true , ByteBuffer .wrap ("toto" .getBytes ("UTF-8" )), new Date (), (int )LocalDate .now ().toEpochDay (), InetAddresses .forString ("127.0.0.1" ), UUID .randomUUID (), new BigDecimal ( "3.1416" ) };
158160 for (int i =0 ; i < types .length ; i ++) {
159161 String type = types [i ];
160162 Object value = values [i ];
@@ -197,9 +199,9 @@ public void testCompoundPkTypesTest() throws Exception {
197199 ensureGreen ("ks" );
198200
199201 Date now = new Date ();
200- String [] types = new String [] { "text" , "int" ,"smallint" ,"tinyint" , "bigint" ,"double" ,"float" ,"boolean" ,"blob" ,"timestamp" ,"date" , "inet" ,"uuid" ,"timeuuid" ,"timeuuid" };
201- String [] names = new String [] { "text" , "int" ,"smallint" ,"tinyint" , "bigint" ,"double" ,"float" ,"boolean" ,"blob" ,"timestamp" ,"date2" , "inet" ,"uuid" ,"timeuuid" ,"timeuuid2" };
202- Object [] values = new Object [] { "foo" , 1 , (short )1 , (byte )1 , 2L , new Double (3.14 ), new Float (3.14 ), true , ByteBuffer .wrap ("toto" .getBytes ("UTF-8" )), new Date (), (int )LocalDate .now ().toEpochDay (), InetAddresses .forString ("127.0.0.1" ), UUID .randomUUID (), UUIDGen .getTimeUUID (now .getTime ()), UUIDGen .getTimeUUID (now .getTime ()) };
202+ String [] types = new String [] { "text" , "int" ,"smallint" ,"tinyint" , "bigint" ,"double" ,"float" ,"boolean" ,"blob" ,"timestamp" ,"date" , "inet" ,"uuid" ,"timeuuid" ,"timeuuid" , "decimal" };
203+ String [] names = new String [] { "text" , "int" ,"smallint" ,"tinyint" , "bigint" ,"double" ,"float" ,"boolean" ,"blob" ,"timestamp" ,"date2" , "inet" ,"uuid" ,"timeuuid" ,"timeuuid2" , "decimal" };
204+ Object [] values = new Object [] { "foo" , 1 , (short )1 , (byte )1 , 2L , new Double (3.14 ), new Float (3.14 ), true , ByteBuffer .wrap ("toto" .getBytes ("UTF-8" )), new Date (), (int )LocalDate .now ().toEpochDay (), InetAddresses .forString ("127.0.0.1" ), UUID .randomUUID (), UUIDGen .getTimeUUID (now .getTime ()), UUIDGen .getTimeUUID (now .getTime ()), new BigDecimal ( "3.1416" ) };
203205 int randomCk = randomInt (types .length -1 );
204206 int randomVal = randomInt (types .length -1 );
205207 for (int i =0 ; i < types .length ; i ++) {
@@ -249,7 +251,8 @@ public void testCompoundPkTypesTest() throws Exception {
249251 System .out .println ("delete pk name=" +name +" type=" +type +" value=" +values [i ]+" ck type=" +types [randomCk ]+" value=" +values [randomCk ]);
250252 process (ConsistencyLevel .ONE ,String .format (Locale .ROOT ,"DELETE FROM ks.t%s WHERE pk%s = ? AND ck >= ?" , name , name ), values [i ], values [randomCk ]);
251253 // blob not supported for delete by query
252- assertThat (client ().prepareSearch ()
254+ assertThat ("search in ks" +i +" type=" +String .format (Locale .ROOT ,"t%s" , name )+" cql_type=" +type ,
255+ client ().prepareSearch ()
253256 .setIndices ("ks" +i )
254257 .setTypes (String .format (Locale .ROOT ,"t%s" , name ))
255258 .setQuery (QueryBuilders .matchAllQuery ())
0 commit comments