Skip to content

Commit

Permalink
Merge pull request #2100 from kuzudb/add-prop
Browse files Browse the repository at this point in the history
Fix add-prop
  • Loading branch information
acquamarin committed Sep 28, 2023
2 parents e110344 + 926ad4a commit 9cc01df
Show file tree
Hide file tree
Showing 5 changed files with 1,857 additions and 1,761 deletions.
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 @@ -75,7 +75,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

0 comments on commit 9cc01df

Please sign in to comment.