Skip to content

Commit

Permalink
fix: use Vec<Vec<String>> for external engine (#138)
Browse files Browse the repository at this point in the history
* Revert "trim string before rowsort (#137)"

This reverts commit 693583b.

Signed-off-by: xxchan <xxchan22f@gmail.com>

* fix: use Vec<Vec<String>> for external engine

Signed-off-by: xxchan <xxchan22f@gmail.com>

* fix doctest

Signed-off-by: xxchan <xxchan22f@gmail.com>

Signed-off-by: xxchan <xxchan22f@gmail.com>
  • Loading branch information
xxchan committed Dec 30, 2022
1 parent 693583b commit 6b2f981
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
29 changes: 24 additions & 5 deletions sqllogictest-bin/src/engines/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,32 @@ use async_trait::async_trait;
use bytes::{Buf, BytesMut};
use futures::StreamExt;
use serde::{Deserialize, Serialize};
use sqllogictest::{AsyncDB, ColumnType, DBOutput};
use sqllogictest::{AsyncDB, DBOutput};
use thiserror::Error;
use tokio::io::AsyncWriteExt;
use tokio::process::{Child, ChildStdin, ChildStdout, Command};
use tokio_util::codec::{Decoder, FramedRead};

/// Communicates with a subprocess via its stdin/stdout.
///
/// # Protocol
///
/// Sends JSON stream:
/// ```json
/// {"sql":"SELECT 1,2"}
/// ```
///
/// Receives JSON stream:
///
/// If the query succeeds:
/// ```json
/// {"result":[["1","2"]]}
/// ```
///
/// If the query fails:
/// ```json
/// {"err":"..."}
/// ```
pub struct ExternalDriver {
child: Child,
stdin: ChildStdin,
Expand All @@ -27,7 +47,7 @@ struct Input {
#[derive(Deserialize)]
#[serde(untagged)]
enum Output {
Success { result: String },
Success { result: Vec<Vec<String>> },
Failed { err: String },
}

Expand Down Expand Up @@ -83,10 +103,9 @@ impl AsyncDB for ExternalDriver {
None => return Err(io::Error::from(io::ErrorKind::UnexpectedEof).into()),
};
match output {
// FIXME: split result into columns and rows?
Output::Success { result } => Ok(DBOutput::Rows {
types: vec![ColumnType::Any],
rows: vec![vec![result]],
types: vec![], // FIXME: Fix it after https://github.com/risinglightdb/sqllogictest-rs/issues/36 is resolved.
rows: result,
}),
Output::Failed { err } => Err(ExternalDriverError::Sql(err)),
}
Expand Down
9 changes: 0 additions & 9 deletions sqllogictest/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,6 @@ impl<D: AsyncDB> Runner<D> {
}
};

// trim strings
for row in &mut rows {
for value in row {
if value.trim() != value {
*value = value.trim().to_string();
}
}
}

match sort_mode.as_ref().or(self.sort_mode.as_ref()) {
None | Some(SortMode::NoSort) => {}
Some(SortMode::RowSort) => {
Expand Down

0 comments on commit 6b2f981

Please sign in to comment.