Skip to content

Commit

Permalink
builtins: fix crdb_internal.hide_sql_constants array overload
Browse files Browse the repository at this point in the history
Previously, erroring on parsing a stmt provided in
one of the array elements to crdb_internal.hide_sql_constants
would result in an error. This commit ensures that
the empty string is returned for an unparseable stmt.

Epic: none

Release note: None
  • Loading branch information
xinhaoz committed Mar 1, 2023
1 parent 46b1afa commit 17f635d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/builtin_function
Original file line number Diff line number Diff line change
Expand Up @@ -3732,9 +3732,9 @@ SELECT crdb_internal.hide_sql_constants('select _, _, _')
SELECT _, _, _

query T
SELECT crdb_internal.hide_sql_constants(ARRAY('select 1', NULL, 'select ''hello''', ''))
SELECT crdb_internal.hide_sql_constants(ARRAY('select 1', NULL, 'select ''hello''', '', 'not a sql stmt'))
----
{"SELECT _",NULL,"SELECT '_'",""}
{"SELECT _",NULL,"SELECT '_'","",""}

query T
SELECT crdb_internal.hide_sql_constants('SELECT ''yes'' IN (''no'', ''maybe'', ''yes'')')
Expand Down
7 changes: 3 additions & 4 deletions pkg/sql/sem/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -7746,11 +7746,10 @@ expires until the statement bundle is collected`,

if len(sql) != 0 {
parsed, err := parser.ParseOne(sql)
if err != nil {
return tree.NewDString(sqlNoConstants), nil //nolint:returnerrcheck
// Leave result as empty string on parsing error.
if err == nil {
sqlNoConstants = tree.AsStringWithFlags(parsed.AST, tree.FmtHideConstants)
}

sqlNoConstants = tree.AsStringWithFlags(parsed.AST, tree.FmtHideConstants)
}

if err := result.Append(tree.NewDString(sqlNoConstants)); err != nil {
Expand Down

0 comments on commit 17f635d

Please sign in to comment.