mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Add a test
This commit is contained in:
parent
3ea3bb067b
commit
6738a0457a
@ -287,10 +287,6 @@ void LocalServer::tryInitPath()
|
||||
if (getClientConfiguration().has("path"))
|
||||
{
|
||||
/// User-supplied path.
|
||||
/// By default it is a subdirectory in the current directory (it will be created lazily only if needed).
|
||||
/// The subdirectory is named `clickhouse.local`. This name is to not collide with the possible names
|
||||
/// of the binary file, `clickhouse` or `clickhouse-local`.
|
||||
|
||||
path = getClientConfiguration().getString("path");
|
||||
Poco::trimInPlace(path);
|
||||
|
||||
@ -302,7 +298,7 @@ void LocalServer::tryInitPath()
|
||||
" correct the --path.");
|
||||
}
|
||||
}
|
||||
else if (getClientConfiguration().has("tmp"))
|
||||
else
|
||||
{
|
||||
/// The user requested to use a temporary path - use a unique path in the system temporary directory
|
||||
/// (or in the current dir if a temporary doesn't exist)
|
||||
@ -844,12 +840,12 @@ void LocalServer::processConfig()
|
||||
attachInformationSchema(global_context, *createMemoryDatabaseIfNotExists(global_context, DatabaseCatalog::INFORMATION_SCHEMA_UPPERCASE));
|
||||
|
||||
String path = global_context->getPath();
|
||||
|
||||
/// Lock path directory before read
|
||||
status.emplace(fs::path(path) / "status", StatusFile::write_full_info);
|
||||
|
||||
if (fs::exists(fs::path(path) / "metadata"))
|
||||
{
|
||||
/// Lock path directory before read
|
||||
/// Note: this is slightly unsafe. The first instance of clickhouse-local will not be protected.
|
||||
status.emplace(fs::path(path) / "status", StatusFile::write_full_info);
|
||||
|
||||
LOG_DEBUG(log, "Loading metadata from {}", path);
|
||||
|
||||
if (fs::exists(std::filesystem::path(path) / "metadata" / "system.sql"))
|
||||
@ -939,8 +935,7 @@ void LocalServer::addOptions(OptionsDescription & options_description)
|
||||
("logger.level", po::value<std::string>(), "Log level")
|
||||
|
||||
("no-system-tables", "do not attach system tables (better startup time)")
|
||||
("path", po::value<std::string>()->default_value("clickhouse.local"), "storage path")
|
||||
("tmp", "use a temporary directory for tables and delete it on exit")
|
||||
("path", po::value<std::string>(), "Storage path. If it was not specified, we will use a temporary directory, that is cleaned up on exit.")
|
||||
("only-system-tables", "attach only system tables from specified path")
|
||||
("top_level_domains_path", po::value<std::string>(), "Path to lists with custom TLDs")
|
||||
;
|
||||
@ -978,8 +973,6 @@ void LocalServer::processOptions(const OptionsDescription &, const CommandLineOp
|
||||
getClientConfiguration().setString("table-file", options["file"].as<std::string>());
|
||||
if (options.count("structure"))
|
||||
getClientConfiguration().setString("table-structure", options["structure"].as<std::string>());
|
||||
if (options.count("tmp"))
|
||||
getClientConfiguration().setBool("tmp", true);
|
||||
if (options.count("no-system-tables"))
|
||||
getClientConfiguration().setBool("no-system-tables", true);
|
||||
if (options.count("only-system-tables"))
|
||||
|
@ -0,0 +1,35 @@
|
||||
1
|
||||
0 Hello0
|
||||
1 Hello1
|
||||
2 Hello2
|
||||
3 Hello3
|
||||
4 Hello4
|
||||
5 Hello5
|
||||
6 Hello6
|
||||
7 Hello7
|
||||
8 Hello8
|
||||
9 Hello9
|
||||
default Overlay
|
||||
World0
|
||||
World1
|
||||
World2
|
||||
World3
|
||||
World4
|
||||
World5
|
||||
World6
|
||||
World7
|
||||
World8
|
||||
World9
|
||||
|
||||
World0
|
||||
World1
|
||||
World2
|
||||
World3
|
||||
World4
|
||||
World5
|
||||
World6
|
||||
World7
|
||||
World8
|
||||
World9
|
||||
Hello
|
||||
World
|
37
tests/queries/0_stateless/03271_clickhouse_local_persistency.sh
Executable file
37
tests/queries/0_stateless/03271_clickhouse_local_persistency.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
# shellcheck source=../shell_config.sh
|
||||
. "$CUR_DIR"/../shell_config.sh
|
||||
|
||||
cd "${CLICKHOUSE_TMP}"
|
||||
rm -rf "clickhouse.local"
|
||||
rm -f test
|
||||
|
||||
# You can specify the path explicitly.
|
||||
$CLICKHOUSE_LOCAL --path "clickhouse.local" --query "SELECT 1"
|
||||
|
||||
# You can create tables.
|
||||
$CLICKHOUSE_LOCAL --path "clickhouse.local" --query "CREATE TABLE test (x UInt64, s String) ENGINE = MergeTree ORDER BY x"
|
||||
|
||||
# The data is persisted between restarts
|
||||
$CLICKHOUSE_LOCAL --path "clickhouse.local" --query "INSERT INTO test SELECT number, 'Hello' || number FROM numbers(10)"
|
||||
$CLICKHOUSE_LOCAL --path "clickhouse.local" --query "SELECT * FROM test ORDER BY x"
|
||||
|
||||
# The default database is an Overlay on top of Atomic, which lets you exchange tables.
|
||||
$CLICKHOUSE_LOCAL --path "clickhouse.local" --query "SELECT name, engine FROM system.databases WHERE name = 'default'"
|
||||
$CLICKHOUSE_LOCAL --path "clickhouse.local" --query "CREATE OR REPLACE TABLE test (s String) ENGINE = MergeTree ORDER BY ()"
|
||||
$CLICKHOUSE_LOCAL --path "clickhouse.local" --query "SELECT * FROM test"
|
||||
$CLICKHOUSE_LOCAL --path "clickhouse.local" --query "INSERT INTO test SELECT 'World' || number FROM numbers(10)"
|
||||
$CLICKHOUSE_LOCAL --path "clickhouse.local" --query "SELECT * FROM test"
|
||||
|
||||
# It is an overlay database. If you don't have a table with the same name, it will look for a file with that name.
|
||||
# Files are searched relative to the current working directory.
|
||||
echo '"Hello"
|
||||
"World"' > "test"
|
||||
|
||||
echo
|
||||
$CLICKHOUSE_LOCAL --path "clickhouse.local" --query "SELECT * FROM test; DROP TABLE test; SELECT * FROM test;"
|
||||
|
||||
rm -rf "clickhouse.local"
|
||||
rm test
|
Loading…
Reference in New Issue
Block a user