You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/04/20 05:16:20 UTC

[GitHub] [arrow-datafusion] matthewmturner opened a new pull request, #2279: Add `CREATE VIEW`

matthewmturner opened a new pull request, #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #1740 
   
    # Rationale for this change
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   # What changes are included in this PR?
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] matthewmturner commented on pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
matthewmturner commented on PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#issuecomment-1123855344

   @andygrove @alamb hopefully this is good now.
   
   was i able to complete it in time for the 8.0 release?


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#discussion_r869654798


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -121,11 +117,171 @@ mod tests {
             "| column1 | column2 | column3 |",
             "+---------+---------+---------+",
             "| 1       | 2       | 3       |",
+            "| 4       | 5       | 6       |",
             "+---------+---------+---------+",
         ];
 
         assert_batches_eq!(expected, &results);
 
         Ok(())
     }
+
+    #[tokio::test]
+    async fn query_view_with_projection() -> Result<()> {
+        let session_ctx = SessionContext::with_config(
+            SessionConfig::new().with_information_schema(true),
+        );
+
+        session_ctx
+            .sql("CREATE TABLE abc AS VALUES (1,2,3), (4,5,6)")
+            .await?
+            .collect()
+            .await?;
+
+        let view_sql = "CREATE VIEW xyz AS SELECT column1, column2 FROM abc";
+        session_ctx.sql(view_sql).await?.collect().await?;
+
+        let results = session_ctx.sql("SELECT * FROM information_schema.tables WHERE table_type='VIEW' AND table_name = 'xyz'").await?.collect().await?;
+        assert_eq!(results[0].num_rows(), 1);
+
+        let results = session_ctx
+            .sql("SELECT column1 FROM xyz")
+            .await?
+            .collect()
+            .await?;
+
+        let expected = vec![
+            "+---------+",
+            "| column1 |",
+            "+---------+",
+            "| 1       |",
+            "| 4       |",
+            "+---------+",
+        ];
+
+        assert_batches_eq!(expected, &results);
+
+        Ok(())
+    }
+
+    #[tokio::test]
+    async fn query_view_plan() -> Result<()> {
+        let session_ctx = SessionContext::with_config(
+            SessionConfig::new().with_information_schema(true),
+        );
+
+        session_ctx
+            .sql("CREATE TABLE abc AS VALUES (1,2,3), (4,5,6)")
+            .await?
+            .collect()
+            .await?;
+
+        let view_sql = "CREATE VIEW xyz AS SELECT * FROM abc";
+        session_ctx.sql(view_sql).await?.collect().await?;
+
+        let results = session_ctx
+            .sql("EXPLAIN CREATE VIEW xyz AS SELECT * FROM abc")
+            .await?
+            .collect()
+            .await?;
+
+        let expected = vec![
+            "+---------------+--------------------------------------------------------+",
+            "| plan_type     | plan                                                   |",
+            "+---------------+--------------------------------------------------------+",
+            "| logical_plan  | CreateView: \"xyz\"                                      |",
+            "|               |   Projection: #abc.column1, #abc.column2, #abc.column3 |",
+            "|               |     TableScan: abc projection=Some([0, 1, 2])          |",
+            "| physical_plan | EmptyExec: produce_one_row=false                       |",
+            "|               |                                                        |",
+            "+---------------+--------------------------------------------------------+",
+        ];
+
+        assert_batches_eq!(expected, &results);
+
+        let results = session_ctx

Review Comment:
   I think more interesting tests might be to create a view and then run queries against the view (also adding things like filters to on the view
   
   For example
   
   ```sql
   select coumn1, count(colum2) from xyz where column3 > 2
   ```
   



##########
datafusion/core/src/datasource/view.rs:
##########
@@ -0,0 +1,131 @@
+// 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.
+
+//! The table implementation.
+
+use std::{any::Any, sync::Arc};
+
+use arrow::datatypes::SchemaRef;
+use async_trait::async_trait;
+
+use crate::{
+    error::Result,
+    execution::context::SessionContext,
+    logical_plan::{Expr, LogicalPlan},
+    physical_plan::ExecutionPlan,
+};
+
+use crate::datasource::{
+    datasource::TableProviderFilterPushDown, TableProvider, TableType,
+};
+
+/// An implementation of `TableProvider` that uses the object store
+/// or file system listing capability to get the list of files.
+pub struct ViewTable {
+    /// To create ExecutionPlan
+    context: SessionContext,
+    /// LogicalPlan of the view
+    logical_plan: LogicalPlan,
+    /// File fields + partition columns
+    table_schema: SchemaRef,
+}
+
+impl ViewTable {
+    /// Create new view that is executed at query runtime.
+    /// Takes a `LogicalPlan` as input.
+    pub fn try_new(context: SessionContext, logical_plan: LogicalPlan) -> Result<Self> {
+        let table_schema = logical_plan.schema().as_ref().to_owned().into();
+
+        let view = Self {
+            context,
+            logical_plan,
+            table_schema,
+        };
+
+        Ok(view)
+    }
+}
+
+#[async_trait]
+impl TableProvider for ViewTable {
+    fn as_any(&self) -> &dyn Any {
+        self
+    }
+
+    fn schema(&self) -> SchemaRef {
+        Arc::clone(&self.table_schema)
+    }
+
+    fn table_type(&self) -> TableType {
+        TableType::View
+    }
+
+    async fn scan(
+        &self,
+        projection: &Option<Vec<usize>>,
+        filters: &[Expr],
+        limit: Option<usize>,
+    ) -> Result<Arc<dyn ExecutionPlan>> {
+        self.context.create_physical_plan(&self.logical_plan).await

Review Comment:
   👍 



##########
datafusion/core/src/datasource/view.rs:
##########
@@ -0,0 +1,131 @@
+// 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.
+
+//! The table implementation.
+
+use std::{any::Any, sync::Arc};
+
+use arrow::datatypes::SchemaRef;
+use async_trait::async_trait;
+
+use crate::{
+    error::Result,
+    execution::context::SessionContext,
+    logical_plan::{Expr, LogicalPlan},
+    physical_plan::ExecutionPlan,
+};
+
+use crate::datasource::{
+    datasource::TableProviderFilterPushDown, TableProvider, TableType,
+};
+
+/// An implementation of `TableProvider` that uses the object store
+/// or file system listing capability to get the list of files.

Review Comment:
   The implementation uses another LogicalPlan



-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] matthewmturner commented on pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
matthewmturner commented on PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#issuecomment-1123781227

   @andygrove thanks - i removed.


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] matthewmturner commented on pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
matthewmturner commented on PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#issuecomment-1122685415

   @andygrove FYI I'm hoping to get this in for 8.0 release. 


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] matthewmturner commented on pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
matthewmturner commented on PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#issuecomment-1105776419

   @alamb I actually hadn't even made it to the point of implementing that yet - just wanted to see if conceptually you thought that was the right approach. Wasn't expecting you to review anything yet. If you aren't sure and it would require you looking into it I can just give it a shot and get back to you. I don't want you to have to do unnecessary work.


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#discussion_r870249996


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -0,0 +1,364 @@
+// 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.
+
+//! View data source which uses a LogicalPlan as it's input.
+
+use std::{any::Any, sync::Arc};
+
+use arrow::datatypes::SchemaRef;
+use async_trait::async_trait;
+
+use crate::{
+    error::Result,
+    execution::context::SessionContext,
+    logical_plan::{Expr, LogicalPlan},
+    physical_plan::ExecutionPlan,
+};
+
+use crate::datasource::{TableProvider, TableType};
+
+/// An implementation of `TableProvider` that uses another logical plan.
+pub struct ViewTable {
+    /// To create ExecutionPlan
+    context: SessionContext,
+    /// LogicalPlan of the view
+    logical_plan: LogicalPlan,

Review Comment:
   I think so



-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#discussion_r871242265


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -0,0 +1,364 @@
+// 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.
+
+//! View data source which uses a LogicalPlan as it's input.
+
+use std::{any::Any, sync::Arc};
+
+use arrow::datatypes::SchemaRef;
+use async_trait::async_trait;
+
+use crate::{
+    error::Result,
+    execution::context::SessionContext,
+    logical_plan::{Expr, LogicalPlan},
+    physical_plan::ExecutionPlan,
+};
+
+use crate::datasource::{TableProvider, TableType};
+
+/// An implementation of `TableProvider` that uses another logical plan.
+pub struct ViewTable {
+    /// To create ExecutionPlan
+    context: SessionContext,
+    /// LogicalPlan of the view
+    logical_plan: LogicalPlan,

Review Comment:
   👋  welcome @Veeupup . That would be great.  I will try and write up a ticket later today that describes the work in some more detail in case that is helpful
   
   Thank you!



-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] andygrove merged pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
andygrove merged PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#issuecomment-1106809142

   Sorry for the late review @matthewmturner 
   
   At a high level, I would expect a VIEW to be represented by a query -- maybe as a SQL string / parsed `Query` or perhaps a `LogicalPlan`
   
   So let's say we have a query like this
   
   ```sql
   select sum(y) from T where a > 5 group by a;
   ```
   
   If `T` is a table, I would expect the plan to look like
   ```
   GroupBy (gby a, sum(y))
     Filter(a > 5)
       TableScan T
   ```
   
   If `T` is a view, 
   
   ```sql
   create view T as select  a, y from bar where y > 10000
   ```
   
   I would expect the plan to look like:
   
   ```
   GroupBy (gby a, sum(y))
     Filter(a > 5)
       Project (a, y) <-- the LogicalPlan for the View is pasted in here
         Filter (y > 10000)
          TableScan bar
   ```
   
   The question then becomes how do you want to get the `LogicalPlan` for the view when it is referenced. Storing a SQL string might be the simplest, but I am not sure how that would work with the [DataFrame API](https://github.com/apache/arrow-datafusion/blob/baa2a367ec159992705befc5c735fe3324a83680/datafusion/core/src/dataframe.rs)
   
   But then again, I am not sure a view makes sense in the context of a dataframe -- the user would just clone the DataFrame (which is a wrapper around a `LogicalPlan` 🤔 )


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] Dandandan commented on a diff in pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
Dandandan commented on code in PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#discussion_r869751636


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -0,0 +1,364 @@
+// 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.
+
+//! View data source which uses a LogicalPlan as it's input.
+
+use std::{any::Any, sync::Arc};
+
+use arrow::datatypes::SchemaRef;
+use async_trait::async_trait;
+
+use crate::{
+    error::Result,
+    execution::context::SessionContext,
+    logical_plan::{Expr, LogicalPlan},
+    physical_plan::ExecutionPlan,
+};
+
+use crate::datasource::{TableProvider, TableType};
+
+/// An implementation of `TableProvider` that uses another logical plan.
+pub struct ViewTable {
+    /// To create ExecutionPlan
+    context: SessionContext,
+    /// LogicalPlan of the view
+    logical_plan: LogicalPlan,

Review Comment:
   Original SQL might be useful too to store, to preserve formatting when doing things like `describe view`.



-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] matthewmturner commented on pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
matthewmturner commented on PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#issuecomment-1123711004

   Ah - i believe the tpch tests use a published version of ballista. so i dont think we can run Q15 until our next release.  let me know if im misunderstanding, i didnt have time to dig too far into it.


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#issuecomment-1105773160

   Thanks @matthewmturner  -- I'll try and give it a look tomorrow


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] matthewmturner commented on pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
matthewmturner commented on PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#issuecomment-1123873652

   @Igosuki FYI


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] andygrove commented on pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
andygrove commented on PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#issuecomment-1123737439

   > Ah - i believe the tpch tests use a published version of ballista. so i dont think we can run Q15 until our next release. let me know if im misunderstanding, i didnt have time to dig too far into it.
   
   q15 was definitely a stretch goal for this PR :smile:  I will take a look


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] matthewmturner commented on a diff in pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
matthewmturner commented on code in PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#discussion_r870230271


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -0,0 +1,364 @@
+// 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.
+
+//! View data source which uses a LogicalPlan as it's input.
+
+use std::{any::Any, sync::Arc};
+
+use arrow::datatypes::SchemaRef;
+use async_trait::async_trait;
+
+use crate::{
+    error::Result,
+    execution::context::SessionContext,
+    logical_plan::{Expr, LogicalPlan},
+    physical_plan::ExecutionPlan,
+};
+
+use crate::datasource::{TableProvider, TableType};
+
+/// An implementation of `TableProvider` that uses another logical plan.
+pub struct ViewTable {
+    /// To create ExecutionPlan
+    context: SessionContext,
+    /// LogicalPlan of the view
+    logical_plan: LogicalPlan,

Review Comment:
   Indeed that would be nice, do you think we could do it as a follow on PR?



-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] matthewmturner commented on pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
matthewmturner commented on PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#issuecomment-1121896403

   @alamb would you mind checking this out and see if its in the right direction?  I still have to resolve conflicts and update ballista but wanted to make sure this was at least getting close before proceeding.


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] andygrove commented on pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
andygrove commented on PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#issuecomment-1123739280

   RAT is failing due to an empty file @ datafusion/core/src/physical_plan/view.rs


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#discussion_r872637265


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -0,0 +1,364 @@
+// 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.
+
+//! View data source which uses a LogicalPlan as it's input.
+
+use std::{any::Any, sync::Arc};
+
+use arrow::datatypes::SchemaRef;
+use async_trait::async_trait;
+
+use crate::{
+    error::Result,
+    execution::context::SessionContext,
+    logical_plan::{Expr, LogicalPlan},
+    physical_plan::ExecutionPlan,
+};
+
+use crate::datasource::{TableProvider, TableType};
+
+/// An implementation of `TableProvider` that uses another logical plan.
+pub struct ViewTable {
+    /// To create ExecutionPlan
+    context: SessionContext,
+    /// LogicalPlan of the view
+    logical_plan: LogicalPlan,

Review Comment:
   https://github.com/apache/arrow-datafusion/issues/2529
   
   @Dandandan  not sure if you had specific ideas on what command you wanted to show view definitions. 



-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] matthewmturner commented on pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
matthewmturner commented on PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#issuecomment-1105490103

   My idea here is to create a new `ViewTable` struct (similar concept to how `MemTable` is used but obviously not in memory) which of course would have `TableType::View` and we just use that with the existing `register_table` functionality within `ExecutionContext` / `SchemaProvider`.  @alamb does that sound good from your end?


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] Veeupup commented on a diff in pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
Veeupup commented on code in PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#discussion_r871015669


