polars_lazy/scan/
catalog.rs

1use polars_core::error::{PolarsResult, feature_gated, polars_bail};
2use polars_io::catalog::unity::models::{DataSourceFormat, TableInfo};
3use polars_io::catalog::unity::schema::table_info_to_schemas;
4use polars_io::cloud::CloudOptions;
5
6use crate::frame::LazyFrame;
7
8impl LazyFrame {
9    pub fn scan_catalog_table(
10        table_info: &TableInfo,
11        cloud_options: Option<CloudOptions>,
12    ) -> PolarsResult<Self> {
13        let Some(data_source_format) = &table_info.data_source_format else {
14            polars_bail!(ComputeError: "scan_catalog_table requires Some(_) for data_source_format")
15        };
16
17        let Some(storage_location) = table_info.storage_location.as_deref() else {
18            polars_bail!(ComputeError: "scan_catalog_table requires Some(_) for storage_location")
19        };
20
21        match data_source_format {
22            DataSourceFormat::Parquet => feature_gated!("parquet", {
23                use polars_io::HiveOptions;
24
25                use crate::frame::ScanArgsParquet;
26                let (schema, hive_schema) = table_info_to_schemas(table_info)?;
27
28                let args = ScanArgsParquet {
29                    schema,
30                    cloud_options,
31                    hive_options: HiveOptions {
32                        schema: hive_schema,
33                        ..Default::default()
34                    },
35                    ..Default::default()
36                };
37
38                Self::scan_parquet(storage_location, args)
39            }),
40            DataSourceFormat::Csv => feature_gated!("csv", {
41                use crate::frame::{LazyCsvReader, LazyFileListReader};
42                let (schema, _) = table_info_to_schemas(table_info)?;
43
44                LazyCsvReader::new(storage_location)
45                    .with_schema(schema)
46                    .finish()
47            }),
48            v => polars_bail!(
49                ComputeError:
50                "not yet supported data_source_format: {:?}",
51                v
52            ),
53        }
54    }
55}