From e8d2e823357ddbc44b942f4c81b93778f4fd0d98 Mon Sep 17 00:00:00 2001 From: Ruihang Xia Date: Tue, 14 Mar 2023 21:18:43 +0800 Subject: [PATCH] fix: ambiguous column reference (#1177) Signed-off-by: Ruihang Xia --- Cargo.lock | 35 +++++++++---------- Cargo.toml | 13 ++++--- src/promql/src/planner.rs | 9 +++-- src/query/src/optimizer.rs | 2 ++ .../common/optimizer/filter_push_down.result | 8 ++++- 5 files changed, 38 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 09b1856d3a..4e07c2a9ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2107,8 +2107,8 @@ dependencies = [ [[package]] name = "datafusion" -version = "19.0.0" -source = "git+https://github.com/MichaelScofield/arrow-datafusion.git?rev=d7b3c730049f2561755f9d855f638cb580c38eff#d7b3c730049f2561755f9d855f638cb580c38eff" +version = "20.0.0" +source = "git+https://github.com/apache/arrow-datafusion.git?rev=146a949218ec970784974137277cde3b4e547d0a#146a949218ec970784974137277cde3b4e547d0a" dependencies = [ "ahash 0.8.3", "arrow", @@ -2137,7 +2137,6 @@ dependencies = [ "object_store", "parking_lot", "parquet", - "paste", "percent-encoding", "pin-project-lite", "rand", @@ -2155,8 +2154,8 @@ dependencies = [ [[package]] name = "datafusion-common" -version = "19.0.0" -source = "git+https://github.com/MichaelScofield/arrow-datafusion.git?rev=d7b3c730049f2561755f9d855f638cb580c38eff#d7b3c730049f2561755f9d855f638cb580c38eff" +version = "20.0.0" +source = "git+https://github.com/apache/arrow-datafusion.git?rev=146a949218ec970784974137277cde3b4e547d0a#146a949218ec970784974137277cde3b4e547d0a" dependencies = [ "arrow", "chrono", @@ -2168,8 +2167,8 @@ dependencies = [ [[package]] name = "datafusion-execution" -version = "19.0.0" -source = "git+https://github.com/MichaelScofield/arrow-datafusion.git?rev=d7b3c730049f2561755f9d855f638cb580c38eff#d7b3c730049f2561755f9d855f638cb580c38eff" +version = "20.0.0" +source = "git+https://github.com/apache/arrow-datafusion.git?rev=146a949218ec970784974137277cde3b4e547d0a#146a949218ec970784974137277cde3b4e547d0a" dependencies = [ "dashmap", "datafusion-common", @@ -2185,20 +2184,19 @@ dependencies = [ [[package]] name = "datafusion-expr" -version = "19.0.0" -source = "git+https://github.com/MichaelScofield/arrow-datafusion.git?rev=d7b3c730049f2561755f9d855f638cb580c38eff#d7b3c730049f2561755f9d855f638cb580c38eff" +version = "20.0.0" +source = "git+https://github.com/apache/arrow-datafusion.git?rev=146a949218ec970784974137277cde3b4e547d0a#146a949218ec970784974137277cde3b4e547d0a" dependencies = [ "ahash 0.8.3", "arrow", "datafusion-common", - "log", "sqlparser", ] [[package]] name = "datafusion-optimizer" -version = "19.0.0" -source = "git+https://github.com/MichaelScofield/arrow-datafusion.git?rev=d7b3c730049f2561755f9d855f638cb580c38eff#d7b3c730049f2561755f9d855f638cb580c38eff" +version = "20.0.0" +source = "git+https://github.com/apache/arrow-datafusion.git?rev=146a949218ec970784974137277cde3b4e547d0a#146a949218ec970784974137277cde3b4e547d0a" dependencies = [ "arrow", "async-trait", @@ -2214,8 +2212,8 @@ dependencies = [ [[package]] name = "datafusion-physical-expr" -version = "19.0.0" -source = "git+https://github.com/MichaelScofield/arrow-datafusion.git?rev=d7b3c730049f2561755f9d855f638cb580c38eff#d7b3c730049f2561755f9d855f638cb580c38eff" +version = "20.0.0" +source = "git+https://github.com/apache/arrow-datafusion.git?rev=146a949218ec970784974137277cde3b4e547d0a#146a949218ec970784974137277cde3b4e547d0a" dependencies = [ "ahash 0.8.3", "arrow", @@ -2233,7 +2231,6 @@ dependencies = [ "itertools", "lazy_static", "md-5", - "num-traits", "paste", "petgraph", "rand", @@ -2245,8 +2242,8 @@ dependencies = [ [[package]] name = "datafusion-row" -version = "19.0.0" -source = "git+https://github.com/MichaelScofield/arrow-datafusion.git?rev=d7b3c730049f2561755f9d855f638cb580c38eff#d7b3c730049f2561755f9d855f638cb580c38eff" +version = "20.0.0" +source = "git+https://github.com/apache/arrow-datafusion.git?rev=146a949218ec970784974137277cde3b4e547d0a#146a949218ec970784974137277cde3b4e547d0a" dependencies = [ "arrow", "datafusion-common", @@ -2256,8 +2253,8 @@ dependencies = [ [[package]] name = "datafusion-sql" -version = "19.0.0" -source = "git+https://github.com/MichaelScofield/arrow-datafusion.git?rev=d7b3c730049f2561755f9d855f638cb580c38eff#d7b3c730049f2561755f9d855f638cb580c38eff" +version = "20.0.0" +source = "git+https://github.com/apache/arrow-datafusion.git?rev=146a949218ec970784974137277cde3b4e547d0a#146a949218ec970784974137277cde3b4e547d0a" dependencies = [ "arrow-schema", "datafusion-common", diff --git a/Cargo.toml b/Cargo.toml index fdb5366910..ab0d3136f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,13 +57,12 @@ arrow-schema = { version = "34.0", features = ["serde"] } async-stream = "0.3" async-trait = "0.1" chrono = { version = "0.4", features = ["serde"] } -# TODO(LFC): Use official DataFusion, when https://github.com/apache/arrow-datafusion/pull/5542 got merged -datafusion = { git = "https://github.com/MichaelScofield/arrow-datafusion.git", rev = "d7b3c730049f2561755f9d855f638cb580c38eff" } -datafusion-common = { git = "https://github.com/MichaelScofield/arrow-datafusion.git", rev = "d7b3c730049f2561755f9d855f638cb580c38eff" } -datafusion-expr = { git = "https://github.com/MichaelScofield/arrow-datafusion.git", rev = "d7b3c730049f2561755f9d855f638cb580c38eff" } -datafusion-optimizer = { git = "https://github.com/MichaelScofield/arrow-datafusion.git", rev = "d7b3c730049f2561755f9d855f638cb580c38eff" } -datafusion-physical-expr = { git = "https://github.com/MichaelScofield/arrow-datafusion.git", rev = "d7b3c730049f2561755f9d855f638cb580c38eff" } -datafusion-sql = { git = "https://github.com/MichaelScofield/arrow-datafusion.git", rev = "d7b3c730049f2561755f9d855f638cb580c38eff" } +datafusion = { git = "https://github.com/apache/arrow-datafusion.git", rev = "146a949218ec970784974137277cde3b4e547d0a" } +datafusion-common = { git = "https://github.com/apache/arrow-datafusion.git", rev = "146a949218ec970784974137277cde3b4e547d0a" } +datafusion-expr = { git = "https://github.com/apache/arrow-datafusion.git", rev = "146a949218ec970784974137277cde3b4e547d0a" } +datafusion-optimizer = { git = "https://github.com/apache/arrow-datafusion.git", rev = "146a949218ec970784974137277cde3b4e547d0a" } +datafusion-physical-expr = { git = "https://github.com/apache/arrow-datafusion.git", rev = "146a949218ec970784974137277cde3b4e547d0a" } +datafusion-sql = { git = "https://github.com/apache/arrow-datafusion.git", rev = "146a949218ec970784974137277cde3b4e547d0a" } futures = "0.3" futures-util = "0.3" parquet = "34.0" diff --git a/src/promql/src/planner.rs b/src/promql/src/planner.rs index a89c9abb4d..c64f0d53a3 100644 --- a/src/promql/src/planner.rs +++ b/src/promql/src/planner.rs @@ -957,7 +957,12 @@ impl PromPlanner { .tag_columns .iter() .chain(self.ctx.time_index_column.iter()) - .map(|col| Ok(DfExpr::Column(Column::from(col)))); + .map(|col| { + Ok(DfExpr::Column(Column::new( + self.ctx.table_name.clone(), + col, + ))) + }); // build computation exprs let result_value_columns = self @@ -1485,7 +1490,7 @@ mod test { .unwrap(); let expected = String::from( - "Projection: lhs.tag_0, lhs.timestamp, some_metric.field_0 + some_metric.field_0 AS some_metric.field_0 + some_metric.field_0 [tag_0:Utf8, timestamp:Timestamp(Millisecond, None), some_metric.field_0 + some_metric.field_0:Float64;N]\ + "Projection: some_metric.tag_0, some_metric.timestamp, some_metric.field_0 + some_metric.field_0 AS some_metric.field_0 + some_metric.field_0 [tag_0:Utf8, timestamp:Timestamp(Millisecond, None), some_metric.field_0 + some_metric.field_0:Float64;N]\ \n Inner Join: lhs.tag_0 = some_metric.tag_0, lhs.timestamp = some_metric.timestamp [tag_0:Utf8, timestamp:Timestamp(Millisecond, None), field_0:Float64;N, tag_0:Utf8, timestamp:Timestamp(Millisecond, None), field_0:Float64;N]\ \n SubqueryAlias: lhs [tag_0:Utf8, timestamp:Timestamp(Millisecond, None), field_0:Float64;N]\ \n PromInstantManipulate: range=[0..100000000], lookback=[1000], interval=[5000], time index=[timestamp] [tag_0:Utf8, timestamp:Timestamp(Millisecond, None), field_0:Float64;N]\ diff --git a/src/query/src/optimizer.rs b/src/query/src/optimizer.rs index fc986c7e20..06efe1f410 100644 --- a/src/query/src/optimizer.rs +++ b/src/query/src/optimizer.rs @@ -34,6 +34,8 @@ use datatypes::arrow::datatypes::DataType; pub struct TypeConversionRule; impl OptimizerRule for TypeConversionRule { + // TODO(ruihang): fix this warning + #[allow(deprecated)] fn try_optimize( &self, plan: &LogicalPlan, diff --git a/tests/cases/standalone/common/optimizer/filter_push_down.result b/tests/cases/standalone/common/optimizer/filter_push_down.result index 369da7da84..118680dd3b 100644 --- a/tests/cases/standalone/common/optimizer/filter_push_down.result +++ b/tests/cases/standalone/common/optimizer/filter_push_down.result @@ -121,7 +121,13 @@ SELECT * FROM integers WHERE i IN ((SELECT i FROM integers)) AND i<3 ORDER BY i; SELECT i1.i,i2.i FROM integers i1, integers i2 WHERE i IN ((SELECT i FROM integers)) AND i1.i=i2.i ORDER BY 1; -Error: 3000(PlanQuery), Error during planning: column reference i is ambiguous ++---+---+ +| i | i | ++---+---+ +| 1 | 1 | +| 2 | 2 | +| 3 | 3 | ++---+---+ SELECT * FROM integers i1 WHERE EXISTS(SELECT i FROM integers WHERE i=i1.i) ORDER BY i1.i;