Skip to content

Commit

Permalink
Update sqllogictest requirement from 0.11.1 to 0.12.0 apache#5237 (ap…
Browse files Browse the repository at this point in the history
…ache#5244)

* Update sqllogictest requirement from 0.11.1 to 0.12.0

Updates the requirements on [sqllogictest](https://github.com/risinglightdb/sqllogictest-rs) to permit the latest version.
- [Release notes](https://github.com/risinglightdb/sqllogictest-rs/releases)
- [Changelog](https://github.com/risinglightdb/sqllogictest-rs/blob/main/CHANGELOG.md)
- [Commits](risinglightdb/sqllogictest-rs@v0.11.1...v0.12.0)

---
updated-dependencies:
- dependency-name: sqllogictest
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* fmt

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and comphead committed Feb 11, 2023
1 parent 5cee71b commit 2bd050c
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 19 deletions.
2 changes: 1 addition & 1 deletion datafusion/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ postgres-protocol = "0.6.4"
postgres-types = { version = "0.2.4", features = ["derive", "with-chrono-0_4"] }
rstest = "0.16.0"
rust_decimal = { version = "1.27.0", features = ["tokio-pg"] }
sqllogictest = "0.11.1"
sqllogictest = "0.12.0"
test-utils = { path = "../../test-utils" }
thiserror = "1.0.37"
tokio-postgres = "0.7.7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
// under the License.

use super::error::Result;
use crate::engines::datafusion::error::DFSqlLogicTestError;
use crate::engines::datafusion::util::LogicTestContextProvider;
use crate::{engines::datafusion::error::DFSqlLogicTestError, output::DFOutput};
use datafusion::datasource::MemTable;
use datafusion::prelude::SessionContext;
use datafusion_common::{DataFusionError, OwnedTableReference};
Expand All @@ -32,7 +32,7 @@ pub async fn create_table(
columns: Vec<ColumnDef>,
if_not_exists: bool,
or_replace: bool,
) -> Result<DBOutput> {
) -> Result<DFOutput> {
let table_reference =
object_name_to_table_reference(name, ctx.enable_ident_normalization())?;
let existing_table = ctx.table(&table_reference).await;
Expand Down Expand Up @@ -60,7 +60,7 @@ fn create_new_table(
ctx: &SessionContext,
table_reference: OwnedTableReference,
columns: Vec<ColumnDef>,
) -> Result<DBOutput> {
) -> Result<DFOutput> {
let config = ctx.copied_config();
let sql_to_rel = SqlToRel::new_with_options(
&LogicTestContextProvider {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// under the License.

use super::error::Result;
use crate::engines::datafusion::util::LogicTestContextProvider;
use crate::{engines::datafusion::util::LogicTestContextProvider, output::DFOutput};
use arrow::record_batch::RecordBatch;
use datafusion::datasource::MemTable;
use datafusion::prelude::SessionContext;
Expand All @@ -27,7 +27,7 @@ use sqllogictest::DBOutput;
use sqlparser::ast::{Expr, SetExpr, Statement as SQLStatement};
use std::sync::Arc;

pub async fn insert(ctx: &SessionContext, insert_stmt: SQLStatement) -> Result<DBOutput> {
pub async fn insert(ctx: &SessionContext, insert_stmt: SQLStatement) -> Result<DFOutput> {
// First, use sqlparser to get table name and insert values
let table_reference;
let insert_values: Vec<Vec<Expr>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use std::path::PathBuf;
use std::time::Duration;

use sqllogictest::DBOutput;
use crate::output::{DFColumnType, DFOutput};

use self::error::{DFSqlLogicTestError, Result};
use async_trait::async_trait;
Expand Down Expand Up @@ -49,8 +49,9 @@ impl DataFusion {
#[async_trait]
impl sqllogictest::AsyncDB for DataFusion {
type Error = DFSqlLogicTestError;
type ColumnType = DFColumnType;

async fn run(&mut self, sql: &str) -> Result<DBOutput> {
async fn run(&mut self, sql: &str) -> Result<DFOutput> {
println!(
"[{}] Running query: \"{}\"",
self.relative_path.display(),
Expand All @@ -75,7 +76,7 @@ impl sqllogictest::AsyncDB for DataFusion {
}
}

async fn run_query(ctx: &SessionContext, sql: impl Into<String>) -> Result<DBOutput> {
async fn run_query(ctx: &SessionContext, sql: impl Into<String>) -> Result<DFOutput> {
let sql = sql.into();
// Check if the sql is `insert`
if let Ok(mut statements) = DFParser::parse_sql(&sql) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
// under the License.

use arrow::{array, array::ArrayRef, datatypes::DataType, record_batch::RecordBatch};
use sqllogictest::{ColumnType, DBOutput};
use datafusion::error::DataFusionError;
use sqllogictest::DBOutput;

use crate::output::{DFColumnType, DFOutput};

use super::super::conversion::*;
use super::error::{DFSqlLogicTestError, Result};
Expand All @@ -25,19 +28,30 @@ use super::error::{DFSqlLogicTestError, Result};
///
/// Assumes empty record batches are a successful statement completion
///
pub fn convert_batches(batches: Vec<RecordBatch>) -> Result<DBOutput> {
pub fn convert_batches(batches: Vec<RecordBatch>) -> Result<DFOutput> {
if batches.is_empty() {
// DataFusion doesn't report number of rows complete
return Ok(DBOutput::StatementComplete(0));
}

let schema = batches[0].schema();

// TODO: report the the actual types of the result
// https://github.com/apache/arrow-datafusion/issues/4499
let types = vec![ColumnType::Any; batches[0].num_columns()];
let types = vec![DFColumnType::Any; batches[0].num_columns()];

let mut rows = vec![];
for batch in batches {
// Verify schema
if schema != batch.schema() {
return Err(DFSqlLogicTestError::DataFusion(DataFusionError::Internal(
format!(
"Schema mismatch. Previously had\n{:#?}\n\nGot:\n{:#?}",
schema,
batch.schema()
),
)));
}
rows.append(&mut convert_batch(batch)?);
}

Expand Down
13 changes: 8 additions & 5 deletions datafusion/core/tests/sqllogictests/src/engines/postgres/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ use async_trait::async_trait;
use bytes::Bytes;
use futures::{SinkExt, StreamExt};
use log::debug;
use sqllogictest::{ColumnType, DBOutput};
use sqllogictest::DBOutput;
use tokio::task::JoinHandle;

use crate::output::{DFColumnType, DFOutput};

use super::conversion::*;
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
use postgres_types::Type;
Expand Down Expand Up @@ -131,7 +133,7 @@ impl Postgres {
/// ```
///
/// And read the file locally.
async fn run_copy_command(&mut self, sql: &str) -> Result<DBOutput> {
async fn run_copy_command(&mut self, sql: &str) -> Result<DFOutput> {
let canonical_sql = sql.trim_start().to_ascii_lowercase();

debug!("Handling COPY command: {sql}");
Expand Down Expand Up @@ -256,8 +258,9 @@ fn cell_to_string(row: &Row, column: &Column, idx: usize) -> String {
#[async_trait]
impl sqllogictest::AsyncDB for Postgres {
type Error = Error;
type ColumnType = DFColumnType;

async fn run(&mut self, sql: &str) -> Result<DBOutput, Self::Error> {
async fn run(&mut self, sql: &str) -> Result<DFOutput, Self::Error> {
println!(
"[{}] Running query: \"{}\"",
self.relative_path.display(),
Expand Down Expand Up @@ -301,12 +304,12 @@ impl sqllogictest::AsyncDB for Postgres {
if output.is_empty() {
let stmt = self.client.prepare(sql).await?;
Ok(DBOutput::Rows {
types: vec![ColumnType::Any; stmt.columns().len()],
types: vec![DFColumnType::Any; stmt.columns().len()],
rows: vec![],
})
} else {
Ok(DBOutput::Rows {
types: vec![ColumnType::Any; output[0].len()],
types: vec![DFColumnType::Any; output[0].len()],
rows: output,
})
}
Expand Down
6 changes: 4 additions & 2 deletions datafusion/core/tests/sqllogictests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::engines::datafusion::DataFusion;
use crate::engines::postgres::Postgres;

mod engines;
mod output;
mod setup;
mod utils;

Expand Down Expand Up @@ -90,15 +91,16 @@ async fn run_complete_file(
path: &Path,
relative_path: PathBuf,
) -> Result<(), Box<dyn Error>> {
use sqllogictest::{default_validator, update_test_file};
use sqllogictest::default_validator;

info!("Using complete mode to complete: {}", path.display());

let ctx = context_for_test_file(&relative_path).await;
let mut runner = sqllogictest::Runner::new(DataFusion::new(ctx, relative_path));
let col_separator = " ";
let validator = default_validator;
update_test_file(path, &mut runner, col_separator, validator)
runner
.update_test_file(path, col_separator, validator)
.await
.map_err(|e| e.to_string())?;

Expand Down
26 changes: 26 additions & 0 deletions datafusion/core/tests/sqllogictests/src/output.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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 sqllogictest::{DBOutput, DefaultColumnType};

pub type DFColumnType = DefaultColumnType;

/// The output type fed to the sqllogictest Runner
///
/// See <https://github.com/apache/arrow-datafusion/issues/4499> for
/// potentially more full featured support.
pub type DFOutput = DBOutput<DFColumnType>;

0 comments on commit 2bd050c

Please sign in to comment.