@@ -24,8 +24,8 @@ def get_all_rows(res):
2424
2525class ObVecJsonTableTest (unittest .TestCase ):
2626 def setUp (self ) -> None :
27- self .root_client = ObVecJsonTableClient (user_id = 0 )
28- self .client = ObVecJsonTableClient (user_id = 1 , user = "jtuser@test" )
27+ self .root_client = ObVecJsonTableClient (user_id = '0' )
28+ self .client = ObVecJsonTableClient (user_id = 'e5a69db04c5ea54adf324907d4b8f364' , user = "jtuser@test" )
2929
3030 def test_create_and_alter_jtable (self ):
3131 self .root_client ._reset ()
@@ -34,7 +34,7 @@ def test_create_and_alter_jtable(self):
3434 self .client .perform_json_table_sql (
3535 "create table `t2` (c1 int NOT NULL DEFAULT 10, c2 varchar(30) DEFAULT 'ca', c3 varchar not null, c4 decimal(10, 2));"
3636 )
37- tmp_client = ObVecJsonTableClient (user_id = 1 )
37+ tmp_client = ObVecJsonTableClient (user_id = 'e5a69db04c5ea54adf324907d4b8f364' )
3838 self .assertEqual (sub_dict (tmp_client .jmetadata .meta_cache ['t2' ], keys_to_check ),
3939 [
4040 {'jcol_id' : 16 , 'jcol_name' : 'c1' , 'jcol_type' : 'INT' , 'jcol_nullable' : False , 'jcol_has_default' : True , 'jcol_default' : '10' },
@@ -364,3 +364,101 @@ def test_col_name_conflict(self):
364364 (2 , 'bob' ),
365365 ]
366366 )
367+
368+ def test_timestamp_datatype (self ):
369+ self .root_client ._reset ()
370+ self .client .refresh_metadata ()
371+ self .client .perform_json_table_sql (
372+ "create table `t1` (c1 int DEFAULT NULL, c2 TIMESTAMP);"
373+ )
374+
375+ self .client .perform_json_table_sql (
376+ "insert into t1 values (1, CURRENT_DATE - INTERVAL '1' MONTH);"
377+ )
378+
379+ self .client .perform_json_table_sql (
380+ "select * from t1"
381+ )
382+
383+ def test_online_cases (self ):
384+ self .root_client ._reset ()
385+ self .client .refresh_metadata ()
386+ keys_to_check = ['jcol_id' , 'jcol_name' , 'jcol_type' , 'jcol_nullable' , 'jcol_has_default' , 'jcol_default' ]
387+ self .client .perform_json_table_sql (
388+ "CREATE TABLE `table_unit_test`(id INT, field0 VARCHAR(1024), field1 INT, field2 DECIMAL(10,2), field3 timestamp NOT NULL default CURRENT_TIMESTAMP, field4 varchar(1024));"
389+ )
390+ logger .info (sub_dict (self .client .jmetadata .meta_cache ['table_unit_test' ], keys_to_check ))
391+ self .assertEqual (sub_dict (self .client .jmetadata .meta_cache ['table_unit_test' ], keys_to_check ),
392+ [
393+ {'jcol_id' : 16 , 'jcol_name' : 'id' , 'jcol_type' : 'INT' , 'jcol_nullable' : True , 'jcol_has_default' : False , 'jcol_default' : None },
394+ {'jcol_id' : 17 , 'jcol_name' : 'field0' , 'jcol_type' : 'VARCHAR(1024)' , 'jcol_nullable' : True , 'jcol_has_default' : False , 'jcol_default' : None },
395+ {'jcol_id' : 18 , 'jcol_name' : 'field1' , 'jcol_type' : 'INT' , 'jcol_nullable' : True , 'jcol_has_default' : False , 'jcol_default' : None },
396+ {'jcol_id' : 19 , 'jcol_name' : 'field2' , 'jcol_type' : 'DECIMAL(10,2)' , 'jcol_nullable' : True , 'jcol_has_default' : False , 'jcol_default' : None },
397+ {'jcol_id' : 20 , 'jcol_name' : 'field3' , 'jcol_type' : 'TIMESTAMP' , 'jcol_nullable' : False , 'jcol_has_default' : True , 'jcol_default' : 'CURRENT_TIMESTAMP()' },
398+ {'jcol_id' : 21 , 'jcol_name' : 'field4' , 'jcol_type' : 'VARCHAR(1024)' , 'jcol_nullable' : True , 'jcol_has_default' : False , 'jcol_default' : None },
399+ ]
400+ )
401+ self .client .perform_json_table_sql (
402+ "INSERT INTO `table_unit_test` (id, field0, field1, field2, field4) VALUES (1, '汽车保养', 1, 1000.00, '4S 店')"
403+ )
404+ self .client .perform_json_table_sql (
405+ "INSERT INTO `table_unit_test` (id, field0, field1, field2, field3, field4) VALUES (2, '奶茶', 2, 15.00, CURRENT_TIMESTAMP(), '商场'), (3, '书', 2, 40.00, NOW() - INTERVAL '1' DAY, '商场'), (4, '手机', 2, 6000.00, '2025-03-09', '商场')"
406+ )
407+
408+ res = self .client .perform_json_table_sql (
409+ "SELECT field0 AS 消费内容, field1 AS 消费类型, field2 AS 消费金额, field4 AS 消费地点 FROM `table_unit_test` LIMIT 2"
410+ )
411+ self .assertEqual (
412+ get_all_rows (res ),
413+ [
414+ ('汽车保养' , 1 , Decimal ('1000.00' ), '4S 店' ),
415+ ('奶茶' , 2 , Decimal ('15.00' ), '商场' )
416+ ]
417+ )
418+
419+ res = self .client .perform_json_table_sql (
420+ "SELECT field2 FROM `table_unit_test` WHERE field0 like '%汽车%' AND field4 like '%店%' ORDER BY field2 DESC LIMIT 2"
421+ )
422+ self .assertEqual (
423+ get_all_rows (res ),
424+ [(Decimal ('1000.00' ),)]
425+ )
426+
427+ res = self .client .perform_json_table_sql (
428+ "SELECT field0, field1, field2 FROM `table_unit_test` WHERE DATE(field3)='2025-03-09' ORDER BY field2 DESC LIMIT 2"
429+ )
430+ # logger.info(get_all_rows(res))
431+ self .assertEqual (
432+ get_all_rows (res ),
433+ [('手机' , 2 , Decimal ('6000.00' ))]
434+ )
435+
436+ res = self .client .perform_json_table_sql (
437+ "SELECT field0, field1, field2, field3 FROM `table_unit_test` WHERE field4 like '%商场%' AND field3 <= CAST('2025-03-10' AS DATE) LIMIT 20"
438+ )
439+ self .assertEqual (
440+ get_all_rows (res ),
441+ [('手机' , 2 , Decimal ('6000.00' ), datetime .datetime (2025 , 3 , 9 , 0 , 0 ))]
442+ )
443+
444+ self .client .perform_json_table_sql (
445+ "UPDATE `table_unit_test` SET field3 = '2025-03-14' WHERE field0 = '汽车保养'"
446+ )
447+ res = self .client .perform_json_table_sql (
448+ "SELECT field0, field1, field2, field3 FROM `table_unit_test` WHERE DATE(field3) = '2025-03-14' AND field0 = '汽车保养'"
449+ )
450+ self .assertEqual (
451+ get_all_rows (res ),
452+ [('汽车保养' , 1 , Decimal ('1000.00' ), datetime .datetime (2025 , 3 , 14 , 0 , 0 ))]
453+ )
454+
455+ self .client .perform_json_table_sql (
456+ "UPDATE `table_unit_test` SET field0 = CONCAT(field0, '代办') WHERE DATE(field3) = '2025-03-14'"
457+ )
458+ res = self .client .perform_json_table_sql (
459+ "SELECT field0, field1, field2, field3 FROM `table_unit_test` WHERE DATE(field3) = '2025-03-14'"
460+ )
461+ self .assertEqual (
462+ get_all_rows (res ),
463+ [('汽车保养代办' , 1 , Decimal ('1000.00' ), datetime .datetime (2025 , 3 , 14 , 0 , 0 ))]
464+ )
0 commit comments