Skip to content

Commit

Permalink
Enable literal expression for config option value
Browse files Browse the repository at this point in the history
  • Loading branch information
manh9203 committed Apr 24, 2024
1 parent ccfd096 commit f4e44b3
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion scripts/antlr4/Cypher.g4.copy
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ USE:
( 'U' | 'u') ( 'S' | 's') ( 'E' | 'e');

kU_StandaloneCall
: CALL SP oC_SymbolicName SP? '=' SP? oC_Literal ;
: CALL SP oC_SymbolicName SP? '=' SP? oC_Expression ;

CALL : ( 'C' | 'c' ) ( 'A' | 'a' ) ( 'L' | 'l' ) ( 'L' | 'l' ) ;

Expand Down
2 changes: 1 addition & 1 deletion src/antlr4/Cypher.g4
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ USE:
( 'U' | 'u') ( 'S' | 's') ( 'E' | 'e');

kU_StandaloneCall
: CALL SP oC_SymbolicName SP? '=' SP? oC_Literal ;
: CALL SP oC_SymbolicName SP? '=' SP? oC_Expression ;

CALL : ( 'C' | 'c' ) ( 'A' | 'a' ) ( 'L' | 'l' ) ( 'L' | 'l' ) ;

Expand Down
11 changes: 8 additions & 3 deletions src/binder/bind/bind_standalone_call.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "binder/binder.h"
#include "binder/bound_standalone_call.h"
#include "binder/expression/expression_util.h"
#include "binder/expression_visitor.h"
#include "common/exception/binder.h"
#include "extension/extension.h"
#include "main/db_config.h"
Expand All @@ -22,9 +23,13 @@ std::unique_ptr<BoundStatement> Binder::bindStandaloneCall(const parser::Stateme
if (option == nullptr) {
throw BinderException{"Invalid option name: " + callStatement.getOptionName() + "."};
}
auto optionValue = expressionBinder.bindLiteralExpression(*callStatement.getOptionValue());
// TODO(Ziyi): add casting rule for option value.
ExpressionUtil::validateDataType(*optionValue, option->parameterType);
auto optionValue = expressionBinder.bindExpression(*callStatement.getOptionValue());
ExpressionUtil::validateExpressionType(*optionValue, ExpressionType::LITERAL);
optionValue =
expressionBinder.implicitCastIfNecessary(optionValue, LogicalType(option->parameterType));
if (ExpressionVisitor::needFold(*optionValue)) {
optionValue = expressionBinder.foldExpression(optionValue);
}
return std::make_unique<BoundStandaloneCall>(option, std::move(optionValue));
}

