Skip to content

Commit c1e50fb

Browse files
committed
make WrapFunction not panic
1 parent 123b9a6 commit c1e50fb

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

parser_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ import (
88
)
99

1010
func TestParser(t *testing.T) {
11-
_, err := parser.Parse("SELECT 1")
11+
_, err := parser.Parse("CREATE TABLE t (a TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP)")
1212
require.NoError(t, err)
1313
}

pkg/sql/sem/tree/function_name.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/cockroachdb/cockroachdb-parser/pkg/sql/pgwire/pgerror"
2020
"github.com/cockroachdb/cockroachdb-parser/pkg/sql/sem/catconstants"
2121
"github.com/cockroachdb/errors"
22-
"github.com/cockroachdb/redact"
2322
"github.com/lib/pq/oid"
2423
)
2524

@@ -144,7 +143,7 @@ type CustomBuiltinFunctionWrapper interface {
144143
func WrapFunction(n string) ResolvableFunctionReference {
145144
fd, ok := FunDefs[n]
146145
if !ok {
147-
panic(errors.AssertionFailedf("function %s() not defined", redact.Safe(n)))
146+
return ResolvableFunctionReference{&FunctionDefinition{Name: n}}
148147
}
149148
return ResolvableFunctionReference{fd}
150149
}

snapshot.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ rm pkg/sql/lexbase/.gitignore pkg/sql/parser/.gitignore
4242
find pkg -type f -name '*_test.go' | xargs rm
4343
# sed replace any instances of cockroachdb
4444
find pkg -type f -name '*.go' | xargs sed -i '' -e 's_github\.com/cockroachdb/cockroach/_github.com/cockroachdb/cockroachdb-parser/_g'
45+
# replace WrapFunction
46+
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
47+
goimports -w pkg/sql/sem/tree/function_name.go
4548

4649
echo "Cleaning up go and testing everything works"
4750
go mod tidy

0 commit comments

Comments
 (0)