alamb commented on code in PR #11387:
URL: https://github.com/apache/datafusion/pull/11387#discussion_r1675793468
##########
datafusion/proto/tests/cases/roundtrip_physical_plan.rs:
##########
@@ -658,6 +662,147 @@ async fn
roundtrip_parquet_exec_with_table_partition_cols() -> Result<()> {
roundtrip_test(ParquetExec::builder(scan_config).build_arc())
}
+#[test]
+fn roundtrip_parquet_exec_with_custom_predicate_expr() -> Result<()> {
+ let scan_config = FileScanConfig {
+ object_store_url: ObjectStoreUrl::local_filesystem(),
+ file_schema: Arc::new(Schema::new(vec![Field::new(
+ "col",
+ DataType::Utf8,
+ false,
+ )])),
+ file_groups: vec![vec![PartitionedFile::new(
+ "/path/to/file.parquet".to_string(),
+ 1024,
+ )]],
+ statistics: Statistics {
+ num_rows: Precision::Inexact(100),
+ total_byte_size: Precision::Inexact(1024),
+ column_statistics:
Statistics::unknown_column(&Arc::new(Schema::new(vec![
+ Field::new("col", DataType::Utf8, false),
+ ]))),
+ },
+ projection: None,
+ limit: None,
+ table_partition_cols: vec![],
+ output_ordering: vec![],
+ };
+
+ #[derive(Debug, Hash, Clone)]
+ struct CustomPredicateExpr {
+ inner: Arc<dyn PhysicalExpr>,
+ }
+ impl Display for CustomPredicateExpr {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "CustomPredicateExpr")
+ }
+ }
+ impl PartialEq<dyn Any> for CustomPredicateExpr {
+ fn eq(&self, other: &dyn Any) -> bool {
+ down_cast_any_ref(other)
+ .downcast_ref::<Self>()
+ .map(|x| self.inner.eq(&x.inner))
+ .unwrap_or(false)
+ }
+ }
+ impl PhysicalExpr for CustomPredicateExpr {
+ fn as_any(&self) -> &dyn Any {
+ self
+ }
+
+ fn data_type(&self, _input_schema: &Schema) -> Result<DataType> {
+ unreachable!()
+ }
+
+ fn nullable(&self, _input_schema: &Schema) -> Result<bool> {
+ unreachable!()
+ }
+
+ fn evaluate(&self, _batch: &RecordBatch) -> Result<ColumnarValue> {
+ unreachable!()
+ }
+
+ fn children(&self) -> Vec<&Arc<dyn PhysicalExpr>> {
+ vec![&self.inner]
+ }
+
+ fn with_new_children(
+ self: Arc<Self>,
+ _children: Vec<Arc<dyn PhysicalExpr>>,
+ ) -> Result<Arc<dyn PhysicalExpr>> {
+ todo!()
+ }
+
+ fn dyn_hash(&self, _state: &mut dyn Hasher) {
+ unreachable!()
+ }
+ }
+
+ #[derive(Debug)]
+ struct CustomPhysicalExtensionCodec;
+ impl PhysicalExtensionCodec for CustomPhysicalExtensionCodec {
+ fn try_decode(
+ &self,
+ _buf: &[u8],
+ _inputs: &[Arc<dyn ExecutionPlan>],
+ _registry: &dyn FunctionRegistry,
+ ) -> Result<Arc<dyn ExecutionPlan>> {
+ unreachable!()
+ }
+
+ fn try_encode(
+ &self,
+ _node: Arc<dyn ExecutionPlan>,
+ _buf: &mut Vec<u8>,
+ ) -> Result<()> {
+ unreachable!()
+ }
+
+ fn try_decode_expr(
+ &self,
+ buf: &[u8],
+ inputs: &[Arc<dyn PhysicalExpr>],
+ ) -> Result<Arc<dyn PhysicalExpr>> {
+ if buf == "CustomPredicateExpr".as_bytes() {
+ Ok(Arc::new(CustomPredicateExpr {
+ inner: inputs[0].clone(),
+ }))
+ } else {
+ internal_err!("Not supported")
+ }
+ }
+
+ fn try_encode_expr(
+ &self,
+ node: Arc<dyn PhysicalExpr>,
+ buf: &mut Vec<u8>,
+ ) -> Result<()> {
+ if node
+ .as_ref()
+ .as_any()
+ .downcast_ref::<CustomPredicateExpr>()
+ .is_some()
+ {
+ buf.extend_from_slice("CustomPredicateExpr".as_bytes());
Review Comment:
nice
--
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]