Skip to content

Commit

Permalink
Merge branch 'main' into li0k/object_store_fix_retry
Browse files Browse the repository at this point in the history
  • Loading branch information
Li0k authored May 9, 2024
2 parents fa24a66 + f78eb21 commit d8943fa
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 101 deletions.
2 changes: 1 addition & 1 deletion src/frontend/src/handler/create_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ fn derive_default_column_project_for_sink(

// If users specified the columns to be inserted e.g. `CREATE SINK s INTO t(a, b)`, the expressions of `Project` will be generated accordingly.
// The missing columns will be filled with default value (`null` if not explicitly defined).
// Otherwhise, e.g. `CREATE SINK s INTO t`, the columns will be matched by their order in `select` query and the target table.
// Otherwise, e.g. `CREATE SINK s INTO t`, the columns will be matched by their order in `select` query and the target table.
#[allow(clippy::collapsible_else_if)]
if user_specified_columns {
if let Some(idx) = sink_visible_col_idxes_by_name.get(table_column.name()) {
Expand Down
4 changes: 2 additions & 2 deletions src/meta/model_v2/src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct Model {
pub retention_seconds: i64,
pub definition: String,
pub subscription_state: i32,
pub dependent_table_id: u32,
pub dependent_table_id: i32,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down Expand Up @@ -59,7 +59,7 @@ impl From<PbSubscription> for ActiveModel {
retention_seconds: Set(pb_subscription.retention_seconds as _),
definition: Set(pb_subscription.definition),
subscription_state: Set(pb_subscription.subscription_state),
dependent_table_id: Set(pb_subscription.dependent_table_id),
dependent_table_id: Set(pb_subscription.dependent_table_id as _),
}
}
}
2 changes: 1 addition & 1 deletion src/meta/src/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl From<ObjectModel<subscription::Model>> for PbSubscription {
),
initialized_at_cluster_version: value.1.initialized_at_cluster_version,
created_at_cluster_version: value.1.created_at_cluster_version,
dependent_table_id: value.0.dependent_table_id,
dependent_table_id: value.0.dependent_table_id as _,
subscription_state: PbSubscriptionState::Init as _,
}
}
Expand Down
112 changes: 42 additions & 70 deletions src/sqlparser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,6 @@ pub struct Parser {
/// Since we cannot distinguish `>>` and double `>`, so use `angle_brackets_num` to store the
/// number of `<` to match `>` in sql like `struct<v1 struct<v2 int>>`.
angle_brackets_num: i32,
/// It's important that already in named Array or not. so use this field check in or not.
/// Consider 0 is you're not in named Array. if more than 0 is you're in named Array
array_depth: usize,
/// We cannot know current array should be keep named or not, so by using this field store
/// every depth of array that should be keep named or not.
array_named_stack: Vec<bool>,
}

impl Parser {
Expand All @@ -195,8 +189,6 @@ impl Parser {
tokens,
index: 0,
angle_brackets_num: 0,
array_depth: 0,
array_named_stack: Vec::new(),
}
}

Expand Down Expand Up @@ -312,25 +304,6 @@ impl Parser {
Ok(Statement::Analyze { table_name })
}

/// Check is enter array expression.
pub fn peek_array_depth(&self) -> usize {
self.array_depth
}

/// When enter specify ARRAY prefix expression.
pub fn increase_array_depth(&mut self, num: usize) {
self.array_depth += num;
}

/// When exit specify ARRAY prefix expression.
pub fn decrease_array_depth(&mut self, num: usize) {
self.array_depth -= num;
}

pub fn is_in_array(&self) -> bool {
self.peek_array_depth() > 0
}

