datafusion_datasource/
schema_adapter.rs1#![allow(deprecated)]
25
26use arrow::array::{ArrayRef, RecordBatch};
27use arrow::datatypes::{Field, Schema, SchemaRef};
28use datafusion_common::{ColumnStatistics, Result, not_impl_err};
29use log::warn;
30use std::fmt::Debug;
31use std::sync::Arc;
32
33#[deprecated(
40 since = "52.0.0",
41 note = "SchemaAdapter has been removed. Use PhysicalExprAdapterFactory instead. See upgrading.md for more details."
42)]
43pub type CastColumnFn = dyn Fn(&ArrayRef, &Field, &arrow::compute::CastOptions) -> Result<ArrayRef>
44 + Send
45 + Sync;
46
47#[deprecated(
54 since = "52.0.0",
55 note = "SchemaAdapter has been removed. Use PhysicalExprAdapterFactory instead. See upgrading.md for more details."
56)]
57pub trait SchemaAdapterFactory: Debug + Send + Sync + 'static {
58 fn create(
60 &self,
61 projected_table_schema: SchemaRef,
62 table_schema: SchemaRef,
63 ) -> Box<dyn SchemaAdapter>;
64
65 fn create_with_projected_schema(
67 &self,
68 projected_table_schema: SchemaRef,
69 ) -> Box<dyn SchemaAdapter> {
70 self.create(Arc::clone(&projected_table_schema), projected_table_schema)
71 }
72}
73
74#[deprecated(
81 since = "52.0.0",
82 note = "SchemaAdapter has been removed. Use PhysicalExprAdapterFactory instead. See upgrading.md for more details."
83)]
84pub trait SchemaAdapter: Send + Sync {
85 fn map_column_index(&self, index: usize, file_schema: &Schema) -> Option<usize>;
87
88 fn map_schema(
90 &self,
91 file_schema: &Schema,
92 ) -> Result<(Arc<dyn SchemaMapper>, Vec<usize>)>;
93}
94
95#[deprecated(
102 since = "52.0.0",
103 note = "SchemaMapper has been removed. Use PhysicalExprAdapterFactory instead. See upgrading.md for more details."
104)]
105pub trait SchemaMapper: Debug + Send + Sync {
106 fn map_batch(&self, batch: RecordBatch) -> Result<RecordBatch>;
108
109 fn map_column_statistics(
111 &self,
112 file_col_statistics: &[ColumnStatistics],
113 ) -> Result<Vec<ColumnStatistics>>;
114}
115
116#[deprecated(
123 since = "52.0.0",
124 note = "DefaultSchemaAdapterFactory has been removed. Use PhysicalExprAdapterFactory instead. See upgrading.md for more details."
125)]
126#[derive(Clone, Debug, Default)]
127pub struct DefaultSchemaAdapterFactory;
128
129impl SchemaAdapterFactory for DefaultSchemaAdapterFactory {
130 fn create(
131 &self,
132 projected_table_schema: SchemaRef,
133 _table_schema: SchemaRef,
134 ) -> Box<dyn SchemaAdapter> {
135 Box::new(DeprecatedSchemaAdapter {
136 _projected_table_schema: projected_table_schema,
137 })
138 }
139}
140
141impl DefaultSchemaAdapterFactory {
142 #[deprecated(
144 since = "52.0.0",
145 note = "DefaultSchemaAdapterFactory has been removed. Use PhysicalExprAdapterFactory instead. See upgrading.md for more details."
146 )]
147 pub fn from_schema(table_schema: SchemaRef) -> Box<dyn SchemaAdapter> {
148 warn!(
150 "DefaultSchemaAdapterFactory::from_schema is deprecated. Use PhysicalExprAdapterFactory instead. See upgrading.md for more details."
151 );
152 Box::new(DeprecatedSchemaAdapter {
153 _projected_table_schema: table_schema,
154 })
155 }
156}
157
158struct DeprecatedSchemaAdapter {
160 _projected_table_schema: SchemaRef,
161}
162
163impl SchemaAdapter for DeprecatedSchemaAdapter {
164 fn map_column_index(&self, _index: usize, _file_schema: &Schema) -> Option<usize> {
165 None }
167
168 fn map_schema(
169 &self,
170 _file_schema: &Schema,
171 ) -> Result<(Arc<dyn SchemaMapper>, Vec<usize>)> {
172 not_impl_err!(
173 "SchemaAdapter has been removed. Use PhysicalExprAdapterFactory instead. \
174 See upgrading.md for more details."
175 )
176 }
177}
178
179#[deprecated(
186 since = "52.0.0",
187 note = "SchemaMapping has been removed. Use PhysicalExprAdapterFactory instead. See upgrading.md for more details."
188)]
189#[derive(Debug)]
190pub struct SchemaMapping {
191 _private: (),
193}
194
195impl SchemaMapper for SchemaMapping {
196 fn map_batch(&self, _batch: RecordBatch) -> Result<RecordBatch> {
197 not_impl_err!(
198 "SchemaMapping has been removed. Use PhysicalExprAdapterFactory instead. \
199 See upgrading.md for more details."
200 )
201 }
202
203 fn map_column_statistics(
204 &self,
205 _file_col_statistics: &[ColumnStatistics],
206 ) -> Result<Vec<ColumnStatistics>> {
207 not_impl_err!(
208 "SchemaMapping has been removed. Use PhysicalExprAdapterFactory instead. \
209 See upgrading.md for more details."
210 )
211 }
212}