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