alamb commented on code in PR #4995:
URL: https://github.com/apache/arrow-datafusion/pull/4995#discussion_r1082633781


##########
datafusion/core/src/datasource/listing/table.rs:
##########
@@ -67,6 +67,10 @@ pub struct ListingTableConfig {
     pub file_schema: Option<SchemaRef>,
     /// Optional `ListingOptions` for the to be created `ListingTable`.
     pub options: Option<ListingOptions>,
+    /// Optional default is false, if temporary is true, then it means that
+    /// we will create a temporary table for select * from `xxx.file`
+    /// or describe 'xxx.file', the temporary table will be registered to the 
schema
+    pub temporary_file: bool,

Review Comment:
   💯  for the comments. Thank you @xiaoyong-z 
   
   I think the term `temporary_files` often means something different -- 
specifically files in `/tmp` or similar -- so it may be confusing to use the 
same term. 
   
   What would you think about using a different term than `temporary`? Perhaps 
`ephemeral` would be appropriate. 



##########
datafusion/core/tests/sqllogictests/test_files/describe.slt:
##########
@@ -0,0 +1,43 @@
+# 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.
+
+
+##########
+# Describe internal tables
+##########
+
+statement ok
+set datafusion.catalog.information_schema = true
+
+statement ok
+CREATE external table aggregate_simple(c1 real, c2 double, c3 boolean) STORED 
as CSV WITH HEADER ROW LOCATION 'tests/data/aggregate_simple.csv';
+
+query C1
+DESCRIBE aggregate_simple;

Review Comment:
   This test works on master -- I don't think it needs the changes in this PR
   
   ```
   (arrow_dev) alamb@MacBook-Pro-8:~/Software/arrow-datafusion/datafusion/core$ 
datafusion-cli
   DataFusion CLI v16.0.0
   ❯ CREATE external table aggregate_simple(c1 real, c2 double, c3 boolean) 
STORED as CSV WITH HEADER ROW LOCATION 'tests/data/aggregate_simple.csv';
   0 rows in set. Query took 0.005 seconds.
   ❯ 
   DESCRIBE aggregate_simple;
   +-------------+-----------+-------------+
   | column_name | data_type | is_nullable |
   +-------------+-----------+-------------+
   | c1          | Float32   | NO          |
   | c2          | Float64   | NO          |
   | c3          | Boolean   | NO          |
   +-------------+-----------+-------------+
   3 rows in set. Query took 0.002 seconds.
   ❯ 
   ```



##########
datafusion/expr/src/logical_plan/plan.rs:
##########
@@ -1625,6 +1637,15 @@ pub struct Prepare {
     pub input: Arc<LogicalPlan>,
 }
 
+/// Describe a file

Review Comment:
   What would you think about making this more general `DescribeTable` and 
rather than taking a file_path it would have a `table_provider`? I think then 
we wouldn't have to special case describe for file / table -- instead 
DataFusion could always create `DescribeTable` 
   
   The query in terms of information_schema is sort of a hack in the first 
place. What you have started here with an actual LogicalPlan variant I think is 
much better 👍 



##########
datafusion/sql/src/statement.rs:
##########
@@ -385,25 +385,32 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
         let DescribeTable { table_name } = statement;
 
         let where_clause = object_name_to_qualifier(&table_name);
+        let table_str_name = object_name_to_table_str_name(&table_name);
         let table_ref = object_name_to_table_reference(table_name)?;
 
-        // check if table_name exists
-        let _ = self
+        let table_source = self
             .schema_provider
             .get_table_provider((&table_ref).into())?;
 
-        if self.has_table("information_schema", "tables") {
-            let sql = format!(
-                "SELECT column_name, data_type, is_nullable \
-                                FROM information_schema.columns WHERE 
{where_clause};"
-            );
-            let mut rewrite = DFParser::parse_sql(&sql)?;
-            self.statement_to_plan(rewrite.pop_front().unwrap())
+        if !table_source.is_temporary_file() {

Review Comment:
   I wonder if we can figure out a way to avoid special casing here. Perhaps we 
can always create a DescribeTable plan?



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to