Skip to content

Commit

Permalink
make WrapFunction not panic
Browse files Browse the repository at this point in the history
  • Loading branch information
otan committed Oct 24, 2022
1 parent 123b9a6 commit c1e50fb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import (
)

func TestParser(t *testing.T) {
_, err := parser.Parse("SELECT 1")
_, err := parser.Parse("CREATE TABLE t (a TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP)")
require.NoError(t, err)
}
3 changes: 1 addition & 2 deletions pkg/sql/sem/tree/function_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/cockroachdb/cockroachdb-parser/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroachdb-parser/pkg/sql/sem/catconstants"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/redact"
"github.com/lib/pq/oid"
)

Expand Down Expand Up @@ -144,7 +143,7 @@ type CustomBuiltinFunctionWrapper interface {
func WrapFunction(n string) ResolvableFunctionReference {
fd, ok := FunDefs[n]
if !ok {
panic(errors.AssertionFailedf("function %s() not defined", redact.Safe(n)))
return ResolvableFunctionReference{&FunctionDefinition{Name: n}}
}
return ResolvableFunctionReference{fd}
}
Expand Down
3 changes: 3 additions & 0 deletions snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ rm pkg/sql/lexbase/.gitignore pkg/sql/parser/.gitignore
find pkg -type f -name '*_test.go' | xargs rm
# sed replace any instances of cockroachdb
find pkg -type f -name '*.go' | xargs sed -i '' -e 's_github\.com/cockroachdb/cockroach/_github.com/cockroachdb/cockroachdb-parser/_g'
# replace WrapFunction
sed -i '' -e 's_panic(errors.AssertionFailedf("function %s() not defined", redact.Safe(n)))_return ResolvableFunctionReference{\&FunctionDefinition{Name: n}}_g' pkg/sql/sem/tree/function_name.go
goimports -w pkg/sql/sem/tree/function_name.go

echo "Cleaning up go and testing everything works"
go mod tidy
Expand Down

0 comments on commit c1e50fb

Please sign in to comment.