mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 01:22:04 +00:00
Merge pull request #33829 from Avogar/autodetect-format
Add format autodetect in clickhouse-local
This commit is contained in:
commit
7116572702
@ -37,6 +37,7 @@
|
|||||||
#include <Dictionaries/registerDictionaries.h>
|
#include <Dictionaries/registerDictionaries.h>
|
||||||
#include <Disks/registerDisks.h>
|
#include <Disks/registerDisks.h>
|
||||||
#include <Formats/registerFormats.h>
|
#include <Formats/registerFormats.h>
|
||||||
|
#include <Formats/FormatFactory.h>
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
#include <boost/program_options/options_description.hpp>
|
#include <boost/program_options/options_description.hpp>
|
||||||
#include <base/argsToConfig.h>
|
#include <base/argsToConfig.h>
|
||||||
@ -319,9 +320,9 @@ std::string LocalServer::getInitialCreateTableQuery()
|
|||||||
|
|
||||||
auto table_name = backQuoteIfNeed(config().getString("table-name", "table"));
|
auto table_name = backQuoteIfNeed(config().getString("table-name", "table"));
|
||||||
auto table_structure = config().getString("table-structure", "auto");
|
auto table_structure = config().getString("table-structure", "auto");
|
||||||
auto data_format = backQuoteIfNeed(config().getString("table-data-format", "TSV"));
|
|
||||||
|
|
||||||
String table_file;
|
String table_file;
|
||||||
|
String format_from_file_name;
|
||||||
if (!config().has("table-file") || config().getString("table-file") == "-")
|
if (!config().has("table-file") || config().getString("table-file") == "-")
|
||||||
{
|
{
|
||||||
/// Use Unix tools stdin naming convention
|
/// Use Unix tools stdin naming convention
|
||||||
@ -330,9 +331,14 @@ std::string LocalServer::getInitialCreateTableQuery()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/// Use regular file
|
/// Use regular file
|
||||||
table_file = quoteString(config().getString("table-file"));
|
auto file_name = config().getString("table-file");
|
||||||
|
table_file = quoteString(file_name);
|
||||||
|
format_from_file_name = FormatFactory::instance().getFormatFromFileName(file_name, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto data_format
|
||||||
|
= backQuoteIfNeed(config().getString("table-data-format", format_from_file_name.empty() ? "TSV" : format_from_file_name));
|
||||||
|
|
||||||
if (table_structure == "auto")
|
if (table_structure == "auto")
|
||||||
table_structure = "";
|
table_structure = "";
|
||||||
else
|
else
|
||||||
|
@ -3,7 +3,7 @@ CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|||||||
# shellcheck source=../shell_config.sh
|
# shellcheck source=../shell_config.sh
|
||||||
. "$CURDIR"/../shell_config.sh
|
. "$CURDIR"/../shell_config.sh
|
||||||
|
|
||||||
SAMPLE_FILE=$(mktemp 01947_multiple_pipe_read_sample_data_XXXXXX.csv)
|
SAMPLE_FILE=$(mktemp 01947_multiple_pipe_read_sample_data_XXXXXX.tsv)
|
||||||
|
|
||||||
echo 'File generated:'
|
echo 'File generated:'
|
||||||
${CLICKHOUSE_LOCAL} -q "SELECT number AS x, if(number in (4,6), 'AAA', 'BBB') AS s from numbers(7)" > "$SAMPLE_FILE"
|
${CLICKHOUSE_LOCAL} -q "SELECT number AS x, if(number in (4,6), 'AAA', 'BBB') AS s from numbers(7)" > "$SAMPLE_FILE"
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
0
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
6
|
||||||
|
7
|
||||||
|
8
|
||||||
|
9
|
11
tests/queries/0_stateless/02181_format_from_file_extension_local.sh
Executable file
11
tests/queries/0_stateless/02181_format_from_file_extension_local.sh
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Tags: no-parallel, no-fasttest
|
||||||
|
|
||||||
|
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||||
|
# shellcheck source=../shell_config.sh
|
||||||
|
. "$CURDIR"/../shell_config.sh
|
||||||
|
|
||||||
|
|
||||||
|
$CLICKHOUSE_LOCAL -q "select * from numbers(10) format Parquet" > $CLICKHOUSE_TMP/data.parquet
|
||||||
|
$CLICKHOUSE_LOCAL -q "select * from table" --file $CLICKHOUSE_TMP/data.parquet
|
||||||
|
|
Loading…
Reference in New Issue
Block a user