Phoenix500526 commented on code in PR #23752:
URL: https://github.com/apache/datafusion/pull/23752#discussion_r3658593685
##########
datafusion/proto/tests/cases/roundtrip_physical_plan.rs:
##########
@@ -1956,6 +1958,122 @@ fn roundtrip_analyze() -> Result<()> {
))
}
+#[derive(Debug)]
+struct ProtoHookSink {
+ schema: SchemaRef,
+}
+
+impl DisplayAs for ProtoHookSink {
+ fn fmt_as(&self, _t: DisplayFormatType, f: &mut Formatter) ->
std::fmt::Result {
+ write!(f, "ProtoHookSink")
+ }
+}
+
+#[async_trait]
+impl DataSink for ProtoHookSink {
+ fn schema(&self) -> &SchemaRef {
+ &self.schema
+ }
+
+ async fn write_all(
+ &self,
+ _data: SendableRecordBatchStream,
+ _context: &Arc<TaskContext>,
+ ) -> Result<u64> {
+ unreachable!("serialization test does not execute the sink")
+ }
+
+ fn try_to_proto(
+ &self,
+ input: PhysicalPlanNode,
+ sort_order: Option<protobuf::PhysicalSortExprNodeCollection>,
+ sink_schema: &Schema,
+ ) -> Result<Option<PhysicalPlanNode>> {
+ assert!(matches!(
+ input.physical_plan_type,
+
Some(protobuf::physical_plan_node::PhysicalPlanType::PlaceholderRow(_))
+ ));
+ assert_eq!(
+ sort_order
+ .as_ref()
+ .map(|ordering| ordering.physical_sort_expr_nodes.len()),
+ Some(1)
+ );
+ assert_eq!(sink_schema.fields().len(), 1);
+
+ Ok(Some(PhysicalPlanNode {
+ physical_plan_type: Some(
+ protobuf::physical_plan_node::PhysicalPlanType::Empty(
+ protobuf::EmptyExecNode {
+ schema: Some(sink_schema.try_into()?),
+ partitions: 1,
+ },
+ ),
+ ),
+ }))
+ }
+}
+
+#[test]
+fn data_sink_exec_delegates_to_sink_proto_hook() -> Result<()> {
+ let input_schema = Arc::new(Schema::new(vec![Field::new(
+ "value",
+ DataType::Int64,
+ false,
+ )]));
+ let input = Arc::new(PlaceholderRowExec::new(Arc::clone(&input_schema)));
+ let sink = Arc::new(ProtoHookSink {
+ schema: Arc::clone(&input_schema),
+ });
+ let sort_order = [PhysicalSortRequirement::new(
+ Arc::new(Column::new("value", 0)),
+ Some(SortOptions::default()),
+ )]
+ .into();
+ let plan = Arc::new(DataSinkExec::new(input, sink, Some(sort_order)));
+
+ let node = PhysicalPlanNode::try_from_physical_plan(
+ plan,
+ &DefaultPhysicalExtensionCodec {},
+ )?;
+
+ assert!(matches!(
+ node.physical_plan_type,
+ Some(protobuf::physical_plan_node::PhysicalPlanType::Empty(_))
+ ));
+ Ok(())
+}
+
+#[test]
+fn file_sink_config_conversion_preserves_compatibility_api() -> Result<()> {
+ let schema = Arc::new(Schema::new(vec![Field::new(
+ "partition",
+ DataType::Utf8,
+ false,
+ )]));
+ let config = FileSinkConfig {
+ original_url: "file:///tmp/output".to_string(),
+ object_store_url: ObjectStoreUrl::local_filesystem(),
+ file_group: FileGroup::new(vec![PartitionedFile::new("/tmp/output",
1)]),
+ table_paths: vec![ListingTableUrl::parse("file:///tmp/output")?],
+ output_schema: schema,
+ table_partition_cols: vec![("partition".to_string(), DataType::Utf8)],
+ insert_op: InsertOp::Overwrite,
+ keep_partition_by_columns: true,
+ file_extension: "parquet".to_string(),
+ file_output_mode: FileOutputMode::Directory,
+ };
+
+ let direct = config.to_proto()?;
+ let compatibility = protobuf::FileSinkConfig::try_from_proto(&config)?;
+ assert_eq!(direct, compatibility);
+
+ let direct = FileSinkConfig::from_proto(&direct)?;
Review Comment:
Done
--
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]