/// Tries to parse a wildcard expression. If it is not a wildcard, parses an expression.
///
/// A wildcard expression either means:
Expand Down Expand Up @@ -596,17 +569,14 @@ impl Parser {
expr: Box::new(self.parse_subexpr(Precedence::UnaryNot)?),
}),
Keyword::ROW => self.parse_row_expr(),
Keyword::ARRAY if self.peek_token() == Token::LBracket => {
self.expect_token(&Token::LBracket)?;
self.parse_array_expr(true)
}
Keyword::ARRAY if self.peek_token() == Token::LParen => {
// similar to `exists(subquery)`
self.expect_token(&Token::LParen)?;
let exists_node = Expr::ArraySubquery(Box::new(self.parse_query()?));
self.expect_token(&Token::RParen)?;
Ok(exists_node)
}
Keyword::ARRAY if self.peek_token() == Token::LBracket => self.parse_array_expr(),
// `LEFT` and `RIGHT` are reserved as identifier but okay as function
Keyword::LEFT | Keyword::RIGHT => {
self.parse_function(ObjectName(vec![w.to_ident()?]))
Expand Down Expand Up @@ -669,8 +639,6 @@ impl Parser {
},
}, // End of Token::Word

Token::LBracket if self.is_in_array() => self.parse_array_expr(false),

