Skip to content

Commit 8d60834

Browse files
authored
Merge branch 'main' into implement_groups_accumulator_count_distinct_primitive_types
2 parents 651acf3 + a13c23d commit 8d60834

100 files changed

Lines changed: 5245 additions & 1083 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

datafusion-cli/src/catalog.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use std::any::Any;
1918
use std::sync::{Arc, Weak};
2019

2120
use crate::object_storage::{AwsOptions, GcpOptions, get_object_store};
@@ -50,10 +49,6 @@ impl DynamicObjectStoreCatalog {
5049
}
5150

5251
impl CatalogProviderList for DynamicObjectStoreCatalog {
53-
fn as_any(&self) -> &dyn Any {
54-
self
55-
}
56-
5752
fn register_catalog(
5853
&self,
5954
name: String,
@@ -91,10 +86,6 @@ impl DynamicObjectStoreCatalogProvider {
9186
}
9287

9388
impl CatalogProvider for DynamicObjectStoreCatalogProvider {
94-
fn as_any(&self) -> &dyn Any {
95-
self
96-
}
97-
9889
fn schema_names(&self) -> Vec<String> {
9990
self.inner.schema_names()
10091
}
@@ -134,10 +125,6 @@ impl DynamicObjectStoreSchemaProvider {
134125

135126
#[async_trait]
136127
impl SchemaProvider for DynamicObjectStoreSchemaProvider {
137-
fn as_any(&self) -> &dyn Any {
138-
self
139-
}
140-
141128
fn table_names(&self) -> Vec<String> {
142129
self.inner.table_names()
143130
}

datafusion-cli/src/functions.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,6 @@ struct ParquetMetadataTable {
229229

230230
#[async_trait]
231231
impl TableProvider for ParquetMetadataTable {
232-
fn as_any(&self) -> &dyn std::any::Any {
233-
self
234-
}
235-
236232
fn schema(&self) -> SchemaRef {
237233
self.schema.clone()
238234
}
@@ -479,10 +475,6 @@ struct MetadataCacheTable {
479475

480476
#[async_trait]
481477
impl TableProvider for MetadataCacheTable {
482-
fn as_any(&self) -> &dyn std::any::Any {
483-
self
484-
}
485-
486478
fn schema(&self) -> SchemaRef {
487479
self.schema.clone()
488480
}
@@ -598,10 +590,6 @@ struct StatisticsCacheTable {
598590

599591
#[async_trait]
600592
impl TableProvider for StatisticsCacheTable {
601-
fn as_any(&self) -> &dyn std::any::Any {
602-
self
603-
}
604-
605593
fn schema(&self) -> SchemaRef {
606594
self.schema.clone()
607595
}
@@ -734,10 +722,6 @@ struct ListFilesCacheTable {
734722

735723
#[async_trait]
736724
impl TableProvider for ListFilesCacheTable {
737-
fn as_any(&self) -> &dyn std::any::Any {
738-
self
739-
}
740-
741725
fn schema(&self) -> SchemaRef {
742726
self.schema.clone()
743727
}

datafusion-examples/examples/custom_data_source/custom_datasource.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
//! See `main.rs` for how to run it.
1919
20-
use std::any::Any;
2120
use std::collections::{BTreeMap, HashMap};
2221
use std::fmt::{self, Debug, Formatter};
2322
use std::sync::{Arc, Mutex};
@@ -162,10 +161,6 @@ impl Default for CustomDataSource {
162161

163162
#[async_trait]
164163
impl TableProvider for CustomDataSource {
165-
fn as_any(&self) -> &dyn Any {
166-
self
167-
}
168-
169164
fn schema(&self) -> SchemaRef {
170165
SchemaRef::new(Schema::new(vec![
171166
Field::new("id", DataType::UInt8, false),

datafusion-examples/examples/custom_data_source/custom_file_casts.rs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use datafusion::execution::context::SessionContext;
3333
use datafusion::execution::object_store::ObjectStoreUrl;
3434
use datafusion::parquet::arrow::ArrowWriter;
3535
use datafusion::physical_expr::PhysicalExpr;
36-
use datafusion::physical_expr::expressions::{CastColumnExpr, CastExpr};
36+
use datafusion::physical_expr::expressions::CastExpr;
3737
use datafusion::prelude::SessionConfig;
3838
use datafusion_physical_expr_adapter::{
3939
DefaultPhysicalExprAdapterFactory, PhysicalExprAdapter, PhysicalExprAdapterFactory,
@@ -43,9 +43,10 @@ use object_store::path::Path;
4343
use object_store::{ObjectStore, ObjectStoreExt, PutPayload};
4444

4545
// Example showing how to implement custom casting rules to adapt file schemas.
46-
// This example enforces that casts must be strictly widening: if the file type is Int64 and the table type is Int32, it will error
47-
// before even reading the data.
48-
// 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.
46+
// This example enforces strictly widening casts: if the file type is Int64 and
47+
// the table type is Int32, it errors before reading the data. Without this
48+
// custom cast rule DataFusion would apply the narrowing cast and might only
49+
// error after reading a row that it could not cast.
4950
pub async fn custom_file_casts() -> Result<()> {
5051
println!("=== Creating example data ===");
5152

@@ -139,7 +140,7 @@ async fn write_data(
139140
Ok(())
140141
}
141142

142-
/// Factory for creating DefaultValuePhysicalExprAdapter instances
143+
/// Factory for creating custom cast physical expression adapters
143144
#[derive(Debug)]
144145
struct CustomCastPhysicalExprAdapterFactory {
145146
inner: Arc<dyn PhysicalExprAdapterFactory>,
@@ -167,8 +168,8 @@ impl PhysicalExprAdapterFactory for CustomCastPhysicalExprAdapterFactory {
167168
}
168169
}
169170

170-
/// Custom PhysicalExprAdapter that handles missing columns with default values from metadata
171-
/// and wraps DefaultPhysicalExprAdapter for standard schema adaptation
171+
/// Custom `PhysicalExprAdapter` that wraps the default adapter and rejects
172+
/// narrowing file-schema casts.
172173
#[derive(Debug, Clone)]
173174
struct CustomCastsPhysicalExprAdapter {
174175
physical_file_schema: SchemaRef,
@@ -177,34 +178,23 @@ struct CustomCastsPhysicalExprAdapter {
177178

178179
impl PhysicalExprAdapter for CustomCastsPhysicalExprAdapter {
179180
fn rewrite(&self, mut expr: Arc<dyn PhysicalExpr>) -> Result<Arc<dyn PhysicalExpr>> {
180-
// First delegate to the inner adapter to handle missing columns and discover any necessary casts
181+
// First delegate to the inner adapter to handle standard schema adaptation
182+
// and discover any necessary casts.
181183
expr = self.inner.rewrite(expr)?;
182-
// Now we can apply custom casting rules or even swap out all CastExprs for a custom cast kernel / expression
183-
// For example, [DataFusion Comet](https://github.com/apache/datafusion-comet) has a [custom cast kernel](https://github.com/apache/datafusion-comet/blob/b4ac876ab420ed403ac7fc8e1b29f42f1f442566/native/spark-expr/src/conversion_funcs/cast.rs#L133-L138).
184+
// Now apply custom casting rules or swap CastExprs for a custom cast
185+
// kernel / expression. For example, DataFusion Comet has a custom cast
186+
// kernel in its native Spark expression implementation.
184187
expr.transform(|expr| {
185188
if let Some(cast) = expr.as_any().downcast_ref::<CastExpr>() {
186189
let input_data_type =
187190
cast.expr().data_type(&self.physical_file_schema)?;
188-
let output_data_type = cast.data_type(&self.physical_file_schema)?;
191+
let output_data_type = cast.target_field().data_type();
189192
if !cast.is_bigger_cast(&input_data_type) {
190193
return not_impl_err!(
191194
"Unsupported CAST from {input_data_type} to {output_data_type}"
192195
);
193196
}
194197
}
195-
if let Some(cast) = expr.as_any().downcast_ref::<CastColumnExpr>() {
196-
let input_data_type =
197-
cast.expr().data_type(&self.physical_file_schema)?;
198-
let output_data_type = cast.data_type(&self.physical_file_schema)?;
199-
if !CastExpr::check_bigger_cast(
200-
cast.target_field().data_type(),
201-
&input_data_type,
202-
) {
203-
return not_impl_err!(
204-
"Unsupported CAST from {input_data_type} to {output_data_type}"
205-
);
206-
}
207-
}
208198
Ok(Transformed::no(expr))
209199
})
210200
.data()

datafusion-examples/examples/custom_data_source/default_column_values.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
//! See `main.rs` for how to run it.
1919
20-
use std::any::Any;
2120
use std::collections::HashMap;
2221
use std::sync::Arc;
2322

@@ -201,10 +200,6 @@ impl DefaultValueTableProvider {
201200

202201
#[async_trait]
203202
impl TableProvider for DefaultValueTableProvider {
204-
fn as_any(&self) -> &dyn Any {
205-
self
206-
}
207-
208203
fn schema(&self) -> SchemaRef {
209204
Arc::clone(&self.schema)
210205
}

datafusion-examples/examples/custom_data_source/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
//!
2222
//! ## Usage
2323
//! ```bash
24-
//! cargo run --example custom_data_source -- [all|csv_json_opener|csv_sql_streaming|custom_datasource|custom_file_casts|custom_file_format|default_column_values|file_stream_provider]
24+
//! cargo run --example custom_data_source -- [all|adapter_serialization|csv_json_opener|csv_sql_streaming|custom_datasource|custom_file_casts|custom_file_format|default_column_values|file_stream_provider]
2525
//! ```
2626
//!
2727
//! Each subcommand runs a corresponding example:

datafusion-examples/examples/data_io/catalog.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use datafusion::{
3232
prelude::SessionContext,
3333
};
3434
use std::sync::RwLock;
35-
use std::{any::Any, collections::HashMap, path::Path, sync::Arc};
35+
use std::{collections::HashMap, path::Path, sync::Arc};
3636
use std::{fs::File, io::Write};
3737
use tempfile::TempDir;
3838

@@ -178,10 +178,6 @@ impl DirSchema {
178178

179179
#[async_trait]
180180
impl SchemaProvider for DirSchema {
181-
fn as_any(&self) -> &dyn Any {
182-
self
183-
}
184-
185181
fn table_names(&self) -> Vec<String> {
186182
let tables = self.tables.read().unwrap();
187183
tables.keys().cloned().collect::<Vec<_>>()
@@ -231,10 +227,6 @@ impl DirCatalog {
231227
}
232228

233229
impl CatalogProvider for DirCatalog {
234-
fn as_any(&self) -> &dyn Any {
235-
self
236-
}
237-
238230
fn register_schema(
239231
&self,
240232
name: &str,
@@ -277,10 +269,6 @@ impl CustomCatalogProviderList {
277269
}
278270

279271
impl CatalogProviderList for CustomCatalogProviderList {
280-
fn as_any(&self) -> &dyn Any {
281-
self
282-
}
283-
284272
fn register_catalog(
285273
&self,
286274
name: String,

datafusion-examples/examples/data_io/parquet_advanced_index.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
//! See `main.rs` for how to run it.
1919
20-
use std::any::Any;
2120
use std::collections::{HashMap, HashSet};
2221
use std::fs::File;
2322
use std::ops::Range;
@@ -451,10 +450,6 @@ impl IndexedFile {
451450
/// so that we can query it as a table.
452451
#[async_trait]
453452
impl TableProvider for IndexTableProvider {
454-
fn as_any(&self) -> &dyn Any {
455-
self
456-
}
457-
458453
fn schema(&self) -> SchemaRef {
459454
Arc::clone(&self.indexed_file.schema)
460455
}

datafusion-examples/examples/data_io/parquet_embedded_index.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,6 @@ fn get_key_value<'a>(file_meta_data: &'a FileMetaData, key: &'_ str) -> Option<&
393393
/// Implement TableProvider for DistinctIndexTable, using the distinct index to prune files
394394
#[async_trait]
395395
impl TableProvider for DistinctIndexTable {
396-
fn as_any(&self) -> &dyn std::any::Any {
397-
self
398-
}
399396
fn schema(&self) -> SchemaRef {
400397
self.schema.clone()
401398
}

datafusion-examples/examples/data_io/parquet_index.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ use datafusion::physical_expr::PhysicalExpr;
4545
use datafusion::physical_optimizer::pruning::PruningPredicate;
4646
use datafusion::physical_plan::ExecutionPlan;
4747
use datafusion::prelude::*;
48-
use std::any::Any;
4948
use std::collections::HashSet;
5049
use std::fmt::Display;
5150
use std::fs;
@@ -208,10 +207,6 @@ impl IndexTableProvider {
208207

209208
#[async_trait]
210209
impl TableProvider for IndexTableProvider {
211-
fn as_any(&self) -> &dyn Any {
212-
self
213-
}
214-
215210
fn schema(&self) -> SchemaRef {
216211
self.index.schema().clone()
217212
}

0 commit comments

Comments
 (0)