mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 03:22:14 +00:00
Kusto-phase2: fix unit test
This commit is contained in:
parent
87d3ba87a7
commit
cafb9f810e
@ -7,7 +7,7 @@
|
||||
#include <Parsers/Kusto/ParserKQLQuery.h>
|
||||
#include <Parsers/Kusto/ParserKQLStatement.h>
|
||||
#include <Parsers/ParserSetQuery.h>
|
||||
|
||||
#include "Poco/String.h"
|
||||
#include <format>
|
||||
#include <regex>
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <Parsers/Kusto/ParserKQLQuery.h>
|
||||
#include <Parsers/Kusto/ParserKQLStatement.h>
|
||||
#include <Parsers/ParserSetQuery.h>
|
||||
|
||||
#include "Poco/String.h"
|
||||
namespace DB::ErrorCodes
|
||||
{
|
||||
extern const int BAD_ARGUMENTS;
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include <Parsers/tests/gtest_common.h>
|
||||
#include <IO/WriteBufferFromOStream.h>
|
||||
#include <Interpreters/applyTableOverride.h>
|
||||
#include <Parsers/ASTCreateQuery.h>
|
||||
#include <Parsers/ASTFunction.h>
|
||||
#include <Parsers/ASTIdentifier.h>
|
||||
#include <Parsers/Access/ASTCreateUserQuery.h>
|
||||
#include <Parsers/Access/ParserCreateUserQuery.h>
|
||||
#include <Parsers/Access/ASTAuthenticationData.h>
|
||||
#include <Parsers/ParserAlterQuery.h>
|
||||
@ -17,6 +17,8 @@
|
||||
#include <Parsers/PRQL/ParserPRQLQuery.h>
|
||||
#include <string_view>
|
||||
#include <regex>
|
||||
#include <gtest/gtest.h>
|
||||
#include "gtest_common.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -554,58 +556,59 @@ INSTANTIATE_TEST_SUITE_P(ParserKQLQuery, ParserTest,
|
||||
{
|
||||
"print parse_url('https://john:123@google.com:1234/this/is/a/path?k1=v1&k2=v2#fragment')",
|
||||
"SELECT concat('{', concat('\"Scheme\":\"', protocol('https://john:123@google.com:1234/this/is/a/path?k1=v1&k2=v2#fragment'), '\"'), ',', concat('\"Host\":\"', domain('https://john:123@google.com:1234/this/is/a/path?k1=v1&k2=v2#fragment'), '\"'), ',', concat('\"Port\":\"', toString(port('https://john:123@google.com:1234/this/is/a/path?k1=v1&k2=v2#fragment')), '\"'), ',', concat('\"Path\":\"', path('https://john:123@google.com:1234/this/is/a/path?k1=v1&k2=v2#fragment'), '\"'), ',', concat('\"Username\":\"', splitByChar(':', splitByChar('@', netloc('https://john:123@google.com:1234/this/is/a/path?k1=v1&k2=v2#fragment'))[1])[1], '\"'), ',', concat('\"Password\":\"', splitByChar(':', splitByChar('@', netloc('https://john:123@google.com:1234/this/is/a/path?k1=v1&k2=v2#fragment'))[1])[2], '\"'), ',', concat('\"Query Parameters\":', concat('{\"', replace(replace(queryString('https://john:123@google.com:1234/this/is/a/path?k1=v1&k2=v2#fragment'), '=', '\":\"'), '&', '\",\"'), '\"}')), ',', concat('\"Fragment\":\"', fragment('https://john:123@google.com:1234/this/is/a/path?k1=v1&k2=v2#fragment'), '\"'), '}')"
|
||||
},{
|
||||
"Customers | summarize t = make_list(FirstName) by FirstName",
|
||||
"SELECT\n FirstName,\n groupArrayIf(FirstName, FirstName IS NOT NULL) AS t\nFROM Customers\nGROUP BY FirstName"
|
||||
},
|
||||
{
|
||||
"Customers | summarize t = make_list(FirstName, 10) by FirstName",
|
||||
"SELECT\n FirstName,\n groupArrayIf(10)(FirstName, FirstName IS NOT NULL) AS t\nFROM Customers\nGROUP BY FirstName"
|
||||
},
|
||||
{
|
||||
"Customers | summarize t = make_list_if(FirstName, Age > 10) by FirstName",
|
||||
"SELECT\n FirstName,\n groupArrayIf(FirstName, Age > 10) AS t\nFROM Customers\nGROUP BY FirstName"
|
||||
},
|
||||
{
|
||||
"Customers | summarize t = make_list_if(FirstName, Age > 10, 10) by FirstName",
|
||||
"SELECT\n FirstName,\n groupArrayIf(10)(FirstName, Age > 10) AS t\nFROM Customers\nGROUP BY FirstName"
|
||||
},
|
||||
{
|
||||
"Customers | summarize t = make_set(FirstName) by FirstName",
|
||||
"SELECT\n FirstName,\n groupUniqArray(FirstName) AS t\nFROM Customers\nGROUP BY FirstName"
|
||||
},
|
||||
{
|
||||
"Customers | summarize t = make_set(FirstName, 10) by FirstName",
|
||||
"SELECT\n FirstName,\n groupUniqArray(10)(FirstName) AS t\nFROM Customers\nGROUP BY FirstName"
|
||||
},
|
||||
{
|
||||
"Customers | summarize t = make_set_if(FirstName, Age > 10) by FirstName",
|
||||
"SELECT\n FirstName,\n groupUniqArrayIf(FirstName, Age > 10) AS t\nFROM Customers\nGROUP BY FirstName"
|
||||
},
|
||||
{
|
||||
"Customers | summarize t = make_set_if(FirstName, Age > 10, 10) by FirstName",
|
||||
"SELECT\n FirstName,\n groupUniqArrayIf(10)(FirstName, Age > 10) AS t\nFROM Customers\nGROUP BY FirstName"
|
||||
},
|
||||
{
|
||||
"print output = dynamic([1, 2, 3])",
|
||||
"SELECT [1, 2, 3] AS output"
|
||||
},
|
||||
{
|
||||
"print output = dynamic(['a', 'b', 'c'])",
|
||||
"SELECT ['a', 'b', 'c'] AS output"
|
||||
},
|
||||
{
|
||||
"T | extend duration = endTime - startTime",
|
||||
"SELECT\n * EXCEPT duration,\n endTime - startTime AS duration\nFROM T"
|
||||
},
|
||||
{
|
||||
"T |project endTime, startTime | extend duration = endTime - startTime",
|
||||
"SELECT\n * EXCEPT duration,\n endTime - startTime AS duration\nFROM\n(\n SELECT\n endTime,\n startTime\n FROM T\n)"
|
||||
},
|
||||
{
|
||||
"T | extend c =c*2, b-a, d = a +b , a*b",
|
||||
"SELECT\n * EXCEPT c EXCEPT d,\n c * 2 AS c,\n b - a AS Column1,\n a + b AS d,\n a * b AS Column2\nFROM T"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Customers | summarize t = make_list(FirstName) by FirstName",
|
||||
"SELECT\n FirstName,\n groupArrayIf(FirstName, FirstName IS NOT NULL) AS t\nFROM Customers\nGROUP BY FirstName"
|
||||
},
|
||||
{
|
||||
"Customers | summarize t = make_list(FirstName, 10) by FirstName",
|
||||
"SELECT\n FirstName,\n groupArrayIf(10)(FirstName, FirstName IS NOT NULL) AS t\nFROM Customers\nGROUP BY FirstName"
|
||||
},
|
||||
{
|
||||
"Customers | summarize t = make_list_if(FirstName, Age > 10) by FirstName",
|
||||
"SELECT\n FirstName,\n groupArrayIf(FirstName, Age > 10) AS t\nFROM Customers\nGROUP BY FirstName"
|
||||
},
|
||||
{
|
||||
"Customers | summarize t = make_list_if(FirstName, Age > 10, 10) by FirstName",
|
||||
"SELECT\n FirstName,\n groupArrayIf(10)(FirstName, Age > 10) AS t\nFROM Customers\nGROUP BY FirstName"
|
||||
},
|
||||
{
|
||||
"Customers | summarize t = make_set(FirstName) by FirstName",
|
||||
"SELECT\n FirstName,\n groupUniqArray(FirstName) AS t\nFROM Customers\nGROUP BY FirstName"
|
||||
},
|
||||
{
|
||||
"Customers | summarize t = make_set(FirstName, 10) by FirstName",
|
||||
"SELECT\n FirstName,\n groupUniqArray(10)(FirstName) AS t\nFROM Customers\nGROUP BY FirstName"
|
||||
},
|
||||
{
|
||||
"Customers | summarize t = make_set_if(FirstName, Age > 10) by FirstName",
|
||||
"SELECT\n FirstName,\n groupUniqArrayIf(FirstName, Age > 10) AS t\nFROM Customers\nGROUP BY FirstName"
|
||||
},
|
||||
{
|
||||
"Customers | summarize t = make_set_if(FirstName, Age > 10, 10) by FirstName",
|
||||
"SELECT\n FirstName,\n groupUniqArrayIf(10)(FirstName, Age > 10) AS t\nFROM Customers\nGROUP BY FirstName"
|
||||
},
|
||||
{
|
||||
"print output = dynamic([1, 2, 3])",
|
||||
"SELECT [1, 2, 3] AS output"
|
||||
},
|
||||
{
|
||||
"print output = dynamic(['a', 'b', 'c'])",
|
||||
"SELECT ['a', 'b', 'c'] AS output"
|
||||
},
|
||||
{
|
||||
"T | extend duration = endTime - startTime",
|
||||
"SELECT\n * EXCEPT duration,\n endTime - startTime AS duration\nFROM T"
|
||||
},
|
||||
{
|
||||
"T |project endTime, startTime | extend duration = endTime - startTime",
|
||||
"SELECT\n * EXCEPT duration,\n endTime - startTime AS duration\nFROM\n(\n SELECT\n endTime,\n startTime\n FROM T\n)"
|
||||
},
|
||||
{
|
||||
"T | extend c =c*2, b-a, d = a +b , a*b",
|
||||
"SELECT\n * EXCEPT c EXCEPT d,\n c * 2 AS c,\n b - a AS Column1,\n a + b AS d,\n a * b AS Column2\nFROM T"
|
||||
}
|
||||
})));
|
||||
|
||||
static constexpr size_t kDummyMaxQuerySize = 256 * 1024;
|
||||
|
@ -8,48 +8,6 @@
|
||||
|
||||
#include <regex>
|
||||
|
||||
TEST_P(ParserTest, parseQuery)
|
||||
{
|
||||
const auto & parser = std::get<0>(GetParam());
|
||||
const auto & [input_text, expected_ast] = std::get<1>(GetParam());
|
||||
|
||||
ASSERT_NE(nullptr, parser);
|
||||
|
||||
if (expected_ast)
|
||||
{
|
||||
if (std::string(expected_ast).starts_with("throws"))
|
||||
{
|
||||
EXPECT_THROW(parseQuery(*parser, input_text.begin(), input_text.end(), 0, 0), DB::Exception);
|
||||
}
|
||||
else
|
||||
{
|
||||
DB::ASTPtr ast;
|
||||
ASSERT_NO_THROW(ast = parseQuery(*parser, input_text.begin(), input_text.end(), 0, 0));
|
||||
if (std::string("CREATE USER or ALTER USER query") != parser->getName()
|
||||
&& std::string("ATTACH access entity query") != parser->getName())
|
||||
{
|
||||
EXPECT_EQ(expected_ast, serializeAST(*ast->clone(), false));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (input_text.starts_with("ATTACH"))
|
||||
{
|
||||
auto salt = (dynamic_cast<const DB::ASTCreateUserQuery *>(ast.get())->auth_data)->getSalt();
|
||||
EXPECT_TRUE(std::regex_match(salt, std::regex(expected_ast)));
|
||||
}
|
||||
else
|
||||
{
|
||||
EXPECT_TRUE(std::regex_match(serializeAST(*ast->clone(), false), std::regex(expected_ast)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT_THROW(parseQuery(*parser, input_text.begin(), input_text.end(), 0, 0), DB::Exception);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(ParserRegexTest, parseQuery)
|
||||
{
|
||||
const auto & parser = std::get<0>(GetParam());
|
||||
|
Loading…
Reference in New Issue
Block a user