timsaucer commented on code in PR #24028:
URL: https://github.com/apache/datafusion/pull/24028#discussion_r3721507586


##########
datafusion/ffi/tests/ffi_query_planner.rs:
##########
@@ -0,0 +1,223 @@
+// 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.
+
+mod utils;
+
+#[cfg(feature = "integration-tests")]
+mod tests {
+    use std::sync::{Arc, OnceLock, Weak};
+
+    use arrow::datatypes::SchemaRef;
+    use datafusion::execution::SessionStateBuilder;
+    use datafusion::prelude::SessionContext;
+    use datafusion_catalog::TableProvider;
+    use datafusion_common::{
+        DataFusionError, Result, TableReference, exec_err, not_impl_err,
+    };
+    use datafusion_execution::{TaskContext, TaskContextProvider};
+    use datafusion_expr::LogicalPlan;
+    use datafusion_expr::logical_plan::Extension;
+    use datafusion_ffi::execution::FFI_TaskContextProvider;
+    use datafusion_ffi::execution_plan::ForeignExecutionPlan;
+    use 
datafusion_ffi::proto::logical_extension_codec::FFI_LogicalExtensionCodec;
+    use 
datafusion_ffi::proto::physical_extension_codec::FFI_PhysicalExtensionCodec;
+    use datafusion_ffi::query_planner::ForeignQueryPlanner;
+    use datafusion_ffi::table_provider::ForeignTableProvider;
+    use datafusion_ffi::tests::{
+        create_test_schema,
+        utils::{get_module, get_module_copy},
+    };
+    use datafusion_physical_plan::ExecutionPlan;
+    use datafusion_physical_plan::empty::EmptyExec;
+    use datafusion_physical_plan::union::UnionExec;
+    use datafusion_proto::logical_plan::LogicalExtensionCodec;
+    use datafusion_proto::physical_plan::{
+        DefaultPhysicalExtensionCodec, PhysicalExtensionCodec,
+        PhysicalProtoConverterExtension,
+    };
+    use datafusion_session::QueryPlanner;
+
+    #[tokio::test]
+    async fn test_ffi_query_planner() -> Result<(), DataFusionError> {
+        let module = get_module()?;
+        let (ctx, logical_codec) = crate::utils::ctx_and_codec();
+        let task_ctx_provider = Arc::clone(&ctx) as Arc<dyn 
TaskContextProvider>;
+        let task_ctx_provider = 
FFI_TaskContextProvider::from(&task_ctx_provider);
+        let physical_codec = FFI_PhysicalExtensionCodec::new(
+            Arc::new(DefaultPhysicalExtensionCodec {}),
+            None,
+            task_ctx_provider,
+        );
+
+        let ffi_planner = (module.create_query_planner)(logical_codec, 
physical_codec);
+        let planner: Arc<dyn QueryPlanner + Send + Sync> = 
(&ffi_planner).into();
+
+        let any_ref: &dyn std::any::Any = planner.as_ref();
+        assert!(any_ref.downcast_ref::<ForeignQueryPlanner>().is_some());
+
+        let logical_plan = 
datafusion_expr::LogicalPlanBuilder::empty(false).build()?;
+        let state = ctx.state();
+        let physical_plan = planner.create_physical_plan(&logical_plan, 
&state).await?;
+
+        assert_eq!(physical_plan.name(), "EmptyExec");
+        assert!(physical_plan.is::<EmptyExec>());
+
+        Ok(())
+    }
+
+    /// Library A's logical codec stores library B's provider while the logical
+    /// plan crosses into library C. A real application would encode enough
+    /// metadata to reconstruct or locate the provider instead.

Review Comment:
   I think "metadata" was poor phrasing. Basically you need enough data to 
faithfully reproduce the plan on both sides of the (de)serialization. I'm 
updating the docstring to make it more clear.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to