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 add-prop #2100

Merged
merged 1 commit into from
Sep 28, 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
2 changes: 1 addition & 1 deletion src/antlr4/Cypher.g4
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ TO: ( 'T' | 't' ) ( 'O' | 'o' ) ;

kU_DataType
: oC_SymbolicName
| ( oC_SymbolicName kU_ListIdentifiers )
| kU_DataType kU_ListIdentifiers
| UNION SP? '(' SP? kU_PropertyDefinitions SP? ')'
| oC_SymbolicName SP? '(' SP? kU_PropertyDefinitions SP? ')'
| oC_SymbolicName SP? '(' SP? kU_DataType SP? ',' SP? kU_DataType SP? ')' ;
Expand Down
2 changes: 1 addition & 1 deletion src/function/vector_list_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ std::unique_ptr<FunctionBindData> ListCreationVectorFunction::bindFunc(
auto resultChildType = VarListType::getChildType(&resultType);
// Cast parameters with ANY dataType to resultChildType.
for (auto& argument : arguments) {
auto parameterType = argument->getDataType();
auto& parameterType = argument->getDataTypeReference();
if (parameterType != *resultChildType) {
if (parameterType.getLogicalTypeID() == LogicalTypeID::ANY) {
binder::ExpressionBinder::resolveAnyDataType(*argument, *resultChildType);
Expand Down
55 changes: 52 additions & 3 deletions test/runner/e2e_ddl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,15 @@ class TinySnbDDLTest : public DBTest {
}
}

void addPropertyToPersonTableWithDefaultValue(
std::string propertyType, std::string defaultVal, TransactionTestType transactionTestType) {
void addPropertyToPersonTableWithDefaultValue(std::string propertyType, std::string defaultVal,
TransactionTestType transactionTestType, std::string expectedVal = "") {
executeQueryWithoutCommit(
"ALTER TABLE person ADD random " + propertyType + " DEFAULT " + defaultVal);
// The convertResultToString function will remove the single quote around the result
// std::string, so we should also remove the single quote in the expected result.
defaultVal.erase(remove(defaultVal.begin(), defaultVal.end(), '\''), defaultVal.end());
std::vector<std::string> expectedResult(8 /* numOfNodesInPesron */, defaultVal);
std::vector<std::string> expectedResult(
8 /* numOfNodesInPesron */, expectedVal.empty() ? defaultVal : expectedVal);
if (transactionTestType == TransactionTestType::RECOVERY) {
conn->query("COMMIT_SKIP_CHECKPOINT");
initWithoutLoadingGraph();
Expand Down Expand Up @@ -559,6 +560,27 @@ TEST_F(TinySnbDDLTest, AddListOfStringPropertyToPersonTableWithoutDefaultValueRe
"STRING[]" /* propertyType */, TransactionTestType::RECOVERY);
}

TEST_F(TinySnbDDLTest, AddListOfStructPropertyToPersonTableWithoutDefaultValueNormalExecution) {
addPropertyToPersonTableWithoutDefaultValue(
"STRUCT(revenue int64, ages double[])[]" /* propertyType */,
TransactionTestType::NORMAL_EXECUTION);
}

TEST_F(TinySnbDDLTest, AddListOfStructPropertyToPersonTableWithoutDefaultValueRecovery) {
addPropertyToPersonTableWithoutDefaultValue(
"STRUCT(revenue int64, ages double[])[]" /* propertyType */, TransactionTestType::RECOVERY);
}

TEST_F(TinySnbDDLTest, AddMapPropertyToPersonTableWithoutDefaultValueNormalExecution) {
addPropertyToPersonTableWithoutDefaultValue(
"MAP(INT64, INT32)" /* propertyType */, TransactionTestType::NORMAL_EXECUTION);
}

TEST_F(TinySnbDDLTest, AddMapPropertyToPersonTableWithoutDefaultValueRecovery) {
addPropertyToPersonTableWithoutDefaultValue(
"MAP(STRING, INT64)" /* propertyType */, TransactionTestType::RECOVERY);
}

TEST_F(TinySnbDDLTest, AddStructPropertyToPersonTableWithoutDefaultValueNormalExecution) {
addPropertyToPersonTableWithoutDefaultValue(
"STRUCT(revenue int16, location string[])" /* propertyType */,
Expand Down Expand Up @@ -626,6 +648,33 @@ TEST_F(TinySnbDDLTest, AddListOfListOfStringPropertyToPersonTableWithDefaultValu
TransactionTestType::RECOVERY);
}

TEST_F(TinySnbDDLTest, AddListOfStructPropertyToPersonTableWithDefaultValueNormalExecution) {
addPropertyToPersonTableWithDefaultValue(
"STRUCT(revenue int64, ages double[])[]" /* propertyType */,
"[{revenue: 23, ages: [1.300000,2.500000]},{revenue: 33, ages: [2.700000]},{revenue: "
"-4, ages: [22.500000,11.300000,33.200000]}]" /* defaultValue */,
TransactionTestType::NORMAL_EXECUTION);
}

TEST_F(TinySnbDDLTest, AddListOfStructPropertyToPersonTableWithDefaultValueRecovery) {
addPropertyToPersonTableWithDefaultValue(
"STRUCT(revenue int64, ages double[])[]" /* propertyType */,
"[{revenue: 144, ages: [3.200000,7.200000]}]" /* defaultValue */,
TransactionTestType::RECOVERY);
}

TEST_F(TinySnbDDLTest, AddMapPropertyToPersonTableWithDefaultValueNormalExecution) {
addPropertyToPersonTableWithDefaultValue("MAP(STRING, INT64)" /* propertyType */,
"map(['key1','key2'],[400,250])" /* defaultValue */, TransactionTestType::NORMAL_EXECUTION,
"{key1=400, key2=250}" /* expectedVal */);
}

TEST_F(TinySnbDDLTest, AddMapPropertyToPersonTableWithDefaultValueRecovery) {
addPropertyToPersonTableWithDefaultValue("MAP(STRING, INT64[])" /* propertyType */,
"map(['key3'],[[3,2,1]])" /* defaultValue */, TransactionTestType::RECOVERY,
"{key3=[3,2,1]}" /* expectedVal */);
}

TEST_F(TinySnbDDLTest, AddStructPropertyToPersonTableWithDefaultValueNormalExecution) {
addPropertyToPersonTableWithDefaultValue(
"STRUCT(revenue int64, ages double[])" /* propertyType */,
Expand Down
Loading