lliangyu-lin commented on code in PR #1764:
URL: https://github.com/apache/iceberg-rust/pull/1764#discussion_r2443988868
##########
crates/sqllogictest/src/engine/datafusion.rs:
##########
@@ -15,53 +15,76 @@
// specific language governing permissions and limitations
// under the License.
+use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::Arc;
-use anyhow::{Context, anyhow};
use datafusion::catalog::CatalogProvider;
use datafusion::prelude::{SessionConfig, SessionContext};
use datafusion_sqllogictest::DataFusion;
+use iceberg::CatalogBuilder;
+use iceberg::memory::{MEMORY_CATALOG_WAREHOUSE, MemoryCatalogBuilder};
+use iceberg_datafusion::IcebergCatalogProvider;
use indicatif::ProgressBar;
-use sqllogictest::runner::AsyncDB;
+use tempfile::TempDir;
use toml::Table as TomlTable;
-use crate::engine::EngineRunner;
+use crate::engine::{EngineRunner, run_slt_with_runner};
use crate::error::Result;
pub struct DataFusionEngine {
- datafusion: DataFusion,
+ test_data_path: PathBuf,
+ session_context: SessionContext,
}
#[async_trait::async_trait]
impl EngineRunner for DataFusionEngine {
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))?;
+ let ctx = self.session_context.clone();
+ let testdata = self.test_data_path.clone();
- self.datafusion
- .run(content.as_str())
- .await
- .with_context(|| format!("Failed to run slt file {:?}", path))
- .map_err(|e| anyhow!(e))?;
+ let runner = sqllogictest::Runner::new({
+ move || {
+ let ctx = ctx.clone();
+ let testdata = testdata.clone();
+ async move {
+ // Everything here is owned; no `self` capture.
+ Ok(DataFusion::new(ctx, testdata, ProgressBar::new(100)))
+ }
+ }
+ });
- Ok(())
+ run_slt_with_runner(runner, path).await
}
}
impl DataFusionEngine {
pub async fn new(config: TomlTable) -> Result<Self> {
- let session_config = SessionConfig::new().with_target_partitions(4);
+ 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?);
Ok(Self {
- datafusion: DataFusion::new(ctx, PathBuf::from("testdata"),
ProgressBar::new(100)),
+ test_data_path: PathBuf::from("testdata"),
+ session_context: ctx,
})
}
async fn create_catalog(_: &TomlTable) -> anyhow::Result<Arc<dyn
CatalogProvider>> {
- todo!()
+ let temp_dir = TempDir::new()?;
Review Comment:
Planning to make catalog configurable based on schedule file in separate PR
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]