Skip to content

Commit

Permalink
feat(query): new implementation of analyze table (#14725)
Browse files Browse the repository at this point in the history
* update

* update

* update

* update

* update

* update

* update

* update

* update tests

* update tests

* update
  • Loading branch information
sundy-li authored Feb 27, 2024
1 parent 42db3ac commit d164a00
Show file tree
Hide file tree
Showing 45 changed files with 1,156 additions and 522 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/query/ast/src/ast/format/ast_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2925,6 +2925,7 @@ impl<'ast> Visitor<'ast> for AstFormatVisitor {
table,
alias,
travel_point,
since_point,
pivot,
unpivot,
} => {
Expand Down Expand Up @@ -2955,6 +2956,11 @@ impl<'ast> Visitor<'ast> for AstFormatVisitor {
self.visit_time_travel_point(travel_point);
children.push(self.children.pop().unwrap());
}

if let Some(travel_point) = since_point {
self.visit_time_travel_point(travel_point);
children.push(self.children.pop().unwrap());
}
let format_ctx = if let Some(alias) = alias {
AstFormatContext::with_children_alias(
name,
Expand Down
8 changes: 8 additions & 0 deletions src/query/ast/src/ast/format/syntax/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ pub(crate) fn pretty_table(table: TableReference) -> RcDoc<'static> {
table,
alias,
travel_point,
since_point,
pivot,
unpivot,
} => if let Some(catalog) = catalog {
Expand Down Expand Up @@ -350,6 +351,13 @@ pub(crate) fn pretty_table(table: TableReference) -> RcDoc<'static> {
} else {
RcDoc::nil()
})
.append(if let Some(TimeTravelPoint::Snapshot(sid)) = since_point {
RcDoc::text(format!(" SINCE (SNAPSHOT => {sid})"))
} else if let Some(TimeTravelPoint::Timestamp(ts)) = since_point {
RcDoc::text(format!(" SINCE (TIMESTAMP => {ts})"))
} else {
RcDoc::nil()
})
.append(if let Some(alias) = alias {
RcDoc::text(format!(" AS {alias}"))
} else {
Expand Down
10 changes: 10 additions & 0 deletions src/query/ast/src/ast/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ pub enum TableReference {
table: Identifier,
alias: Option<TableAlias>,
travel_point: Option<TimeTravelPoint>,
since_point: Option<TimeTravelPoint>,
pivot: Option<Box<Pivot>>,
unpivot: Option<Box<Unpivot>>,
},
Expand Down Expand Up @@ -454,6 +455,7 @@ impl Display for TableReference {
table,
alias,
travel_point,
since_point,
pivot,
unpivot,
} => {
Expand All @@ -470,6 +472,14 @@ impl Display for TableReference {
write!(f, " AT (TIMESTAMP => {ts})")?;
}

if let Some(TimeTravelPoint::Snapshot(sid)) = since_point {
write!(f, " SINCE (SNAPSHOT => {sid})")?;
}

if let Some(TimeTravelPoint::Timestamp(ts)) = since_point {
write!(f, " SINCE (TIMESTAMP => {ts})")?;
}

if let Some(alias) = alias {
write!(f, " AS {alias}")?;
}
Expand Down
1 change: 1 addition & 0 deletions src/query/ast/src/ast/statements/merge_into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ impl MergeSource {
table: table.clone(),
alias: alias.clone(),
travel_point: None,
since_point: None,
pivot: None,
unpivot: None,
},
Expand Down
8 changes: 6 additions & 2 deletions src/query/ast/src/parser/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ pub enum TableReferenceElement {
table: Identifier,
alias: Option<TableAlias>,
travel_point: Option<TimeTravelPoint>,
since_point: Option<TimeTravelPoint>,
pivot: Option<Box<Pivot>>,
unpivot: Option<Box<Unpivot>>,
},
Expand Down Expand Up @@ -685,15 +686,16 @@ pub fn table_reference_element(i: Input) -> IResult<WithSpan<TableReferenceEleme
);
let aliased_table = map(
rule! {
#dot_separated_idents_1_to_3 ~ (AT ~ ^#travel_point)? ~ #table_alias? ~ #pivot? ~ #unpivot?
#dot_separated_idents_1_to_3 ~ (AT ~ ^#travel_point)? ~ (SINCE ~ ^#travel_point)? ~ #table_alias? ~ #pivot? ~ #unpivot?
},
|((catalog, database, table), travel_point_opt, alias, pivot, unpivot)| {
|((catalog, database, table), travel_point_opt, since_point_opt, alias, pivot, unpivot)| {
TableReferenceElement::Table {
catalog,
database,
table,
alias,
travel_point: travel_point_opt.map(|p| p.1),
since_point: since_point_opt.map(|p| p.1),
pivot: pivot.map(Box::new),
unpivot: unpivot.map(Box::new),
}
Expand Down Expand Up @@ -804,6 +806,7 @@ impl<'a, I: Iterator<Item = WithSpan<'a, TableReferenceElement>>> PrattParser<I>
table,
alias,
travel_point,
since_point,
pivot,
unpivot,
} => TableReference::Table {
Expand All @@ -813,6 +816,7 @@ impl<'a, I: Iterator<Item = WithSpan<'a, TableReferenceElement>>> PrattParser<I>
table,
alias,
travel_point,
since_point,
pivot,
unpivot,
},
Expand Down
2 changes: 2 additions & 0 deletions src/query/ast/src/parser/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3471,6 +3471,7 @@ pub fn table_reference_with_alias(i: Input) -> IResult<TableReference> {
columns: vec![],
}),
travel_point: None,
since_point: None,
pivot: None,
unpivot: None,
},
Expand All @@ -3489,6 +3490,7 @@ pub fn table_reference_only(i: Input) -> IResult<TableReference> {
table,
alias: None,
travel_point: None,
since_point: None,
pivot: None,
unpivot: None,
},
Expand Down
2 changes: 2 additions & 0 deletions src/query/ast/src/parser/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,8 @@ pub enum TokenKind {
SHA256_PASSWORD,
#[token("SHOW", ignore(ascii_case))]
SHOW,
#[token("SINCE", ignore(ascii_case))]
SINCE,
#[token("SIGNED", ignore(ascii_case))]
SIGNED,
#[token("SINGLE", ignore(ascii_case))]
Expand Down
Loading

0 comments on commit d164a00

Please sign in to comment.