alamb commented on a change in pull request #2012:
URL: https://github.com/apache/arrow-datafusion/pull/2012#discussion_r831451367
##########
File path: datafusion-common/src/dfschema.rs
##########
@@ -222,6 +222,16 @@ impl DFSchema {
}
}
+ pub fn fields_with_qualified(&self, qualifier: &str) -> Vec<&DFField> {
Review comment:
It would be nice to add a docstring (`/// comment`) to this function
explaining what it does
##########
File path: datafusion-common/src/dfschema.rs
##########
@@ -222,6 +222,16 @@ impl DFSchema {
}
}
+ pub fn fields_with_qualified(&self, qualifier: &str) -> Vec<&DFField> {
+ self.fields
+ .iter()
+ .filter(|field| {
+ field.qualifier().is_some()
+ && field.qualifier.as_ref().unwrap().eq(qualifier)
Review comment:
I think you can write this a bit more concisely / rusty like
```rust
field.qualifier
.map(|q| q.eq(qualifier))
.unwrap_or(false)
```
##########
File path: datafusion/tests/sql/wildcard.rs
##########
@@ -0,0 +1,97 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use super::*;
+
+#[tokio::test]
+async fn select_qualified_wildcard() -> Result<()> {
+ let mut ctx = SessionContext::new();
+ register_aggregate_simple_csv(&mut ctx).await?;
+
+ let sql = "SELECT agg.* FROM aggregate_simple as agg order by c1";
+ let results = execute_to_batches(&ctx, sql).await;
+
+ let expected = vec![
+ "+---------+----------------+-------+",
+ "| c1 | c2 | c3 |",
+ "+---------+----------------+-------+",
+ "| 0.00001 | 0.000000000001 | true |",
+ "| 0.00002 | 0.000000000002 | false |",
+ "| 0.00002 | 0.000000000002 | false |",
+ "| 0.00003 | 0.000000000003 | true |",
+ "| 0.00003 | 0.000000000003 | true |",
+ "| 0.00003 | 0.000000000003 | true |",
+ "| 0.00004 | 0.000000000004 | false |",
+ "| 0.00004 | 0.000000000004 | false |",
+ "| 0.00004 | 0.000000000004 | false |",
+ "| 0.00004 | 0.000000000004 | false |",
+ "| 0.00005 | 0.000000000005 | true |",
+ "| 0.00005 | 0.000000000005 | true |",
+ "| 0.00005 | 0.000000000005 | true |",
+ "| 0.00005 | 0.000000000005 | true |",
+ "| 0.00005 | 0.000000000005 | true |",
+ "+---------+----------------+-------+",
+ ];
+
+ assert_batches_eq!(expected, &results);
+
+ Ok(())
+}
+
+#[tokio::test]
+async fn select_qualified_wildcard_join() -> Result<()> {
+ let ctx = create_join_context("t1_id", "t2_id")?;
+ let sql =
+ "SELECT tb1.*, tb2.* FROM t1 tb1 JOIN t2 tb2 ON t2_id = t1_id ORDER BY
t1_id";
+ let expected = vec![
+ "+-------+---------+-------+---------+",
+ "| t1_id | t1_name | t2_id | t2_name |",
+ "+-------+---------+-------+---------+",
+ "| 11 | a | 11 | z |",
+ "| 22 | b | 22 | y |",
+ "| 44 | d | 44 | x |",
+ "+-------+---------+-------+---------+",
+ ];
+
+ let results = execute_to_batches(&ctx, sql).await;
+
+ assert_batches_eq!(expected, &results);
+
+ Ok(())
+}
+
+#[tokio::test]
+async fn select_non_alias_qualified_wildcard_join() -> Result<()> {
+ let ctx = create_join_context("t1_id", "t2_id")?;
+ let sql =
+ "SELECT t1.*, tb2.* FROM t1 tb1 JOIN t2 tb2 ON t2_id = t1_id ORDER BY
t1_id";
+ let expected = vec![
+ "+-------+---------+-------+---------+",
+ "| t1_id | t1_name | t2_id | t2_name |",
+ "+-------+---------+-------+---------+",
+ "| 11 | a | 11 | z |",
+ "| 22 | b | 22 | y |",
+ "| 44 | d | 44 | x |",
+ "+-------+---------+-------+---------+",
+ ];
+
+ let results = execute_to_batches(&ctx, sql).await;
+
+ assert_batches_eq!(expected, &results);
+
+ Ok(())
+}
Review comment:
I wonder if an error test might be useful too
like `SELECT foo.* from t1` I would expect to return an error
##########
File path: datafusion/tests/sql/wildcard.rs
##########
@@ -0,0 +1,97 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use super::*;
+
+#[tokio::test]
+async fn select_qualified_wildcard() -> Result<()> {
+ let mut ctx = SessionContext::new();
+ register_aggregate_simple_csv(&mut ctx).await?;
+
+ let sql = "SELECT agg.* FROM aggregate_simple as agg order by c1";
Review comment:
👍
##########
File path: datafusion-expr/src/expr.rs
##########
@@ -228,6 +228,9 @@ pub enum Expr {
},
/// Represents a reference to all fields in a schema.
Wildcard,
+ QualifiedWildcard {
Review comment:
Do you mean
```rust
Wildcard {
qualifier: Option<String>
}
```
?
##########
File path: datafusion-expr/src/expr.rs
##########
@@ -696,6 +700,9 @@ fn create_name(e: &Expr, input_schema: &DFSchema) ->
Result<String> {
Expr::Wildcard => Err(DataFusionError::Internal(
"Create name does not support wildcard".to_string(),
)),
+ Expr::QualifiedWildcard { .. } => Err(DataFusionError::Internal(
Review comment:
I agree including the name of the qualifier in the message might be
helpful
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]