From b13876956e6913db92114dec7774dd9c3512520b Mon Sep 17 00:00:00 2001 From: Marcus Gartner Date: Wed, 20 Jul 2022 10:31:01 -0400 Subject: [PATCH] opt: set opt tester search path to empty `OptTester` now sets its `SemaContext`'s `SearchPath` to `EmptySearchPath`, instead of `nil`, to avoid nil pointer exceptions when resolving unknown functions. Release note: None --- pkg/sql/opt/optbuilder/testdata/udf | 4 ++++ pkg/sql/opt/testutils/opttester/opt_tester.go | 1 + 2 files changed, 5 insertions(+) create mode 100644 pkg/sql/opt/optbuilder/testdata/udf diff --git a/pkg/sql/opt/optbuilder/testdata/udf b/pkg/sql/opt/optbuilder/testdata/udf new file mode 100644 index 000000000000..7d3ca7b03f86 --- /dev/null +++ b/pkg/sql/opt/optbuilder/testdata/udf @@ -0,0 +1,4 @@ +build +SELECT foo() +---- +error (42883): unknown function: foo() diff --git a/pkg/sql/opt/testutils/opttester/opt_tester.go b/pkg/sql/opt/testutils/opttester/opt_tester.go index c9af74dd8d31..9fec4efa2ce4 100644 --- a/pkg/sql/opt/testutils/opttester/opt_tester.go +++ b/pkg/sql/opt/testutils/opttester/opt_tester.go @@ -274,6 +274,7 @@ func New(catalog cat.Catalog, sql string) *OptTester { semaCtx: tree.MakeSemaContext(), evalCtx: eval.MakeTestingEvalContext(cluster.MakeTestingClusterSettings()), } + ot.semaCtx.SearchPath = tree.EmptySearchPath ot.semaCtx.FunctionResolver = ot.catalog // To allow opttester tests to use now(), we hardcode a preset transaction // time. May 10, 2017 is a historic day: the release date of CockroachDB 1.0.