99import org .junit .Before ;
1010import org .junit .Test ;
1111
12- import java .sql .Connection ;
13- import java .sql .DriverManager ;
14- import java .sql .SQLException ;
15- import java .sql .Statement ;
12+ import java .math .BigDecimal ;
13+ import java .math .BigInteger ;
14+ import java .sql .*;
1615import java .time .Duration ;
1716import java .util .Collections ;
1817import java .util .Properties ;
@@ -24,6 +23,7 @@ public class WSConsumerSubscribeDBTest {
2423 private static final String dbName = "tmq_ws_enh_test" ;
2524 private static final String superTable1 = "st1" ;
2625 private static final String superTable2 = "st2" ;
26+ private static final String superTableFullType = "st3" ;
2727 private static Connection connection ;
2828 private static Statement statement ;
2929 private static String [] topics = {"topic_ws_map" };
@@ -41,7 +41,7 @@ public void testWSEhnMapDB() throws Exception {
4141 properties .setProperty (TMQConstants .BOOTSTRAP_SERVERS , "127.0.0.1:6041" );
4242 properties .setProperty (TMQConstants .MSG_WITH_TABLE_NAME , "true" );
4343 properties .setProperty (TMQConstants .ENABLE_AUTO_COMMIT , "true" );
44- properties .setProperty (TMQConstants .GROUP_ID , "ws_map " );
44+ properties .setProperty (TMQConstants .GROUP_ID , "ws_map1 " );
4545 properties .setProperty (TMQConstants .VALUE_DESERIALIZER , "com.taosdata.jdbc.tmq.MapEnhanceDeserializer" );
4646 properties .setProperty (TMQConstants .CONNECT_TYPE , "ws" );
4747 properties .setProperty ("fetch.max.wait.ms" , "5000" );
@@ -84,6 +84,90 @@ public void testWSEhnMapDB() throws Exception {
8484 }
8585 }
8686
87+ @ Test
88+ public void testWSEhnMapDBAllType () throws Exception {
89+ AtomicInteger a = new AtomicInteger (1 );
90+ String topic = topics [0 ];
91+ // create topic
92+ statement .executeUpdate ("create topic if not exists " + topic + " as database " + dbName );
93+
94+ Properties properties = new Properties ();
95+ properties .setProperty (TMQConstants .CONNECT_USER , "root" );
96+ properties .setProperty (TMQConstants .CONNECT_PASS , "taosdata" );
97+ properties .setProperty (TMQConstants .BOOTSTRAP_SERVERS , "127.0.0.1:6041" );
98+ properties .setProperty (TMQConstants .MSG_WITH_TABLE_NAME , "true" );
99+ properties .setProperty (TMQConstants .ENABLE_AUTO_COMMIT , "true" );
100+ properties .setProperty (TMQConstants .GROUP_ID , "ws_map2" );
101+ properties .setProperty (TMQConstants .VALUE_DESERIALIZER , "com.taosdata.jdbc.tmq.MapEnhanceDeserializer" );
102+ properties .setProperty (TMQConstants .CONNECT_TYPE , "ws" );
103+ properties .setProperty ("fetch.max.wait.ms" , "5000" );
104+ properties .setProperty ("min.poll.rows" , "1000" );
105+
106+ boolean pass = false ;
107+ try (TaosConsumer <TMQEnhMap > consumer = new TaosConsumer <>(properties )) {
108+ consumer .subscribe (Collections .singletonList (topic ));
109+ for (int i = 0 ; i < 10 ; i ++) {
110+ ConsumerRecords <TMQEnhMap > consumerRecords = consumer .poll (Duration .ofMillis (100 ));
111+ if (i == 0 ){
112+ statement .executeUpdate ("insert into " + dbName + ".ct0 values(1747474225447, 1, 100, 2.2, 2.3, '1', 12, 2, true, '一', 'POINT(1 1)', '\\ x0101', 1.2234, 1747474225448, 255, 65535, 4294967295, 18446744073709551615, -12345678901234567890123.4567890000, 12345678.901234)" );
113+ }
114+ if (consumerRecords .isEmpty ()){
115+ continue ;
116+ }
117+ for (ConsumerRecord <TMQEnhMap > r : consumerRecords ) {
118+ if (r .value ().getTableName ().equalsIgnoreCase ("ct0" )){
119+ Assert .assertEquals (20 , r .value ().getMap ().size ());
120+
121+ Assert .assertTrue (r .value ().getMap ().get ("ts" ) instanceof Timestamp );
122+ Assert .assertTrue (r .value ().getMap ().get ("c1" ) instanceof Integer );
123+ Assert .assertTrue (r .value ().getMap ().get ("c2" ) instanceof Long );
124+ Assert .assertTrue (r .value ().getMap ().get ("c3" ) instanceof Float );
125+ Assert .assertTrue (r .value ().getMap ().get ("c4" ) instanceof Double );
126+ Assert .assertTrue (r .value ().getMap ().get ("c5" ) instanceof byte []);
127+ Assert .assertTrue (r .value ().getMap ().get ("c6" ) instanceof Short );
128+ Assert .assertTrue (r .value ().getMap ().get ("c7" ) instanceof Byte );
129+ Assert .assertTrue (r .value ().getMap ().get ("c8" ) instanceof Boolean );
130+ Assert .assertTrue (r .value ().getMap ().get ("c9" ) instanceof String );
131+ Assert .assertTrue (r .value ().getMap ().get ("c10" ) instanceof byte []);
132+ Assert .assertTrue (r .value ().getMap ().get ("c11" ) instanceof byte []);
133+ Assert .assertTrue (r .value ().getMap ().get ("c12" ) instanceof Double );
134+ Assert .assertTrue (r .value ().getMap ().get ("c13" ) instanceof Timestamp );
135+ Assert .assertTrue (r .value ().getMap ().get ("c14" ) instanceof Short );
136+ Assert .assertTrue (r .value ().getMap ().get ("c15" ) instanceof Integer );
137+ Assert .assertTrue (r .value ().getMap ().get ("c16" ) instanceof Long );
138+ Assert .assertTrue (r .value ().getMap ().get ("c17" ) instanceof BigInteger );
139+ Assert .assertTrue (r .value ().getMap ().get ("c18" ) instanceof BigDecimal );
140+ Assert .assertTrue (r .value ().getMap ().get ("c19" ) instanceof BigDecimal );
141+
142+ Assert .assertEquals (new Timestamp (1747474225447L ), r .value ().getMap ().get ("ts" ));
143+ Assert .assertEquals (r .value ().getMap ().get ("c1" ), 1 );
144+ Assert .assertEquals (100L , r .value ().getMap ().get ("c2" ));
145+ Assert .assertEquals (2.2F , r .value ().getMap ().get ("c3" ));
146+ Assert .assertEquals (2.3 , r .value ().getMap ().get ("c4" ));
147+ Assert .assertArrayEquals ("1" .getBytes (), (byte []) r .value ().getMap ().get ("c5" ));
148+ Assert .assertEquals ((short ) 12 , r .value ().getMap ().get ("c6" ));
149+ Assert .assertEquals ((byte ) 2 , r .value ().getMap ().get ("c7" ));
150+ Assert .assertEquals (true , r .value ().getMap ().get ("c8" ));
151+ Assert .assertEquals ("一" , r .value ().getMap ().get ("c9" ));
152+ Assert .assertArrayEquals (new byte []{1 , 1 }, (byte []) r .value ().getMap ().get ("c11" ));
153+ Assert .assertEquals (1.2234 , r .value ().getMap ().get ("c12" ));
154+ Assert .assertEquals (new Timestamp (1747474225448L ), r .value ().getMap ().get ("c13" ));
155+ Assert .assertEquals ((short ) 255 , r .value ().getMap ().get ("c14" ));
156+ Assert .assertEquals (65535 , r .value ().getMap ().get ("c15" ));
157+ Assert .assertEquals (4294967295L , r .value ().getMap ().get ("c16" ));
158+ Assert .assertEquals (new BigInteger ("18446744073709551615" ), r .value ().getMap ().get ("c17" ));
159+ Assert .assertEquals (new BigDecimal ("-12345678901234567890123.4567890000" ), r .value ().getMap ().get ("c18" ));
160+ Assert .assertEquals (new BigDecimal ("12345678.901234" ), r .value ().getMap ().get ("c19" ));
161+ pass = true ;
162+ }
163+ }
164+ }
165+
166+ consumer .unsubscribe ();
167+ Assert .assertTrue (pass );
168+ }
169+ }
170+
87171 @ Test
88172 public void testWSEhnMapStable () throws Exception {
89173 AtomicInteger a = new AtomicInteger (1 );
@@ -97,7 +181,7 @@ public void testWSEhnMapStable() throws Exception {
97181 properties .setProperty (TMQConstants .BOOTSTRAP_SERVERS , "127.0.0.1:6041" );
98182 properties .setProperty (TMQConstants .MSG_WITH_TABLE_NAME , "true" );
99183 properties .setProperty (TMQConstants .ENABLE_AUTO_COMMIT , "true" );
100- properties .setProperty (TMQConstants .GROUP_ID , "ws_map " );
184+ properties .setProperty (TMQConstants .GROUP_ID , "ws_map3 " );
101185 properties .setProperty (TMQConstants .VALUE_DESERIALIZER , "com.taosdata.jdbc.tmq.MapEnhanceDeserializer" );
102186 properties .setProperty (TMQConstants .CONNECT_TYPE , "ws" );
103187 properties .setProperty ("fetch.max.wait.ms" , "5000" );
@@ -164,6 +248,12 @@ public void before() throws SQLException {
164248
165249 statement .execute ("create stable if not exists " + superTable2
166250 + " (ts timestamp, cc1 int) tags(t1 int, t2 int)" );
251+
252+ statement .execute ("create stable if not exists " + superTableFullType
253+ + " (ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(10), c6 SMALLINT, c7 TINYINT, " +
254+ "c8 BOOL, c9 nchar(100), c10 GEOMETRY(100), c11 VARBINARY(100), c12 double, c13 timestamp, " +
255+ "c14 tinyint unsigned, c15 smallint unsigned, c16 int unsigned, c17 bigint unsigned, c18 decimal(38, 10), c19 decimal(18, 6)) tags(t1 int)" );
256+ statement .execute ("create table if not exists ct0 using " + superTableFullType + " tags(1000)" );
167257 }
168258
169259 @ After
0 commit comments