Skip to content

Commit d7674e8

Browse files
authored
Folding improvement (#19832)
2 parents 722054e + e4c6d6e commit d7674e8

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

ydb/core/kqp/opt/kqp_constant_folding_transformer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ namespace {
3939
return;
4040
}
4141

42+
if (TCoAsStruct::Match(input.Get())) {
43+
for (auto child : TExprBase(input).Cast<TCoAsStruct>()) {
44+
ExtractConstantExprs(child.Item(1).Ptr(), replaces, ctx);
45+
}
46+
return;
47+
}
48+
4249
if (input->IsCallable() && input->Content() != "EvaluateExpr") {
4350
if (input->ChildrenSize() >= 1) {
4451
for (size_t i = 0; i < input->ChildrenSize(); i++) {

ydb/core/kqp/ut/olap/kqp_olap_ut.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3887,5 +3887,56 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
38873887
CompareYson(result, R"([[20u]])");
38883888
}
38893889
}
3890+
3891+
Y_UNIT_TEST(GroupByWithMakeDatetime) {
3892+
auto settings = TKikimrSettings()
3893+
.SetWithSampleTables(false);
3894+
TKikimrRunner kikimr(settings);
3895+
3896+
auto tableClient = kikimr.GetTableClient();
3897+
auto tableSession = tableClient.CreateSession().GetValueSync().GetSession();
3898+
3899+
auto queryClient = kikimr.GetQueryClient();
3900+
auto result = queryClient.GetSession().GetValueSync();
3901+
NStatusHelpers::ThrowOnError(result);
3902+
auto querySession = result.GetSession();
3903+
3904+
{
3905+
auto result = tableSession.ExecuteSchemeQuery(R"(
3906+
CREATE TABLE `/Root/query_stat` (
3907+
ts Timestamp NOT NULL,
3908+
folder_id String,
3909+
primary key(ts)
3910+
)
3911+
PARTITION BY HASH(ts)
3912+
WITH (STORE = COLUMN);
3913+
)").GetValueSync();
3914+
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
3915+
}
3916+
3917+
{
3918+
auto result = querySession.ExecuteQuery(R"(
3919+
INSERT INTO `/Root/query_stat` (ts, folder_id)
3920+
VALUES (
3921+
CurrentUtcTimestamp(),
3922+
"abc"
3923+
)
3924+
)", NYdb::NQuery::TTxControl::NoTx()).GetValueSync();
3925+
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
3926+
}
3927+
3928+
{
3929+
auto result = querySession.ExecuteQuery(R"(
3930+
SELECT
3931+
ts1, count(*)
3932+
FROM
3933+
query_stat
3934+
where
3935+
folder_id not in [ "b1g0gammoel2iuh0hir6" ]
3936+
GROUP BY DateTime::MakeDatetime(DateTime::StartOf(ts, DateTime::IntervalFromDays(1))) as ts1
3937+
)", NYdb::NQuery::TTxControl::NoTx()).GetValueSync();
3938+
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
3939+
}
3940+
}
38903941
}
38913942
}

0 commit comments

Comments
 (0)