lliangyu-lin commented on code in PR #1764:
URL: https://github.com/apache/iceberg-rust/pull/1764#discussion_r2454124834
##########
crates/sqllogictest/src/engine/mod.rs:
##########
@@ -19,70 +19,94 @@ mod datafusion;
use std::path::Path;
+use anyhow::anyhow;
+use sqllogictest::{AsyncDB, MakeConnection, Runner, parse_file};
use toml::Table as TomlTable;
use crate::engine::datafusion::DataFusionEngine;
-use crate::error::Result;
+use crate::error::{Error, Result};
-const KEY_TYPE: &str = "type";
const TYPE_DATAFUSION: &str = "datafusion";
+const ERRS_PER_FILE_LIMIT: usize = 10;
#[async_trait::async_trait]
-pub trait EngineRunner: Sized {
+pub trait EngineRunner: Send {
async fn run_slt_file(&mut self, path: &Path) -> Result<()>;
}
-pub enum Engine {
- DataFusion(DataFusionEngine),
+pub async fn load_engine_runner(
+ engine_type: &str,
+ cfg: TomlTable,
+) -> Result<Box<dyn EngineRunner>> {
+ match engine_type {
+ TYPE_DATAFUSION => Ok(Box::new(DataFusionEngine::new(cfg).await?)),
+ _ => Err(anyhow::anyhow!("Unsupported engine type: {}",
engine_type).into()),
+ }
}
-impl Engine {
- pub async fn new(config: TomlTable) -> Result<Self> {
- let engine_type = config
- .get(KEY_TYPE)
- .ok_or_else(|| anyhow::anyhow!("Missing required key:
{KEY_TYPE}"))?
- .as_str()
- .ok_or_else(|| anyhow::anyhow!("Config value for {KEY_TYPE} must
be a string"))?;
-
- match engine_type {
- TYPE_DATAFUSION => {
- let engine = DataFusionEngine::new(config).await?;
- Ok(Engine::DataFusion(engine))
- }
- _ => Err(anyhow::anyhow!("Unsupported engine type:
{engine_type}").into()),
+pub async fn run_slt_with_runner<D, M>(
+ mut runner: Runner<D, M>,
+ step_slt_file: impl AsRef<Path>,
+) -> Result<()>
+where
+ D: AsyncDB + Send + 'static,
+ M: MakeConnection<Conn = D> + Send + 'static,
+{
+ let path = step_slt_file.as_ref().canonicalize()?;
+
+ let records = parse_file(&path).map_err(|e| Error(anyhow!("parsing SLT
file failed: {e}")))?;
+
+ let mut errs = vec![];
+ for record in records {
+ if let Err(err) = runner.run_async(record).await {
Review Comment:
I think the runner error already includes the line number. I did a quick
check. This is the error message.
```
---- schedule: df_test.toml ----
SLT record execution failed: query failed: DataFusion error: Error during
planning: table 'datafusion.public.test_tb' not found
[SQL] SELECT * FROM test_tb;
at
/local/home/lliangyu/repository/iceberg-rust/crates/sqllogictest/testdata/slts/df_test/show_tables.slt:18
```
--
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]