Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject FOR TIMESTAMP AS OF ... with future temporal value #12720

Merged
merged 2 commits into from
Jun 10, 2022

Conversation

findepi
Copy link
Member

@findepi findepi commented Jun 7, 2022

The time travel FOR ... AS OF ... syntax is meant to return consistent
state of a table. The future state isn't known, so it cannot be
consistently queried. Reject such queries on the engine side so that
connectors do not have to deal with this complexity.

@findepi
Copy link
Member Author

findepi commented Jun 7, 2022

Currently, based on #12719

@@ -4578,6 +4582,14 @@ private void validateVersionPointer(QualifiedObjectName tableName, QueryPeriod q
if (pointer == null) {
throw semanticException(INVALID_ARGUMENTS, queryPeriod, "Pointer value cannot be NULL");
}
long pointerTimestampMillis = unpackMillisUtc((long) coerce(type, pointer, createTimestampWithTimeZoneType(3)));
if (pointerTimestampMillis >= System.currentTimeMillis()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Compare with session start time.
This will make AS OF now() queries fail deterministically. (Otherwise they will work sometimes, but not always)

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed.

However, i decided to do the math with maximum precision. The AS OF now() has millisecond precision and thus may be rounded to a milli that's sub-milli before the session start, thus may or may not be rejected.
The AS OF now(9) (or higher precision) will deterministically be rejected, since session start time is measured with nano precision (Instant).

@findepi
Copy link
Member Author

findepi commented Jun 9, 2022

rebasing after #12719 merged.

@findepi
Copy link
Member Author

findepi commented Jun 9, 2022

cc @martint and @electrum.

`StatementAnalyzer` sporadically needs to coerce a value to a desired
type. Extract the existing code into a utility method.
@findepi findepi force-pushed the findepi/as-of-future branch from 6d74fb9 to 1946182 Compare June 9, 2022 10:02
The time travel `FOR ... AS OF ...` syntax is meant to return consistent
state of a table. The future state isn't known, so it cannot be
consistently queried. Reject such queries on the engine side so that
connectors do not have to deal with this complexity.
@findepi findepi force-pushed the findepi/as-of-future branch from 1946182 to 02a63bf Compare June 9, 2022 10:24
@findepi findepi merged commit d0d5c6b into trinodb:master Jun 10, 2022
@findepi findepi deleted the findepi/as-of-future branch June 10, 2022 08:31
@github-actions github-actions bot added this to the 386 milestone Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants