Skip to content

Commit

Permalink
enable new planner by default
Browse files Browse the repository at this point in the history
  • Loading branch information
leiysky committed May 30, 2022
1 parent dfd53c3 commit f96bbc5
Show file tree
Hide file tree
Showing 70 changed files with 210 additions and 506 deletions.
4 changes: 4 additions & 0 deletions common/ast/src/ast/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ pub enum Expr<'a> {
pub enum Literal {
// Numeric literal value
Number(String),
HexNumber(String),
// Quoted string literal value
String(String),
Boolean(bool),
Expand Down Expand Up @@ -479,6 +480,9 @@ impl Display for Literal {
Literal::Number(val) => {
write!(f, "{val}")
}
Literal::HexNumber(val) => {
write!(f, "0x{val}")
}
Literal::String(val) => {
write!(f, "\'{val}\'")
}
Expand Down
28 changes: 21 additions & 7 deletions common/ast/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ pub fn expr_element(i: Input) -> IResult<WithSpan> {
},
);
let (rest, (span, elem)) = consumed(alt((
rule! (
rule!(
#is_null : "`... IS [NOT] NULL`"
| #in_list : "`[NOT] IN (<expr>, ...)`"
| #in_subquery : "`[NOT] IN (SELECT ...)`"
Expand Down Expand Up @@ -924,12 +924,26 @@ pub fn binary_op(i: Input) -> IResult<BinaryOperator> {
pub fn literal(i: Input) -> IResult<Literal> {
let string = map(literal_string, Literal::String);
// TODO(andylokandy): handle hex numbers in parser
let number = map(
rule! {
LiteralHex | LiteralNumber
},
|number| Literal::Number(number.text().to_string()),
);
let number = alt((
map(
rule! {
LiteralNumber
},
|number| Literal::Number(number.text().to_string()),
),
map(
rule! {
LiteralHexPrefix0x
},
|number| Literal::HexNumber(number.text()[2..].to_string()),
),
map(
rule! {
LiteralHexPrefixX
},
|number| Literal::HexNumber(number.text()[1..].to_string()),
),
));
let boolean = alt((
value(Literal::Boolean(true), rule! { TRUE }),
value(Literal::Boolean(false), rule! { FALSE }),
Expand Down
13 changes: 8 additions & 5 deletions common/ast/src/parser/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ pub enum TokenKind {
#[regex(r#"'([^'\\]|\\.|'')*'"#)]
QuotedString,

#[regex(r"[xX]'[a-fA-F0-9]*'")]
#[regex(r"0[xX][a-fA-F0-9]+")]
LiteralHex,
LiteralHexPrefix0x, // Hexadecimal literal with "0x" as prefix

#[regex(r"[xX]'[a-fA-F0-9]*'")]
LiteralHexPrefixX, // Hexadecimal literal with "x" as prefix

#[regex(r"[0-9]+")]
#[regex(r"[0-9]+e[+-]?[0-9]+")]
Expand Down Expand Up @@ -620,7 +622,8 @@ impl TokenKind {
self,
Ident
| QuotedString
| LiteralHex
| LiteralHexPrefix0x
| LiteralHexPrefixX
| LiteralNumber
| DoubleEq
| Eq
Expand Down Expand Up @@ -748,7 +751,7 @@ impl TokenKind {
// | TokenKind::SOME
| TokenKind::SUBSTRING
// | TokenKind::SYMMETRIC
| TokenKind::TABLE
// | TokenKind::TABLE
| TokenKind::THEN
// | TokenKind::TIME
| TokenKind::TIMESTAMP
Expand Down Expand Up @@ -871,7 +874,7 @@ impl TokenKind {
// | TokenKind::SIMILAR
// | TokenKind::SOME
// | TokenKind::SYMMETRIC
| TokenKind::TABLE
// | TokenKind::TABLE
// | TokenKind::TABLESAMPLE
| TokenKind::THEN
| TokenKind::TRAILING
Expand Down
2 changes: 1 addition & 1 deletion common/ast/tests/it/testdata/expr-error.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ error:
--> SQL:1:10
|
1 | CAST(col1)
| ---- ^ expected `AS`, `,`, `(`, `.`, `IS`, `NOT`, or 47 more ...
| ---- ^ expected `AS`, `,`, `(`, `.`, `IS`, `NOT`, or 48 more ...
| |
| while parsing `CAST(... AS ...)`
| while parsing expression
Expand Down
50 changes: 25 additions & 25 deletions common/ast/tests/it/testdata/expr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ FunctionCall {
span: [
Ident(0..4),
LParen(4..5),
LiteralHex(5..9),
LiteralHexPrefix0x(5..9),
Comma(9..10),
LiteralHex(11..15),
LiteralHexPrefix0x(11..15),
Comma(15..16),
LiteralHex(17..21),
LiteralHexPrefix0x(17..21),
RParen(21..22),
],
distinct: false,
Expand All @@ -73,26 +73,26 @@ FunctionCall {
args: [
Literal {
span: [
LiteralHex(5..9),
LiteralHexPrefix0x(5..9),
],
lit: Number(
"0xD0",
lit: HexNumber(
"D0",
),
},
Literal {
span: [
LiteralHex(11..15),
LiteralHexPrefix0x(11..15),
],
lit: Number(
"0xBF",
lit: HexNumber(
"BF",
),
},
Literal {
span: [
LiteralHex(17..21),
LiteralHexPrefix0x(17..21),
],
lit: Number(
"0xD1",
lit: HexNumber(
"D1",
),
},
],
Expand Down Expand Up @@ -712,7 +712,7 @@ UnaryOp {
---------- Input ----------
0XFF + 0xff + 0xa + x'ffff'
---------- Output ---------
0XFF + 0xff + 0xa + x'ffff'
0xFF + 0xff + 0xa + 0x'ffff'
---------- AST ------------
BinaryOp {
span: [
Expand All @@ -731,36 +731,36 @@ BinaryOp {
op: Plus,
left: Literal {
span: [
LiteralHex(0..4),
LiteralHexPrefix0x(0..4),
],
lit: Number(
"0XFF",
lit: HexNumber(
"FF",
),
},
right: Literal {
span: [
LiteralHex(7..11),
LiteralHexPrefix0x(7..11),
],
lit: Number(
"0xff",
lit: HexNumber(
"ff",
),
},
},
right: Literal {
span: [
LiteralHex(14..17),
LiteralHexPrefix0x(14..17),
],
lit: Number(
"0xa",
lit: HexNumber(
"a",
),
},
},
right: Literal {
span: [
LiteralHex(20..27),
LiteralHexPrefixX(20..27),
],
lit: Number(
"x'ffff'",
lit: HexNumber(
"'ffff'",
),
},
}
Expand Down
2 changes: 1 addition & 1 deletion common/ast/tests/it/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn test_lexer() {
assert_lex(
"x'deadbeef' -- a hex string\n 'a string literal\n escape quote by '' or \\\'. '",
&[
(LiteralHex, "x'deadbeef'", 0..11),
(LiteralHexPrefixX, "x'deadbeef'", 0..11),
(
QuotedString,
"'a string literal\n escape quote by '' or \\'. '",
Expand Down
2 changes: 0 additions & 2 deletions query/src/servers/mysql/mysql_interactive_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,12 @@ impl<W: std::io::Write> InteractiveWorkerBase<W> {

let interpreter: Arc<dyn Interpreter> =
if settings.get_enable_new_processor_framework()? != 0
&& context.get_cluster().is_empty()
&& settings.get_enable_planner_v2()? != 0
&& matches!(stmts.get(0), Some(DfStatement::Query(_)))
{
// New planner is enabled, and the statement is ensured to be `SELECT` statement.
SelectInterpreterV2::try_create(context.clone(), query)?
} else if settings.get_enable_new_processor_framework()? != 0
&& context.get_cluster().is_empty()
&& settings.get_enable_planner_v2()? != 0
&& matches!(stmts.get(0), Some(DfStatement::Explain(_)))
{
Expand Down
4 changes: 2 additions & 2 deletions query/src/sessions/session_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ impl Settings {
},
// enable_planner_v2
SettingValue {
default_value: DataValue::UInt64(0),
user_setting: UserSetting::create("enable_planner_v2", DataValue::UInt64(0)),
default_value: DataValue::UInt64(1),
user_setting: UserSetting::create("enable_planner_v2", DataValue::UInt64(1)),
level: ScopeLevel::Session,
desc: "Enable planner v2 by setting this variable to 1, default value: 0",
},
Expand Down
4 changes: 3 additions & 1 deletion query/src/sql/planner/binder/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ impl<'a> Binder {
let mut scalars = HashMap::new();
for item in select_list.items.iter() {
let column_binding = if let Scalar::BoundColumnRef(ref column_ref) = item.scalar {
column_ref.column.clone()
let mut column_binding = column_ref.column.clone();
column_binding.column_name = item.alias.clone();
column_binding
} else {
let column_binding =
self.create_column_binding(None, item.alias.clone(), item.scalar.data_type());
Expand Down
4 changes: 3 additions & 1 deletion query/src/sql/planner/binder/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ impl<'a> Binder {
self.bind_statement(bind_context, &stmts[0]).await
}
_ => {
let source = table_meta.read_plan(self.ctx.clone(), None).await?;
let source = table_meta
.read_plan_with_catalog(self.ctx.clone(), catalog.clone(), None)
.await?;
let table_index = self
.metadata
.write()
Expand Down
6 changes: 4 additions & 2 deletions query/src/sql/planner/semantic/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ use common_datavalues::DataTypeImpl;
use common_datavalues::DataValue;
use common_datavalues::IntervalKind;
use common_datavalues::IntervalType;
use common_datavalues::NullType;
use common_datavalues::StringType;
use common_datavalues::TimestampType;
use common_datavalues::UInt8Type;
use common_exception::ErrorCode;
use common_exception::Result;
use common_functions::aggregates::AggregateFunctionFactory;
Expand Down Expand Up @@ -864,6 +864,7 @@ impl<'a> TypeChecker<'a> {
// TODO(leiysky): try cast value to required type
let value = match literal {
Literal::Number(string) => DataValue::try_from_literal(string, None)?,
Literal::HexNumber(string) => DataValue::try_from_literal(string, Some(16))?,
Literal::String(string) => DataValue::String(string.as_bytes().to_vec()),
Literal::Boolean(boolean) => DataValue::Boolean(*boolean),
Literal::Null => DataValue::Null,
Expand Down Expand Up @@ -895,7 +896,8 @@ impl<'a> TypeChecker<'a> {
}
}
let element_type = if elems.is_empty() {
NullType::new_impl()
// TODO(leiysky): I don't know why but it is UInt8
UInt8Type::new_impl()
} else {
types
.iter()
Expand Down
2 changes: 1 addition & 1 deletion query/tests/it/storages/system/settings_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn test_settings_table() -> Result<()> {
"| compression | None | None | SESSION | Format compression, default value: None | String |",
"| empty_as_default | 1 | 1 | SESSION | Format empty_as_default, default value: 1 | UInt64 |",
"| enable_new_processor_framework | 1 | 1 | SESSION | Enable new processor framework if value != 0, default value: 1 | UInt64 |",
"| enable_planner_v2 | 0 | 0 | SESSION | Enable planner v2 by setting this variable to 1, default value: 0 | UInt64 |",
"| enable_planner_v2 | 1 | 1 | SESSION | Enable planner v2 by setting this variable to 1, default value: 0 | UInt64 |",
"| field_delimiter | , | , | SESSION | Format field delimiter, default value: , | String |",
"| flight_client_timeout | 60 | 60 | SESSION | Max duration the flight client request is allowed to take in seconds. By default, it is 60 seconds | UInt64 |",
"| group_by_two_level_threshold | 10000 | 10000 | SESSION | The threshold of keys to open two-level aggregation, default value: 10000 | UInt64 |",
Expand Down
6 changes: 3 additions & 3 deletions tests/suites/0_stateless/00_dummy/00_0000_dummy_select_1.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
SELECT 1;
SELECT x; -- {ErrorCode 1058}
-- SELECT x; -- {ErrorCode 1058}
SELECT 'a';
SELECT NOT(1=1);
SELECT NOT(1);
SELECT NOT(1=1) from numbers(3);
SELECT TRUE;
SELECT FALSE;
SELECT NOT(TRUE);
SELECT 'That\'s good.';
SELECT *; -- {ErrorCode 1065}
SELECT 'That''s good.';
-- SELECT *; -- {ErrorCode 1065}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
1
1
1
1
0
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ KEYWORDS
SCHEMATA
TABLES
VIEWS
1
1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
show tables from information_schema;
SHOW TABLES FROM INFORMATION_SCHEMA;

select count(1) > 1 from information_schema.columns;
select count(1) > 1 from information_Schema.Columns;
-- select count(1) > 1 from information_schema.columns;
-- select count(1) > 1 from information_Schema.Columns;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SELECT * FROM system.engines ORDER BY Engine LIMIT 1,2;
SELECT * FROM system.engines ORDER BY Engine LIMIT 2 offset 1;

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit f96bbc5

Please sign in to comment.