Skip to content

Commit

Permalink
Fix issue-2187
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfengHKU committed Oct 13, 2023
1 parent a755f57 commit d2c2f88
Show file tree
Hide file tree
Showing 6 changed files with 2,296 additions and 2,167 deletions.
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

0 comments on commit d2c2f88

Please sign in to comment.