##########
datafusion/core/src/datasource/view.rs:
##########
@@ -0,0 +1,364 @@
+// 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.
+
+//! View data source which uses a LogicalPlan as it's input.
+
+use std::{any::Any, sync::Arc};
+
+use arrow::datatypes::SchemaRef;
+use async_trait::async_trait;
+
+use crate::{
+    error::Result,
+    execution::context::SessionContext,
+    logical_plan::{Expr, LogicalPlan},
+    physical_plan::ExecutionPlan,
+};
+
+use crate::datasource::{TableProvider, TableType};
+
+/// An implementation of `TableProvider` that uses another logical plan.
+pub struct ViewTable {
+    /// To create ExecutionPlan
+    context: SessionContext,
+    /// LogicalPlan of the view
+    logical_plan: LogicalPlan,

Review Comment:
   hi, I'm new to datafusion and maybe I can help with the follow work ?



-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] matthewmturner commented on pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
matthewmturner commented on PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#issuecomment-1117426144

   I apologize I have been quite busy lately and havent been able to continue my efforts on this.  Im really hoping to get this in for 8.0 release, I will try to work on this over the weekend.


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#issuecomment-1118044806

   > I apologize I have been quite busy lately ...
   
   No worries at all - I totally understand!


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] andygrove commented on pull request #2279: Add `CREATE VIEW`

Posted by GitBox <gi...@apache.org>.
andygrove commented on PR #2279:
URL: https://github.com/apache/arrow-datafusion/pull/2279#issuecomment-1122933884

   I just took a quick look through this and LGTM :heart: 


-- 
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-unsubscribe@arrow.apache.org

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