@@ -1038,7 +1038,6 @@ def test_select_truncate(self, suffix):
1038
1038
1039
1039
res , extra_res = table_obj .output (["trunc(c1, 14)" , "trunc(c2, 2)" , "trunc(c3, 2)" ]).to_df ()
1040
1040
print (res )
1041
- print (res .dtypes )
1042
1041
pd .testing .assert_frame_equal (res , pd .DataFrame ({'(c1 trunc 14)' : ("2.12300000000000" , "-2.12300000000000" , "2.00000000000000" , "2.10000000000000" ),
1043
1042
'(c2 trunc 2)' : ("2.12" , "-2.12" , "2.00" , "2.10" ),
1044
1043
'(c3 trunc 2)' : ("2.12" , "-2.12" , "2.00" , "2.10" )
@@ -1062,10 +1061,134 @@ def test_select_reverse(self, suffix):
1062
1061
1063
1062
res , extra_res = table_obj .output (["reverse(c1)" , "reverse(c2)" ]).to_df ()
1064
1063
print (res )
1065
- print (res .dtypes )
1066
1064
pd .testing .assert_frame_equal (res , pd .DataFrame ({'reverse(c1)' : ('cba' , '321a' , 'c' , 'nmlkjihgfedcba' ),
1067
1065
'reverse(c2)' : ('CBA' , '321a' , 'C' , 'NMLKJIHGFEDCBA' )})
1068
1066
.astype ({'reverse(c1)' : dtype ('str_' ), 'reverse(c2)' : dtype ('str_' )}))
1069
1067
1070
1068
res = db_obj .drop_table ("test_select_reverse" + suffix )
1069
+ assert res .error_code == ErrorCode .OK
1070
+
1071
+
1072
+ def test_select_year (self , suffix ):
1073
+ db_obj = self .infinity_obj .get_database ("default_db" )
1074
+ db_obj .drop_table ("test_select_year" + suffix , ConflictType .Ignore )
1075
+ table_obj = db_obj .create_table (
1076
+ "test_select_year" + suffix , {
1077
+ "c1" : {"type" : "date" },
1078
+ "c2" : {"type" : "datetime" },
1079
+ "c3" : {"type" : "timestamp" }},
1080
+ ConflictType .Error )
1081
+ table_obj = db_obj .get_table ("test_select_year" + suffix )
1082
+ table_obj .insert (
1083
+ [{"c1" : "2024-09-23" , "c2" : "2022-05-26 21:44:33" , "c3" :"2024-09-23 20:45:11" }])
1084
+
1085
+ res , extra_res = table_obj .output (["year(c1)" , "year(c2)" , "year(c3)" ]).to_pl ()
1086
+ print (res )
1087
+ assert res ['year(c1)' ][0 ] == 2024 , "The value of year(c1) should be 2024"
1088
+ assert res ['year(c2)' ][0 ] == 2022 , "The value of year(c2) should be 2022"
1089
+ assert res ['year(c3)' ][0 ] == 2024 , "The value of year(c3) should be 2024"
1090
+
1091
+ res = db_obj .drop_table ("test_select_year" + suffix )
1092
+ assert res .error_code == ErrorCode .OK
1093
+
1094
+
1095
+ def test_select_month (self , suffix ):
1096
+ db_obj = self .infinity_obj .get_database ("default_db" )
1097
+ db_obj .drop_table ("test_select_month" + suffix , ConflictType .Ignore )
1098
+ table_obj = db_obj .create_table (
1099
+ "test_select_month" + suffix , {
1100
+ "c1" : {"type" : "date" },
1101
+ "c2" : {"type" : "datetime" },
1102
+ "c3" : {"type" : "timestamp" }},
1103
+ ConflictType .Error )
1104
+ table_obj = db_obj .get_table ("test_select_month" + suffix )
1105
+ table_obj .insert (
1106
+ [{"c1" : "2024-09-23" , "c2" : "2022-05-26 21:44:33" , "c3" :"2024-09-23 20:45:11" }])
1107
+
1108
+ res , extra_res = table_obj .output (["month(c1)" , "month(c2)" , "month(c3)" ]).to_pl ()
1109
+ print (res )
1110
+ assert res ['month(c1)' ][0 ] == 9 , "The value of month(c1) should be 9"
1111
+ assert res ['month(c2)' ][0 ] == 5 , "The value of month(c2) should be 5"
1112
+ assert res ['month(c3)' ][0 ] == 9 , "The value of month(c3) should be 9"
1113
+ res = db_obj .drop_table ("test_select_month" + suffix )
1114
+ assert res .error_code == ErrorCode .OK
1115
+
1116
+
1117
+ def test_select_day (self , suffix ):
1118
+ db_obj = self .infinity_obj .get_database ("default_db" )
1119
+ db_obj .drop_table ("test_select_day" + suffix , ConflictType .Ignore )
1120
+ db_obj .create_table ("test_select_day" + suffix ,
1121
+ {"c1" : {"type" : "date" },
1122
+ "c2" : {"type" : "datetime" },
1123
+ "c3" : {"type" : "timestamp" }}, ConflictType .Error )
1124
+ table_obj = db_obj .get_table ("test_select_day" + suffix )
1125
+ table_obj .insert (
1126
+ [{"c1" : "2024-09-23" , "c2" : "2022-05-26 21:44:33" , "c3" :"2024-09-23 20:45:11" }])
1127
+
1128
+ res , extra_res = table_obj .output (["day(c1)" , "day(c2)" , "day(c3)" ]).to_pl ()
1129
+ print (res )
1130
+ assert res ['day(c1)' ][0 ] == 23 , "The value of day(c1) should be 23"
1131
+ assert res ['day(c2)' ][0 ] == 26 , "The value of day(c2) should be 26"
1132
+ assert res ['day(c3)' ][0 ] == 23 , "The value of day(c3) should be 23"
1133
+ res = db_obj .drop_table ("test_select_day" + suffix )
1134
+ assert res .error_code == ErrorCode .OK
1135
+
1136
+
1137
+ def test_select_hour (self , suffix ):
1138
+ db_obj = self .infinity_obj .get_database ("default_db" )
1139
+ db_obj .drop_table ("test_select_hour" + suffix , ConflictType .Ignore )
1140
+ db_obj .create_table ("test_select_hour" + suffix ,
1141
+ {"c1" : {"type" : "time" },
1142
+ "c2" : {"type" : "datetime" },
1143
+ "c3" : {"type" : "timestamp" }}, ConflictType .Error )
1144
+ table_obj = db_obj .get_table ("test_select_hour" + suffix )
1145
+ table_obj .insert (
1146
+ [{"c1" :"0:0:0" , "c2" : "2022-05-26 21:44:33" , "c3" :"2024-09-23 20:45:11" }])
1147
+
1148
+ res , extra_res = table_obj .output (["hour(c1)" ,"hour(c2)" , "hour(c3)" ]).to_pl ()
1149
+ print (res )
1150
+ assert res ['hour(c1)' ][0 ] == 0 , "The value of hour(c1) should be 0"
1151
+ assert res ['hour(c2)' ][0 ] == 21 , "The value of hour(c2) should be 21"
1152
+ assert res ['hour(c3)' ][0 ] == 20 , "The value of hour(c3) should be 20"
1153
+
1154
+ res = db_obj .drop_table ("test_select_hour" + suffix )
1155
+ assert res .error_code == ErrorCode .OK
1156
+
1157
+ def test_select_minute (self , suffix ):
1158
+ db_obj = self .infinity_obj .get_database ("default_db" )
1159
+ db_obj .drop_table ("test_select_minute" + suffix , ConflictType .Ignore )
1160
+ db_obj .create_table ("test_select_minute" + suffix ,
1161
+ {"c1" : {"type" : "time" },
1162
+ "c2" : {"type" : "datetime" },"c3" : {"type" : "timestamp" }}, ConflictType .Error )
1163
+ table_obj = db_obj .get_table ("test_select_minute" + suffix )
1164
+ table_obj .insert (
1165
+ [{"c1" :"0:0:0" , "c2" : "2022-05-26 21:44:33" , "c3" :"2024-09-23 20:45:11" }])
1166
+
1167
+ res , extra_res = table_obj .output (["minute(c1)" , "minute(c2)" , "minute(c3)" ]).to_pl ()
1168
+ print (res )
1169
+ assert res ['minute(c1)' ][0 ] == 0 , "The value of minute(c1) should be 0"
1170
+ assert res ['minute(c2)' ][0 ] == 44 , "The value of minute(c2) should be 44"
1171
+ assert res ['minute(c3)' ][0 ] == 45 , "The value of minute(c3) should be 45"
1172
+
1173
+ res = db_obj .drop_table ("test_select_minute" + suffix )
1174
+ assert res .error_code == ErrorCode .OK
1175
+
1176
+ def test_select_second (self , suffix ):
1177
+ db_obj = self .infinity_obj .get_database ("default_db" )
1178
+ db_obj .drop_table ("test_select_second" + suffix , ConflictType .Ignore )
1179
+ db_obj .create_table ("test_select_second" + suffix ,
1180
+ {"c1" : {"type" : "time" },
1181
+ "c2" : {"type" : "datetime" },
1182
+ "c3" : {"type" : "timestamp" }}, ConflictType .Error )
1183
+ table_obj = db_obj .get_table ("test_select_second" + suffix )
1184
+ table_obj .insert (
1185
+ [{"c1" :"0:0:0" , "c2" : "2022-05-26 21:44:33" , "c3" :"2024-09-23 20:45:11" }])
1186
+
1187
+ res , extra_res = table_obj .output (["second(c1)" , "second(c2)" , "second(c3)" ]).to_pl ()
1188
+ print (res )
1189
+ assert res ['second(c1)' ][0 ] == 0 , "The value of second(c1) should be 0"
1190
+ assert res ['second(c2)' ][0 ] == 33 , "The value of second(c2) should be 33"
1191
+ assert res ['second(c3)' ][0 ] == 11 , "The value of second(c3) should be 11"
1192
+
1193
+ res = db_obj .drop_table ("test_select_second" + suffix )
1071
1194
assert res .error_code == ErrorCode .OK
0 commit comments