Uh oh!
There was an error while loading. Please reload this page.
generalize table provider df impl - #1712
Conversation
houqp
commented
Jan 30, 2022
@cpcloud good point on lack of access to the trait_upcasting feature :( I found an interesting workaround for this online based on https://articles.bchlr.de/traits-dynamic-dispatch-upcasting: diff --git a/datafusion/src/datasource/datasource.rs b/datafusion/src/datasource/datasource.rs
index 1b59c857f..703d14493 100644
--- a/datafusion/src/datasource/datasource.rs
+++ b/datafusion/src/datasource/datasource.rs
@@ -55,9 +55,15 @@ pubenumTableType{Temporary,}
+pubtraitAsDynTableProvider{
+ fn as_dyn_table<'a>(self:Arc<Self>) -> Arc<dynTableProvider + 'a>
+ where
+ Self:'a;
+}
+
/// Source table #[async_trait]
-pubtraitTableProvider:Sync + Send{
+pubtraitTableProvider:Sync + Send + AsDynTableProvider{/// Returns the table provider as [`Any`](std::any::Any) so that it can be/// downcast to a specific implementation.fnas_any(&self) -> &dynAny;
@@ -94,3 +100,12 @@ pubtraitTableProvider:Sync + Send{Ok(TableProviderFilterPushDown::Unsupported)}}
+
+impl<T:TableProvider + Sized>AsDynTableProviderforT{
+ fnas_dyn_table<'a>(self:Arc<Self>) -> Arc<dynTableProvider + 'a>
+ where
+ Self:'a,
+ {
+ self
+ }
+}
diff --git a/datafusion/src/execution/dataframe_impl.rs b/datafusion/src/execution/dataframe_impl.rs
index c1933adaa..eb59e3a93 100644
--- a/datafusion/src/execution/dataframe_impl.rs
+++ b/datafusion/src/execution/dataframe_impl.rs
@@ -550,7 +550,7 @@ modtests{letmut ctx = ExecutionContext::new();// register a dataframe as a table
- ctx.register_table("test_table", df)?;
+ ctx.register_table("test_table", df.as_dyn_table())?;Ok(())}The schema method name conflict is unfortunate and I don't have a good solution for that other than renaming one of the methods :( Perhaps other contributors can jump in to help suggest workarounds. |
As for the first issue you mentioned, I think we need to avoid referencing both However, now that we don't have a separate Dataframe implementation in ballista anymore, I am not sure what we gain from having the |
It seems to make sense to me -- it seems to me if someone wanted a different dataframe implementation they would probably just implement it themselves rather than trying to conform to an interface defined by DataFusion. However, I may not be a good arbiter of what is useful and what is not as I don't use the DataFrame impl much I can't seem to find where the |
realno
commented
Feb 1, 2022
I like the idea of simplifying interfaces - given the issues with this PR I think it seems to be a good idea to just consolidate |
houqp
commented
Feb 1, 2022
@alamb it's defined in https://github.com/apache/arrow-datafusion/blob/master/datafusion/src/dataframe.rs. @realno should have no impact to the python binding since traits are implementation details in the Rust land that won't get exposed to the python runtime. Let's leave this on for couple days to see if @andygrove@jimexist@yahoNanJing has a strong opinion on this or not. |
alamb
commented
Feb 1, 2022
Thanks @houqp -- looking at the history of that file the |
matthewmturner
commented
Mar 4, 2022
While working on #1922 i also ran into some issues with the |
houqp
commented
Mar 9, 2022
Great, I filed #1962 to track the work. |
andygrove
commented
Mar 10, 2022
I think my original intent was to provide different implementations for DataFusion vs Ballista but we have a better solution now with the DataFusion context allowing a pluggable query planner. |
This is a draft PR following up a discussion on #1699.
Issues:
Default, it compiles and tests pass,but I don't know if that's the right thing to do there.
dyn DataFramewithout thetrait_upcastingfeature, which is unstable.schemamethods are ambiguous whenuse datafusion::prelude::*is used (because both traits have aschemamethod), which makes using either's method without fully qualified syntax pretty ugly.