Expand Down
3 changes: 2 additions & 1 deletion src/binder/expression_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ bool ExpressionVisitor::isConstant(const Expression& expression) {
if (expression.expressionType == ExpressionType::AGGREGATE_FUNCTION) {
return false; // We don't have a framework to fold aggregated constant.
}
if (expression.getNumChildren() == 0) {
if (expression.getNumChildren() == 0 &&
expression.expressionType != ExpressionType::CASE_ELSE) {
return expression.expressionType == ExpressionType::LITERAL;
}
for (auto& child : ExpressionChildrenCollector::collectChildren(expression)) {
Expand Down
2 changes: 1 addition & 1 deletion src/parser/transform/transform_standalone_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace parser {
std::unique_ptr<Statement> Transformer::transformStandaloneCall(
CypherParser::KU_StandaloneCallContext& ctx) {
auto optionName = transformSymbolicName(*ctx.oC_SymbolicName());
auto parameter = transformLiteral(*ctx.oC_Literal());
auto parameter = transformExpression(*ctx.oC_Expression());
return std::make_unique<StandaloneCall>(std::move(optionName), std::move(parameter));
}

Expand Down
2 changes: 1 addition & 1 deletion test/test_files/exceptions/binder/binder_error.test
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ Binder exception: Invalid option name: thread.
-LOG InvalidCallOptionValue
-STATEMENT CALL threads='abc'
---- error
Binder exception: abc has data type STRING but INT64 was expected.
Binder exception: Expression abc has data type STRING but expected INT64. Implicit cast is not supported.

-LOG AllShortestPathInvalidLowerBound
-STATEMENT MATCH p = (a)-[* ALL SHORTEST 2..3]-(b) RETURN p
Expand Down
10 changes: 10 additions & 0 deletions test/test_files/tinysnb/call/call.test
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
-STATEMENT CALL current_setting('timeout') RETURN *
---- 1
20000
-STATEMENT CALL timeout=(1+2+3)*10000
---- ok
-STATEMENT CALL current_setting('timeout') RETURN *
---- 1
60000

-LOG SetGetVarLengthMaxDepth
-STATEMENT CALL var_length_extend_max_depth=10
Expand All @@ -53,6 +58,11 @@ True
-STATEMENT CALL current_setting('progress_bar') RETURN *
---- 1
False
-STATEMENT CALL progress_bar=CASE WHEN 1<2 THEN True ELSE False END
---- ok
-STATEMENT CALL current_setting('progress_bar') RETURN *
---- 1
True

-LOG SetGetProgressBarTime
-STATEMENT CALL progress_bar_time=4000
Expand Down
8 changes: 4 additions & 4 deletions third_party/antlr4_cypher/cypher_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ void cypherParserInitialize() {
0,519,520,5,49,0,0,520,521,5,150,0,0,521,523,3,286,143,0,522,524,5,150,
0,0,523,522,1,0,0,0,523,524,1,0,0,0,524,525,1,0,0,0,525,527,5,6,0,0,526,
528,5,150,0,0,527,526,1,0,0,0,527,528,1,0,0,0,528,529,1,0,0,0,529,530,
3,238,119,0,530,27,1,0,0,0,531,532,5,50,0,0,532,533,5,150,0,0,533,534,
3,190,95,0,530,27,1,0,0,0,531,532,5,50,0,0,532,533,5,150,0,0,533,534,
5,94,0,0,534,535,5,150,0,0,535,536,5,60,0,0,536,537,5,150,0,0,537,538,
3,284,142,0,538,539,5,150,0,0,539,540,5,125,0,0,540,541,5,150,0,0,541,
542,5,136,0,0,542,29,1,0,0,0,543,544,5,92,0,0,544,545,5,150,0,0,545,546,
Expand Down Expand Up @@ -2612,8 +2612,8 @@ CypherParser::OC_SymbolicNameContext* CypherParser::KU_StandaloneCallContext::oC
return getRuleContext<CypherParser::OC_SymbolicNameContext>(0);
}

CypherParser::OC_LiteralContext* CypherParser::KU_StandaloneCallContext::oC_Literal() {
return getRuleContext<CypherParser::OC_LiteralContext>(0);
CypherParser::OC_ExpressionContext* CypherParser::KU_StandaloneCallContext::oC_Expression() {
return getRuleContext<CypherParser::OC_ExpressionContext>(0);
}


Expand Down Expand Up @@ -2661,7 +2661,7 @@ CypherParser::KU_StandaloneCallContext* CypherParser::kU_StandaloneCall() {
match(CypherParser::SP);
}
setState(529);
oC_Literal();
oC_Expression();

}
catch (RecognitionException &e) {
Expand Down
2 changes: 1 addition & 1 deletion third_party/antlr4_cypher/include/cypher_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ class CypherParser : public antlr4::Parser {
std::vector<antlr4::tree::TerminalNode *> SP();
antlr4::tree::TerminalNode* SP(size_t i);
OC_SymbolicNameContext *oC_SymbolicName();
OC_LiteralContext *oC_Literal();
OC_ExpressionContext *oC_Expression();


};
Expand Down

0 comments on commit f4e44b3

Please sign in to comment.