Skip to content

Commit

Permalink
Force cast when scanning (#4041)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxwli authored Aug 7, 2024
1 parent 8781c0b commit c6ae098
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/binder/bind/copy/bind_copy_from.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static std::pair<ColumnEvaluateType, std::shared_ptr<Expression>> matchColumnExp
return {ColumnEvaluateType::REFERENCE, column};
} else {
return {ColumnEvaluateType::CAST,
expressionBinder.implicitCastIfNecessary(column, property.getDataType())};
expressionBinder.forceCast(column, property.getDataType())};
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_files/copy/copy_partial_column.test
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ listOfString, listOfListOfInt64, structColumn) FROM
listOfString, listOfListOfInt64, structColumn) FROM
"${KUZU_ROOT_DIRECTORY}/dataset/copy-test/node/parquet/types_50k*.parquet";
---- error
Binder exception: Expression int64Column has data type DATE but expected INT64. Implicit cast is not supported.
Conversion exception: Unsupported casting function from DATE to INT64.

-LOG PartialColumnsDefault
-STATEMENT CREATE NODE TABLE tableOfTypes14 (nullDateColumn DATE DEFAULT date('2022-06-06'), booleanColumn BOOLEAN,
Expand Down
4 changes: 2 additions & 2 deletions test/test_files/demo_db/demo_db_copy.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
---- ok
-STATEMENT Copy User1 FROM "${KUZU_ROOT_DIRECTORY}/dataset/demo-db/parquet/user.parquet";
---- error
Binder exception: Expression name has data type STRING but expected INT64. Implicit cast is not supported.
Conversion exception: Cast failed. Could not convert "Adam" to INT64.
-STATEMENT CREATE NODE TABLE User2(name STRING, age DOUBLE, PRIMARY KEY (name));
---- ok
-STATEMENT Copy User2 FROM "${KUZU_ROOT_DIRECTORY}/dataset/demo-db/parquet/user.parquet";
Expand All @@ -23,7 +23,7 @@ Zhang|50.000000
---- ok
-STATEMENT Copy Follows1 FROM "${KUZU_ROOT_DIRECTORY}/dataset/demo-db/parquet/follows.parquet";
---- error
Binder exception: Expression since has data type INT64 but expected INT64[]. Implicit cast is not supported.
Conversion exception: Unsupported casting function from INT64 to LIST.
-STATEMENT CREATE REL TABLE Follows2(FROM User2 TO User2, since DOUBLE);
---- ok
-STATEMENT Copy Follows2 FROM "${KUZU_ROOT_DIRECTORY}/dataset/demo-db/parquet/follows.parquet";
Expand Down
6 changes: 3 additions & 3 deletions test/test_files/exceptions/copy/wrong_header.test
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Copy exception: Error in file ${KUZU_ROOT_DIRECTORY}/dataset/copy-fault-tests/wr
---- ok
-STATEMENT COPY User1 FROM "${KUZU_ROOT_DIRECTORY}/dataset/demo-db/parquet/user.parquet";
---- error
Binder exception: Expression name has data type STRING but expected INT64. Implicit cast is not supported.
Conversion exception: Cast failed. Could not convert "Adam" to INT64.
-STATEMENT COPY User1 FROM ["${KUZU_ROOT_DIRECTORY}/dataset/demo-db/parquet/user.parquet",
"${KUZU_ROOT_DIRECTORY}/dataset/demo-db/parquet/lives-in.parquet"];
---- error
Expand All @@ -63,12 +63,12 @@ Binder exception: Column `f1` type mismatch. Expected INT64 but got STRING.
Binder exception: Number of columns mismatch. Expected 3 but got 2.
-STATEMENT COPY User3 FROM "${KUZU_ROOT_DIRECTORY}/dataset/demo-db/parquet/user.parquet";
---- error
Binder exception: Expression age has data type INT64 but expected INT16[]. Implicit cast is not supported.
Conversion exception: Unsupported casting function from INT64 to LIST.
-STATEMENT CREATE REL TABLE Follows1(FROM User TO User, since INT64[]);
---- ok
-STATEMENT COPY Follows1 FROM "${KUZU_ROOT_DIRECTORY}/dataset/demo-db/parquet/follows.parquet";
---- error
Binder exception: Expression since has data type INT64 but expected INT64[]. Implicit cast is not supported.
Conversion exception: Unsupported casting function from INT64 to LIST.
-STATEMENT COPY Follows1 FROM ["${KUZU_ROOT_DIRECTORY}/dataset/demo-db/parquet/follows.parquet",
"${KUZU_ROOT_DIRECTORY}/dataset/demo-db/parquet/lives-in.parquet"];
---- error
Expand Down
11 changes: 11 additions & 0 deletions tools/python_api/test/test_scan_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,14 @@ def test_copy_from_pandas_date(tmp_path: Path) -> None:
assert result.get_next() == [1, datetime.datetime(2024,1,3)]
assert result.get_next() == [2, datetime.datetime(2023,10,10)]
assert result.has_next() is False

def test_scan_string_to_nested(tmp_path: Path) -> None:
db = kuzu.Database(tmp_path)
conn = kuzu.Connection(db)
df = pd.DataFrame({"id": ["1"], "lstcol": ["[1,2,3]"], "mapcol": ["{'a'=1,'b'=2}"], "structcol": ["{a:1,b:2}"], "lstlstcol": ["[[],[1,2,3],[4,5,6]]"]})
conn.execute("CREATE NODE TABLE tab(id INT64, lstcol INT64[], mapcol MAP(STRING, INT64), structcol STRUCT(a INT64, b INT64), lstlstcol INT64[][], PRIMARY KEY(id))")
conn.execute("COPY tab from df")
result = conn.execute("match (t:tab) return t.*")
assert result.get_next() == [1, [1,2,3], {"'a'": 1, "'b'": 2}, {"a": 1, "b": 2}, [[],[1,2,3],[4,5,6]]]
assert not result.has_next()

0 comments on commit c6ae098

Please sign in to comment.