Skip to content

Treat empty cells in CSV as default values. - #5625

Merged
akuzm merged 4 commits into
masterfrom
aku/csv-defaults-5349
Jun 20, 2019
Merged

akuzm merged 4 commits into
masterfrom
aku/csv-defaults-5349

Conversation

@akuzm

@akuzm akuzm commented Jun 14, 2019

Copy link
Copy Markdown
Contributor

#5349

For changelog. Remove if this is non-significant change.

When inserting data in CSV format, empty unquoted input values are replaced with default values for the respective columns, if [input_format_defaults_for_omitted_fields](../operations/settings/settings.md#session_settings-input_format_defaults_for_omitted_fields) is enabled.

При импорте данных в формате CSV пустые ячейки без кавычек заменяются значениями по умолчанию для соответствующих колонок, если включён параметр [input_format_defaults_for_omitted_fields](../operations/settings/settings.md#session_settings-input_format_defaults_for_omitted_fields).

Category (leave one):

  • Improvement

Comment thread dbms/src/Formats/CSVRowInputStream.cpp Outdated
/// 2. The value is overwritten by
/// AddingDefaultsBlockInputStream, so we don't care what it
/// is. Should we use IColumn::insertDefault() instead?
data_types[i]->insertDefaultInto(*columns[i]);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anybody know the answer to the above questions?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remebmer correctly:

We need to return block with columns of corresponding size. Non-existing values should be prefilled nevertheless. Then we fill default values through applying if function or in similar way (that expect block with proper column sizes).

@alexey-milovidov alexey-milovidov Jun 15, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(you can update your comment to mine)

@akuzm akuzm added the pr-improvement Pull request with some product improvements label Jun 14, 2019

- Inserting data in [JSONEachRow](../../interfaces/formats.md#jsoneachrow) format.

For all other operations, ClickHouse doesn't apply the setting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted this big explanation about the extended data exchange and slightly extended the note about performance below. This option replaces empty cells with defaults, and the detailed description of how it's implemented doesn't make any difference to the user.

Comment thread dbms/src/Formats/CSVRowInputStream.cpp Outdated
skipWhitespacesAndTabs(istr);
const auto & type = data_types[*column_index];
if (*istr.position() == delimiter
&& format_settings.csv.empty_as_default)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we check for empty values at the last column?

INSERT INTO table (a, b) FORMAT CSV
Hello,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(it requires comparison with \r and \n; we assume that unquoted newlines are not possible in value)

@alexey-milovidov alexey-milovidov self-assigned this Jun 15, 2019
@akuzm
akuzm force-pushed the aku/csv-defaults-5349 branch from fe4e880 to 81ead1c Compare June 19, 2019 15:33
@akuzm
akuzm merged commit 4cc9f63 into master Jun 20, 2019
@akuzm
akuzm deleted the aku/csv-defaults-5349 branch December 9, 2019 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants