@@ -394,7 +394,7 @@ TEST_F(PostgresParserTests, ExpressionUpdateTest) {
394
394
(expression::ConstantValueExpression *)update_stmt->updates .at (0 )
395
395
->value .get ();
396
396
EXPECT_EQ (CmpBool::CmpTrue, constant->GetValue ().CompareEquals (
397
- type::ValueFactory::GetDecimalValue (48 )));
397
+ type::ValueFactory::GetDecimalValue (48 )));
398
398
399
399
// Test Second Set Condition
400
400
EXPECT_EQ (update_stmt->updates .at (1 )->column , " s_ytd" );
@@ -404,7 +404,7 @@ TEST_F(PostgresParserTests, ExpressionUpdateTest) {
404
404
EXPECT_EQ (child1->GetColumnName (), " s_ytd" );
405
405
auto child2 = (expression::ConstantValueExpression *)op_expr->GetChild (1 );
406
406
EXPECT_EQ (CmpBool::CmpTrue, child2->GetValue ().CompareEquals (
407
- type::ValueFactory::GetIntegerValue (1 )));
407
+ type::ValueFactory::GetIntegerValue (1 )));
408
408
409
409
// Test Where clause
410
410
auto where = (expression::OperatorExpression *)update_stmt->where .get ();
@@ -415,14 +415,14 @@ TEST_F(PostgresParserTests, ExpressionUpdateTest) {
415
415
EXPECT_EQ (column->GetColumnName (), " s_i_id" );
416
416
constant = (expression::ConstantValueExpression *)cond1->GetChild (1 );
417
417
EXPECT_EQ (CmpBool::CmpTrue, constant->GetValue ().CompareEquals (
418
- type::ValueFactory::GetIntegerValue (68999 )));
418
+ type::ValueFactory::GetIntegerValue (68999 )));
419
419
auto cond2 = (expression::OperatorExpression *)where->GetChild (1 );
420
420
EXPECT_EQ (cond2->GetExpressionType (), ExpressionType::COMPARE_EQUAL);
421
421
column = (expression::TupleValueExpression *)cond2->GetChild (0 );
422
422
EXPECT_EQ (column->GetColumnName (), " s_w_id" );
423
423
constant = (expression::ConstantValueExpression *)cond2->GetChild (1 );
424
424
EXPECT_EQ (CmpBool::CmpTrue, constant->GetValue ().CompareEquals (
425
- type::ValueFactory::GetIntegerValue (4 )));
425
+ type::ValueFactory::GetIntegerValue (4 )));
426
426
}
427
427
428
428
TEST_F (PostgresParserTests, StringUpdateTest) {
@@ -857,9 +857,9 @@ TEST_F(PostgresParserTests, ConstraintTest) {
857
857
(expression::ConstantValueExpression *)default_expr->GetChild (1 );
858
858
EXPECT_TRUE (child2 != nullptr );
859
859
EXPECT_EQ (CmpBool::CmpTrue, child1->GetValue ().CompareEquals (
860
- type::ValueFactory::GetIntegerValue (1 )));
860
+ type::ValueFactory::GetIntegerValue (1 )));
861
861
EXPECT_EQ (CmpBool::CmpTrue, child2->GetValue ().CompareEquals (
862
- type::ValueFactory::GetIntegerValue (2 )));
862
+ type::ValueFactory::GetIntegerValue (2 )));
863
863
864
864
// Check Second column
865
865
column = create_stmt->columns .at (1 ).get ();
@@ -907,13 +907,13 @@ TEST_F(PostgresParserTests, ConstraintTest) {
907
907
(expression::ConstantValueExpression *)check_child1->GetChild (1 );
908
908
EXPECT_TRUE (plus_child2 != nullptr );
909
909
EXPECT_EQ (CmpBool::CmpTrue, plus_child2->GetValue ().CompareEquals (
910
- type::ValueFactory::GetIntegerValue (1 )));
910
+ type::ValueFactory::GetIntegerValue (1 )));
911
911
auto check_child2 =
912
912
(expression::ConstantValueExpression *)column->check_expression ->GetChild (
913
913
1 );
914
914
EXPECT_TRUE (check_child2 != nullptr );
915
915
EXPECT_EQ (CmpBool::CmpTrue, check_child2->GetValue ().CompareEquals (
916
- type::ValueFactory::GetIntegerValue (0 )));
916
+ type::ValueFactory::GetIntegerValue (0 )));
917
917
918
918
// Check the last foreign key
919
919
column = create_stmt->foreign_keys .at (2 ).get ();
@@ -1090,7 +1090,7 @@ TEST_F(PostgresParserTests, FuncCallTest) {
1090
1090
(expression::ConstantValueExpression *)fun_expr->GetChild (0 );
1091
1091
EXPECT_TRUE (const_expr != nullptr );
1092
1092
EXPECT_EQ (CmpBool::CmpTrue, const_expr->GetValue ().CompareEquals (
1093
- type::ValueFactory::GetIntegerValue (1 )));
1093
+ type::ValueFactory::GetIntegerValue (1 )));
1094
1094
auto tv_expr = (expression::TupleValueExpression *)fun_expr->GetChild (1 );
1095
1095
EXPECT_TRUE (tv_expr != nullptr );
1096
1096
EXPECT_EQ (" a" , tv_expr->GetColumnName ());
@@ -1104,7 +1104,7 @@ TEST_F(PostgresParserTests, FuncCallTest) {
1104
1104
const_expr = (expression::ConstantValueExpression *)fun_expr->GetChild (0 );
1105
1105
EXPECT_TRUE (const_expr != nullptr );
1106
1106
EXPECT_EQ (CmpBool::CmpTrue, const_expr->GetValue ().CompareEquals (
1107
- type::ValueFactory::GetIntegerValue (99 )));
1107
+ type::ValueFactory::GetIntegerValue (99 )));
1108
1108
1109
1109
// Check FUN(b) > 2
1110
1110
auto op_expr =
@@ -1120,7 +1120,7 @@ TEST_F(PostgresParserTests, FuncCallTest) {
1120
1120
const_expr = (expression::ConstantValueExpression *)op_expr->GetChild (1 );
1121
1121
EXPECT_TRUE (const_expr != nullptr );
1122
1122
EXPECT_EQ (CmpBool::CmpTrue, const_expr->GetValue ().CompareEquals (
1123
- type::ValueFactory::GetIntegerValue (2 )));
1123
+ type::ValueFactory::GetIntegerValue (2 )));
1124
1124
}
1125
1125
1126
1126
TEST_F (PostgresParserTests, UDFFuncCallTest) {
@@ -1143,7 +1143,7 @@ TEST_F(PostgresParserTests, UDFFuncCallTest) {
1143
1143
(expression::ConstantValueExpression *)fun_expr->GetChild (0 );
1144
1144
EXPECT_TRUE (const_expr != nullptr );
1145
1145
EXPECT_EQ (CmpBool::CmpTrue, const_expr->GetValue ().CompareEquals (
1146
- type::ValueFactory::GetIntegerValue (1 )));
1146
+ type::ValueFactory::GetIntegerValue (1 )));
1147
1147
1148
1148
auto tv_expr = (expression::TupleValueExpression *)fun_expr->GetChild (1 );
1149
1149
EXPECT_TRUE (tv_expr != nullptr );
@@ -1220,5 +1220,25 @@ TEST_F(PostgresParserTests, TypeCastTest) {
1220
1220
}
1221
1221
}
1222
1222
1223
+ TEST_F (PostgresParserTests, TypeCastInExpressionTest) {
1224
+ std::vector<std::string> queries;
1225
+ queries.push_back (" SELECT * FROM a WHERE d <= date '2018-04-04';" );
1226
+ queries.push_back (" SELECT '12345'::INTEGER - 12" );
1227
+ // Parsing
1228
+ UNUSED_ATTRIBUTE int ii = 0 ;
1229
+ for (auto query : queries) {
1230
+ std::unique_ptr<parser::SQLStatementList> result (
1231
+ parser::PostgresParser::ParseSQLString (query.c_str ()));
1232
+
1233
+ if (result->is_valid == false ) {
1234
+ LOG_ERROR (" Message: %s, line: %d, col: %d" , result->parser_msg ,
1235
+ result->error_line , result->error_col );
1236
+ }
1237
+ EXPECT_EQ (result->is_valid , true );
1238
+
1239
+ LOG_TRACE (" %d : %s" , ++ii, result->GetInfo ().c_str ());
1240
+ }
1241
+ }
1242
+
1223
1243
} // namespace test
1224
1244
} // namespace peloton
0 commit comments