From 58362e7cebe3a592001f3d717d9d3755cfadb1d4 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Tue, 21 Apr 2026 10:05:14 +0200 Subject: [PATCH 1/3] Test function providers implementation completeness --- .../metadata/TestGlobalFunctionCatalog.java | 12 +++++++ .../function/TestFunctionBundleProvider.java | 34 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 core/trino-spi/src/test/java/io/trino/spi/function/TestFunctionBundleProvider.java diff --git a/core/trino-main/src/test/java/io/trino/metadata/TestGlobalFunctionCatalog.java b/core/trino-main/src/test/java/io/trino/metadata/TestGlobalFunctionCatalog.java index f8e3e0e5a6f0..afd9d195aa2f 100644 --- a/core/trino-main/src/test/java/io/trino/metadata/TestGlobalFunctionCatalog.java +++ b/core/trino-main/src/test/java/io/trino/metadata/TestGlobalFunctionCatalog.java @@ -22,11 +22,13 @@ import io.trino.spi.function.BoundSignature; import io.trino.spi.function.FunctionBundle; import io.trino.spi.function.FunctionMetadata; +import io.trino.spi.function.FunctionProvider; import io.trino.spi.function.OperatorType; import io.trino.spi.function.ScalarFunction; import io.trino.spi.function.Signature; import io.trino.spi.function.SqlType; import io.trino.spi.function.TypeVariableConstraint; +import io.trino.spi.function.table.ConnectorTableFunctionHandle; import io.trino.spi.type.ArrayType; import io.trino.spi.type.StandardTypes; import io.trino.spi.type.Type; @@ -55,6 +57,7 @@ import static io.trino.spi.type.HyperLogLogType.HYPER_LOG_LOG; import static io.trino.sql.analyzer.TypeSignatureProvider.fromTypeSignatures; import static io.trino.sql.analyzer.TypeSignatureTranslator.parseTypeSignature; +import static io.trino.testing.InterfaceTestUtils.assertAllMethodsOverridden; import static java.util.Collections.nCopies; import static java.util.stream.Collectors.toList; import static org.assertj.core.api.Assertions.assertThat; @@ -62,6 +65,15 @@ public class TestGlobalFunctionCatalog { + @Test + void testEverythingImplemented() + throws Exception + { + assertAllMethodsOverridden(FunctionProvider.class, GlobalFunctionCatalog.class, Set.of( + // Default implementation of getTableFunctionProcessorProviderFactory is OK + FunctionProvider.class.getMethod("getTableFunctionProcessorProviderFactory", ConnectorTableFunctionHandle.class))); + } + @Test public void testIdentityCast() { diff --git a/core/trino-spi/src/test/java/io/trino/spi/function/TestFunctionBundleProvider.java b/core/trino-spi/src/test/java/io/trino/spi/function/TestFunctionBundleProvider.java new file mode 100644 index 000000000000..cff085487b07 --- /dev/null +++ b/core/trino-spi/src/test/java/io/trino/spi/function/TestFunctionBundleProvider.java @@ -0,0 +1,34 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.trino.spi.function; + +import io.trino.spi.function.table.ConnectorTableFunctionHandle; +import org.junit.jupiter.api.Test; + +import java.util.Set; + +import static io.trino.testing.InterfaceTestUtils.assertAllMethodsOverridden; + +class TestFunctionBundleProvider +{ + @Test + void testEverythingImplemented() + throws Exception + { + assertAllMethodsOverridden(FunctionProvider.class, FunctionBundleProvider.class, Set.of( + // Table functions are not part of the function bundle + FunctionProvider.class.getMethod("getTableFunctionProcessorProvider", ConnectorTableFunctionHandle.class), + FunctionProvider.class.getMethod("getTableFunctionProcessorProviderFactory", ConnectorTableFunctionHandle.class))); + } +} From 048a8dd80e1100a0bea45415434770205fd704e6 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Tue, 21 Apr 2026 10:16:20 +0200 Subject: [PATCH 2/3] Fix indentation in TestFakerQueries --- .../trino/plugin/faker/TestFakerQueries.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerQueries.java b/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerQueries.java index 4b45206b22bc..e51bd83d78bd 100644 --- a/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerQueries.java +++ b/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerQueries.java @@ -166,9 +166,9 @@ SELECT count(rnd_bigint) // generating data should be deterministic String testQuery = - """ - SELECT to_hex(checksum(rnd_bigint)) - FROM (SELECT rnd_bigint FROM %s LIMIT %d) a""".formatted(table.getName(), 3 * MAX_ROWS_PER_SPLIT); + """ + SELECT to_hex(checksum(rnd_bigint)) + FROM (SELECT rnd_bigint FROM %s LIMIT %d) a""".formatted(table.getName(), 3 * MAX_ROWS_PER_SPLIT); assertQuery(testQuery, "VALUES ('1FB3289AC3A44EEA')"); assertQuery(testQuery, "VALUES ('1FB3289AC3A44EEA')"); assertQuery(testQuery, "VALUES ('1FB3289AC3A44EEA')"); @@ -572,14 +572,14 @@ void testCreateTableAsSelect() void testCreateTableAsSelectSequence() { String source = - """ - SELECT - cast(greatest(least(sequential_number, 0x7f), -0x80) AS TINYINT) AS seq_tinyint, - cast(sequential_number AS SMALLINT) AS seq_smallint, - cast(sequential_number AS INTEGER) AS seq_integer, - cast(sequential_number AS BIGINT) AS seq_bigint - FROM TABLE(sequence(start => -500, stop => 500, step => 1)) - """; + """ + SELECT + cast(greatest(least(sequential_number, 0x7f), -0x80) AS TINYINT) AS seq_tinyint, + cast(sequential_number AS SMALLINT) AS seq_smallint, + cast(sequential_number AS INTEGER) AS seq_integer, + cast(sequential_number AS BIGINT) AS seq_bigint + FROM TABLE(sequence(start => -500, stop => 500, step => 1)) + """; try (TestTable sourceTable = new TestTable(getQueryRunner()::execute, "seq_src", "WITH (null_probability = 0, default_limit = 1000, dictionary_detection_enabled = false) AS " + source); TestTable table = new TestTable(getQueryRunner()::execute, "seq", "WITH (null_probability = 0, default_limit = 1000, dictionary_detection_enabled = false) AS SELECT * FROM %s".formatted(sourceTable.getName()))) { String createTable = (String) computeScalar("SHOW CREATE TABLE " + table.getName()); @@ -594,11 +594,11 @@ FROM TABLE(sequence(start => -500, stop => 500, step => 1)) void testCreateTableAsSelectNulls() { String source = - """ - SELECT - cast(NULL AS INTEGER) AS nullable - FROM TABLE(sequence(start => 0, stop => 1000, step => 1)) - """; + """ + SELECT + cast(NULL AS INTEGER) AS nullable + FROM TABLE(sequence(start => 0, stop => 1000, step => 1)) + """; try (TestTable table = new TestTable(getQueryRunner()::execute, "only_nulls", "WITH (dictionary_detection_enabled = false) AS " + source)) { String createTable = (String) computeScalar("SHOW CREATE TABLE " + table.getName()); assertThat(createTable).containsPattern("nullable integer WITH \\(null_probability = 1E0\\)"); @@ -609,9 +609,9 @@ FROM TABLE(sequence(start => 0, stop => 1000, step => 1)) void testCreateTableAsSelectVarchar() { String source = - """ - SELECT * FROM tpch.tiny.orders - """; + """ + SELECT * FROM tpch.tiny.orders + """; try (TestTable table = new TestTable(getQueryRunner()::execute, "varchars", "AS " + source)) { String createTable = (String) computeScalar("SHOW CREATE TABLE " + table.getName()); assertThat(createTable).containsPattern("orderkey bigint WITH \\(max = '60000', min = '1', null_probability = 0E0, step = '1'\\)"); @@ -630,12 +630,12 @@ void testCreateTableAsSelectVarchar() void testCreateTableAsSelectBoolean() { String source = - """ - SELECT - sequential_number % 2 = 0 AS boolean, - ARRAY[true, false, sequential_number % 2 = 0] AS boolean_array - FROM TABLE(sequence(start => 0, stop => 1000, step => 1)) - """; + """ + SELECT + sequential_number % 2 = 0 AS boolean, + ARRAY[true, false, sequential_number % 2 = 0] AS boolean_array + FROM TABLE(sequence(start => 0, stop => 1000, step => 1)) + """; try (TestTable table = new TestTable(getQueryRunner()::execute, "booleans", "AS " + source)) { String createTable = (String) computeScalar("SHOW CREATE TABLE " + table.getName()); assertThat(createTable).containsPattern("boolean boolean WITH \\(null_probability = 0E0\\)"); From e264ef8dfdef91c67e81e8e5a438dbf1da47958f Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Tue, 21 Apr 2026 10:15:09 +0200 Subject: [PATCH 3/3] Fix Faker listFunctions to correctly filter by schema name --- .../main/java/io/trino/plugin/faker/FakerMetadata.java | 2 +- .../java/io/trino/plugin/faker/TestFakerQueries.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerMetadata.java b/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerMetadata.java index 031d38cd265a..090a746ff96f 100644 --- a/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerMetadata.java +++ b/plugin/trino-faker/src/main/java/io/trino/plugin/faker/FakerMetadata.java @@ -765,7 +765,7 @@ public Optional> applyLimit( @Override public Collection listFunctions(ConnectorSession session, String schemaName) { - return functionBundle.getFunctions(); + return schemaName.equals(SCHEMA_NAME) ? functionBundle.getFunctions() : List.of(); } @Override diff --git a/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerQueries.java b/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerQueries.java index e51bd83d78bd..2c46692f403d 100644 --- a/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerQueries.java +++ b/plugin/trino-faker/src/test/java/io/trino/plugin/faker/TestFakerQueries.java @@ -246,6 +246,16 @@ void testSelectFunctions() assertQuery(testQuery, "VALUES (true)"); } + @Test + void testListFunctionsRespectsSchemaName() + { + assertUpdate("CREATE SCHEMA faker.other_schema"); + assertThat(query("SHOW FUNCTIONS FROM faker.other_schema")) + .result() + .isEmpty(); + assertUpdate("DROP SCHEMA faker.other_schema"); + } + @Test void testSelectRangeProperties() {