tok @ Token::Minus | tok @ Token::Plus => {
let op = if tok == Token::Plus {
UnaryOperator::Plus
Expand Down Expand Up @@ -1242,46 +1210,50 @@ impl Parser {
}

/// Parses an array expression `[ex1, ex2, ..]`
/// if `named` is `true`, came from an expression like `ARRAY[ex1, ex2]`
pub fn parse_array_expr(&mut self, named: bool) -> Result<Expr, ParserError> {
self.increase_array_depth(1);
if self.array_named_stack.len() < self.peek_array_depth() {
self.array_named_stack.push(named);
} else if let Err(parse_err) = self.check_same_named_array(named) {
Err(parse_err)?
}

if self.peek_token() == Token::RBracket {
let _ = self.next_token(); // consume ]
self.decrease_array_depth(1);
Ok(Expr::Array(Array {
elem: vec![],
named,
}))
} else {
let exprs = self.parse_comma_separated(Parser::parse_expr)?;
self.expect_token(&Token::RBracket)?;
if self.array_named_stack.len() > self.peek_array_depth() {
self.array_named_stack.pop();
}
self.decrease_array_depth(1);
Ok(Expr::Array(Array { elem: exprs, named }))
}
pub fn parse_array_expr(&mut self) -> Result<Expr, ParserError> {
let mut expected_depth = None;
let exprs = self.parse_array_inner(0, &mut expected_depth)?;
Ok(Expr::Array(Array {
elem: exprs,
// Top-level array is named.
named: true,
}))
}

fn check_same_named_array(&mut self, current_named: bool) -> Result<(), ParserError> {
let previous_named = self.array_named_stack.last().unwrap();
if current_named != *previous_named {
// for '['
self.prev_token();
if current_named {
// for keyword 'array'
self.prev_token();
}
parser_err!(format!("syntax error at or near {}", self.peek_token()))?
fn parse_array_inner(
&mut self,
depth: usize,
expected_depth: &mut Option<usize>,
) -> Result<Vec<Expr>, ParserError> {
self.expect_token(&Token::LBracket)?;
if let Some(expected_depth) = *expected_depth
&& depth > expected_depth
{
return self.expected("]", self.peek_token());
}
let exprs = if self.peek_token() == Token::LBracket {
self.parse_comma_separated(|parser| {
let exprs = parser.parse_array_inner(depth + 1, expected_depth)?;
Ok(Expr::Array(Array {
elem: exprs,
named: false,
}))
})?
} else {
Ok(())
}
if let Some(expected_depth) = *expected_depth {
if depth < expected_depth {
return self.expected("[", self.peek_token());
}
} else {
*expected_depth = Some(depth);
}
if self.consume_token(&Token::RBracket) {
return Ok(vec![]);
}
self.parse_comma_separated(Self::parse_expr)?
};
self.expect_token(&Token::RBracket)?;
Ok(exprs)
}

// This function parses date/time fields for interval qualifiers.
Expand Down
32 changes: 5 additions & 27 deletions src/sqlparser/tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,41 +1119,19 @@ fn parse_array() {
);

let sql = "SELECT ARRAY[ARRAY[1, 2], [3, 4]]";
assert_eq!(
parse_sql_statements(sql),
Err(ParserError::ParserError(
"syntax error at or near [ at line:1, column:28".to_string()
))
);
assert!(parse_sql_statements(sql).is_err());

let sql = "SELECT ARRAY[ARRAY[], []]";
assert_eq!(
parse_sql_statements(sql),
Err(ParserError::ParserError(
"syntax error at or near [ at line:1, column:24".to_string()
))
);
assert!(parse_sql_statements(sql).is_err());

let sql = "SELECT ARRAY[[1, 2], ARRAY[3, 4]]";
assert_eq!(
parse_sql_statements(sql),
Err(ParserError::ParserError(
"syntax error at or near ARRAY at line:1, column:27".to_string()
))
);
assert!(parse_sql_statements(sql).is_err());

let sql = "SELECT ARRAY[[], ARRAY[]]";
assert_eq!(
parse_sql_statements(sql),
Err(ParserError::ParserError(
"syntax error at or near ARRAY at line:1, column:23".to_string()
))
);
assert!(parse_sql_statements(sql).is_err());

let sql = "SELECT [[1, 2], [3, 4]]";
let res = parse_sql_statements(sql);
let err_msg = "Expected an expression:, found: [";
assert!(format!("{}", res.unwrap_err()).contains(err_msg));
assert!(parse_sql_statements(sql).is_err());
}

#[test]
Expand Down
38 changes: 38 additions & 0 deletions src/sqlparser/tests/testdata/array.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,41 @@
formatted_sql: SELECT (CAST(ARRAY[ARRAY[2, 3]] AS INT[][]))[1][2]
- input: SELECT ARRAY[]
formatted_sql: SELECT ARRAY[]
- input: SELECT ARRAY[[1,2],[3,4]]
formatted_sql: SELECT ARRAY[[1, 2], [3, 4]]
- input: SELECT ARRAY[ARRAY[1,2],ARRAY[3,4]]
formatted_sql: SELECT ARRAY[ARRAY[1, 2], ARRAY[3, 4]]
- input: SELECT ARRAY[[],[]]
formatted_sql: SELECT ARRAY[[], []]
- input: SELECT ARRAY[ARRAY[],[]]
error_msg: |-
sql parser error: Expected an expression:, found: [ at line:1, column:23
Near "SELECT ARRAY[ARRAY[],["
- input: SELECT ARRAY[[],ARRAY[]]
error_msg: |-
sql parser error: Expected [, found: ARRAY at line:1, column:22
Near "SELECT ARRAY[[],"
- input: SELECT ARRAY[[1,2],3]
error_msg: |-
sql parser error: Expected [, found: 3 at line:1, column:21
Near "SELECT ARRAY[[1,2],"
- input: SELECT ARRAY[1,[2,3]]
error_msg: |-
sql parser error: Expected an expression:, found: [ at line:1, column:17
Near "SELECT ARRAY[1,["
- input: SELECT ARRAY[ARRAY[1,2],[3,4]]
error_msg: |-
sql parser error: Expected an expression:, found: [ at line:1, column:26
Near "ARRAY[ARRAY[1,2],["
- input: SELECT ARRAY[[1,2],ARRAY[3,4]]
error_msg: |-
sql parser error: Expected [, found: ARRAY at line:1, column:25
Near "SELECT ARRAY[[1,2],"
- input: SELECT ARRAY[[1,2],[3] || [4]]
error_msg: |-
sql parser error: Expected ], found: || at line:1, column:25
Near "[[1,2],[3]"
- input: SELECT [1,2]
error_msg: |-
sql parser error: Expected an expression:, found: [ at line:1, column:9
Near "SELECT ["

0 comments on commit d8943fa

Please sign in to comment.