You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by xu...@apache.org on 2025/04/17 07:33:10 UTC

(iceberg-rust) branch main updated: Introduce datafusion engine for sqllogictests. (#1215)

This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-rust.git


The following commit(s) were added to refs/heads/main by this push:
     new 31b0c0a6 Introduce datafusion engine for sqllogictests. (#1215)
31b0c0a6 is described below

commit 31b0c0a602b81e01da9d969b62beffc567bfc0cc
Author: Renjie Liu <li...@gmail.com>
AuthorDate: Thu Apr 17 15:33:06 2025 +0800

    Introduce datafusion engine for sqllogictests. (#1215)
    
    ## Which issue does this PR close?
    
    - Closes #1212.
    
    ## What changes are included in this PR?
    
    Introduces datafusion engine for sqllogictests.
    
    ## Are these changes tested?
    
    Not yet, will tests later.
---
 Cargo.lock                                        | 214 +++++++++++++++++++++-
 Cargo.toml                                        |   6 +-
 crates/sqllogictest/Cargo.toml                    |  13 +-
 crates/sqllogictest/src/engine/datafusion.rs      |  67 +++++++
 crates/sqllogictest/src/{lib.rs => engine/mod.rs} |  16 +-
 crates/sqllogictest/src/lib.rs                    |   2 +
 6 files changed, 308 insertions(+), 10 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 8bc9a5a0..b1ab51bd 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1457,7 +1457,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "4a65ebfec4fb190b6f90e944a817d60499ee0744e582530e2c9900a22e591d9a"
 dependencies = [
  "unicode-segmentation",
- "unicode-width",
+ "unicode-width 0.2.0",
 ]
 
 [[package]]
@@ -1469,6 +1469,19 @@ dependencies = [
  "crossbeam-utils",
 ]
 
+[[package]]
+name = "console"
+version = "0.15.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8"
+dependencies = [
+ "encode_unicode",
+ "libc",
+ "once_cell",
+ "unicode-width 0.2.0",
+ "windows-sys 0.59.0",
+]
+
 [[package]]
 name = "const-oid"
 version = "0.9.6"
@@ -2199,6 +2212,34 @@ dependencies = [
  "sqlparser",
 ]
 
+[[package]]
+name = "datafusion-sqllogictest"
+version = "45.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "566054cd0f446e6f83604c5dd9248c040976c57373a37d87e950b41f3f41e102"
+dependencies = [
+ "arrow",
+ "async-trait",
+ "bigdecimal",
+ "clap",
+ "datafusion",
+ "datafusion-catalog",
+ "datafusion-common",
+ "datafusion-common-runtime",
+ "futures",
+ "half",
+ "indicatif",
+ "itertools 0.14.0",
+ "log",
+ "object_store",
+ "rust_decimal",
+ "sqllogictest",
+ "sqlparser",
+ "tempfile",
+ "thiserror 2.0.11",
+ "tokio",
+]
+
 [[package]]
 name = "der"
 version = "0.7.9"
@@ -2339,6 +2380,18 @@ version = "0.15.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
 
+[[package]]
+name = "educe"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1d7bc049e1bd8cdeb31b68bbd586a9464ecf9f3944af3958a7a9d0f8b9799417"
+dependencies = [
+ "enum-ordinalize",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.98",
+]
+
 [[package]]
 name = "either"
 version = "1.15.0"
@@ -2348,12 +2401,38 @@ dependencies = [
  "serde",
 ]
 
+[[package]]
+name = "encode_unicode"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
+
 [[package]]
 name = "endian-type"
 version = "0.1.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d"
 
+[[package]]
+name = "enum-ordinalize"
+version = "4.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fea0dcfa4e54eeb516fe454635a95753ddd39acda650ce703031c6973e315dd5"
+dependencies = [
+ "enum-ordinalize-derive",
+]
+
+[[package]]
+name = "enum-ordinalize-derive"
+version = "4.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.98",
+]
+
 [[package]]
 name = "env_filter"
 version = "0.1.3"
@@ -2399,6 +2478,12 @@ version = "3.3.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "a5d9305ccc6942a704f4335694ecd3de2ea531b114ac2d51f5f843750787a92f"
 
+[[package]]
+name = "escape8259"
+version = "0.5.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5692dd7b5a1978a5aeb0ce83b7655c58ca8efdcb79d21036ea249da95afec2c6"
+
 [[package]]
 name = "etcetera"
 version = "0.8.0"
@@ -2447,6 +2532,12 @@ dependencies = [
  "once_cell",
 ]
 
+[[package]]
+name = "fallible-iterator"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7"
+
 [[package]]
 name = "fastrand"
 version = "2.3.0"
@@ -3349,6 +3440,20 @@ dependencies = [
  "uuid",
 ]
 
+[[package]]
+name = "iceberg-sqllogictest"
+version = "0.4.0"
+dependencies = [
+ "anyhow",
+ "async-trait",
+ "datafusion",
+ "datafusion-sqllogictest",
+ "enum-ordinalize",
+ "indicatif",
+ "sqllogictest",
+ "toml",
+]
+
 [[package]]
 name = "iceberg_test_utils"
 version = "0.4.0"
@@ -3540,6 +3645,19 @@ dependencies = [
  "serde",
 ]
 
+[[package]]
+name = "indicatif"
+version = "0.17.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "183b3088984b400f4cfac3620d5e076c84da5364016b4f49473de574b2586235"
+dependencies = [
+ "console",
+ "number_prefix",
+ "portable-atomic",
+ "unicode-width 0.2.0",
+ "web-time",
+]
+
 [[package]]
 name = "inout"
 version = "0.1.3"
@@ -3809,6 +3927,18 @@ dependencies = [
  "vcpkg",
 ]
 
+[[package]]
+name = "libtest-mimic"
+version = "0.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5297962ef19edda4ce33aaa484386e0a5b3d7f2f4e037cbeee00503ef6b29d33"
+dependencies = [
+ "anstream",
+ "anstyle",
+ "clap",
+ "escape8259",
+]
+
 [[package]]
 name = "linked-hash-map"
 version = "0.5.6"
@@ -4249,6 +4379,12 @@ dependencies = [
  "syn 2.0.98",
 ]
 
+[[package]]
+name = "number_prefix"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
+
 [[package]]
 name = "object"
 version = "0.36.7"
@@ -4377,6 +4513,12 @@ version = "0.1.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
 
+[[package]]
+name = "owo-colors"
+version = "4.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1036865bb9422d3300cf723f657c2851d0e9ab12567854b1f4eba3d77decf564"
+
 [[package]]
 name = "parking"
 version = "2.2.1"
@@ -4732,6 +4874,35 @@ dependencies = [
  "portable-atomic",
 ]
 
+[[package]]
+name = "postgres-protocol"
+version = "0.6.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "76ff0abab4a9b844b93ef7b81f1efc0a366062aaef2cd702c76256b5dc075c54"
+dependencies = [
+ "base64 0.22.1",
+ "byteorder",
+ "bytes",
+ "fallible-iterator",
+ "hmac",
+ "md-5",
+ "memchr",
+ "rand 0.9.0",
+ "sha2",
+ "stringprep",
+]
+
+[[package]]
+name = "postgres-types"
+version = "0.2.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "613283563cd90e1dfc3518d548caee47e0e725455ed619881f5cf21f36de4b48"
+dependencies = [
+ "bytes",
+ "fallible-iterator",
+ "postgres-protocol",
+]
+
 [[package]]
 name = "powerfmt"
 version = "0.2.0"
@@ -5341,6 +5512,7 @@ dependencies = [
  "borsh",
  "bytes",
  "num-traits",
+ "postgres-types",
  "rand 0.8.5",
  "rkyv 0.7.45",
  "serde",
@@ -5518,7 +5690,7 @@ dependencies = [
  "nix",
  "radix_trie",
  "unicode-segmentation",
- "unicode-width",
+ "unicode-width 0.2.0",
  "utf8parse",
  "windows-sys 0.59.0",
 ]
@@ -5956,9 +6128,27 @@ dependencies = [
 
 [[package]]
 name = "sqllogictest"
-version = "0.4.0"
+version = "0.26.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3bc65b5525b4674a844eb6e39a5d4ef2385a3a2b96c13ef82bbe73220f24bcad"
 dependencies = [
- "anyhow",
+ "async-trait",
+ "educe",
+ "fs-err",
+ "futures",
+ "glob",
+ "humantime",
+ "itertools 0.13.0",
+ "libtest-mimic",
+ "md-5",
+ "owo-colors",
+ "rand 0.8.5",
+ "regex",
+ "similar",
+ "subst",
+ "tempfile",
+ "thiserror 2.0.11",
+ "tracing",
 ]
 
 [[package]]
@@ -6230,6 +6420,16 @@ dependencies = [
  "syn 2.0.98",
 ]
 
+[[package]]
+name = "subst"
+version = "0.3.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "33e7942675ea19db01ef8cf15a1e6443007208e6c74568bd64162da26d40160d"
+dependencies = [
+ "memchr",
+ "unicode-width 0.1.14",
+]
+
 [[package]]
 name = "subtle"
 version = "2.6.1"
@@ -6815,6 +7015,12 @@ version = "1.12.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
 
+[[package]]
+name = "unicode-width"
+version = "0.1.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
+
 [[package]]
 name = "unicode-width"
 version = "0.2.0"
diff --git a/Cargo.toml b/Cargo.toml
index 04dbc210..c38706d7 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -61,9 +61,11 @@ clap = { version = "4.5.27", features = ["derive", "cargo"] }
 ctor = "0.2.8"
 datafusion = "45"
 datafusion-cli = "45"
+datafusion-sqllogictest = "45"
 derive_builder = "0.20"
 dirs = "6"
 expect-test = "1"
+enum-ordinalize = "4.3.0"
 faststr = "0.2.31"
 fnv = "1.0.7"
 fs-err = "3.1.0"
@@ -74,6 +76,7 @@ iceberg = { version = "0.4.0", path = "./crates/iceberg" }
 iceberg-catalog-memory = { version = "0.4.0", path = "./crates/catalog/memory" }
 iceberg-catalog-rest = { version = "0.4.0", path = "./crates/catalog/rest" }
 iceberg-datafusion = { version = "0.4.0", path = "./crates/integrations/datafusion" }
+indicatif = "0.17"
 itertools = "0.13"
 linkedbytes = "0.1.8"
 metainfo = "0.7.14"
@@ -92,13 +95,14 @@ rand = "0.8.5"
 regex = "1.10.5"
 reqwest = { version = "0.12.12", default-features = false, features = ["json"] }
 roaring = { version = "0.10", git = "https://github.com/RoaringBitmap/roaring-rs.git" }
-rust_decimal = "1.31"
+rust_decimal = "1.36"
 serde = { version = "1.0.204", features = ["rc"] }
 serde_bytes = "0.11.15"
 serde_derive = "1.0.204"
 serde_json = "1.0.138"
 serde_repr = "0.1.16"
 serde_with = "3.4"
+sqllogictest = "0.26.4"
 stacker = "0.1.20"
 tempfile = "3.18"
 tera = "1"
diff --git a/crates/sqllogictest/Cargo.toml b/crates/sqllogictest/Cargo.toml
index 8be18bd9..d11a1a87 100644
--- a/crates/sqllogictest/Cargo.toml
+++ b/crates/sqllogictest/Cargo.toml
@@ -19,10 +19,21 @@
 edition = { workspace = true }
 homepage = { workspace = true }
 license = { workspace = true }
-name = "sqllogictest"
+name = "iceberg-sqllogictest"
 repository = { workspace = true }
 rust-version = { workspace = true }
 version = { workspace = true }
 
 [dependencies]
 anyhow = { workspace = true }
+async-trait = {workspace = true}
+toml = {workspace = true}
+datafusion = {workspace = true}
+datafusion-sqllogictest = {workspace = true}
+enum-ordinalize = {workspace = true}
+sqllogictest = {workspace = true}
+indicatif = {workspace = true}
+
+[package.metadata.cargo-machete]
+# These dependencies are added to ensure minimal dependency version
+ignored = ["enum-ordinalize"]
diff --git a/crates/sqllogictest/src/engine/datafusion.rs b/crates/sqllogictest/src/engine/datafusion.rs
new file mode 100644
index 00000000..bddc59d9
--- /dev/null
+++ b/crates/sqllogictest/src/engine/datafusion.rs
@@ -0,0 +1,67 @@
+// 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.
+
+use std::path::{Path, PathBuf};
+use std::sync::Arc;
+
+use anyhow::{anyhow, Context};
+use datafusion::catalog::CatalogProvider;
+use datafusion::prelude::{SessionConfig, SessionContext};
+use datafusion_sqllogictest::DataFusion;
+use indicatif::ProgressBar;
+use sqllogictest::runner::AsyncDB;
+use toml::Table as TomlTable;
+
+use crate::engine::Engine;
+use crate::error::Result;
+
+pub struct DataFusionEngine {
+    datafusion: DataFusion,
+}
+
+#[async_trait::async_trait]
+impl Engine for DataFusionEngine {
+    async fn new(config: TomlTable) -> Result<Self> {
+        let session_config = SessionConfig::new().with_target_partitions(4);
+        let ctx = SessionContext::new_with_config(session_config);
+        ctx.register_catalog("default", Self::create_catalog(&config).await?);
+
+        Ok(Self {
+            datafusion: DataFusion::new(ctx, PathBuf::from("testdata"), ProgressBar::new(100)),
+        })
+    }
+
+    async fn run_slt_file(&mut self, path: &Path) -> Result<()> {
+        let content = std::fs::read_to_string(path)
+            .with_context(|| format!("Failed to read slt file {:?}", path))
+            .map_err(|e| anyhow!(e))?;
+
+        self.datafusion
+            .run(content.as_str())
+            .await
+            .with_context(|| format!("Failed to run slt file {:?}", path))
+            .map_err(|e| anyhow!(e))?;
+
+        Ok(())
+    }
+}
+
+impl DataFusionEngine {
+    async fn create_catalog(_: &TomlTable) -> anyhow::Result<Arc<dyn CatalogProvider>> {
+        todo!()
+    }
+}
diff --git a/crates/sqllogictest/src/lib.rs b/crates/sqllogictest/src/engine/mod.rs
similarity index 74%
copy from crates/sqllogictest/src/lib.rs
copy to crates/sqllogictest/src/engine/mod.rs
index 196d16c6..61722f66 100644
--- a/crates/sqllogictest/src/lib.rs
+++ b/crates/sqllogictest/src/engine/mod.rs
@@ -15,8 +15,16 @@
 // specific language governing permissions and limitations
 // under the License.
 
-// This lib contains codes copied from
-// [Apache Datafusion](https://github.com/apache/datafusion/tree/main/datafusion/sqllogictest)
+mod datafusion;
 
-#[allow(dead_code)]
-mod error;
+use std::path::Path;
+
+use toml::Table as TomlTable;
+
+use crate::error::Result;
+
+#[async_trait::async_trait]
+pub trait Engine: Sized {
+    async fn new(config: TomlTable) -> Result<Self>;
+    async fn run_slt_file(&mut self, path: &Path) -> Result<()>;
+}
diff --git a/crates/sqllogictest/src/lib.rs b/crates/sqllogictest/src/lib.rs
index 196d16c6..c72d50c4 100644
--- a/crates/sqllogictest/src/lib.rs
+++ b/crates/sqllogictest/src/lib.rs
@@ -18,5 +18,7 @@
 // This lib contains codes copied from
 // [Apache Datafusion](https://github.com/apache/datafusion/tree/main/datafusion/sqllogictest)
 
+#[allow(dead_code)]
+mod engine;
 #[allow(dead_code)]
 mod error;