diff --git a/pkg/BUILD.bazel b/pkg/BUILD.bazel index c8320fc23196..238b77a13235 100644 --- a/pkg/BUILD.bazel +++ b/pkg/BUILD.bazel @@ -359,7 +359,6 @@ ALL_TESTS = [ "//pkg/sql/logictest/tests/fakedist:fakedist_test", "//pkg/sql/logictest/tests/local-mixed-21.2-22.1:local-mixed-21_2-22_1_test", "//pkg/sql/logictest/tests/local-mixed-22.1-22.2:local-mixed-22_1-22_2_test", - "//pkg/sql/logictest/tests/local-udf:local-udf_test", "//pkg/sql/logictest/tests/local-v1.1-at-v1.0-noupgrade:local-v1_1-at-v1_0-noupgrade_test", "//pkg/sql/logictest/tests/local-vec-off:local-vec-off_test", "//pkg/sql/logictest/tests/local:local_test", @@ -376,7 +375,6 @@ ALL_TESTS = [ "//pkg/sql/opt/exec/execbuilder/tests/fakedist-disk:fakedist-disk_test", "//pkg/sql/opt/exec/execbuilder/tests/fakedist-vec-off:fakedist-vec-off_test", "//pkg/sql/opt/exec/execbuilder/tests/fakedist:fakedist_test", - "//pkg/sql/opt/exec/execbuilder/tests/local-udf:local-udf_test", "//pkg/sql/opt/exec/execbuilder/tests/local-vec-off:local-vec-off_test", "//pkg/sql/opt/exec/execbuilder/tests/local:local_test", "//pkg/sql/opt/exec/execbuilder:execbuilder_test", @@ -1450,7 +1448,6 @@ GO_TARGETS = [ "//pkg/sql/logictest/tests/fakedist:fakedist_test", "//pkg/sql/logictest/tests/local-mixed-21.2-22.1:local-mixed-21_2-22_1_test", "//pkg/sql/logictest/tests/local-mixed-22.1-22.2:local-mixed-22_1-22_2_test", - "//pkg/sql/logictest/tests/local-udf:local-udf_test", "//pkg/sql/logictest/tests/local-v1.1-at-v1.0-noupgrade:local-v1_1-at-v1_0-noupgrade_test", "//pkg/sql/logictest/tests/local-vec-off:local-vec-off_test", "//pkg/sql/logictest/tests/local:local_test", @@ -1476,7 +1473,6 @@ GO_TARGETS = [ "//pkg/sql/opt/exec/execbuilder/tests/fakedist-disk:fakedist-disk_test", "//pkg/sql/opt/exec/execbuilder/tests/fakedist-vec-off:fakedist-vec-off_test", "//pkg/sql/opt/exec/execbuilder/tests/fakedist:fakedist_test", - "//pkg/sql/opt/exec/execbuilder/tests/local-udf:local-udf_test", "//pkg/sql/opt/exec/execbuilder/tests/local-vec-off:local-vec-off_test", "//pkg/sql/opt/exec/execbuilder/tests/local:local_test", "//pkg/sql/opt/exec/execbuilder:execbuilder", @@ -2565,7 +2561,6 @@ GET_X_DATA_TARGETS = [ "//pkg/sql/logictest/tests/local:get_x_data", "//pkg/sql/logictest/tests/local-mixed-21.2-22.1:get_x_data", "//pkg/sql/logictest/tests/local-mixed-22.1-22.2:get_x_data", - "//pkg/sql/logictest/tests/local-udf:get_x_data", "//pkg/sql/logictest/tests/local-v1.1-at-v1.0-noupgrade:get_x_data", "//pkg/sql/logictest/tests/local-vec-off:get_x_data", "//pkg/sql/logictest/tests/multiregion-9node-3region-3azs:get_x_data", @@ -2586,7 +2581,6 @@ GET_X_DATA_TARGETS = [ "//pkg/sql/opt/exec/execbuilder/tests/fakedist-disk:get_x_data", "//pkg/sql/opt/exec/execbuilder/tests/fakedist-vec-off:get_x_data", "//pkg/sql/opt/exec/execbuilder/tests/local:get_x_data", - "//pkg/sql/opt/exec/execbuilder/tests/local-udf:get_x_data", "//pkg/sql/opt/exec/execbuilder/tests/local-vec-off:get_x_data", "//pkg/sql/opt/exec/explain:get_x_data", "//pkg/sql/opt/idxconstraint:get_x_data", diff --git a/pkg/ccl/logictestccl/tests/3node-tenant/generated_test.go b/pkg/ccl/logictestccl/tests/3node-tenant/generated_test.go index 0406dbb84292..eb18c16bbe79 100644 --- a/pkg/ccl/logictestccl/tests/3node-tenant/generated_test.go +++ b/pkg/ccl/logictestccl/tests/3node-tenant/generated_test.go @@ -1926,6 +1926,13 @@ func TestTenantLogic_typing( runLogicTest(t, "typing") } +func TestTenantLogic_udf( + t *testing.T, +) { + defer leaktest.AfterTest(t)() + runLogicTest(t, "udf") +} + func TestTenantLogic_union( t *testing.T, ) { diff --git a/pkg/sql/distsql_physical_planner.go b/pkg/sql/distsql_physical_planner.go index e6fc9287070d..306432298241 100644 --- a/pkg/sql/distsql_physical_planner.go +++ b/pkg/sql/distsql_physical_planner.go @@ -270,6 +270,10 @@ func (v *distSQLExprCheckVisitor) VisitPre(expr tree.Expr) (recurse bool, newExp v.err = newQueryNotSupportedErrorf("function %s cannot be executed with distsql", t) return false, expr } + case *tree.RoutineExpr: + // TODO(86310): enable UDFs in DistSQL. + v.err = newQueryNotSupportedErrorf("user-defined routine %s cannot be executed with distsql", t) + return false, expr case *tree.DOid: v.err = newQueryNotSupportedError("OID expressions are not supported by distsql") return false, expr diff --git a/pkg/sql/logictest/logic.go b/pkg/sql/logictest/logic.go index 65a961947ca1..b70f810deae0 100644 --- a/pkg/sql/logictest/logic.go +++ b/pkg/sql/logictest/logic.go @@ -3644,9 +3644,6 @@ SELECT encode(descriptor, 'hex') AS descriptor } func (t *logicTest) maybeDropDatabases() error { - if t.cfg.SkipDropDatabases { - return nil - } var dbNames pq.StringArray if err := t.db.QueryRow( `SELECT array_agg(database_name) FROM [SHOW DATABASES] WHERE database_name NOT IN ('system', 'postgres')`, diff --git a/pkg/sql/logictest/logictestbase/logictestbase.go b/pkg/sql/logictest/logictestbase/logictestbase.go index 202b9dcb9967..cf8808cfe969 100644 --- a/pkg/sql/logictest/logictestbase/logictestbase.go +++ b/pkg/sql/logictest/logictestbase/logictestbase.go @@ -82,12 +82,6 @@ type TestClusterConfig struct { // disableLocalityOptimizedSearch disables the cluster setting // locality_optimized_partitioned_index_scan, which is enabled by default. DisableLocalityOptimizedSearch bool - // SkipDropDatabases allows a configuration to skip dropping of the database. - // This exists to enable development while DROP DATABASE for a feature is - // broken. - // - // TODO(ajwerner,chengxiong-ruan): Remove this before 22.2 is released. - SkipDropDatabases bool // DeclarativeCorpusCollection enables support for collecting corpuses // for the declarative schema changer. DeclarativeCorpusCollection bool @@ -468,16 +462,6 @@ var LogicTestConfigs = []TestClusterConfig{ DisableUpgrade: true, DeclarativeCorpusCollection: true, }, - { - Name: "local-udf", - NumNodes: 1, - // local is the configuration where we run all tests which have bad - // interactions with the default test tenant. - DisableDefaultTestTenant: true, - // Set SkipDropDatabases to true for now to enable development on UDFs. - // TODO(ajwerner,chengxiong-ruan): Remove this before the 22.2 release. - SkipDropDatabases: true, - }, } // ConfigIdx is an index in the above slice. diff --git a/pkg/sql/logictest/testdata/logic_test/udf b/pkg/sql/logictest/testdata/logic_test/udf index a460330f9e7f..fa662480abe7 100644 --- a/pkg/sql/logictest/testdata/logic_test/udf +++ b/pkg/sql/logictest/testdata/logic_test/udf @@ -1,5 +1,3 @@ -# LogicTest: local-udf - statement ok CREATE TABLE ab ( a INT PRIMARY KEY, @@ -1222,8 +1220,9 @@ query TT $test_alter_sc_f_test_sc ) ) -SELECT fn->'id', fn->'parentSchemaId' - FROM fns; +SELECT fn->>'id' AS id, fn->'parentSchemaId' + FROM fns + ORDER BY id; ---- 170 105 171 105 @@ -1254,8 +1253,9 @@ query TT $test_alter_sc_f_test_sc ) ) -SELECT fn->'id', fn->'parentSchemaId' - FROM fns; +SELECT fn->>'id' AS id, fn->'parentSchemaId' + FROM fns + ORDER BY id; ---- 170 105 171 105 @@ -1303,8 +1303,9 @@ query TT $test_alter_sc_f_test_sc ) ) -SELECT fn->'id', fn->'parentSchemaId' - FROM fns; +SELECT fn->>'id' AS id, fn->'parentSchemaId' + FROM fns + ORDER BY id; ---- 170 105 171 172 diff --git a/pkg/sql/logictest/tests/fakedist-disk/generated_test.go b/pkg/sql/logictest/tests/fakedist-disk/generated_test.go index e1763831d1f9..2479f5054d10 100644 --- a/pkg/sql/logictest/tests/fakedist-disk/generated_test.go +++ b/pkg/sql/logictest/tests/fakedist-disk/generated_test.go @@ -1913,6 +1913,13 @@ func TestLogic_typing( runLogicTest(t, "typing") } +func TestLogic_udf( + t *testing.T, +) { + defer leaktest.AfterTest(t)() + runLogicTest(t, "udf") +} + func TestLogic_union( t *testing.T, ) { diff --git a/pkg/sql/logictest/tests/fakedist-vec-off/generated_test.go b/pkg/sql/logictest/tests/fakedist-vec-off/generated_test.go index 07978fc2c415..ed01a5772178 100644 --- a/pkg/sql/logictest/tests/fakedist-vec-off/generated_test.go +++ b/pkg/sql/logictest/tests/fakedist-vec-off/generated_test.go @@ -1913,6 +1913,13 @@ func TestLogic_typing( runLogicTest(t, "typing") } +func TestLogic_udf( + t *testing.T, +) { + defer leaktest.AfterTest(t)() + runLogicTest(t, "udf") +} + func TestLogic_union( t *testing.T, ) { diff --git a/pkg/sql/logictest/tests/fakedist/generated_test.go b/pkg/sql/logictest/tests/fakedist/generated_test.go index da4a2422fc46..4906e5585551 100644 --- a/pkg/sql/logictest/tests/fakedist/generated_test.go +++ b/pkg/sql/logictest/tests/fakedist/generated_test.go @@ -1927,6 +1927,13 @@ func TestLogic_typing( runLogicTest(t, "typing") } +func TestLogic_udf( + t *testing.T, +) { + defer leaktest.AfterTest(t)() + runLogicTest(t, "udf") +} + func TestLogic_union( t *testing.T, ) { diff --git a/pkg/sql/logictest/tests/local-udf/BUILD.bazel b/pkg/sql/logictest/tests/local-udf/BUILD.bazel deleted file mode 100644 index cfc125a38078..000000000000 --- a/pkg/sql/logictest/tests/local-udf/BUILD.bazel +++ /dev/null @@ -1,28 +0,0 @@ -load("//build/bazelutil/unused_checker:unused.bzl", "get_x_data") -load("@io_bazel_rules_go//go:def.bzl", "go_test") - -go_test( - name = "local-udf_test", - size = "enormous", - srcs = ["generated_test.go"], - data = [ - "//c-deps:libgeos", # keep - "//pkg/sql/logictest:testdata", # keep - ], - shard_count = 1, - tags = ["cpu:1"], - deps = [ - "//pkg/build/bazel", - "//pkg/security/securityassets", - "//pkg/security/securitytest", - "//pkg/server", - "//pkg/sql/logictest", - "//pkg/testutils/serverutils", - "//pkg/testutils/skip", - "//pkg/testutils/testcluster", - "//pkg/util/leaktest", - "//pkg/util/randutil", - ], -) - -get_x_data(name = "get_x_data") diff --git a/pkg/sql/logictest/tests/local-udf/generated_test.go b/pkg/sql/logictest/tests/local-udf/generated_test.go deleted file mode 100644 index 1b29026394d2..000000000000 --- a/pkg/sql/logictest/tests/local-udf/generated_test.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2022 The Cockroach Authors. -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.txt. -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0, included in the file -// licenses/APL.txt. - -// Code generated by generate-logictest, DO NOT EDIT. - -package testlocal_udf - -import ( - "os" - "path/filepath" - "testing" - - "github.com/cockroachdb/cockroach/pkg/build/bazel" - "github.com/cockroachdb/cockroach/pkg/security/securityassets" - "github.com/cockroachdb/cockroach/pkg/security/securitytest" - "github.com/cockroachdb/cockroach/pkg/server" - "github.com/cockroachdb/cockroach/pkg/sql/logictest" - "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" - "github.com/cockroachdb/cockroach/pkg/testutils/skip" - "github.com/cockroachdb/cockroach/pkg/testutils/testcluster" - "github.com/cockroachdb/cockroach/pkg/util/leaktest" - "github.com/cockroachdb/cockroach/pkg/util/randutil" -) - -const configIdx = 20 - -var logicTestDir string - -func init() { - if bazel.BuiltWithBazel() { - var err error - logicTestDir, err = bazel.Runfile("pkg/sql/logictest/testdata/logic_test") - if err != nil { - panic(err) - } - } else { - logicTestDir = "../../../../sql/logictest/testdata/logic_test" - } -} - -func TestMain(m *testing.M) { - securityassets.SetLoader(securitytest.EmbeddedAssets) - randutil.SeedForTests() - serverutils.InitTestServerFactory(server.TestServerFactory) - serverutils.InitTestClusterFactory(testcluster.TestClusterFactory) - os.Exit(m.Run()) -} - -func runLogicTest(t *testing.T, file string) { - skip.UnderDeadlock(t, "times out and/or hangs") - logictest.RunLogicTest(t, logictest.TestServerArgs{}, configIdx, filepath.Join(logicTestDir, file)) -} - -// TestLogic_tmp runs any tests that are prefixed with "_", in which a dedicated -// test is not generated for. This allows developers to create and run temporary -// test files that are not checked into the repository, without repeatedly -// regenerating and reverting changes to this file, generated_test.go. -// -// TODO(mgartner): Add file filtering so that individual files can be run, -// instead of all files with the "_" prefix. -func TestLogic_tmp(t *testing.T) { - defer leaktest.AfterTest(t)() - var glob string - glob = filepath.Join(logicTestDir, "_*") - logictest.RunLogicTests(t, logictest.TestServerArgs{}, configIdx, glob) -} - -func TestLogic_udf( - t *testing.T, -) { - defer leaktest.AfterTest(t)() - runLogicTest(t, "udf") -} diff --git a/pkg/sql/logictest/tests/local-vec-off/generated_test.go b/pkg/sql/logictest/tests/local-vec-off/generated_test.go index 3879a14d2f4f..f6791f2bd8c9 100644 --- a/pkg/sql/logictest/tests/local-vec-off/generated_test.go +++ b/pkg/sql/logictest/tests/local-vec-off/generated_test.go @@ -1920,6 +1920,13 @@ func TestLogic_typing( runLogicTest(t, "typing") } +func TestLogic_udf( + t *testing.T, +) { + defer leaktest.AfterTest(t)() + runLogicTest(t, "udf") +} + func TestLogic_union( t *testing.T, ) { diff --git a/pkg/sql/logictest/tests/local/generated_test.go b/pkg/sql/logictest/tests/local/generated_test.go index d66e4286fcce..4b225f118be6 100644 --- a/pkg/sql/logictest/tests/local/generated_test.go +++ b/pkg/sql/logictest/tests/local/generated_test.go @@ -2074,6 +2074,13 @@ func TestLogic_typing( runLogicTest(t, "typing") } +func TestLogic_udf( + t *testing.T, +) { + defer leaktest.AfterTest(t)() + runLogicTest(t, "udf") +} + func TestLogic_union( t *testing.T, ) { diff --git a/pkg/sql/opt/exec/execbuilder/testdata/udf b/pkg/sql/opt/exec/execbuilder/testdata/udf index 4d855af35967..ba6cc4827b5d 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/udf +++ b/pkg/sql/opt/exec/execbuilder/testdata/udf @@ -1,4 +1,4 @@ -# LogicTest: local-udf +# LogicTest: local statement ok CREATE TABLE t ( diff --git a/pkg/sql/opt/exec/execbuilder/tests/local-udf/BUILD.bazel b/pkg/sql/opt/exec/execbuilder/tests/local-udf/BUILD.bazel deleted file mode 100644 index 017113b56bf9..000000000000 --- a/pkg/sql/opt/exec/execbuilder/tests/local-udf/BUILD.bazel +++ /dev/null @@ -1,29 +0,0 @@ -load("//build/bazelutil/unused_checker:unused.bzl", "get_x_data") -load("@io_bazel_rules_go//go:def.bzl", "go_test") - -go_test( - name = "local-udf_test", - size = "enormous", - srcs = ["generated_test.go"], - data = [ - "//c-deps:libgeos", # keep - "//pkg/sql/opt/exec/execbuilder:testdata", # keep - ], - shard_count = 1, - tags = ["cpu:1"], - deps = [ - "//pkg/build/bazel", - "//pkg/security/securityassets", - "//pkg/security/securitytest", - "//pkg/server", - "//pkg/sql", - "//pkg/sql/logictest", - "//pkg/testutils/serverutils", - "//pkg/testutils/skip", - "//pkg/testutils/testcluster", - "//pkg/util/leaktest", - "//pkg/util/randutil", - ], -) - -get_x_data(name = "get_x_data") diff --git a/pkg/sql/opt/exec/execbuilder/tests/local-udf/generated_test.go b/pkg/sql/opt/exec/execbuilder/tests/local-udf/generated_test.go deleted file mode 100644 index 491c01a326c3..000000000000 --- a/pkg/sql/opt/exec/execbuilder/tests/local-udf/generated_test.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2022 The Cockroach Authors. -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.txt. -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0, included in the file -// licenses/APL.txt. - -// Code generated by generate-logictest, DO NOT EDIT. - -package testlocal_udf - -import ( - "os" - "path/filepath" - "testing" - - "github.com/cockroachdb/cockroach/pkg/build/bazel" - "github.com/cockroachdb/cockroach/pkg/security/securityassets" - "github.com/cockroachdb/cockroach/pkg/security/securitytest" - "github.com/cockroachdb/cockroach/pkg/server" - "github.com/cockroachdb/cockroach/pkg/sql" - "github.com/cockroachdb/cockroach/pkg/sql/logictest" - "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" - "github.com/cockroachdb/cockroach/pkg/testutils/skip" - "github.com/cockroachdb/cockroach/pkg/testutils/testcluster" - "github.com/cockroachdb/cockroach/pkg/util/leaktest" - "github.com/cockroachdb/cockroach/pkg/util/randutil" -) - -const configIdx = 20 - -var execBuildLogicTestDir string - -func init() { - if bazel.BuiltWithBazel() { - var err error - execBuildLogicTestDir, err = bazel.Runfile("pkg/sql/opt/exec/execbuilder/testdata") - if err != nil { - panic(err) - } - } else { - execBuildLogicTestDir = "../../../../../../sql/opt/exec/execbuilder/testdata" - } -} - -func TestMain(m *testing.M) { - securityassets.SetLoader(securitytest.EmbeddedAssets) - randutil.SeedForTests() - serverutils.InitTestServerFactory(server.TestServerFactory) - serverutils.InitTestClusterFactory(testcluster.TestClusterFactory) - os.Exit(m.Run()) -} - -func runExecBuildLogicTest(t *testing.T, file string) { - defer sql.TestingOverrideExplainEnvVersion("CockroachDB execbuilder test version")() - skip.UnderDeadlock(t, "times out and/or hangs") - serverArgs := logictest.TestServerArgs{ - DisableWorkmemRandomization: true, - ForceProductionValues: true, - } - logictest.RunLogicTest(t, serverArgs, configIdx, filepath.Join(execBuildLogicTestDir, file)) -} - -// TestLogic_tmp runs any tests that are prefixed with "_", in which a dedicated -// test is not generated for. This allows developers to create and run temporary -// test files that are not checked into the repository, without repeatedly -// regenerating and reverting changes to this file, generated_test.go. -// -// TODO(mgartner): Add file filtering so that individual files can be run, -// instead of all files with the "_" prefix. -func TestLogic_tmp(t *testing.T) { - defer leaktest.AfterTest(t)() - var glob string - glob = filepath.Join(execBuildLogicTestDir, "_*") - serverArgs := logictest.TestServerArgs{ - DisableWorkmemRandomization: true, - } - logictest.RunLogicTests(t, serverArgs, configIdx, glob) -} - -func TestExecBuild_udf( - t *testing.T, -) { - defer leaktest.AfterTest(t)() - runExecBuildLogicTest(t, "udf") -} diff --git a/pkg/sql/opt/exec/execbuilder/tests/local/generated_test.go b/pkg/sql/opt/exec/execbuilder/tests/local/generated_test.go index 349ee1d25a79..923f7fdbf574 100644 --- a/pkg/sql/opt/exec/execbuilder/tests/local/generated_test.go +++ b/pkg/sql/opt/exec/execbuilder/tests/local/generated_test.go @@ -536,6 +536,13 @@ func TestExecBuild_tuple( runExecBuildLogicTest(t, "tuple") } +func TestExecBuild_udf( + t *testing.T, +) { + defer leaktest.AfterTest(t)() + runExecBuildLogicTest(t, "udf") +} + func TestExecBuild_union( t *testing.T, ) {