roapi/columnq/tests/table_csv_test.rs
QP Hou c1e26a84d1
Some checks failed
build / build (push) Has been cancelled
build / database_test (push) Has been cancelled
build / object_store_memory_test (push) Has been cancelled
build / object_store_direct_test (push) Has been cancelled
build / openssl_build (push) Has been cancelled
build / mac_cross_build (push) Has been cancelled
build / Docker Image Build (push) Has been cancelled
columnq-cli release / Validate git tag (push) Has been cancelled
roapi release / Validate git tag (push) Has been cancelled
columnq-cli release / macos (push) Has been cancelled
columnq-cli release / windows (map[features:database-sqlite python-architecture:x64 target:x86_64-pc-windows-msvc]) (push) Has been cancelled
columnq-cli release / linux (map[features:rustls,database-sqlite image_tag:aarch64-musl manylinux:2014 name_suffix: rustflags: target:aarch64-unknown-linux-musl upload:true]) (push) Has been cancelled
columnq-cli release / linux (map[features:rustls,database-sqlite image_tag:x86_64-musl manylinux:2010 name_suffix: rustflags:-C target-cpu=skylake target:x86_64-unknown-linux-musl upload:true]) (push) Has been cancelled
columnq-cli release / PyPI Release (push) Has been cancelled
roapi release / macos (push) Has been cancelled
roapi release / windows (map[features:database-sqlite python-architecture:x64 target:x86_64-pc-windows-msvc]) (push) Has been cancelled
roapi release / linux (map[features:rustls,database-sqlite image_tag:aarch64-musl manylinux:2014 name_suffix: rustflags: target:aarch64-unknown-linux-musl upload:true]) (push) Has been cancelled
roapi release / linux (map[features:rustls,database-sqlite image_tag:x86_64-musl manylinux:2010 name_suffix: rustflags:-C target-cpu=skylake target:x86_64-unknown-linux-musl upload:true]) (push) Has been cancelled
roapi release / PyPI Release (push) Has been cancelled
roapi release / Docker Image Release (push) Has been cancelled
enable continuous background refresh for delta tables (#352)
2024-12-02 06:49:16 -08:00

60 lines
1.7 KiB
Rust

mod helpers;
use std::sync::Arc;
use datafusion::arrow;
use datafusion::prelude::SessionContext;
use columnq::table::csv::to_datafusion_table;
use columnq::table::{TableIoSource, TableLoadOption, TableOptionCsv, TableSource};
#[tokio::test]
async fn infer_csv_schema_by_selected_files() {
use arrow::datatypes::{DataType, Field, Schema, SchemaBuilder};
let table_path = helpers::test_data_path("partitioned_csv");
let ctx = SessionContext::new();
let table_io_source = TableIoSource::Uri(table_path);
let table_source = TableSource::new("test", table_io_source)
.with_schema_from_files(vec![])
.with_option(TableLoadOption::csv(
TableOptionCsv::default().with_use_memory_table(false),
));
assert!(
!table_source
.option
.as_ref()
.unwrap()
.as_csv()
.unwrap()
.use_memory_table
);
assert!(table_source.schema_from_files.is_some());
assert_eq!(table_source.schema, None);
match to_datafusion_table(&table_source, &ctx).await {
Err(columnq::table::Error::Generic { msg }) => {
assert_eq!(&msg, "schema_from_files is an empty list");
}
_ => panic!("Empty schema_from_files should result in an error"),
}
let t = to_datafusion_table(
&table_source.with_schema_from_files(vec!["year=2023/month=1/p001.csv".to_string()]),
&ctx,
)
.await
.unwrap();
let mut builder = SchemaBuilder::new();
builder.push(Field::new("ts", DataType::Int64, true));
builder.push(Field::new("value", DataType::Float64, true));
assert_eq!(
t.table.schema(),
Arc::new(Schema::new(builder.finish().fields))
);
}