Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](Planner) fix lateral view when use cte as input table #44561

Draft
wants to merge 1 commit into
base: branch-2.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public InlineViewRef(View view, TableRef origTblRef) {
baseTblSmap = new ExprSubstitutionMap();
setJoinAttrs(origTblRef);
explicitColLabels = view.getColLabels();
if (origTblRef.getLateralViewRefs() != null) {
lateralViewRefs = (ArrayList<LateralViewRef>) origTblRef.getLateralViewRefs().clone();
}
// Set implicit aliases if no explicit one was given.
if (hasExplicitAlias()) {
return;
Expand All @@ -124,9 +127,6 @@ public InlineViewRef(View view, TableRef origTblRef) {
} else {
aliases = new String[]{name.toString(), view.getName()};
}
if (origTblRef.getLateralViewRefs() != null) {
lateralViewRefs = (ArrayList<LateralViewRef>) origTblRef.getLateralViewRefs().clone();
}
}

protected InlineViewRef(InlineViewRef other) {
Expand Down
3 changes: 3 additions & 0 deletions regression-test/data/query_p0/lateral_view/lateral_view.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
2 33
2 44

-- !sql_explode_bug_fix --
\N

-- !sql_explode_bitmap1 --
1 1
1 2
Expand Down
153 changes: 153 additions & 0 deletions regression-test/suites/query_p0/lateral_view/lateral_view.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,159 @@ suite("lateral_view") {
sql "SET enable_nereids_planner=false"
qt_sql_explode_bitmap0 """ select dt, e1 from test_explode_bitmap lateral view explode_bitmap(user_id) tmp1 as e1 order by dt, e1;"""

sql """ DROP TABLE IF EXISTS `entity_37_label_summary` """
sql """
CREATE TABLE `entity_37_label_summary` (
`label_id` int(11) NOT NULL COMMENT '标签标识',
`update_time` datetime NOT NULL COMMENT '更新时间',
`label_value` varchar(128) NULL COMMENT '标签值',
`label_type` int(11) NULL COMMENT '标签类型',
`conf_score` DECIMAL(10, 2) NULL COMMENT '可信度分',
`act_score` DECIMAL(10, 2) NULL COMMENT 'ID 活跃度',
`source_dt` datetime NULL,
`seq_id_bitmap` bitmap BITMAP_UNION NOT NULL COMMENT 'SeqID集合'
) ENGINE=OLAP
AGGREGATE KEY(`label_id`, `update_time`, `label_value`, `label_type`, `conf_score`, `act_score`, `source_dt`)
COMMENT '标签汇总表'
PARTITION BY RANGE(`update_time`)
(PARTITION p20220512 VALUES [('0000-01-01 00:00:00'), ('2022-05-13 00:00:00')),
PARTITION p20220513 VALUES [('2022-05-13 00:00:00'), ('2022-05-14 00:00:00')),
PARTITION p20241124 VALUES [('2024-11-24 00:00:00'), ('2024-11-25 00:00:00')))
DISTRIBUTED BY HASH(`label_id`, `label_value`) BUCKETS 3
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"is_being_synced" = "false",
"dynamic_partition.enable" = "true",
"dynamic_partition.time_unit" = "DAY",
"dynamic_partition.time_zone" = "Asia/Shanghai",
"dynamic_partition.start" = "-2147483648",
"dynamic_partition.end" = "2",
"dynamic_partition.prefix" = "p",
"dynamic_partition.replication_allocation" = "tag.location.default: 1",
"dynamic_partition.buckets" = "3",
"dynamic_partition.create_history_partition" = "false",
"dynamic_partition.history_partition_num" = "-1",
"dynamic_partition.hot_partition_num" = "0",
"dynamic_partition.reserved_history_periods" = "NULL",
"dynamic_partition.storage_policy" = "",
"dynamic_partition.storage_medium" = "HDD",
"storage_format" = "V2",
"light_schema_change" = "true",
"disable_auto_compaction" = "false",
"enable_single_replica_compaction" = "false"
);
"""

sql """ DROP TABLE IF EXISTS `entity_49_label_summary` """
sql """
CREATE TABLE `entity_49_label_summary` (
`label_id` int(11) NOT NULL COMMENT '标签标识',
`update_time` datetime NOT NULL COMMENT '更新时间',
`label_value` varchar(128) NULL COMMENT '标签值',
`label_type` int(11) NULL COMMENT '标签类型',
`conf_score` DECIMAL(10, 2) NULL COMMENT '可信度分',
`act_score` DECIMAL(10, 2) NULL COMMENT 'ID 活跃度',
`source_dt` datetime NULL,
`seq_id_bitmap` bitmap BITMAP_UNION NOT NULL COMMENT 'SeqID集合'
) ENGINE=OLAP
AGGREGATE KEY(`label_id`, `update_time`, `label_value`, `label_type`, `conf_score`, `act_score`, `source_dt`)
COMMENT '标签汇总表'
PARTITION BY RANGE(`update_time`)
(PARTITION p20220512 VALUES [('0000-01-01 00:00:00'), ('2022-05-13 00:00:00')),
PARTITION p20220513 VALUES [('2022-05-13 00:00:00'), ('2022-05-14 00:00:00')),
PARTITION p20241124 VALUES [('2024-11-24 00:00:00'), ('2024-11-25 00:00:00')))
DISTRIBUTED BY HASH(`label_id`, `label_value`) BUCKETS 3
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"is_being_synced" = "false",
"dynamic_partition.enable" = "true",
"dynamic_partition.time_unit" = "DAY",
"dynamic_partition.time_zone" = "Asia/Shanghai",
"dynamic_partition.start" = "-2147483648",
"dynamic_partition.end" = "2",
"dynamic_partition.prefix" = "p",
"dynamic_partition.replication_allocation" = "tag.location.default: 1",
"dynamic_partition.buckets" = "3",
"dynamic_partition.create_history_partition" = "false",
"dynamic_partition.history_partition_num" = "-1",
"dynamic_partition.hot_partition_num" = "0",
"dynamic_partition.reserved_history_periods" = "NULL",
"dynamic_partition.storage_policy" = "",
"dynamic_partition.storage_medium" = "HDD",
"storage_format" = "V2",
"light_schema_change" = "true",
"disable_auto_compaction" = "false",
"enable_single_replica_compaction" = "false"
);
"""

qt_sql_explode_bug_fix """
with relation_bitmap as (
select
label_value,
bitmap_union(seq_id_bitmap) as seq_id_bitmap
from
entity_37_label_summary
where
label_id = 1
and label_type = 3
and (
cast(source_dt as date) >= cast('2022-10-06' as date)
)
and (
cast(source_dt as date) <= cast('2022-10-06' as date)
)
group by
label_value
),
from_entity_bitmap as (
(
select
bitmap_intersect(a.seq_id_bitmap) as seq_id_bitmap
from
(
select
bitmap_union(ifnull(b.seq_id_bitmap, bitmap_empty())) as seq_id_bitmap
from
(
select
update_time
from
(
select
1 tmp
) as a lateral view explode(['2024-11-21 13:38:33']) tmp as update_time
) a
left join (
select
*
from
entity_49_label_summary
where
label_id = 1606
and label_type = 1
and update_time in ('2024-11-21 13:38:33')
and (
cast(label_value as BOOLEAN) in (true, false)
)
) b on b.update_time = a.update_time
group by
a.update_time
) a
)
)
select
IFNULL(bitmap_union(rb.seq_id_bitmap), bitmap_empty()) as seq_id_bitmap
from
(
select
seq_id as seq_id
from
from_entity_bitmap b lateral view explode_bitmap(b.seq_id_bitmap) tmp as seq_id
) __tt
join relation_bitmap rb on rb.label_value = __tt.seq_id;
"""

sql "SET enable_nereids_planner=true"
qt_sql_explode_bitmap1 """ select dt, e1 from test_explode_bitmap lateral view explode_bitmap(user_id) tmp1 as e1 order by dt, e1;"""
}
Loading