mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 16:42:05 +00:00
Improve schema inference in clickhouse-local
This commit is contained in:
parent
738355b724
commit
9bbbbdcdd6
@ -313,9 +313,17 @@ void LocalServer::cleanup()
|
||||
}
|
||||
|
||||
|
||||
static bool checkIfStdinIsNotEmpty()
|
||||
{
|
||||
struct stat file_stat;
|
||||
return fstat(STDIN_FILENO, &file_stat) == 0 && (S_ISREG(file_stat.st_mode) || S_ISFIFO(file_stat.st_mode));
|
||||
}
|
||||
|
||||
std::string LocalServer::getInitialCreateTableQuery()
|
||||
{
|
||||
if (!config().has("table-structure") && !config().has("table-file") && !config().has("table-data-format"))
|
||||
/// We can create initial table only when we have data for it
|
||||
/// in file or in stdin (we treat stdin as table data if we have query)
|
||||
if (!config().has("table-file") && (!checkIfStdinIsNotEmpty() || !config().has("query")))
|
||||
return {};
|
||||
|
||||
auto table_name = backQuoteIfNeed(config().getString("table-name", "table"));
|
||||
|
@ -0,0 +1,15 @@
|
||||
x Nullable(Float64)
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
c1 Nullable(String)
|
||||
c2 Nullable(String)
|
||||
c3 Nullable(String)
|
||||
1 2 3
|
17
tests/queries/0_stateless/02211_shcema_inference_from_stdin.sh
Executable file
17
tests/queries/0_stateless/02211_shcema_inference_from_stdin.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
# shellcheck source=../shell_config.sh
|
||||
. "$CURDIR"/../shell_config.sh
|
||||
|
||||
|
||||
$CLICKHOUSE_LOCAL -q "select toUInt32(number) as x from numbers(10) format JSONEachRow" > data.jsoneachrow
|
||||
|
||||
$CLICKHOUSE_LOCAL -q "desc table table" < data.jsoneachrow
|
||||
$CLICKHOUSE_LOCAL -q "select * from table" < data.jsoneachrow
|
||||
|
||||
rm data.jsoneachrow
|
||||
|
||||
echo -e "1\t2\t3" | $CLICKHOUSE_LOCAL -q "desc table table"
|
||||
echo -e "1\t2\t3" | $CLICKHOUSE_LOCAL -q "select * from table"
|
||||
|
Loading…
Reference in New Issue
Block a user