Skip to content

Commit

Permalink
workload/schemachange: detect expected errors for CTAS
Browse files Browse the repository at this point in the history
Previously, when a CTAS statement was executed we did
not correctly detect if the SELECT portion could fail
on generated columns. This could lead to test failures,
even though the observed errors are correct. To address,
this patch will execute the select independently to
validate any generated column errors.

Release note: None
  • Loading branch information
fqazi committed Sep 20, 2022
1 parent ff30d4b commit e1491de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/workload/schemachange/error_screening.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,14 +560,20 @@ SELECT count(*) > 0
return nil
}

func getValidGenerationErrors() errorCodeSet {
return errorCodeSet{
pgcode.NumericValueOutOfRange: true,
pgcode.FloatingPointException: true,
pgcode.InvalidTextRepresentation: true,
}
}

// isValidGenerationError these codes can be observed when evaluating values
// for generated expressions. These are errors are not ignored, but added into
// the expected set of errors.
func isValidGenerationError(code string) bool {
pgCode := pgcode.MakeCode(code)
return pgCode == pgcode.NumericValueOutOfRange ||
pgCode == pgcode.FloatingPointException ||
pgCode == pgcode.InvalidTextRepresentation
return getValidGenerationErrors().contains(pgCode)
}

// validateGeneratedExpressionsForInsert goes through generated expressions and
Expand Down
8 changes: 8 additions & 0 deletions pkg/workload/schemachange/operation_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,14 @@ func (og *operationGenerator) createTableAs(ctx context.Context, tx pgx.Tx) (*op
{code: pgcode.DuplicateColumn, condition: duplicateColumns},
}.add(opStmt.expectedExecErrors)

// Confirm the select itself doesn't run into any column generation errors,
// by executing it independently first until we add validation when adding
// generated columns. See issue: #81698?, which will allow us to remove this
// logic in the future.
if opStmt.expectedExecErrors.empty() {
opStmt.potentialExecErrors.merge(getValidGenerationErrors())
}

opStmt.sql = fmt.Sprintf(`CREATE TABLE %s AS %s FETCH FIRST %d ROWS ONLY`,
destTableName, selectStatement.String(), MaxRowsToConsume)
return opStmt, nil
Expand Down

0 comments on commit e1491de

Please sign in to comment.