Skip to content

Commit 4c428d0

Browse files
alambserprex
authored andcommitted
Remove most instances of #[cfg(feature(bigdecimal))] in tests (apache#910)
1 parent 020464b commit 4c428d0

File tree

8 files changed

+28
-90
lines changed

8 files changed

+28
-90
lines changed

src/ast/value.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ pub enum Value {
3232
#[cfg(not(feature = "bigdecimal"))]
3333
Number(String, bool),
3434
#[cfg(feature = "bigdecimal")]
35+
// HINT: use `test_utils::number` to make an instance of
36+
// Value::Number This might help if you your tests pass locally
37+
// but fail on CI with the `--all-features` flag enabled
3538
Number(BigDecimal, bool),
3639
/// 'string value'
3740
SingleQuotedString(String),

src/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub fn expr_from_projection(item: &SelectItem) -> &Expr {
198198
}
199199

200200
/// Creates a `Value::Number`, panic'ing if n is not a number
201-
pub fn number(n: &'static str) -> Value {
201+
pub fn number(n: &str) -> Value {
202202
Value::Number(n.parse().unwrap(), false)
203203
}
204204

tests/sqlparser_bigquery.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ use sqlparser::ast::*;
1717
use sqlparser::dialect::{BigQueryDialect, GenericDialect};
1818
use test_utils::*;
1919

20-
#[cfg(feature = "bigdecimal")]
21-
use bigdecimal::*;
22-
#[cfg(feature = "bigdecimal")]
23-
use std::str::FromStr;
24-
2520
#[test]
2621
fn parse_literal_string() {
2722
let sql = r#"SELECT 'single', "double""#;
@@ -377,22 +372,13 @@ fn test_select_wildcard_with_replace() {
377372
expr: Expr::BinaryOp {
378373
left: Box::new(Expr::Identifier(Ident::new("quantity"))),
379374
op: BinaryOperator::Divide,
380-
#[cfg(not(feature = "bigdecimal"))]
381-
right: Box::new(Expr::Value(Value::Number("2".to_string(), false))),
382-
#[cfg(feature = "bigdecimal")]
383-
right: Box::new(Expr::Value(Value::Number(
384-
BigDecimal::from_str("2").unwrap(),
385-
false,
386-
))),
375+
right: Box::new(Expr::Value(number("2"))),
387376
},
388377
column_name: Ident::new("quantity"),
389378
as_keyword: true,
390379
}),
391380
Box::new(ReplaceSelectElement {
392-
#[cfg(not(feature = "bigdecimal"))]
393-
expr: Expr::Value(Value::Number("3".to_string(), false)),
394-
#[cfg(feature = "bigdecimal")]
395-
expr: Expr::Value(Value::Number(BigDecimal::from_str("3").unwrap(), false)),
381+
expr: Expr::Value(number("3")),
396382
column_name: Ident::new("order_id"),
397383
as_keyword: true,
398384
}),
@@ -421,7 +407,6 @@ fn bigquery_and_generic() -> TestedDialects {
421407
fn parse_map_access_offset() {
422408
let sql = "SELECT d[offset(0)]";
423409
let _select = bigquery().verified_only_select(sql);
424-
#[cfg(not(feature = "bigdecimal"))]
425410
assert_eq!(
426411
_select.projection[0],
427412
SelectItem::UnnamedExpr(Expr::MapAccess {
@@ -432,7 +417,7 @@ fn parse_map_access_offset() {
432417
keys: vec![Expr::Function(Function {
433418
name: ObjectName(vec!["offset".into()]),
434419
args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value(
435-
Value::Number("0".into(), false)
420+
number("0")
436421
))),],
437422
over: None,
438423
distinct: false,

tests/sqlparser_common.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,6 @@ fn parse_select_having() {
17311731
assert!(select.having.is_some());
17321732
}
17331733

1734-
#[cfg(feature = "bigdecimal")]
17351734
#[test]
17361735
fn parse_select_qualify() {
17371736
let sql = "SELECT i, p, o FROM qt QUALIFY ROW_NUMBER() OVER (PARTITION BY p ORDER BY o) = 1";

tests/sqlparser_duckdb.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,7 @@ fn test_create_macro_default_args() {
9797
MacroArg::new("a"),
9898
MacroArg {
9999
name: Ident::new("b"),
100-
default_expr: Some(Expr::Value(Value::Number(
101-
#[cfg(not(feature = "bigdecimal"))]
102-
5.to_string(),
103-
#[cfg(feature = "bigdecimal")]
104-
bigdecimal::BigDecimal::from(5),
105-
false,
106-
))),
100+
default_expr: Some(Expr::Value(number("5"))),
107101
},
108102
]),
109103
definition: MacroDefinition::Expr(Expr::BinaryOp {

tests/sqlparser_mssql.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ fn parse_mssql_delimited_identifiers() {
5959
fn parse_create_procedure() {
6060
let sql = "CREATE OR ALTER PROCEDURE test (@foo INT, @bar VARCHAR(256)) AS BEGIN SELECT 1 END";
6161

62-
#[cfg(feature = "bigdecimal")]
63-
let one = Value::Number(bigdecimal::BigDecimal::from(1), false);
64-
65-
#[cfg(not(feature = "bigdecimal"))]
66-
let one = Value::Number("1".to_string(), false);
67-
6862
assert_eq!(
6963
ms().verified_stmt(sql),
7064
Statement::CreateProcedure {
@@ -79,7 +73,7 @@ fn parse_create_procedure() {
7973
body: Box::new(SetExpr::Select(Box::new(Select {
8074
distinct: None,
8175
top: None,
82-
projection: vec![SelectItem::UnnamedExpr(Expr::Value(one))],
76+
projection: vec![SelectItem::UnnamedExpr(Expr::Value(number("1")))],
8377
into: None,
8478
from: vec![],
8579
lateral_views: vec![],

tests/sqlparser_mysql.rs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,7 @@ fn parse_set_variables() {
259259
local: true,
260260
hivevar: false,
261261
variable: ObjectName(vec!["autocommit".into()]),
262-
value: vec![Expr::Value(Value::Number(
263-
#[cfg(not(feature = "bigdecimal"))]
264-
"1".to_string(),
265-
#[cfg(feature = "bigdecimal")]
266-
bigdecimal::BigDecimal::from(1),
267-
false
268-
))],
262+
value: vec![Expr::Value(number("1"))],
269263
}
270264
);
271265
}
@@ -643,7 +637,6 @@ fn parse_create_table_unsigned() {
643637
}
644638

645639
#[test]
646-
#[cfg(not(feature = "bigdecimal"))]
647640
fn parse_simple_insert() {
648641
let sql = r"INSERT INTO tasks (title, priority) VALUES ('Test Some Inserts', 1), ('Test Entry 2', 2), ('Test Entry 3', 3)";
649642

@@ -668,15 +661,15 @@ fn parse_simple_insert() {
668661
Expr::Value(Value::SingleQuotedString(
669662
"Test Some Inserts".to_string()
670663
)),
671-
Expr::Value(Value::Number("1".to_string(), false))
664+
Expr::Value(number("1"))
672665
],
673666
vec![
674667
Expr::Value(Value::SingleQuotedString("Test Entry 2".to_string())),
675-
Expr::Value(Value::Number("2".to_string(), false))
668+
Expr::Value(number("2"))
676669
],
677670
vec![
678671
Expr::Value(Value::SingleQuotedString("Test Entry 3".to_string())),
679-
Expr::Value(Value::Number("3".to_string(), false))
672+
Expr::Value(number("3"))
680673
]
681674
]
682675
})),
@@ -895,6 +888,13 @@ fn parse_select_with_numeric_prefix_column_name() {
895888
}
896889
}
897890

891+
// Don't run with bigdecimal as it fails like this on rust beta:
892+
//
893+
// 'parse_select_with_concatenation_of_exp_number_and_numeric_prefix_column'
894+
// panicked at 'assertion failed: `(left == right)`
895+
//
896+
// left: `"SELECT 123e4, 123col_$@123abc FROM \"table\""`,
897+
// right: `"SELECT 1230000, 123col_$@123abc FROM \"table\""`', src/test_utils.rs:114:13
898898
#[cfg(not(feature = "bigdecimal"))]
899899
#[test]
900900
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() {
907907
distinct: None,
908908
top: None,
909909
projection: vec![
910-
SelectItem::UnnamedExpr(Expr::Value(Value::Number(
911-
"123e4".to_string(),
912-
false
913-
))),
910+
SelectItem::UnnamedExpr(Expr::Value(number("123e4"))),
914911
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("123col_$@123abc")))
915912
],
916913
into: None,
@@ -1072,7 +1069,6 @@ fn parse_alter_table_change_column() {
10721069
}
10731070

10741071
#[test]
1075-
#[cfg(not(feature = "bigdecimal"))]
10761072
fn parse_substring_in_select() {
10771073
let sql = "SELECT DISTINCT SUBSTRING(description, 0, 1) FROM test";
10781074
match mysql().one_statement_parses_to(
@@ -1091,14 +1087,8 @@ fn parse_substring_in_select() {
10911087
value: "description".to_string(),
10921088
quote_style: None
10931089
})),
1094-
substring_from: Some(Box::new(Expr::Value(Value::Number(
1095-
"0".to_string(),
1096-
false
1097-
)))),
1098-
substring_for: Some(Box::new(Expr::Value(Value::Number(
1099-
"1".to_string(),
1100-
false
1101-
))))
1090+
substring_from: Some(Box::new(Expr::Value(number("0")))),
1091+
substring_for: Some(Box::new(Expr::Value(number("1"))))
11021092
})],
11031093
into: None,
11041094
from: vec![TableWithJoins {

tests/sqlparser_postgres.rs

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,13 +1100,7 @@ fn parse_set() {
11001100
local: false,
11011101
hivevar: false,
11021102
variable: ObjectName(vec![Ident::new("a")]),
1103-
value: vec![Expr::Value(Value::Number(
1104-
#[cfg(not(feature = "bigdecimal"))]
1105-
"0".to_string(),
1106-
#[cfg(feature = "bigdecimal")]
1107-
bigdecimal::BigDecimal::from(0),
1108-
false,
1109-
))],
1103+
value: vec![Expr::Value(number("0"))],
11101104
}
11111105
);
11121106

@@ -1692,13 +1686,8 @@ fn parse_pg_regex_match_ops() {
16921686

16931687
#[test]
16941688
fn parse_array_index_expr() {
1695-
#[cfg(feature = "bigdecimal")]
16961689
let num: Vec<Expr> = (0..=10)
1697-
.map(|s| Expr::Value(Value::Number(bigdecimal::BigDecimal::from(s), false)))
1698-
.collect();
1699-
#[cfg(not(feature = "bigdecimal"))]
1700-
let num: Vec<Expr> = (0..=10)
1701-
.map(|s| Expr::Value(Value::Number(s.to_string(), false)))
1690+
.map(|s| Expr::Value(number(&s.to_string())))
17021691
.collect();
17031692

17041693
let sql = "SELECT foo[0] FROM foos";
@@ -1786,13 +1775,7 @@ fn parse_array_subquery_expr() {
17861775
left: Box::new(SetExpr::Select(Box::new(Select {
17871776
distinct: None,
17881777
top: None,
1789-
projection: vec![SelectItem::UnnamedExpr(Expr::Value(Value::Number(
1790-
#[cfg(not(feature = "bigdecimal"))]
1791-
"1".to_string(),
1792-
#[cfg(feature = "bigdecimal")]
1793-
bigdecimal::BigDecimal::from(1),
1794-
false,
1795-
)))],
1778+
projection: vec![SelectItem::UnnamedExpr(Expr::Value(number("1")))],
17961779
into: None,
17971780
from: vec![],
17981781
lateral_views: vec![],
@@ -1808,13 +1791,7 @@ fn parse_array_subquery_expr() {
18081791
right: Box::new(SetExpr::Select(Box::new(Select {
18091792
distinct: None,
18101793
top: None,
1811-
projection: vec![SelectItem::UnnamedExpr(Expr::Value(Value::Number(
1812-
#[cfg(not(feature = "bigdecimal"))]
1813-
"2".to_string(),
1814-
#[cfg(feature = "bigdecimal")]
1815-
bigdecimal::BigDecimal::from(2),
1816-
false,
1817-
)))],
1794+
projection: vec![SelectItem::UnnamedExpr(Expr::Value(number("2")))],
18181795
into: None,
18191796
from: vec![],
18201797
lateral_views: vec![],
@@ -2022,10 +1999,6 @@ fn test_composite_value() {
20221999
select.projection[0]
20232000
);
20242001

2025-
#[cfg(feature = "bigdecimal")]
2026-
let num: Expr = Expr::Value(Value::Number(bigdecimal::BigDecimal::from(9), false));
2027-
#[cfg(not(feature = "bigdecimal"))]
2028-
let num: Expr = Expr::Value(Value::Number("9".to_string(), false));
20292002
assert_eq!(
20302003
select.selection,
20312004
Some(Expr::BinaryOp {
@@ -2037,7 +2010,7 @@ fn test_composite_value() {
20372010
]))))
20382011
}),
20392012
op: BinaryOperator::Gt,
2040-
right: Box::new(num)
2013+
right: Box::new(Expr::Value(number("9")))
20412014
})
20422015
);
20432016

0 commit comments

Comments
 (0)