mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-11 01:54:55 +00:00
External queries: fix the case of expr IN table #9756
This commit is contained in:
parent
7d25c1f7f7
commit
8fb64472f2
@ -80,6 +80,24 @@ TEST(TransformQueryForExternalDatabase, InWithSingleElement)
|
||||
state.context, state.columns);
|
||||
}
|
||||
|
||||
TEST(TransformQueryForExternalDatabase, InWithTable)
|
||||
{
|
||||
const State & state = State::instance();
|
||||
|
||||
check("SELECT column FROM test.table WHERE 1 IN external_table",
|
||||
R"(SELECT "column" FROM "test"."table")",
|
||||
state.context, state.columns);
|
||||
check("SELECT column FROM test.table WHERE 1 IN (x)",
|
||||
R"(SELECT "column" FROM "test"."table")",
|
||||
state.context, state.columns);
|
||||
check("SELECT column, field, value FROM test.table WHERE column IN (field, value)",
|
||||
R"(SELECT "column", "field", "value" FROM "test"."table" WHERE "column" IN ("field", "value"))",
|
||||
state.context, state.columns);
|
||||
check("SELECT column FROM test.table WHERE column NOT IN hello AND column = 123",
|
||||
R"(SELECT "column" FROM "test"."table" WHERE ("column" = 123))",
|
||||
state.context, state.columns);
|
||||
}
|
||||
|
||||
TEST(TransformQueryForExternalDatabase, Like)
|
||||
{
|
||||
const State & state = State::instance();
|
||||
|
@ -138,6 +138,12 @@ bool isCompatible(const IAST & node)
|
||||
if (name == "tuple" && function->arguments->children.size() <= 1)
|
||||
return false;
|
||||
|
||||
/// If the right hand side of IN is an identifier (example: x IN table), then it's not compatible.
|
||||
if ((name == "in" || name == "notIn")
|
||||
&& (function->arguments->children.size() != 2
|
||||
|| function->arguments->children[1]->as<ASTIdentifier>()))
|
||||
return false;
|
||||
|
||||
for (const auto & expr : function->arguments->children)
|
||||
if (!isCompatible(*expr))
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user