-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat: add sqllogictests crate #7134
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9381705
feat: add sqllogictests crate
tshauck 4f1507d
feat: cleanup the PR from feedback
tshauck 651653f
fix: fix tests due to name issue
tshauck 9b56992
refactor: cleanup
tshauck fe1ec42
refactor: chopped off license
tshauck 0b9c484
docs: license and module docstrings
tshauck b088240
docs: module docstrings
tshauck c462466
docs: update docs for cargo checks
tshauck f86ffff
Fix doc error
alamb a3649da
Merge remote-tracking branch 'apache/main' into add-sql-logic-tests
alamb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# 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. | ||
|
||
[package] | ||
authors.workspace = true | ||
edition.workspace = true | ||
homepage.workspace = true | ||
license.workspace = true | ||
name = "datafusion-sqllogictest" | ||
readme.workspace = true | ||
repository.workspace = true | ||
rust-version.workspace = true | ||
version.workspace = true | ||
|
||
[lib] | ||
name = "datafusion_sqllogictest" | ||
path = "src/lib.rs" | ||
|
||
[dependencies] | ||
arrow = {workspace = true} | ||
async-trait = "0.1.41" | ||
bigdecimal = "0.4.1" | ||
datafusion = {path = "../core", version = "28.0.0"} | ||
datafusion-common = {path = "../common", version = "28.0.0"} | ||
half = "2.2.1" | ||
itertools = "0.11" | ||
lazy_static = {version = "^1.4.0"} | ||
object_store = "0.6.1" | ||
rust_decimal = {version = "1.27.0"} | ||
sqllogictest = "0.15.0" | ||
sqlparser.workspace = true | ||
thiserror = "1.0.44" | ||
tokio = {version = "1.0"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// 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 arrow::datatypes::{Decimal128Type, DecimalType}; | ||
use bigdecimal::BigDecimal; | ||
use half::f16; | ||
use rust_decimal::prelude::*; | ||
|
||
/// Represents a constant for NULL string in your database. | ||
pub const NULL_STR: &str = "NULL"; | ||
|
||
/// Converts a bool value into a string. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `value` - The bool value to convert. | ||
pub fn bool_to_str(value: bool) -> String { | ||
if value { | ||
"true".to_string() | ||
} else { | ||
"false".to_string() | ||
} | ||
} | ||
|
||
/// Converts a varchar into a string, trimming end line breaks. | ||
/// Returns "(empty)" string for empty input. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `value` - The varchar value to convert. | ||
pub fn varchar_to_str(value: &str) -> String { | ||
if value.is_empty() { | ||
"(empty)".to_string() | ||
} else { | ||
value.trim_end_matches('\n').to_string() | ||
} | ||
} | ||
|
||
/// Converts a 16-bit floating-point number into a string. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `value` - The 16-bit floating-point number to convert. | ||
pub fn f16_to_str(value: f16) -> String { | ||
if value.is_nan() { | ||
"NaN".to_string() | ||
} else if value == f16::INFINITY { | ||
"Infinity".to_string() | ||
} else if value == f16::NEG_INFINITY { | ||
"-Infinity".to_string() | ||
} else { | ||
big_decimal_to_str(BigDecimal::from_str(&value.to_string()).unwrap()) | ||
} | ||
} | ||
|
||
/// Converts a 32-bit floating-point number into a string. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `value` - The 32-bit floating-point number to convert. | ||
pub fn f32_to_str(value: f32) -> String { | ||
if value.is_nan() { | ||
"NaN".to_string() | ||
} else if value == f32::INFINITY { | ||
"Infinity".to_string() | ||
} else if value == f32::NEG_INFINITY { | ||
"-Infinity".to_string() | ||
} else { | ||
big_decimal_to_str(BigDecimal::from_str(&value.to_string()).unwrap()) | ||
} | ||
} | ||
|
||
/// Converts a 64-bit floating-point number into a string. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `value` - The 64-bit floating-point number to convert. | ||
pub fn f64_to_str(value: f64) -> String { | ||
if value.is_nan() { | ||
"NaN".to_string() | ||
} else if value == f64::INFINITY { | ||
"Infinity".to_string() | ||
} else if value == f64::NEG_INFINITY { | ||
"-Infinity".to_string() | ||
} else { | ||
big_decimal_to_str(BigDecimal::from_str(&value.to_string()).unwrap()) | ||
} | ||
} | ||
|
||
/// Converts a 128-bit integer into a string using specified precision and scale. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `value` - The 128-bit integer to convert. | ||
/// * `precision` - The number of significant digits. | ||
/// * `scale` - The number of digits to the right of the decimal point. | ||
pub fn i128_to_str(value: i128, precision: &u8, scale: &i8) -> String { | ||
big_decimal_to_str( | ||
BigDecimal::from_str(&Decimal128Type::format_decimal(value, *precision, *scale)) | ||
.unwrap(), | ||
) | ||
} | ||
|
||
/// Converts a BigDecimal into a string, rounding the result to 12 decimal places. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `value` - The BigDecimal value to convert. | ||
pub fn big_decimal_to_str(value: BigDecimal) -> String { | ||
value.round(12).normalized().to_string() | ||
} |
50 changes: 50 additions & 0 deletions
50
datafusion/sqllogictest/src/engines/datafusion_engine/error.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// 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 arrow::error::ArrowError; | ||
use datafusion_common::DataFusionError; | ||
use sqllogictest::TestError; | ||
use sqlparser::parser::ParserError; | ||
use thiserror::Error; | ||
|
||
pub type Result<T, E = DFSqlLogicTestError> = std::result::Result<T, E>; | ||
|
||
/// DataFusion sql-logicaltest error | ||
#[derive(Debug, Error)] | ||
pub enum DFSqlLogicTestError { | ||
/// Error from sqllogictest-rs | ||
#[error("SqlLogicTest error(from sqllogictest-rs crate): {0}")] | ||
SqlLogicTest(#[from] TestError), | ||
/// Error from datafusion | ||
#[error("DataFusion error: {0}")] | ||
DataFusion(#[from] DataFusionError), | ||
/// Error returned when SQL is syntactically incorrect. | ||
#[error("SQL Parser error: {0}")] | ||
Sql(#[from] ParserError), | ||
/// Error from arrow-rs | ||
#[error("Arrow error: {0}")] | ||
Arrow(#[from] ArrowError), | ||
/// Generic error | ||
#[error("Other Error: {0}")] | ||
Other(String), | ||
} | ||
|
||
impl From<String> for DFSqlLogicTestError { | ||
fn from(value: String) -> Self { | ||
DFSqlLogicTestError::Other(value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mod error; | ||
mod normalize; | ||
mod runner; | ||
|
||
pub use error::*; | ||
pub use normalize::*; | ||
pub use runner::*; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this file needs the apache license header (just copy/paste from another crate)
Also if you could add some high level crate comment like
or something I think that would help future readers