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"))]
|
#[cfg(not(feature = "bigdecimal"))]
|
||||||
Number(String, bool),
|
Number(String, bool),
|
||||||
#[cfg(feature = "bigdecimal")]
|
#[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),
|
Number(BigDecimal, bool),
|
||||||
/// 'string value'
|
/// 'string value'
|
||||||
SingleQuotedString(String),
|
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
|
/// 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)
|
Value::Number(n.parse().unwrap(), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,6 @@ use sqlparser::ast::*;
|
||||||
use sqlparser::dialect::{BigQueryDialect, GenericDialect};
|
use sqlparser::dialect::{BigQueryDialect, GenericDialect};
|
||||||
use test_utils::*;
|
use test_utils::*;
|
||||||
|
|
||||||
#[cfg(feature = "bigdecimal")]
|
|
||||||
use bigdecimal::*;
|
|
||||||
#[cfg(feature = "bigdecimal")]
|
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_literal_string() {
|
fn parse_literal_string() {
|
||||||
let sql = r#"SELECT 'single', "double""#;
|
let sql = r#"SELECT 'single', "double""#;
|
||||||
|
@ -377,22 +372,13 @@ fn test_select_wildcard_with_replace() {
|
||||||
expr: Expr::BinaryOp {
|
expr: Expr::BinaryOp {
|
||||||
left: Box::new(Expr::Identifier(Ident::new("quantity"))),
|
left: Box::new(Expr::Identifier(Ident::new("quantity"))),
|
||||||
op: BinaryOperator::Divide,
|
op: BinaryOperator::Divide,
|
||||||
#[cfg(not(feature = "bigdecimal"))]
|
right: Box::new(Expr::Value(number("2"))),
|
||||||
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,
|
|
||||||
))),
|
|
||||||
},
|
},
|
||||||
column_name: Ident::new("quantity"),
|
column_name: Ident::new("quantity"),
|
||||||
as_keyword: true,
|
as_keyword: true,
|
||||||
}),
|
}),
|
||||||
Box::new(ReplaceSelectElement {
|
Box::new(ReplaceSelectElement {
|
||||||
#[cfg(not(feature = "bigdecimal"))]
|
expr: Expr::Value(number("3")),
|
||||||
expr: Expr::Value(Value::Number("3".to_string(), false)),
|
|
||||||
#[cfg(feature = "bigdecimal")]
|
|
||||||
expr: Expr::Value(Value::Number(BigDecimal::from_str("3").unwrap(), false)),
|
|
||||||
column_name: Ident::new("order_id"),
|
column_name: Ident::new("order_id"),
|
||||||
as_keyword: true,
|
as_keyword: true,
|
||||||
}),
|
}),
|
||||||
|
@ -421,7 +407,6 @@ fn bigquery_and_generic() -> TestedDialects {
|
||||||
fn parse_map_access_offset() {
|
fn parse_map_access_offset() {
|
||||||
let sql = "SELECT d[offset(0)]";
|
let sql = "SELECT d[offset(0)]";
|
||||||
let _select = bigquery().verified_only_select(sql);
|
let _select = bigquery().verified_only_select(sql);
|
||||||
#[cfg(not(feature = "bigdecimal"))]
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
_select.projection[0],
|
_select.projection[0],
|
||||||
SelectItem::UnnamedExpr(Expr::MapAccess {
|
SelectItem::UnnamedExpr(Expr::MapAccess {
|
||||||
|
@ -432,7 +417,7 @@ fn parse_map_access_offset() {
|
||||||
keys: vec![Expr::Function(Function {
|
keys: vec![Expr::Function(Function {
|
||||||
name: ObjectName(vec!["offset".into()]),
|
name: ObjectName(vec!["offset".into()]),
|
||||||
args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value(
|
args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value(
|
||||||
Value::Number("0".into(), false)
|
number("0")
|
||||||
))),],
|
))),],
|
||||||
over: None,
|
over: None,
|
||||||
distinct: false,
|
distinct: false,
|
||||||
|
|
|
@ -1731,7 +1731,6 @@ fn parse_select_having() {
|
||||||
assert!(select.having.is_some());
|
assert!(select.having.is_some());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "bigdecimal")]
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_select_qualify() {
|
fn parse_select_qualify() {
|
||||||
let sql = "SELECT i, p, o FROM qt QUALIFY ROW_NUMBER() OVER (PARTITION BY p ORDER BY o) = 1";
|
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::new("a"),
|
||||||
MacroArg {
|
MacroArg {
|
||||||
name: Ident::new("b"),
|
name: Ident::new("b"),
|
||||||
default_expr: Some(Expr::Value(Value::Number(
|
default_expr: Some(Expr::Value(number("5"))),
|
||||||
#[cfg(not(feature = "bigdecimal"))]
|
|
||||||
5.to_string(),
|
|
||||||
#[cfg(feature = "bigdecimal")]
|
|
||||||
bigdecimal::BigDecimal::from(5),
|
|
||||||
false,
|
|
||||||
))),
|
|
||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
definition: MacroDefinition::Expr(Expr::BinaryOp {
|
definition: MacroDefinition::Expr(Expr::BinaryOp {
|
||||||
|
|
|
@ -59,12 +59,6 @@ fn parse_mssql_delimited_identifiers() {
|
||||||
fn parse_create_procedure() {
|
fn parse_create_procedure() {
|
||||||
let sql = "CREATE OR ALTER PROCEDURE test (@foo INT, @bar VARCHAR(256)) AS BEGIN SELECT 1 END";
|
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!(
|
assert_eq!(
|
||||||
ms().verified_stmt(sql),
|
ms().verified_stmt(sql),
|
||||||
Statement::CreateProcedure {
|
Statement::CreateProcedure {
|
||||||
|
@ -79,7 +73,7 @@ fn parse_create_procedure() {
|
||||||
body: Box::new(SetExpr::Select(Box::new(Select {
|
body: Box::new(SetExpr::Select(Box::new(Select {
|
||||||
distinct: None,
|
distinct: None,
|
||||||
top: None,
|
top: None,
|
||||||
projection: vec![SelectItem::UnnamedExpr(Expr::Value(one))],
|
projection: vec![SelectItem::UnnamedExpr(Expr::Value(number("1")))],
|
||||||
into: None,
|
into: None,
|
||||||
from: vec![],
|
from: vec![],
|
||||||
lateral_views: vec![],
|
lateral_views: vec![],
|
||||||
|
|
|
@ -259,13 +259,7 @@ fn parse_set_variables() {
|
||||||
local: true,
|
local: true,
|
||||||
hivevar: false,
|
hivevar: false,
|
||||||
variable: ObjectName(vec!["autocommit".into()]),
|
variable: ObjectName(vec!["autocommit".into()]),
|
||||||
value: vec![Expr::Value(Value::Number(
|
value: vec![Expr::Value(number("1"))],
|
||||||
#[cfg(not(feature = "bigdecimal"))]
|
|
||||||
"1".to_string(),
|
|
||||||
#[cfg(feature = "bigdecimal")]
|
|
||||||
bigdecimal::BigDecimal::from(1),
|
|
||||||
false
|
|
||||||
))],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -643,7 +637,6 @@ fn parse_create_table_unsigned() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(feature = "bigdecimal"))]
|
|
||||||
fn parse_simple_insert() {
|
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)";
|
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(
|
Expr::Value(Value::SingleQuotedString(
|
||||||
"Test Some Inserts".to_string()
|
"Test Some Inserts".to_string()
|
||||||
)),
|
)),
|
||||||
Expr::Value(Value::Number("1".to_string(), false))
|
Expr::Value(number("1"))
|
||||||
],
|
],
|
||||||
vec![
|
vec![
|
||||||
Expr::Value(Value::SingleQuotedString("Test Entry 2".to_string())),
|
Expr::Value(Value::SingleQuotedString("Test Entry 2".to_string())),
|
||||||
Expr::Value(Value::Number("2".to_string(), false))
|
Expr::Value(number("2"))
|
||||||
],
|
],
|
||||||
vec![
|
vec![
|
||||||
Expr::Value(Value::SingleQuotedString("Test Entry 3".to_string())),
|
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"))]
|
#[cfg(not(feature = "bigdecimal"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_select_with_concatenation_of_exp_number_and_numeric_prefix_column() {
|
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,
|
distinct: None,
|
||||||
top: None,
|
top: None,
|
||||||
projection: vec![
|
projection: vec![
|
||||||
SelectItem::UnnamedExpr(Expr::Value(Value::Number(
|
SelectItem::UnnamedExpr(Expr::Value(number("123e4"))),
|
||||||
"123e4".to_string(),
|
|
||||||
false
|
|
||||||
))),
|
|
||||||
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("123col_$@123abc")))
|
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("123col_$@123abc")))
|
||||||
],
|
],
|
||||||
into: None,
|
into: None,
|
||||||
|
@ -1072,7 +1069,6 @@ fn parse_alter_table_change_column() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(feature = "bigdecimal"))]
|
|
||||||
fn parse_substring_in_select() {
|
fn parse_substring_in_select() {
|
||||||
let sql = "SELECT DISTINCT SUBSTRING(description, 0, 1) FROM test";
|
let sql = "SELECT DISTINCT SUBSTRING(description, 0, 1) FROM test";
|
||||||
match mysql().one_statement_parses_to(
|
match mysql().one_statement_parses_to(
|
||||||
|
@ -1091,14 +1087,8 @@ fn parse_substring_in_select() {
|
||||||
value: "description".to_string(),
|
value: "description".to_string(),
|
||||||
quote_style: None
|
quote_style: None
|
||||||
})),
|
})),
|
||||||
substring_from: Some(Box::new(Expr::Value(Value::Number(
|
substring_from: Some(Box::new(Expr::Value(number("0")))),
|
||||||
"0".to_string(),
|
substring_for: Some(Box::new(Expr::Value(number("1"))))
|
||||||
false
|
|
||||||
)))),
|
|
||||||
substring_for: Some(Box::new(Expr::Value(Value::Number(
|
|
||||||
"1".to_string(),
|
|
||||||
false
|
|
||||||
))))
|
|
||||||
})],
|
})],
|
||||||
into: None,
|
into: None,
|
||||||
from: vec![TableWithJoins {
|
from: vec![TableWithJoins {
|
||||||
|
|
|
@ -1099,13 +1099,7 @@ fn parse_set() {
|
||||||
local: false,
|
local: false,
|
||||||
hivevar: false,
|
hivevar: false,
|
||||||
variable: ObjectName(vec![Ident::new("a")]),
|
variable: ObjectName(vec![Ident::new("a")]),
|
||||||
value: vec![Expr::Value(Value::Number(
|
value: vec![Expr::Value(number("0"))],
|
||||||
#[cfg(not(feature = "bigdecimal"))]
|
|
||||||
"0".to_string(),
|
|
||||||
#[cfg(feature = "bigdecimal")]
|
|
||||||
bigdecimal::BigDecimal::from(0),
|
|
||||||
false,
|
|
||||||
))],
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1691,13 +1685,8 @@ fn parse_pg_regex_match_ops() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_array_index_expr() {
|
fn parse_array_index_expr() {
|
||||||
#[cfg(feature = "bigdecimal")]
|
|
||||||
let num: Vec<Expr> = (0..=10)
|
let num: Vec<Expr> = (0..=10)
|
||||||
.map(|s| Expr::Value(Value::Number(bigdecimal::BigDecimal::from(s), false)))
|
.map(|s| Expr::Value(number(&s.to_string())))
|
||||||
.collect();
|
|
||||||
#[cfg(not(feature = "bigdecimal"))]
|
|
||||||
let num: Vec<Expr> = (0..=10)
|
|
||||||
.map(|s| Expr::Value(Value::Number(s.to_string(), false)))
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let sql = "SELECT foo[0] FROM foos";
|
let sql = "SELECT foo[0] FROM foos";
|
||||||
|
@ -1785,13 +1774,7 @@ fn parse_array_subquery_expr() {
|
||||||
left: Box::new(SetExpr::Select(Box::new(Select {
|
left: Box::new(SetExpr::Select(Box::new(Select {
|
||||||
distinct: None,
|
distinct: None,
|
||||||
top: None,
|
top: None,
|
||||||
projection: vec![SelectItem::UnnamedExpr(Expr::Value(Value::Number(
|
projection: vec![SelectItem::UnnamedExpr(Expr::Value(number("1")))],
|
||||||
#[cfg(not(feature = "bigdecimal"))]
|
|
||||||
"1".to_string(),
|
|
||||||
#[cfg(feature = "bigdecimal")]
|
|
||||||
bigdecimal::BigDecimal::from(1),
|
|
||||||
false,
|
|
||||||
)))],
|
|
||||||
into: None,
|
into: None,
|
||||||
from: vec![],
|
from: vec![],
|
||||||
lateral_views: vec![],
|
lateral_views: vec![],
|
||||||
|
@ -1807,13 +1790,7 @@ fn parse_array_subquery_expr() {
|
||||||
right: Box::new(SetExpr::Select(Box::new(Select {
|
right: Box::new(SetExpr::Select(Box::new(Select {
|
||||||
distinct: None,
|
distinct: None,
|
||||||
top: None,
|
top: None,
|
||||||
projection: vec![SelectItem::UnnamedExpr(Expr::Value(Value::Number(
|
projection: vec![SelectItem::UnnamedExpr(Expr::Value(number("2")))],
|
||||||
#[cfg(not(feature = "bigdecimal"))]
|
|
||||||
"2".to_string(),
|
|
||||||
#[cfg(feature = "bigdecimal")]
|
|
||||||
bigdecimal::BigDecimal::from(2),
|
|
||||||
false,
|
|
||||||
)))],
|
|
||||||
into: None,
|
into: None,
|
||||||
from: vec![],
|
from: vec![],
|
||||||
lateral_views: vec![],
|
lateral_views: vec![],
|
||||||
|
@ -2021,10 +1998,6 @@ fn test_composite_value() {
|
||||||
select.projection[0]
|
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!(
|
assert_eq!(
|
||||||
select.selection,
|
select.selection,
|
||||||
Some(Expr::BinaryOp {
|
Some(Expr::BinaryOp {
|
||||||
|
@ -2036,7 +2009,7 @@ fn test_composite_value() {
|
||||||
]))))
|
]))))
|
||||||
}),
|
}),
|
||||||
op: BinaryOperator::Gt,
|
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