| 387 | } |
| 388 | |
| 389 | string GetExtendedMultiFileError(const MultiFileBindData &bind_data, const Expression &expr, BaseFileReader &reader, |
| 390 | idx_t expr_idx, string &first_message) { |
| 391 | if (expr.type != ExpressionType::OPERATOR_CAST) { |
| 392 | // not a cast |
| 393 | return string(); |
| 394 | } |
| 395 | auto &cast_expr = expr.Cast<BoundCastExpression>(); |
| 396 | if (cast_expr.child->type != ExpressionType::BOUND_REF) { |
| 397 | return string(); |
| 398 | } |
| 399 | auto &ref = cast_expr.child->Cast<BoundReferenceExpression>(); |
| 400 | auto &source_type = ref.return_type; |
| 401 | auto &target_type = cast_expr.return_type; |
| 402 | auto &columns = reader.GetColumns(); |
| 403 | auto local_col_id = reader.column_indexes[ref.index].GetPrimaryIndex(); |
| 404 | auto &local_col = columns[local_col_id]; |
| 405 | |
| 406 | auto reader_type = reader.GetReaderType(); |
| 407 | auto function_name = "read_" + StringUtil::Lower(reader_type); |
| 408 | string extended_error; |
| 409 | if (!bind_data.table_columns.empty()) { |
| 410 | // COPY .. FROM |
| 411 | string target_column; |
| 412 | if (expr_idx < bind_data.table_columns.size()) { |
| 413 | target_column = "\"" + bind_data.table_columns[expr_idx] + "\" "; |
| 414 | } |
| 415 | extended_error = StringUtil::Format( |
| 416 | "In file \"%s\" the column \"%s\" has type %s, but we are trying to load it into column %swith type " |
| 417 | "%s.\nThis means the %s schema does not match the schema of the table.\nPossible solutions:\n* Insert by " |
| 418 | "name instead of by position using \"INSERT INTO tbl BY NAME SELECT * FROM %s(...)\"\n* Manually specify " |
| 419 | "which columns to insert using \"INSERT INTO tbl SELECT ... FROM %s(...)\"", |
| 420 | reader.GetFileName(), local_col.name, source_type, target_column, target_type, reader_type, function_name, |
| 421 | function_name); |
| 422 | } else { |
| 423 | // read_parquet() with multiple files |
| 424 | extended_error = StringUtil::Format( |
| 425 | "In file \"%s\" the column \"%s\" has type %s, but we are trying to read it as type %s." |
| 426 | "\nThis can happen when reading multiple %s files. The schema information is taken from " |
| 427 | "the first %s file by default. Possible solutions:\n" |
| 428 | "* Enable the union_by_name=True option to combine the schema of all %s files " |
| 429 | "(https://duckdb.org/docs/stable/data/multiple_files/combining_schemas)\n" |
| 430 | "* Use a COPY statement to automatically derive types from an existing table.", |
| 431 | reader.GetFileName(), local_col.name, source_type, target_type, reader_type, reader_type, reader_type); |
| 432 | } |
| 433 | first_message = StringUtil::Format("failed to cast column \"%s\" from type %s to %s: ", local_col.name, source_type, |
| 434 | target_type); |
| 435 | return extended_error; |
| 436 | } |
| 437 | |
| 438 | void MultiFileReader::FinalizeChunk(ClientContext &context, const MultiFileBindData &bind_data, BaseFileReader &reader, |
| 439 | const MultiFileReaderData &reader_data, DataChunk &input_chunk, |
no test coverage detected