(
&self,
state: &dyn Session,
cmd: &CreateExternalTable,
)
| 48 | #[async_trait] |
| 49 | impl TableProviderFactory for StreamTableFactory { |
| 50 | async fn create( |
| 51 | &self, |
| 52 | state: &dyn Session, |
| 53 | cmd: &CreateExternalTable, |
| 54 | ) -> Result<Arc<dyn TableProvider>> { |
| 55 | let schema: SchemaRef = Arc::clone(cmd.schema.inner()); |
| 56 | let location = cmd.location.clone(); |
| 57 | let encoding = cmd.file_type.parse()?; |
| 58 | let header = if let Ok(opt) = cmd |
| 59 | .options |
| 60 | .get("format.has_header") |
| 61 | .map(|has_header| bool::from_str(has_header.to_lowercase().as_str())) |
| 62 | .transpose() |
| 63 | { |
| 64 | opt.unwrap_or(false) |
| 65 | } else { |
| 66 | return config_err!( |
| 67 | "Valid values for format.has_header option are 'true' or 'false'" |
| 68 | ); |
| 69 | }; |
| 70 | |
| 71 | let source = FileStreamProvider::new_file(schema, location.into()) |
| 72 | .with_encoding(encoding) |
| 73 | .with_batch_size(state.config().batch_size()) |
| 74 | .with_header(header); |
| 75 | |
| 76 | let config = StreamConfig::new(Arc::new(source)) |
| 77 | .with_order(cmd.order_exprs.clone()) |
| 78 | .with_constraints(cmd.constraints.clone()); |
| 79 | |
| 80 | Ok(Arc::new(StreamTable(Arc::new(config)))) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /// The data encoding for [`StreamTable`] |
no test coverage detected