-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
ttl: validate ttl_expiration_expression is a TIMESTAMPTZ #86269
Conversation
cba7448
to
d663614
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks for doing this!
Reviewed 1 of 11 files at r1.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @ecwall and @rafiss)
pkg/sql/alter_table.go
line 497 at r1 (raw file):
t.Column, ), "use ALTER TABLE %s RESET (ttl) or ALTER TABLE %s SET (ttl_expiration_expression = ...) instead",
need to repeat the argument or use a positional format specifier
pkg/sql/catalog/schemaexpr/expr.go
line 461 at r1 (raw file):
// ValidateTTLExpirationExpressionHasNoDependents verifies that the // ttl_expiration_expression, if any, does not reference the given column. func ValidateTTLExpirationExpressionHasNoDependents(
this is a weird name given you're validating that the TTLExpression
does not depend on the column. Maybe this should be ValidateTTLExpressionDoesNotDependOnColumn
?
pkg/sql/catalog/tabledesc/validate.go
line 786 at r1 (raw file):
}) vea.Report(ValidateRowLevelTTL(desc.GetRowLevelTTL()))
Any reason not to add desc
as the argument to ValidateRowLevelTTL
and call this or add the logic there? It looked to me like all the callers have a descriptor handy.
Code quote:
vea.Report(ValidateRowLevelTTL(desc.GetRowLevelTTL()))
if desc.HasRowLevelTTL() {
pkg/sql/schemachanger/scbuild/builder_state.go
line 473 at r1 (raw file):
panic(errors.AssertionFailedf("failed to get descriptor for table %d", tableID)) } tableDesc, ok := cachedDesc.desc.(catalog.TableDescriptor)
can you revise this error to say that it's not a table and print the type with %T
or DescriptorType()
Code quote:
tableDesc, ok := cachedDesc.desc.(catalog.TableDescriptor)
if !ok {
panic(errors.AssertionFailedf("failed to get descriptor for table %d", tableID))
pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go
line 78 at r1 (raw file):
}) if rowLevelTTL != nil {
nit: invert the condition and early return?
pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go
line 97 at r1 (raw file):
} wrappedExpr := b.WrapExpression(tbl.TableID, expr) for _, referencedCol := range wrappedExpr.ReferencedColumnIDs {
if descpb.ColumnIDs(wrappedExpr.ReferencedColumnIDs).Contains(colToDrop.ColumnID) {
?
Code quote:
for _, referencedCol := range wrappedExpr.ReferencedColumnIDs {
if referencedCol == colToDrop.ColumnID {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner and @ecwall)
pkg/sql/alter_table.go
line 497 at r1 (raw file):
Previously, ajwerner wrote…
need to repeat the argument or use a positional format specifier
fixing
pkg/sql/catalog/schemaexpr/expr.go
line 461 at r1 (raw file):
Previously, ajwerner wrote…
this is a weird name given you're validating that the
TTLExpression
does not depend on the column. Maybe this should beValidateTTLExpressionDoesNotDependOnColumn
?
good call
pkg/sql/catalog/tabledesc/validate.go
line 786 at r1 (raw file):
Previously, ajwerner wrote…
Any reason not to add
desc
as the argument toValidateRowLevelTTL
and call this or add the logic there? It looked to me like all the callers have a descriptor handy.
i attempted to explain in the comment below. the reason is that the usage at
if err := tabledesc.ValidateRowLevelTTL(ttl); err != nil { |
ttl_expiration_expression
param is configured as part of CREATE TABLE
pkg/sql/schemachanger/scbuild/builder_state.go
line 473 at r1 (raw file):
Previously, ajwerner wrote…
can you revise this error to say that it's not a table and print the type with
%T
orDescriptorType()
fixing
pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go
line 78 at r1 (raw file):
Previously, ajwerner wrote…
nit: invert the condition and early return?
fixing
pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go
line 97 at r1 (raw file):
Previously, ajwerner wrote…
if descpb.ColumnIDs(wrappedExpr.ReferencedColumnIDs).Contains(colToDrop.ColumnID) {
?
fixing
d663614
to
08e2247
Compare
08e2247
to
2747b6f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just needs a rewrite of pkg/sql/schemachanger/scbuild
Reviewed 5 of 11 files at r1, 5 of 8 files at r2, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @ajwerner, @ecwall, and @rafiss)
pkg/sql/alter_table.go
line 1997 at r2 (raw file):
} // validate ttl_expiration_expression
nit: fix up this comment.
I appreciate that this PR includes significant coverage in the form of logic tests, still, this seems like a good place to add all of the missing unit test cases in |
2747b6f
to
7737e82
Compare
@postamar i've added a separate commit that focuses on TTL validation testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM
TFTRs! bors r=ajwerner,postamar |
Build failed (retrying...): |
Build failed (retrying...): |
Build failed (retrying...): |
Build failed (retrying...): |
Build failed: |
Previously the only validation is that the expression is valid SQL syntax. Now the expression must also be a TIMESTAMPTZ which will prevent errors in the TTL job when comparing to the cutoff. Validation is also added so that a column cannot be dropped or altered in type if it is used in the TTL expression. If the column is renamed, the expression is automatically updated. Release note: None Release justification: high priority fix to new functionality
This moves more of the TTL validation into ttl.go, and outside of the CrossTableReferences validation. Tests are added for all the TTL validation steps. Release justification: test only change and small refactor Release note: None
7737e82
to
5b5543d
Compare
bors r=ajwerner,postamar |
Build succeeded: |
fixes #86410
fixes #85531
fixes #84725
Previously the only validation is that the expression is valid SQL
syntax. Now the expression must also be a TIMESTAMPTZ which will
prevent errors in the TTL job when comparing to the cutoff.
Validation is also added so that a column cannot be dropped or altered
in type if it is used in the TTL expression. If the column is renamed, the
expression is automatically updated.
Release note: None
Release justification: low risk changes to validation