From 6b2f9810dfcee39c64be961269ae41b11fbc706a Mon Sep 17 00:00:00 2001 From: xxchan Date: Fri, 30 Dec 2022 17:07:41 +0100 Subject: [PATCH] fix: use Vec> for external engine (#138) * Revert "trim string before rowsort (#137)" This reverts commit 693583b18682c85a2338f5be2df83218f397c470. Signed-off-by: xxchan * fix: use Vec> for external engine Signed-off-by: xxchan * fix doctest Signed-off-by: xxchan Signed-off-by: xxchan --- sqllogictest-bin/src/engines/external.rs | 29 ++++++++++++++++++++---- sqllogictest/src/runner.rs | 9 -------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/sqllogictest-bin/src/engines/external.rs b/sqllogictest-bin/src/engines/external.rs index 59d3f17..bb9c6b6 100644 --- a/sqllogictest-bin/src/engines/external.rs +++ b/sqllogictest-bin/src/engines/external.rs @@ -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, @@ -27,7 +47,7 @@ struct Input { #[derive(Deserialize)] #[serde(untagged)] enum Output { - Success { result: String }, + Success { result: Vec> }, Failed { err: String }, } @@ -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)), } diff --git a/sqllogictest/src/runner.rs b/sqllogictest/src/runner.rs index b9e7050..b5349ae 100644 --- a/sqllogictest/src/runner.rs +++ b/sqllogictest/src/runner.rs @@ -512,15 +512,6 @@ impl Runner { } }; - // 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) => {