mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-14 17:23:09 +00:00
fix: wrap tql cte in a subquery alias (#6910)
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
@@ -282,6 +282,16 @@ impl DfLogicalPlanner {
|
||||
.build()
|
||||
.context(PlanSqlSnafu)?;
|
||||
}
|
||||
|
||||
// Wrap in SubqueryAlias to ensure proper table qualification for CTE
|
||||
logical_plan = LogicalPlan::SubqueryAlias(
|
||||
datafusion_expr::SubqueryAlias::try_new(
|
||||
Arc::new(logical_plan),
|
||||
cte.name.value.clone(),
|
||||
)
|
||||
.context(PlanSqlSnafu)?,
|
||||
);
|
||||
|
||||
planner_context.insert_cte(&cte.name.value, logical_plan);
|
||||
}
|
||||
CteContent::Sql(_) => {
|
||||
|
||||
@@ -109,6 +109,22 @@ SELECT count(*) as host1_points FROM host_metrics;
|
||||
| 5 |
|
||||
+--------------+
|
||||
|
||||
-- TQL CTE with column reference
|
||||
WITH host_metrics AS (
|
||||
TQL EVAL (0, 40, '10s') labels{host="host1"}
|
||||
)
|
||||
SELECT host_metrics.ts, host_metrics.host FROM host_metrics;
|
||||
|
||||
+---------------------+-------+
|
||||
| ts | host |
|
||||
+---------------------+-------+
|
||||
| 1970-01-01T00:00:00 | host1 |
|
||||
| 1970-01-01T00:00:10 | host1 |
|
||||
| 1970-01-01T00:00:20 | host1 |
|
||||
| 1970-01-01T00:00:30 | host1 |
|
||||
| 1970-01-01T00:00:40 | host1 |
|
||||
+---------------------+-------+
|
||||
|
||||
-- Multiple TQL CTEs referencing different tables
|
||||
WITH
|
||||
metric_data(ts, val) AS (TQL EVAL (0, 40, '10s') metric),
|
||||
|
||||
@@ -56,6 +56,12 @@ WITH host_metrics AS (
|
||||
)
|
||||
SELECT count(*) as host1_points FROM host_metrics;
|
||||
|
||||
-- TQL CTE with column reference
|
||||
WITH host_metrics AS (
|
||||
TQL EVAL (0, 40, '10s') labels{host="host1"}
|
||||
)
|
||||
SELECT host_metrics.ts, host_metrics.host FROM host_metrics;
|
||||
|
||||
-- Multiple TQL CTEs referencing different tables
|
||||
WITH
|
||||
metric_data(ts, val) AS (TQL EVAL (0, 40, '10s') metric),
|
||||
|
||||
Reference in New Issue
Block a user