mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 08:40:50 +00:00
Merge pull request #11262 from ClickHouse/fix_unit_broken_tests
Fix unit broken tests
This commit is contained in:
commit
9a34310ead
@ -11,15 +11,15 @@ struct ContextHolder
|
||||
: shared_context(DB::Context::createShared())
|
||||
, context(DB::Context::createGlobal(shared_context.get()))
|
||||
{
|
||||
context.makeGlobalContext();
|
||||
context.setPath("./");
|
||||
}
|
||||
|
||||
ContextHolder(ContextHolder &&) = default;
|
||||
};
|
||||
|
||||
inline ContextHolder getContext()
|
||||
inline const ContextHolder & getContext()
|
||||
{
|
||||
ContextHolder holder;
|
||||
holder.context.makeGlobalContext();
|
||||
holder.context.setPath("./");
|
||||
static ContextHolder holder;
|
||||
return holder;
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ using DiskImplementations = testing::Types<DB::DiskMemory, DB::DiskLocal>;
|
||||
TYPED_TEST_SUITE(StorageLogTest, DiskImplementations);
|
||||
|
||||
// Returns data written to table in Values format.
|
||||
std::string writeData(int rows, DB::StoragePtr & table, DB::Context & context)
|
||||
std::string writeData(int rows, DB::StoragePtr & table, const DB::Context & context)
|
||||
{
|
||||
using namespace DB;
|
||||
|
||||
@ -104,7 +104,7 @@ std::string writeData(int rows, DB::StoragePtr & table, DB::Context & context)
|
||||
}
|
||||
|
||||
// Returns all table data in Values format.
|
||||
std::string readData(DB::StoragePtr & table, DB::Context & context)
|
||||
std::string readData(DB::StoragePtr & table, const DB::Context & context)
|
||||
{
|
||||
using namespace DB;
|
||||
|
||||
@ -136,7 +136,7 @@ std::string readData(DB::StoragePtr & table, DB::Context & context)
|
||||
TYPED_TEST(StorageLogTest, testReadWrite)
|
||||
{
|
||||
using namespace DB;
|
||||
auto context_holder = getContext();
|
||||
const auto & context_holder = getContext();
|
||||
|
||||
std::string data;
|
||||
|
||||
|
@ -18,7 +18,7 @@ using namespace DB;
|
||||
/// NOTE How to do better?
|
||||
struct State
|
||||
{
|
||||
Context & context;
|
||||
Context context;
|
||||
NamesAndTypesList columns{
|
||||
{"column", std::make_shared<DataTypeUInt8>()},
|
||||
{"apply_id", std::make_shared<DataTypeUInt64>()},
|
||||
@ -27,7 +27,8 @@ struct State
|
||||
{"create_time", std::make_shared<DataTypeDateTime>()},
|
||||
};
|
||||
|
||||
explicit State(Context & context_) : context(context_)
|
||||
explicit State()
|
||||
: context(getContext().context)
|
||||
{
|
||||
registerFunctions();
|
||||
DatabasePtr database = std::make_shared<DatabaseMemory>("test");
|
||||
@ -38,6 +39,11 @@ struct State
|
||||
}
|
||||
};
|
||||
|
||||
State getState()
|
||||
{
|
||||
static State state;
|
||||
return state;
|
||||
}
|
||||
|
||||
static void check(const std::string & query, const std::string & expected, const Context & context, const NamesAndTypesList & columns)
|
||||
{
|
||||
@ -54,8 +60,7 @@ static void check(const std::string & query, const std::string & expected, const
|
||||
|
||||
TEST(TransformQueryForExternalDatabase, InWithSingleElement)
|
||||
{
|
||||
auto context_holder = getContext();
|
||||
State state(context_holder.context);
|
||||
const State & state = getState();
|
||||
|
||||
check("SELECT column FROM test.table WHERE 1 IN (1)",
|
||||
R"(SELECT "column" FROM "test"."table" WHERE 1)",
|
||||
@ -70,8 +75,7 @@ TEST(TransformQueryForExternalDatabase, InWithSingleElement)
|
||||
|
||||
TEST(TransformQueryForExternalDatabase, Like)
|
||||
{
|
||||
auto context_holder = getContext();
|
||||
State state(context_holder.context);
|
||||
const State & state = getState();
|
||||
|
||||
check("SELECT column FROM test.table WHERE column LIKE '%hello%'",
|
||||
R"(SELECT "column" FROM "test"."table" WHERE "column" LIKE '%hello%')",
|
||||
@ -83,8 +87,7 @@ TEST(TransformQueryForExternalDatabase, Like)
|
||||
|
||||
TEST(TransformQueryForExternalDatabase, Substring)
|
||||
{
|
||||
auto context_holder = getContext();
|
||||
State state(context_holder.context);
|
||||
const State & state = getState();
|
||||
|
||||
check("SELECT column FROM test.table WHERE left(column, 10) = RIGHT(column, 10) AND SUBSTRING(column FROM 1 FOR 2) = 'Hello'",
|
||||
R"(SELECT "column" FROM "test"."table")",
|
||||
@ -93,8 +96,7 @@ TEST(TransformQueryForExternalDatabase, Substring)
|
||||
|
||||
TEST(TransformQueryForExternalDatabase, MultipleAndSubqueries)
|
||||
{
|
||||
auto context_holder = getContext();
|
||||
State state(context_holder.context);
|
||||
const State & state = getState();
|
||||
|
||||
check("SELECT column FROM test.table WHERE 1 = 1 AND toString(column) = '42' AND column = 42 AND left(column, 10) = RIGHT(column, 10) AND column IN (1, 42) AND SUBSTRING(column FROM 1 FOR 2) = 'Hello' AND column != 4",
|
||||
R"(SELECT "column" FROM "test"."table" WHERE 1 AND ("column" = 42) AND ("column" IN (1, 42)) AND ("column" != 4))",
|
||||
@ -106,8 +108,7 @@ TEST(TransformQueryForExternalDatabase, MultipleAndSubqueries)
|
||||
|
||||
TEST(TransformQueryForExternalDatabase, Issue7245)
|
||||
{
|
||||
auto context_holder = getContext();
|
||||
State state(context_holder.context);
|
||||
const State & state = getState();
|
||||
|
||||
check("select apply_id from test.table where apply_type = 2 and create_time > addDays(toDateTime('2019-01-01 01:02:03'),-7) and apply_status in (3,4)",
|
||||
R"(SELECT "apply_id", "apply_type", "apply_status", "create_time" FROM "test"."table" WHERE ("apply_type" = 2) AND ("create_time" > '2018-12-25 01:02:03') AND ("apply_status" IN (3, 4)))",
|
||||
|
Loading…
Reference in New Issue
Block a user