Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ hive_metastore = "0.2.0"
home = "=0.5.11"
http = "1.2"
iceberg = { version = "0.7.0", path = "./crates/iceberg" }
iceberg-catalog-loader = { version = "0.7.0", path = "./crates/catalog/loader" }
iceberg-catalog-glue = { version = "0.7.0", path = "./crates/catalog/glue" }
iceberg-catalog-hms = { version = "0.7.0", path = "./crates/catalog/hms" }
iceberg-catalog-sql = { version = "0.7.0", path = "./crates/catalog/sql" }
Expand Down
2 changes: 2 additions & 0 deletions crates/catalog/loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::sync::Arc;

use async_trait::async_trait;
use iceberg::{Catalog, CatalogBuilder, Error, ErrorKind, Result};
use iceberg::memory::MemoryCatalogBuilder;
use iceberg_catalog_glue::GlueCatalogBuilder;
use iceberg_catalog_hms::HmsCatalogBuilder;
use iceberg_catalog_rest::RestCatalogBuilder;
Expand All @@ -31,6 +32,7 @@ type CatalogBuilderFactory = fn() -> Box<dyn BoxedCatalogBuilder>;

/// A registry of catalog builders.
static CATALOG_REGISTRY: &[(&str, CatalogBuilderFactory)] = &[
("memory", || Box::new(MemoryCatalogBuilder::default())),
("rest", || Box::new(RestCatalogBuilder::default())),
("glue", || Box::new(GlueCatalogBuilder::default())),
("s3tables", || Box::new(S3TablesCatalogBuilder::default())),
Expand Down
1 change: 1 addition & 0 deletions crates/sqllogictest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ datafusion-sqllogictest = { workspace = true }
enum-ordinalize = { workspace = true }
env_logger = { workspace = true }
iceberg = { workspace = true }
iceberg-catalog-loader = { workspace = true }
iceberg-datafusion = { workspace = true }
indicatif = { workspace = true }
log = { workspace = true }
Expand Down
66 changes: 65 additions & 1 deletion crates/sqllogictest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,68 @@ cargo test
The tests are run against the following sql engines:

* [Apache datafusion](https://crates.io/crates/datafusion)
* [Apache spark](https://github.com/apache/spark)
* [Apache spark](https://github.com/apache/spark)

## Catalog Configuration

This crate now supports dynamic catalog configuration in test schedules. You can configure different types of catalogs (memory, rest, glue, sql, etc.) and share them across multiple engines.

### Configuration Format

```toml
# Define catalogs
[catalogs.memory_catalog]
type = "memory"
warehouse = "memory://warehouse"

[catalogs.rest_catalog]
type = "rest"
uri = "http://localhost:8181"
warehouse = "s3://my-bucket/warehouse"
credential = "client_credentials"
token = "xxx"

[catalogs.sql_catalog]
type = "sql"
uri = "postgresql://user:pass@localhost/iceberg"
warehouse = "s3://my-bucket/warehouse"
sql_bind_style = "DollarNumeric"

# Define engines with optional catalog references
[engines.datafusion1]
type = "datafusion"
catalog = "memory_catalog" # Reference to a catalog

[engines.datafusion2]
type = "datafusion"
catalog = "rest_catalog" # Multiple engines can share the same catalog

[engines.datafusion3]
type = "datafusion"
# No catalog specified - uses default MemoryCatalog

# Define test steps
[[steps]]
engine = "datafusion1"
slt = "path/to/test1.slt"

[[steps]]
engine = "datafusion2"
slt = "path/to/test2.slt"
```

### Supported Catalog Types

- `memory`: In-memory catalog for testing
- `rest`: REST catalog for integration testing
- `glue`: AWS Glue catalog
- `sql`: SQL database catalog
- `hms`: Hive Metastore catalog
- `s3tables`: S3 Tables catalog

### Key Features

- **Lazy Loading**: Catalogs are created only when first referenced
- **Sharing**: Multiple engines can share the same catalog instance
- **Backward Compatibility**: Existing schedules continue to work without modification
- **Type Safety**: Catalog configurations are validated at parse time
76 changes: 76 additions & 0 deletions crates/sqllogictest/examples/example_catalog_config.toml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# Example configuration file: demonstrates various catalog configuration methods
# Note: This file is for example purposes only and will not be executed by the test framework
# (because the filename does not end with .toml, but with .example)

# Memory catalog example
[catalogs.memory_example]
type = "memory"
warehouse = "memory://example"

# REST catalog example (for integration testing)
[catalogs.rest_example]
type = "rest"
uri = "http://localhost:8181"
warehouse = "s3://test-bucket/warehouse"
credential = "client_credentials"
token = "your-token-here"

# SQL catalog example
[catalogs.sql_example]
type = "sql"
uri = "postgresql://user:password@localhost:5432/iceberg_test"
warehouse = "s3://test-bucket/warehouse"
sql_bind_style = "DollarNumeric"

# Glue catalog example
[catalogs.glue_example]
type = "glue"
warehouse = "s3://test-bucket/warehouse"
region = "us-east-1"

# Engine configuration example
[engines.memory_engine]
type = "datafusion"
catalog = "memory_example"

[engines.rest_engine]
type = "datafusion"
catalog = "rest_example"

[engines.sql_engine]
type = "datafusion"
catalog = "sql_example"

[engines.glue_engine]
type = "datafusion"
catalog = "glue_example"

[engines.default_engine]
type = "datafusion"
# No catalog specified, uses default MemoryCatalog

# Test steps example
[[steps]]
engine = "memory_engine"
slt = "df_test/show_tables.slt"

[[steps]]
engine = "default_engine"
slt = "df_test/show_tables.slt"
37 changes: 31 additions & 6 deletions crates/sqllogictest/src/engine/datafusion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::sync::Arc;
use datafusion::catalog::CatalogProvider;
use datafusion::prelude::{SessionConfig, SessionContext};
use datafusion_sqllogictest::DataFusion;
use iceberg::CatalogBuilder;
use iceberg::{Catalog, CatalogBuilder};
use iceberg::memory::{MEMORY_CATALOG_WAREHOUSE, MemoryCatalogBuilder};
use iceberg_datafusion::IcebergCatalogProvider;
use indicatif::ProgressBar;
Expand All @@ -36,6 +36,15 @@ pub struct DataFusionEngine {
session_context: SessionContext,
}

impl std::fmt::Debug for DataFusionEngine {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DataFusionEngine")
.field("test_data_path", &self.test_data_path)
.field("session_context", &"<SessionContext>")
.finish()
}
}

#[async_trait::async_trait]
impl EngineRunner for DataFusionEngine {
async fn run_slt_file(&mut self, path: &Path) -> Result<()> {
Expand All @@ -58,22 +67,38 @@ impl EngineRunner for DataFusionEngine {
}

impl DataFusionEngine {
pub async fn new(config: TomlTable) -> Result<Self> {
pub async fn new(
config: TomlTable,
catalog: Option<Arc<dyn Catalog>>,
) -> Result<Self> {
let session_config = SessionConfig::new()
.with_target_partitions(4)
.with_information_schema(true);
let ctx = SessionContext::new_with_config(session_config);
ctx.register_catalog("default", Self::create_catalog(&config).await?);

let catalog_provider = match catalog {
Some(cat) => {
// Use the provided catalog
Arc::new(IcebergCatalogProvider::try_new(cat).await?)
}
None => {
// Fallback: create default MemoryCatalog
Self::create_default_catalog(&config).await?
}
};

ctx.register_catalog("default", catalog_provider);

Ok(Self {
test_data_path: PathBuf::from("testdata"),
session_context: ctx,
})
}

async fn create_catalog(_: &TomlTable) -> anyhow::Result<Arc<dyn CatalogProvider>> {
// TODO: support dynamic catalog configuration
// See: https://github.com/apache/iceberg-rust/issues/1780
async fn create_default_catalog(
_: &TomlTable,
) -> anyhow::Result<Arc<dyn CatalogProvider>> {
// Create default MemoryCatalog as fallback
let catalog = MemoryCatalogBuilder::default()
.load(
"memory",
Expand Down
11 changes: 7 additions & 4 deletions crates/sqllogictest/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
mod datafusion;

use std::path::Path;
use std::sync::Arc;

use anyhow::anyhow;
use iceberg::Catalog;
use sqllogictest::{AsyncDB, MakeConnection, Runner, parse_file};
use toml::Table as TomlTable;

Expand All @@ -29,16 +31,17 @@ use crate::error::{Error, Result};
const TYPE_DATAFUSION: &str = "datafusion";

#[async_trait::async_trait]
pub trait EngineRunner: Send {
pub trait EngineRunner: Send + std::fmt::Debug {
async fn run_slt_file(&mut self, path: &Path) -> Result<()>;
}

pub async fn load_engine_runner(
engine_type: &str,
cfg: TomlTable,
catalog: Option<Arc<dyn Catalog>>,
) -> Result<Box<dyn EngineRunner>> {
match engine_type {
TYPE_DATAFUSION => Ok(Box::new(DataFusionEngine::new(cfg).await?)),
TYPE_DATAFUSION => Ok(Box::new(DataFusionEngine::new(cfg, catalog).await?)),
_ => Err(anyhow::anyhow!("Unsupported engine type: {engine_type}").into()),
}
}
Expand Down Expand Up @@ -74,7 +77,7 @@ mod tests {
random = { type = "random_engine", url = "http://localhost:8181" }
"#;
let tbl = toml::from_str(input).unwrap();
let result = load_engine_runner("random_engine", tbl).await;
let result = load_engine_runner("random_engine", tbl, None).await;

assert!(result.is_err());
}
Expand All @@ -86,7 +89,7 @@ mod tests {
df = { type = "datafusion" }
"#;
let tbl = toml::from_str(input).unwrap();
let result = load_engine_runner(TYPE_DATAFUSION, tbl).await;
let result = load_engine_runner(TYPE_DATAFUSION, tbl, None).await;

assert!(result.is_ok());
}
Expand Down
6 changes: 6 additions & 0 deletions crates/sqllogictest/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@ impl From<std::io::Error> for Error {
Self(value.into())
}
}

impl From<iceberg::Error> for Error {
fn from(value: iceberg::Error) -> Self {
Self(value.into())
}
}
Loading
Loading