Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sqllogictest requirement from 0.11.1 to 0.12.0 #5237 #5244

Merged
merged 3 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -17,7 +17,9 @@

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

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

use super::super::conversion::*;
use super::error::{DFSqlLogicTestError, Result};
Expand All @@ -26,7 +28,7 @@ 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));
Expand All @@ -36,7 +38,7 @@ pub fn convert_batches(batches: Vec<RecordBatch>) -> Result<DBOutput> {

// 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 {
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DBOutput is now generic to support a custom column type description.

cc @melgenek as I think you were discussing this on a previous PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sqllogictest was updated.

The update in this pr doesn't:

  • validate types by default. By default, any types are successful as long as it can be parsed. Validation can be enabled with runner.with_column_validator(strict_column_validator);
  • --complete doesn't fill in the expected types. I need to create another pr in sqllogictest-rs.

Anyway, I was going to work on #4499 this weekend. If you give me a couple of days, I'll create a pr with type validation.


/// 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>;