Skip to content

Commit acccf36

Browse files
committed
Fix bug in csv import
1 parent 124dd00 commit acccf36

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/executor/operator/physical_import.cpp

+19-9
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,15 @@ void PhysicalImport::CSVRowHandler(void *context) {
452452
UniquePtr<BlockEntry> block_entry = std::move(parser_context->block_entry_);
453453

454454
// if column count is larger than columns defined from schema, extra columns are abandoned
455-
if (column_count != table_entry->ColumnCount()) {
456-
UniquePtr<String> err_msg = MakeUnique<String>(
457-
fmt::format("CSV file row count isn't match with table schema, row id: {}, column_count = {}, table_entry->ColumnCount = {}.",
458-
parser_context->row_count_,
459-
column_count,
460-
table_entry->ColumnCount()));
461-
LOG_ERROR(*err_msg);
462-
RecoverableError(Status::ColumnCountMismatch(*err_msg));
463-
}
455+
// if (column_count != table_entry->ColumnCount()) {
456+
// UniquePtr<String> err_msg = MakeUnique<String>(
457+
// fmt::format("CSV file row count isn't match with table schema, row id: {}, column_count = {}, table_entry->ColumnCount = {}.",
458+
// parser_context->row_count_,
459+
// column_count,
460+
// table_entry->ColumnCount()));
461+
// LOG_ERROR(*err_msg);
462+
// RecoverableError(Status::ColumnCountMismatch(*err_msg));
463+
// }
464464

465465
// append data to segment entry
466466
for (SizeT column_idx = 0; column_idx < column_count; ++column_idx) {
@@ -480,6 +480,16 @@ void PhysicalImport::CSVRowHandler(void *context) {
480480
}
481481
}
482482
}
483+
for (SizeT column_idx = column_count; column_idx < table_entry->ColumnCount(); ++column_idx) {
484+
auto column_def = table_entry->GetColumnDefByID(column_idx);
485+
auto &column_vector = parser_context->column_vectors_[column_idx];
486+
if (column_def->has_default_value()) {
487+
auto const_expr = dynamic_cast<ConstantExpr *>(column_def->default_expr_.get());
488+
column_vector.AppendByConstantExpr(const_expr);
489+
} else {
490+
RecoverableError(Status::ImportFileFormatError(fmt::format("Column {} is empty.", column_def->name_)));
491+
}
492+
}
483493
block_entry->IncreaseRowCount(1);
484494
++parser_context->row_count_;
485495

test/data/csv/pysdk_test_import_default.csv

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
5,6,
66
2,,
77
,3,
8-
,,"[1.2,3.4,5.7]"
8+
,,"[1.2,3.4,5.7]"
9+
10,20
10+
100

0 commit comments

Comments
 (0)