adriangb commented on code in PR #16803:
URL: https://github.com/apache/datafusion/pull/16803#discussion_r2213484985


##########
datafusion-examples/examples/custom_file_casts.rs:
##########
@@ -0,0 +1,204 @@
+// 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.
+
+use std::sync::Arc;
+
+use arrow::array::{record_batch, RecordBatch};
+use arrow::datatypes::{DataType, Field, FieldRef, Schema, SchemaRef};
+
+use datafusion::assert_batches_eq;
+use datafusion::common::not_impl_err;
+use datafusion::common::tree_node::{Transformed, TransformedResult, TreeNode};
+use datafusion::common::{Result, ScalarValue};
+use datafusion::datasource::listing::{
+    ListingTable, ListingTableConfig, ListingTableUrl,
+};
+use datafusion::execution::context::SessionContext;
+use datafusion::execution::object_store::ObjectStoreUrl;
+use datafusion::parquet::arrow::ArrowWriter;
+use datafusion::physical_expr::expressions::CastExpr;
+use datafusion::physical_expr::schema_rewriter::{
+    DefaultPhysicalExprAdapterFactory, PhysicalExprAdapter, 
PhysicalExprAdapterFactory,
+};
+use datafusion::physical_expr::PhysicalExpr;
+use datafusion::prelude::SessionConfig;
+use object_store::memory::InMemory;
+use object_store::path::Path;
+use object_store::{ObjectStore, PutPayload};
+
+// Example showing how to implement custom casting rules to adapt file schemas.
+// This example enforces that casts must be stricly widening: if the file type 
is Int64 and the table type is Int32, it will error
+// before even reading the data.

Review Comment:
   ```suggestion
   // Example showing how to implement custom casting rules to adapt file 
schemas.
   // This example enforces that casts must be stricly widening: if the file 
type is Int64 and the table type is Int32, it will error
   // before even reading the data.
   // Without this custom cast rule DataFusion would happily do the narrowing 
cast, potentially erroring only if it found a row with data it could not cast.
   ```



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to