Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,13 +57,23 @@
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;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

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()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ public Optional<LimitApplicationResult<ConnectorTableHandle>> applyLimit(
@Override
public Collection<FunctionMetadata> listFunctions(ConnectorSession session, String schemaName)
{
return functionBundle.getFunctions();
return schemaName.equals(SCHEMA_NAME) ? functionBundle.getFunctions() : List.of();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')");
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -572,14 +582,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());
Expand All @@ -594,11 +604,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\\)");
Expand All @@ -609,9 +619,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'\\)");
Expand All @@ -630,12 +640,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\\)");
Expand Down