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 12, 2023
1 parent 10233ad commit ae1d453
Show file tree
Hide file tree
Showing 7 changed files with 2,296 additions and 2,168 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
13 changes: 11 additions & 2 deletions src/parser/transform/transform_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,17 @@ 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 @@ -251,7 +251,7 @@ static bool tryCastStringToStruct(const char* input, uint64_t len, ValueVector*
skipWhitespace(++input, end);

copyStringToVector(StructVector::getFieldVector(vector, fieldIdx).get(), rowToAdd,
std::string_view{valStart, valEnd}, csvReaderConfig);
std::string_view{valStart, (size_t)(valEnd-valStart)}, csvReaderConfig);
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/storage/store/struct_node_column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void StructNodeColumn::writeInternal(

void StructNodeColumn::append(ColumnChunk* columnChunk, uint64_t nodeGroupIdx) {
NodeColumn::append(columnChunk, nodeGroupIdx);
assert(columnChunk->getDataType().getLogicalTypeID() == LogicalTypeID::STRUCT);
assert(columnChunk->getDataType().getPhysicalType() == PhysicalTypeID::STRUCT);
auto structColumnChunk = static_cast<StructColumnChunk*>(columnChunk);
for (auto i = 0u; i < childColumns.size(); i++) {
childColumns[i]->append(structColumnChunk->getChild(i), nodeGroupIdx);
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 ae1d453

Please sign in to comment.