mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 15:04:04 +00:00
Remove most instances of #[cfg(feature(bigdecimal))]
in tests (#910)
This commit is contained in:
parent
a50671d95d
commit
4efe55dd8a
8 changed files with 28 additions and 90 deletions
|
@ -32,6 +32,9 @@ pub enum Value {
|
|||
#[cfg(not(feature = "bigdecimal"))]
|
||||
Number(String, bool),
|
||||
#[cfg(feature = "bigdecimal")]
|
||||
// HINT: use `test_utils::number` to make an instance of
|
||||
// Value::Number This might help if you your tests pass locally
|
||||
// but fail on CI with the `--all-features` flag enabled
|
||||
Number(BigDecimal, bool),
|
||||
/// 'string value'
|
||||
SingleQuotedString(String),
|
||||
|
|
|
@ -198,7 +198,7 @@ pub fn expr_from_projection(item: &SelectItem) -> &Expr {
|
|||
}
|
||||
|
||||
/// Creates a `Value::Number`, panic'ing if n is not a number
|
||||
pub fn number(n: &'static str) -> Value {
|
||||
pub fn number(n: &str) -> Value {
|
||||
Value::Number(n.parse().unwrap(), false)
|
||||
}
|
||||
|
||||
|
|
|
@ -17,11 +17,6 @@ use sqlparser::ast::*;
|
|||
use sqlparser::dialect::{BigQueryDialect, GenericDialect};
|
||||
use test_utils::*;
|
||||
|
||||
#[cfg(feature = "bigdecimal")]
|
||||
use bigdecimal::*;
|
||||
#[cfg(feature = "bigdecimal")]
|
||||
use std::str::FromStr;
|
||||
|
||||
#[test]
|
||||
fn parse_literal_string() {
|
||||
let sql = r#"SELECT 'single', "double""#;
|
||||
|
@ -377,22 +372,13 @@ fn test_select_wildcard_with_replace() {
|
|||
expr: Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier(Ident::new("quantity"))),
|
||||
op: BinaryOperator::Divide,
|
||||
#[cfg(not(feature = "bigdecimal"))]
|
||||
right: Box::new(Expr::Value(Value::Number("2".to_string(), false))),
|
||||
#[cfg(feature = "bigdecimal")]
|
||||
right: Box::new(Expr::Value(Value::Number(
|
||||
BigDecimal::from_str("2").unwrap(),
|
||||
false,
|
||||
))),
|
||||
right: Box::new(Expr::Value(number("2"))),
|
||||
},
|
||||
column_name: Ident::new("quantity"),
|
||||
as_keyword: true,
|
||||
}),
|
||||
Box::new(ReplaceSelectElement {
|
||||
#[cfg(not(feature = "bigdecimal"))]
|
||||
expr: Expr::Value(Value::Number("3".to_string(), false)),
|
||||
#[cfg(feature = "bigdecimal")]
|
||||
expr: Expr::Value(Value::Number(BigDecimal::from_str("3").unwrap(), false)),
|
||||
expr: Expr::Value(number("3")),
|
||||
column_name: Ident::new("order_id"),
|
||||
as_keyword: true,
|
||||
}),
|
||||
|
@ -421,7 +407,6 @@ fn bigquery_and_generic() -> TestedDialects {
|
|||
fn parse_map_access_offset() {
|
||||
let sql = "SELECT d[offset(0)]";
|
||||
let _select = bigquery().verified_only_select(sql);
|
||||
#[cfg(not(feature = "bigdecimal"))]
|
||||
assert_eq!(
|
||||
_select.projection[0],
|
||||
SelectItem::UnnamedExpr(Expr::MapAccess {
|
||||
|
@ -432,7 +417,7 @@ fn parse_map_access_offset() {
|
|||
keys: vec![Expr::Function(Function {
|
||||
name: ObjectName(vec!["offset".into()]),
|
||||
args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value(
|
||||
Value::Number("0".into(), false)
|
||||
number("0")
|
||||
))),],
|
||||
over: None,
|
||||
distinct: false,
|
||||
|
|
|
@ -1731,7 +1731,6 @@ fn parse_select_having() {
|
|||
assert!(select.having.is_some());
|
||||
}
|
||||
|
||||
#[cfg(feature = "bigdecimal")]
|
||||
#[test]
|
||||
fn parse_select_qualify() {
|
||||
let sql = "SELECT i, p, o FROM qt QUALIFY ROW_NUMBER() OVER (PARTITION BY p ORDER BY o) = 1";
|
||||
|
|
|
@ -97,13 +97,7 @@ fn test_create_macro_default_args() {
|
|||
MacroArg::new("a"),
|
||||
MacroArg {
|
||||
name: Ident::new("b"),
|
||||
default_expr: Some(Expr::Value(Value::Number(
|
||||
#[cfg(not(feature = "bigdecimal"))]
|
||||
5.to_string(),
|
||||
#[cfg(feature = "bigdecimal")]
|
||||
bigdecimal::BigDecimal::from(5),
|
||||
false,
|
||||
))),
|
||||
default_expr: Some(Expr::Value(number("5"))),
|
||||
},
|
||||
]),
|
||||
definition: MacroDefinition::Expr(Expr::BinaryOp {
|
||||
|
|
|
@ -59,12 +59,6 @@ fn parse_mssql_delimited_identifiers() {
|
|||
fn parse_create_procedure() {
|
||||
let sql = "CREATE OR ALTER PROCEDURE test (@foo INT, @bar VARCHAR(256)) AS BEGIN SELECT 1 END";
|
||||
|
||||
#[cfg(feature = "bigdecimal")]
|
||||
let one = Value::Number(bigdecimal::BigDecimal::from(1), false);
|
||||
|
||||
#[cfg(not(feature = "bigdecimal"))]
|
||||
let one = Value::Number("1".to_string(), false);
|
||||
|
||||
assert_eq!(
|
||||
ms().verified_stmt(sql),
|
||||
Statement::CreateProcedure {
|
||||
|
@ -79,7 +73,7 @@ fn parse_create_procedure() {
|
|||
body: Box::new(SetExpr::Select(Box::new(Select {
|
||||
distinct: None,
|
||||
top: None,
|
||||
projection: vec![SelectItem::UnnamedExpr(Expr::Value(one))],
|
||||
projection: vec![SelectItem::UnnamedExpr(Expr::Value(number("1")))],
|
||||
into: None,
|
||||
from: vec![],
|
||||
lateral_views: vec![],
|
||||
|
|
|
@ -259,13 +259,7 @@ fn parse_set_variables() {
|
|||
local: true,
|
||||
hivevar: false,
|
||||
variable: ObjectName(vec!["autocommit".into()]),
|
||||
value: vec![Expr::Value(Value::Number(
|
||||
#[cfg(not(feature = "bigdecimal"))]
|
||||
"1".to_string(),
|
||||
#[cfg(feature = "bigdecimal")]
|
||||
bigdecimal::BigDecimal::from(1),
|
||||
false
|
||||
))],
|
||||
value: vec![Expr::Value(number("1"))],
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -643,7 +637,6 @@ fn parse_create_table_unsigned() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(feature = "bigdecimal"))]
|
||||
fn parse_simple_insert() {
|
||||
let sql = r"INSERT INTO tasks (title, priority) VALUES ('Test Some Inserts', 1), ('Test Entry 2', 2), ('Test Entry 3', 3)";
|
||||
|
||||
|
@ -668,15 +661,15 @@ fn parse_simple_insert() {
|
|||
Expr::Value(Value::SingleQuotedString(
|
||||
"Test Some Inserts".to_string()
|
||||
)),
|
||||
Expr::Value(Value::Number("1".to_string(), false))
|
||||
Expr::Value(number("1"))
|
||||
],
|
||||
vec![
|
||||
Expr::Value(Value::SingleQuotedString("Test Entry 2".to_string())),
|
||||
Expr::Value(Value::Number("2".to_string(), false))
|
||||
Expr::Value(number("2"))
|
||||
],
|
||||
vec![
|
||||
Expr::Value(Value::SingleQuotedString("Test Entry 3".to_string())),
|
||||
Expr::Value(Value::Number("3".to_string(), false))
|
||||
Expr::Value(number("3"))
|
||||
]
|
||||
]
|
||||
})),
|
||||
|
@ -895,6 +888,13 @@ fn parse_select_with_numeric_prefix_column_name() {
|
|||
}
|
||||
}
|
||||
|
||||
// Don't run with bigdecimal as it fails like this on rust beta:
|
||||
//
|
||||
// 'parse_select_with_concatenation_of_exp_number_and_numeric_prefix_column'
|
||||
// panicked at 'assertion failed: `(left == right)`
|
||||
//
|
||||
// left: `"SELECT 123e4, 123col_$@123abc FROM \"table\""`,
|
||||
// right: `"SELECT 1230000, 123col_$@123abc FROM \"table\""`', src/test_utils.rs:114:13
|
||||
#[cfg(not(feature = "bigdecimal"))]
|
||||
#[test]
|
||||
fn parse_select_with_concatenation_of_exp_number_and_numeric_prefix_column() {
|
||||
|
@ -907,10 +907,7 @@ fn parse_select_with_concatenation_of_exp_number_and_numeric_prefix_column() {
|
|||
distinct: None,
|
||||
top: None,
|
||||
projection: vec![
|
||||
SelectItem::UnnamedExpr(Expr::Value(Value::Number(
|
||||
"123e4".to_string(),
|
||||
false
|
||||
))),
|
||||
SelectItem::UnnamedExpr(Expr::Value(number("123e4"))),
|
||||
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("123col_$@123abc")))
|
||||
],
|
||||
into: None,
|
||||
|
@ -1072,7 +1069,6 @@ fn parse_alter_table_change_column() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(feature = "bigdecimal"))]
|
||||
fn parse_substring_in_select() {
|
||||
let sql = "SELECT DISTINCT SUBSTRING(description, 0, 1) FROM test";
|
||||
match mysql().one_statement_parses_to(
|
||||
|
@ -1091,14 +1087,8 @@ fn parse_substring_in_select() {
|
|||
value: "description".to_string(),
|
||||
quote_style: None
|
||||
})),
|
||||
substring_from: Some(Box::new(Expr::Value(Value::Number(
|
||||
"0".to_string(),
|
||||
false
|
||||
)))),
|
||||
substring_for: Some(Box::new(Expr::Value(Value::Number(
|
||||
"1".to_string(),
|
||||
false
|
||||
))))
|
||||
substring_from: Some(Box::new(Expr::Value(number("0")))),
|
||||
substring_for: Some(Box::new(Expr::Value(number("1"))))
|
||||
})],
|
||||
into: None,
|
||||
from: vec![TableWithJoins {
|
||||
|
|
|
@ -1099,13 +1099,7 @@ fn parse_set() {
|
|||
local: false,
|
||||
hivevar: false,
|
||||
variable: ObjectName(vec![Ident::new("a")]),
|
||||
value: vec![Expr::Value(Value::Number(
|
||||
#[cfg(not(feature = "bigdecimal"))]
|
||||
"0".to_string(),
|
||||
#[cfg(feature = "bigdecimal")]
|
||||
bigdecimal::BigDecimal::from(0),
|
||||
false,
|
||||
))],
|
||||
value: vec![Expr::Value(number("0"))],
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -1691,13 +1685,8 @@ fn parse_pg_regex_match_ops() {
|
|||
|
||||
#[test]
|
||||
fn parse_array_index_expr() {
|
||||
#[cfg(feature = "bigdecimal")]
|
||||
let num: Vec<Expr> = (0..=10)
|
||||
.map(|s| Expr::Value(Value::Number(bigdecimal::BigDecimal::from(s), false)))
|
||||
.collect();
|
||||
#[cfg(not(feature = "bigdecimal"))]
|
||||
let num: Vec<Expr> = (0..=10)
|
||||
.map(|s| Expr::Value(Value::Number(s.to_string(), false)))
|
||||
.map(|s| Expr::Value(number(&s.to_string())))
|
||||
.collect();
|
||||
|
||||
let sql = "SELECT foo[0] FROM foos";
|
||||
|
@ -1785,13 +1774,7 @@ fn parse_array_subquery_expr() {
|
|||
left: Box::new(SetExpr::Select(Box::new(Select {
|
||||
distinct: None,
|
||||
top: None,
|
||||
projection: vec![SelectItem::UnnamedExpr(Expr::Value(Value::Number(
|
||||
#[cfg(not(feature = "bigdecimal"))]
|
||||
"1".to_string(),
|
||||
#[cfg(feature = "bigdecimal")]
|
||||
bigdecimal::BigDecimal::from(1),
|
||||
false,
|
||||
)))],
|
||||
projection: vec![SelectItem::UnnamedExpr(Expr::Value(number("1")))],
|
||||
into: None,
|
||||
from: vec![],
|
||||
lateral_views: vec![],
|
||||
|
@ -1807,13 +1790,7 @@ fn parse_array_subquery_expr() {
|
|||
right: Box::new(SetExpr::Select(Box::new(Select {
|
||||
distinct: None,
|
||||
top: None,
|
||||
projection: vec![SelectItem::UnnamedExpr(Expr::Value(Value::Number(
|
||||
#[cfg(not(feature = "bigdecimal"))]
|
||||
"2".to_string(),
|
||||
#[cfg(feature = "bigdecimal")]
|
||||
bigdecimal::BigDecimal::from(2),
|
||||
false,
|
||||
)))],
|
||||
projection: vec![SelectItem::UnnamedExpr(Expr::Value(number("2")))],
|
||||
into: None,
|
||||
from: vec![],
|
||||
lateral_views: vec![],
|
||||
|
@ -2021,10 +1998,6 @@ fn test_composite_value() {
|
|||
select.projection[0]
|
||||
);
|
||||
|
||||
#[cfg(feature = "bigdecimal")]
|
||||
let num: Expr = Expr::Value(Value::Number(bigdecimal::BigDecimal::from(9), false));
|
||||
#[cfg(not(feature = "bigdecimal"))]
|
||||
let num: Expr = Expr::Value(Value::Number("9".to_string(), false));
|
||||
assert_eq!(
|
||||
select.selection,
|
||||
Some(Expr::BinaryOp {
|
||||
|
@ -2036,7 +2009,7 @@ fn test_composite_value() {
|
|||
]))))
|
||||
}),
|
||||
op: BinaryOperator::Gt,
|
||||
right: Box::new(num)
|
||||
right: Box::new(Expr::Value(number("9")))
|
||||
})
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue