Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2187 #2197

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/antlr4/Cypher.g4
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,10 @@ TRUE : ( 'T' | 't' ) ( 'R' | 'r' ) ( 'U' | 'u' ) ( 'E' | 'e' ) ;
FALSE : ( 'F' | 'f' ) ( 'A' | 'a' ) ( 'L' | 'l' ) ( 'S' | 's' ) ( 'E' | 'e' ) ;

oC_ListLiteral
: '[' SP? ( oC_Expression SP? ( ',' SP? oC_Expression SP? )* )? ']' ;
: '[' SP? ( oC_Expression SP? ( kU_ListEntry SP? )* )? ']' ;

kU_ListEntry
: ',' SP? oC_Expression? ;

kU_StructLiteral
: '{' SP? kU_StructField SP? ( ',' SP? kU_StructField SP? )* '}' ;
Expand Down
14 changes: 12 additions & 2 deletions src/parser/transform/transform_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,18 @@ std::unique_ptr<ParsedExpression> Transformer::transformListLiteral(
CypherParser::OC_ListLiteralContext& ctx) {
auto listCreation =
std::make_unique<ParsedFunctionExpression>(LIST_CREATION_FUNC_NAME, ctx.getText());
for (auto& childExpr : ctx.oC_Expression()) {
listCreation->addChild(transformExpression(*childExpr));
if (ctx.oC_Expression() == nullptr) { // empty list
return listCreation;
}
listCreation->addChild(transformExpression(*ctx.oC_Expression()));
for (auto& listEntry : ctx.kU_ListEntry()) {
if (listEntry->oC_Expression() == nullptr) {
auto nullValue = Value::createNullValue();
listCreation->addChild(
std::make_unique<ParsedLiteralExpression>(nullValue.copy(), nullValue.toString()));
} else {
listCreation->addChild(transformExpression(*listEntry->oC_Expression()));
}
}
return listCreation;
}
Expand Down
2 changes: 1 addition & 1 deletion src/processor/operator/persistent/reader/csv/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ struct SplitStringListOperation {
start_copy = end;
}
copyStringToVector(resultVector, offset,
std::string_view{start_copy, (size_t)(end - start_copy)}, csvReaderConfig);
std::string_view{start_copy, (uint32_t)(end - start_copy)}, csvReaderConfig);
offset++;
}
};
Expand Down
37 changes: 37 additions & 0 deletions test/test_files/tinysnb/function/list.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,43 @@

-CASE FunctionList

-LOG ListLiteral
-STATEMENT RETURN [1,,3];
---- 1
[1,,3]
-STATEMENT UNWIND [1,,3] AS a RETURN a IS NULL;
---- 3
False
False
True
-STATEMENT RETURN [1, 'a'];
---- error
Binder exception: Cannot bind LIST_CREATION with parameter type INT64 and STRING.
-STATEMENT RETURN [1,,'a'];
---- error
Binder exception: Cannot bind LIST_CREATION with parameter type INT64 and STRING.
-STATEMENT RETURN [1, NULL];
---- 1
[1,]
-STATEMENT RETURN [];
---- 1
[]
-STATEMENT RETURN [NULL, NULL];
---- 1
[,]
-STATEMENT RETURN ['a', , []];
---- error
Binder exception: Cannot bind LIST_CREATION with parameter type STRING and INT64[].
-STATEMENT RETURN [[], , []];
---- 1
[[],,[]]
-STATEMENT RETURN [[1], , [2]];
---- 1
[[1],,[2]]
-STATEMENT RETURN [[1], , ['a']];
---- error
Binder exception: Cannot bind LIST_CREATION with parameter type INT64[] and STRING[].

-LOG NodeLISTStructuredPropertiesTest
-STATEMENT MATCH (a:person) RETURN a.workedHours, a.usedNames, a.courseScoresPerTerm
---- 8
Expand Down
Loading