Add --silent mode for clickhouse-local. [#CLICKHOUSE-3390]

This commit is contained in:
Vitaliy Lyudvichenko 2018-01-15 17:58:21 +03:00
parent f20f3f21c4
commit a95526cd8a
7 changed files with 59 additions and 40 deletions

View File

@ -4,6 +4,8 @@
#include <Poco/Util/HelpFormatter.h>
#include <Poco/Util/OptionCallback.h>
#include <Poco/String.h>
#include <Poco/Logger.h>
#include <Poco/NullChannel.h>
#include <Databases/DatabaseOrdinary.h>
#include <Storages/System/attachSystemTables.h>
#include <Interpreters/Context.h>
@ -49,6 +51,13 @@ LocalServer::~LocalServer()
void LocalServer::initialize(Poco::Util::Application & self)
{
Poco::Util::Application::initialize(self);
// Turn off server logging to stderr
if (config().has("silent"))
{
Poco::Logger::root().setLevel("none");
Poco::Logger::root().setChannel(Poco::AutoPtr<Poco::NullChannel>(new Poco::NullChannel()));
}
}
@ -66,14 +75,21 @@ void LocalServer::defineOptions(Poco::Util::OptionSet& _options)
/// Arguments that define first query creating initial table:
/// (If structure argument is omitted then initial query is not generated)
_options.addOption(
Poco::Util::Option("structure", "S", "Structe of initial table(list columns names with their types)")
Poco::Util::Option("structure", "S", "Structure of initial table(list columns names with their types)")
.required(false)
.repeatable(false)
.argument("[name Type]")
.binding("table-structure"));
/// Turn off logging
_options.addOption(
Poco::Util::Option("table", "N", "Name of intial table")
Poco::Util::Option("silent", "s", "Quiet mode, print only errors")
.required(false)
.repeatable(false)
.binding("silent"));
_options.addOption(
Poco::Util::Option("table", "N", "Name of initial table")
.required(false)
.repeatable(false)
.argument("[table]")
@ -87,10 +103,10 @@ void LocalServer::defineOptions(Poco::Util::OptionSet& _options)
.binding("table-file"));
_options.addOption(
Poco::Util::Option("input-format", "if", "Input format of intial table data")
Poco::Util::Option("input-format", "if", "Input format of initial table data")
.required(false)
.repeatable(false)
.argument("[TSV]")
.argument("<TSV>")
.binding("table-data-format"));
/// List of queries to execute
@ -98,7 +114,7 @@ void LocalServer::defineOptions(Poco::Util::OptionSet& _options)
Poco::Util::Option("query", "q", "Queries to execute")
.required(false)
.repeatable(false)
.argument("<query>", true)
.argument("<query>")
.binding("query"));
/// Default Output format
@ -109,9 +125,9 @@ void LocalServer::defineOptions(Poco::Util::OptionSet& _options)
.argument("[TSV]", true)
.binding("output-format"));
/// Alias for previous one, required for clickhouse-client compability
/// Alias for previous one, required for clickhouse-client compatibility
_options.addOption(
Poco::Util::Option("format", "", "Default ouput format")
Poco::Util::Option("format", "", "Default output format")
.required(false)
.repeatable(false)
.argument("[TSV]", true)
@ -304,7 +320,7 @@ try
/** Init dummy default DB
* NOTE: We force using isolated default database to avoid conflicts with default database from server enviroment
* Otherwise, metadata of temporary File(format, EXPLICIT_PATH) tables will pollute metadata/ directory;
* if such tables will not be dropped, clickhouse-server can not load them due to security reasons.
* if such tables will not be dropped, clickhouse-server will not be able to load them due to security reasons.
*/
const std::string default_database = "_local";
context->addDatabase(default_database, std::make_shared<DatabaseMemory>(default_database));

View File

@ -22,8 +22,8 @@ table_name="ontime"
table="test.ontime"
function read_src_data {
clickhouse-local --file "$SOURCE" --input-format CSV --structure "$STRUCT" -of Native --query "$@" 2>/dev/null
#clickhouse-local --file "$SOURCE" --input-format Native --structure "$STRUCT" -of Native --query "$@" 2>/dev/null
clickhouse-local -s --file "$SOURCE" --input-format CSV --structure "$STRUCT" -of Native --query "$@"
#clickhouse-local -s --file "$SOURCE" --input-format Native --structure "$STRUCT" -of Native --query "$@"
}
function set_vertical_alg {
@ -71,7 +71,7 @@ function get_last_merge_time {
}
function total_merge_time_from_log {
cat /var/log/clickhouse-server/clickhouse-server.log | grep "(Merger): Merge sorted" | cut -d " " -f 21 | clickhouse-local -S "d Float64" --query "SELECT round(sum(d), 3) FROM table" 2>/dev/null
cat /var/log/clickhouse-server/clickhouse-server.log | grep "(Merger): Merge sorted" | cut -d " " -f 21 | clickhouse-local -s -S "d Float64" --query "SELECT round(sum(d), 3) FROM table"
}
function get_max_clickhouse_server_memory {

View File

@ -34,4 +34,4 @@ SELECT roundToExp2(number) AS k, length(groupArray(1)([hex(number)] AS i)), leng
DROP TABLE test.numbers_mt;
-- Check binary compability:
-- clickhouse-client -h old -q "SELECT arrayReduce('groupArrayState', [['1'], ['22'], ['333']]) FORMAT RowBinary" | clickhouse-local --input-format RowBinary --structure "d AggregateFunction(groupArray2, Array(String))" -q "SELECT groupArray2Merge(d) FROM table"
-- clickhouse-client -h old -q "SELECT arrayReduce('groupArrayState', [['1'], ['22'], ['333']]) FORMAT RowBinary" | clickhouse-local -s --input-format RowBinary --structure "d AggregateFunction(groupArray2, Array(String))" -q "SELECT groupArray2Merge(d) FROM table"

View File

@ -20,8 +20,8 @@ function pack_unpack_compare()
local res_db_file=$(${CLICKHOUSE_CLIENT} --max_threads=1 --query "SELECT $TABLE_HASH FROM test.buf_file")
${CLICKHOUSE_CLIENT} --max_threads=1 --query "SELECT * FROM test.buf FORMAT $3" > "$buf_file"
local res_ch_local1=$(${CLICKHOUSE_LOCAL} --structure "$2" --file "$buf_file" --table "my super table" --input-format "$3" --output-format TabSeparated --query "SELECT $TABLE_HASH FROM \`my super table\`" 2>${CLICKHOUSE_TMP}/stderr || cat stderr 1>&2)
local res_ch_local2=$(${CLICKHOUSE_LOCAL} --structure "$2" --table "my super table" --input-format "$3" --output-format TabSeparated --query "SELECT $TABLE_HASH FROM \`my super table\`" < "$buf_file" 2>${CLICKHOUSE_TMP}/stderr || cat ${CLICKHOUSE_TMP}/stderr 1>&2)
local res_ch_local1=$(${CLICKHOUSE_LOCAL} -s --structure "$2" --file "$buf_file" --table "my super table" --input-format "$3" --output-format TabSeparated --query "SELECT $TABLE_HASH FROM \`my super table\`")
local res_ch_local2=$(${CLICKHOUSE_LOCAL} -s --structure "$2" --table "my super table" --input-format "$3" --output-format TabSeparated --query "SELECT $TABLE_HASH FROM \`my super table\`" < "$buf_file")
${CLICKHOUSE_CLIENT} --query "DROP TABLE IF EXISTS test.buf"
${CLICKHOUSE_CLIENT} --query "DROP TABLE IF EXISTS test.buf_file"
@ -38,7 +38,7 @@ pack_unpack_compare "SELECT name, is_aggregate FROM system.functions" "name Stri
pack_unpack_compare "SELECT name, is_aggregate FROM system.functions" "name String, is_aggregate UInt8" "Native"
pack_unpack_compare "SELECT name, is_aggregate FROM system.functions" "name String, is_aggregate UInt8" "TSKV"
echo
${CLICKHOUSE_LOCAL} -q "CREATE TABLE sophisticated_default
${CLICKHOUSE_LOCAL} -s -q "CREATE TABLE sophisticated_default
(
a UInt8 DEFAULT
(
@ -49,4 +49,7 @@ ${CLICKHOUSE_LOCAL} -q "CREATE TABLE sophisticated_default
SELECT dummy+9 FROM system.one
),
c UInt8
) ENGINE = Memory; SELECT count() FROM system.tables WHERE name='sophisticated_default';" 2>/dev/null
) ENGINE = Memory; SELECT count() FROM system.tables WHERE name='sophisticated_default';"
# Help is not skipped
[[ `${CLICKHOUSE_LOCAL} -s --help 2>&1 | wc -l` > 100 ]]

View File

@ -5,26 +5,26 @@ set -e
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. $CURDIR/../shell_config.sh
echo -ne '\\tHello\t123\t\\N\n\\N\t\t2000-01-01 00:00:00\n' | ${CLICKHOUSE_LOCAL} --input-format=TabSeparated --output-format=TabSeparated --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo -ne 'Hello,123,\\N\n\\N,0,"2000-01-01 00:00:00"' | ${CLICKHOUSE_LOCAL} --input-format=CSV --output-format=TabSeparated --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo -ne '"\\Hello",123,\\N\n"\\N",0,"2000-01-01 00:00:00"' | ${CLICKHOUSE_LOCAL} --input-format=CSV --output-format=TabSeparated --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo -ne '{"s" : null, "x" : 123}, {"s" : "\N", "t":"2000-01-01 00:00:00"}' | ${CLICKHOUSE_LOCAL} --input-format=JSONEachRow --output-format=TabSeparated --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo "(NULL, 111, '2000-01-01 00:00:00'), ('\N', NULL, NULL), ('a\Nb', NULL, NULL)" | ${CLICKHOUSE_LOCAL} --input-format=Values --output-format=TabSeparated --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo -ne '\\tHello\t123\t\\N\n\\N\t\t2000-01-01 00:00:00\n' | ${CLICKHOUSE_LOCAL} -s --input-format=TabSeparated --output-format=TabSeparated --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo -ne 'Hello,123,\\N\n\\N,0,"2000-01-01 00:00:00"' | ${CLICKHOUSE_LOCAL} -s --input-format=CSV --output-format=TabSeparated --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo -ne '"\\Hello",123,\\N\n"\\N",0,"2000-01-01 00:00:00"' | ${CLICKHOUSE_LOCAL} -s --input-format=CSV --output-format=TabSeparated --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo -ne '{"s" : null, "x" : 123}, {"s" : "\N", "t":"2000-01-01 00:00:00"}' | ${CLICKHOUSE_LOCAL} -s --input-format=JSONEachRow --output-format=TabSeparated --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo "(NULL, 111, '2000-01-01 00:00:00'), ('\N', NULL, NULL), ('a\Nb', NULL, NULL)" | ${CLICKHOUSE_LOCAL} -s --input-format=Values --output-format=TabSeparated --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo -ne '\\tHello\t123\t\\N\n\\N\t\t2000-01-01 00:00:00\n' | ${CLICKHOUSE_LOCAL} --input-format=TabSeparated --output-format=CSV --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo -ne 'Hello,123,\\N\n\\N,0,"2000-01-01 00:00:00"' | ${CLICKHOUSE_LOCAL} --input-format=CSV --output-format=CSV --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo -ne '"\\Hello",123,\\N\n"\\N",0,"2000-01-01 00:00:00"' | ${CLICKHOUSE_LOCAL} --input-format=CSV --output-format=CSV --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo -ne '{"s" : null, "x" : 123}, {"s" : "\N", "t":"2000-01-01 00:00:00"}' | ${CLICKHOUSE_LOCAL} --input-format=JSONEachRow --output-format=CSV --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo "(NULL, 111, '2000-01-01 00:00:00'), ('\N', NULL, NULL), ('a\Nb', NULL, NULL)" | ${CLICKHOUSE_LOCAL} --input-format=Values --output-format=CSV --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo -ne '\\tHello\t123\t\\N\n\\N\t\t2000-01-01 00:00:00\n' | ${CLICKHOUSE_LOCAL} -s --input-format=TabSeparated --output-format=CSV --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo -ne 'Hello,123,\\N\n\\N,0,"2000-01-01 00:00:00"' | ${CLICKHOUSE_LOCAL} -s --input-format=CSV --output-format=CSV --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo -ne '"\\Hello",123,\\N\n"\\N",0,"2000-01-01 00:00:00"' | ${CLICKHOUSE_LOCAL} -s --input-format=CSV --output-format=CSV --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo -ne '{"s" : null, "x" : 123}, {"s" : "\N", "t":"2000-01-01 00:00:00"}' | ${CLICKHOUSE_LOCAL} -s --input-format=JSONEachRow --output-format=CSV --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo "(NULL, 111, '2000-01-01 00:00:00'), ('\N', NULL, NULL), ('a\Nb', NULL, NULL)" | ${CLICKHOUSE_LOCAL} -s --input-format=Values --output-format=CSV --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo -ne '\\tHello\t123\t\\N\n\\N\t\t2000-01-01 00:00:00\n' | ${CLICKHOUSE_LOCAL} --input-format=TabSeparated --output-format=JSONEachRow --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo -ne 'Hello,123,\\N\n\\N,0,"2000-01-01 00:00:00"' | ${CLICKHOUSE_LOCAL} --input-format=CSV --output-format=JSONEachRow --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo -ne '"\\Hello",123,\\N\n"\\N",0,"2000-01-01 00:00:00"' | ${CLICKHOUSE_LOCAL} --input-format=CSV --output-format=JSONEachRow --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo -ne '{"s" : null, "x" : 123}, {"s" : "\N", "t":"2000-01-01 00:00:00"}' | ${CLICKHOUSE_LOCAL} --input-format=JSONEachRow --output-format=JSONEachRow --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo "(NULL, 111, '2000-01-01 00:00:00'), ('\N', NULL, NULL), ('a\Nb', NULL, NULL)" | ${CLICKHOUSE_LOCAL} --input-format=Values --output-format=JSONEachRow --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo -ne '\\tHello\t123\t\\N\n\\N\t\t2000-01-01 00:00:00\n' | ${CLICKHOUSE_LOCAL} -s --input-format=TabSeparated --output-format=JSONEachRow --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo -ne 'Hello,123,\\N\n\\N,0,"2000-01-01 00:00:00"' | ${CLICKHOUSE_LOCAL} -s --input-format=CSV --output-format=JSONEachRow --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo -ne '"\\Hello",123,\\N\n"\\N",0,"2000-01-01 00:00:00"' | ${CLICKHOUSE_LOCAL} -s --input-format=CSV --output-format=JSONEachRow --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo -ne '{"s" : null, "x" : 123}, {"s" : "\N", "t":"2000-01-01 00:00:00"}' | ${CLICKHOUSE_LOCAL} -s --input-format=JSONEachRow --output-format=JSONEachRow --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo "(NULL, 111, '2000-01-01 00:00:00'), ('\N', NULL, NULL), ('a\Nb', NULL, NULL)" | ${CLICKHOUSE_LOCAL} -s --input-format=Values --output-format=JSONEachRow --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo -ne '\\tHello\t123\t\\N\n\\N\t\t2000-01-01 00:00:00\n' | ${CLICKHOUSE_LOCAL} --input-format=TabSeparated --output-format=Values --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo -ne 'Hello,123,\\N\n\\N,0,"2000-01-01 00:00:00"' | ${CLICKHOUSE_LOCAL} --input-format=CSV --output-format=Values --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo -ne '"\\Hello",123,\\N\n"\\N",0,"2000-01-01 00:00:00"' | ${CLICKHOUSE_LOCAL} --input-format=CSV --output-format=Values --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo -ne '{"s" : null, "x" : 123}, {"s" : "\N", "t":"2000-01-01 00:00:00"}' | ${CLICKHOUSE_LOCAL} --input-format=JSONEachRow --output-format=Values --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo "(NULL, 111, '2000-01-01 00:00:00'), ('\N', NULL, NULL), ('a\Nb', NULL, NULL)" | ${CLICKHOUSE_LOCAL} --input-format=Values --output-format=Values --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table" 2>/dev/null
echo -ne '\\tHello\t123\t\\N\n\\N\t\t2000-01-01 00:00:00\n' | ${CLICKHOUSE_LOCAL} -s --input-format=TabSeparated --output-format=Values --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo -ne 'Hello,123,\\N\n\\N,0,"2000-01-01 00:00:00"' | ${CLICKHOUSE_LOCAL} -s --input-format=CSV --output-format=Values --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo -ne '"\\Hello",123,\\N\n"\\N",0,"2000-01-01 00:00:00"' | ${CLICKHOUSE_LOCAL} -s --input-format=CSV --output-format=Values --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo -ne '{"s" : null, "x" : 123}, {"s" : "\N", "t":"2000-01-01 00:00:00"}' | ${CLICKHOUSE_LOCAL} -s --input-format=JSONEachRow --output-format=Values --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"
echo "(NULL, 111, '2000-01-01 00:00:00'), ('\N', NULL, NULL), ('a\Nb', NULL, NULL)" | ${CLICKHOUSE_LOCAL} -s --input-format=Values --output-format=Values --structure='s Nullable(String), x Nullable(UInt64), t Nullable(DateTime)' --query="SELECT * FROM table"

View File

@ -27,7 +27,7 @@ perform "bad_union_all" "SELECT 1, 2 INTO OUTFILE '${CLICKHOUSE_TMP}/test_into_o
perform "describe_table" "DESCRIBE TABLE system.one INTO OUTFILE '${CLICKHOUSE_TMP}/test_into_outfile_describe_table.out'"
echo "performing test: clickhouse-local"
echo -e '1\t2' | ${CLICKHOUSE_LOCAL} --structure 'col1 UInt32, col2 UInt32' --query "SELECT col1 + 1, col2 + 1 FROM table INTO OUTFILE '${CLICKHOUSE_TMP}/test_into_outfile_clickhouse-local.out'" 2>/dev/null
echo -e '1\t2' | ${CLICKHOUSE_LOCAL} -s --structure 'col1 UInt32, col2 UInt32' --query "SELECT col1 + 1, col2 + 1 FROM table INTO OUTFILE '${CLICKHOUSE_TMP}/test_into_outfile_clickhouse-local.out'"
if [ "$?" -eq 0 ]; then
cat "${CLICKHOUSE_TMP}/test_into_outfile_clickhouse-local.out"
else

View File

@ -3,6 +3,6 @@
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. $CURDIR/../shell_config.sh
TZ=Europe/Moscow ${CLICKHOUSE_LOCAL} --query="SELECT toDateTime('1990-10-19 00:00:00')" 2>/dev/null
TZ=Asia/Colombo ${CLICKHOUSE_LOCAL} --query="SELECT toDateTime('1990-10-19 00:00:00')" 2>/dev/null
TZ=Asia/Kathmandu ${CLICKHOUSE_LOCAL} --query="SELECT toDateTime('1990-10-19 00:00:00')" 2>/dev/null
TZ=Europe/Moscow ${CLICKHOUSE_LOCAL} -s --query="SELECT toDateTime('1990-10-19 00:00:00')"
TZ=Asia/Colombo ${CLICKHOUSE_LOCAL} -s --query="SELECT toDateTime('1990-10-19 00:00:00')"
TZ=Asia/Kathmandu ${CLICKHOUSE_LOCAL} -s --query="SELECT toDateTime('1990-10-19 00:00:00')"