Skip to content

Conversation

@gruuya
Copy link
Contributor

@gruuya gruuya commented Aug 14, 2023

Also moved the existing and the new time travel test into a separate file.

Closes #170.

@gruuya gruuya requested a review from mildbyte August 14, 2023 11:35
Comment on lines +990 to +997
// Create a mutable clone of the statement so that we can rewrite table names if we encounter
// time travel syntax.
// Alternatively, this could be done without the `mut`, except then we'd need to construct
// and return a new `DFStatement` after the rewrite. In case of `Statement::Query` this is
// straight-forward as that enum variant contains a struct, however `Statement::Insert` and
// `Statement::CreateTable` wrap dozens of fields in curly braces, and we'd need to capture
// and re-populate each of those, so it would be very verbose.
// TODO: If `sqlparser-rs` encapsulates these fields inside a struct at some point remove
// the mut and go with @ capture and de-structuring to pass along other fields unchanged.
let mut stmt = statement.clone();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already cloned the statement so that wont incur a time penalty. In theory the mut might, but I think it's negligible if any, given that it's local to a single function.

The alternative I mention is to have things as before and then capture and re-create a enum value with all the fields explicitly (since @ capture doesn't work in this case), i.e. https://github.com/sqlparser-rs/sqlparser-rs/blob/main/src/ast/mod.rs#L1178-L1198 for insert (even more verbose for create table).

@gruuya gruuya force-pushed the write-time-travel branch from 1706983 to fe5bc5d Compare August 14, 2023 13:41
@gruuya gruuya force-pushed the write-time-travel branch from fe5bc5d to 016f7b6 Compare August 14, 2023 13:54
@gruuya gruuya merged commit 4bd1e84 into main Aug 15, 2023
@gruuya gruuya deleted the write-time-travel branch August 15, 2023 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend support for table time travel syntax to write statements

3 participants