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


##########
datafusion/core/tests/sql/create_drop.rs:
##########
@@ -262,6 +267,69 @@ async fn create_pipe_delimited_csv_table() -> Result<()> {
     Ok(())
 }
 
+struct TestTableProvider {
+    name: String,
+    path: String,
+}
+
+impl TestTableProvider {
+    pub fn new(name: &str, path: &str) -> Self {
+        Self {
+            name: name.to_string(),
+            path: path.to_string()
+        }
+    }
+}
+
+#[async_trait]
+impl TableProvider for TestTableProvider {
+    fn as_any(&self) -> &dyn Any {
+        todo!()
+    }
+
+    fn schema(&self) -> SchemaRef {
+        todo!()
+    }
+
+    fn table_type(&self) -> TableType {
+        todo!()
+    }
+
+    async fn scan(
+        &self,
+        ctx: &SessionState,
+        projection: &Option<Vec<usize>>,
+        filters: &[Expr],
+        limit: Option<usize>
+    ) -> Result<Arc<dyn ExecutionPlan>> {
+        todo!()
+    }
+}
+
+struct TestTableFactory {}
+
+impl TableProviderFactory for TestTableFactory {
+    fn create(&self, name: &str, path: &str) -> Arc<dyn TableProvider> {
+        Arc::new(TestTableProvider::new(name, path))
+    }
+}
+
+#[tokio::test]
+async fn create_custom_table() -> Result<()> {
+    let mut ctx = SessionContext::new();
+    ctx.register_table_factory("DELTATABLE", Arc::new(TestTableFactory {}));
+
+    let sql = "CREATE EXTERNAL TABLE dt STORED AS DELTATABLE LOCATION 
's3://bucket/schema/table';";
+    ctx.sql(sql).await.unwrap();
+

Review Comment:
   This API is very cool -- I like it a lot 💯 



##########
datafusion/core/src/execution/context.rs:
##########
@@ -174,6 +175,8 @@ pub struct SessionContext {
     pub session_start_time: DateTime<Utc>,
     /// Shared session state for the session
     pub state: Arc<RwLock<SessionState>>,
+    // Custom table types

Review Comment:
   ```suggestion
       // Dynamic table providers
   ```



##########
datafusion/core/src/datasource/datasource.rs:
##########
@@ -72,3 +72,7 @@ pub trait TableProvider: Sync + Send {
         Ok(TableProviderFilterPushDown::Unsupported)
     }
 }
+
+pub trait TableProviderFactory: Sync + Send {
+    fn create(&self, name: &str, path: &str) -> Arc<dyn TableProvider>;

Review Comment:
   Minor comment would be to call this `url` rather than `path`  to hint that 
the table provider factory could interpret it however it wanted and it wasn't 
necessarily a path to a local file system?



-- 
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]

Reply via email to