forked from apache/datafusion-sqlparser-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlparser_oracle.rs
More file actions
105 lines (98 loc) · 3.89 KB
/
sqlparser_oracle.rs
File metadata and controls
105 lines (98 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// 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.
//! Test SQL syntax, specific to [sqlparser::dialect::OracleDialect].
#[cfg(test)]
use pretty_assertions::assert_eq;
use sqlparser::{
ast::{BinaryOperator, Expr, Value, ValueWithSpan},
dialect::OracleDialect,
tokenizer::Span,
};
use test_utils::{expr_from_projection, number, TestedDialects};
mod test_utils;
fn oracle() -> TestedDialects {
TestedDialects::new(vec![Box::new(OracleDialect)])
}
/// Oracle: `||` has a lower precedence than `*` and `/`
#[test]
fn muldiv_have_higher_precedence_than_strconcat() {
// ............... A .. B ...... C .. D ...........
let sql = "SELECT 3 / 5 || 'asdf' || 7 * 9 FROM dual";
let select = oracle().verified_only_select(sql);
assert_eq!(1, select.projection.len());
assert_eq!(
expr_from_projection(&select.projection[0]),
// (C || D)
&Expr::BinaryOp {
// (A || B)
left: Box::new(Expr::BinaryOp {
// A
left: Box::new(Expr::BinaryOp {
left: Box::new(Expr::Value(number("3").into())),
op: BinaryOperator::Divide,
right: Box::new(Expr::Value(number("5").into())),
}),
op: BinaryOperator::StringConcat,
right: Box::new(Expr::Value(ValueWithSpan {
value: Value::SingleQuotedString("asdf".into()),
span: Span::empty(),
})),
}),
op: BinaryOperator::StringConcat,
// D
right: Box::new(Expr::BinaryOp {
left: Box::new(Expr::Value(number("7").into())),
op: BinaryOperator::Multiply,
right: Box::new(Expr::Value(number("9").into())),
}),
}
);
}
/// Oracle: `+`, `-`, and `||` have the same precedence and parse from left-to-right
#[test]
fn plusminus_have_same_precedence_as_strconcat() {
// ................ A .. B .... C .. D ............
let sql = "SELECT 3 + 5 || '.3' || 7 - 9 FROM dual";
let select = oracle().verified_only_select(sql);
assert_eq!(1, select.projection.len());
assert_eq!(
expr_from_projection(&select.projection[0]),
// D
&Expr::BinaryOp {
left: Box::new(Expr::BinaryOp {
// B
left: Box::new(Expr::BinaryOp {
// A
left: Box::new(Expr::BinaryOp {
left: Box::new(Expr::Value(number("3").into())),
op: BinaryOperator::Plus,
right: Box::new(Expr::Value(number("5").into())),
}),
op: BinaryOperator::StringConcat,
right: Box::new(Expr::Value(ValueWithSpan {
value: Value::SingleQuotedString(".3".into()),
span: Span::empty(),
})),
}),
op: BinaryOperator::StringConcat,
right: Box::new(Expr::Value(number("7").into())),
}),
op: BinaryOperator::Minus,
right: Box::new(Expr::Value(number("9").into()))
}
);
}