diff --git a/core/trino-main/src/main/java/io/trino/metadata/FunctionResolver.java b/core/trino-main/src/main/java/io/trino/metadata/FunctionResolver.java index 569c8f47bac3..48913ce8b2fa 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/FunctionResolver.java +++ b/core/trino-main/src/main/java/io/trino/metadata/FunctionResolver.java @@ -144,10 +144,9 @@ FunctionBinding resolveFunction(Session session, Collection al List expectedParameters = new ArrayList<>(); for (FunctionMetadata function : allCandidates) { - expectedParameters.add(format("%s(%s) %s", - name, - Joiner.on(", ").join(function.getSignature().getArgumentTypes()), - Joiner.on(", ").join(function.getSignature().getTypeVariableConstraints()))); + String arguments = Joiner.on(", ").join(function.getSignature().getArgumentTypes()); + String constraints = Joiner.on(", ").join(function.getSignature().getTypeVariableConstraints()); + expectedParameters.add(format("%s(%s) %s", name, arguments, constraints).stripTrailing()); } String parameters = Joiner.on(", ").join(parameterTypes); diff --git a/core/trino-main/src/main/java/io/trino/operator/scalar/TypeOfFunction.java b/core/trino-main/src/main/java/io/trino/operator/scalar/TypeOfFunction.java index b277ffa9ff51..a794d6bfcc32 100644 --- a/core/trino-main/src/main/java/io/trino/operator/scalar/TypeOfFunction.java +++ b/core/trino-main/src/main/java/io/trino/operator/scalar/TypeOfFunction.java @@ -38,31 +38,4 @@ public static Slice typeof( { return utf8Slice(type.getDisplayName()); } - - @TypeParameter("T") - @SqlType(StandardTypes.VARCHAR) - public static Slice typeof( - @TypeParameter("T") Type type, - @SqlNullable @SqlType("T") Long value) - { - return typeof(type, (Object) value); - } - - @TypeParameter("T") - @SqlType(StandardTypes.VARCHAR) - public static Slice typeof( - @TypeParameter("T") Type type, - @SqlNullable @SqlType("T") Double value) - { - return typeof(type, (Object) value); - } - - @TypeParameter("T") - @SqlType(StandardTypes.VARCHAR) - public static Slice typeof( - @TypeParameter("T") Type type, - @SqlNullable @SqlType("T") Boolean value) - { - return typeof(type, (Object) value); - } } diff --git a/core/trino-main/src/main/java/io/trino/sql/analyzer/TypeSignatureProvider.java b/core/trino-main/src/main/java/io/trino/sql/analyzer/TypeSignatureProvider.java index d3b22694b76f..9490c910d4ff 100644 --- a/core/trino-main/src/main/java/io/trino/sql/analyzer/TypeSignatureProvider.java +++ b/core/trino-main/src/main/java/io/trino/sql/analyzer/TypeSignatureProvider.java @@ -90,7 +90,7 @@ public static List fromTypeSignatures(List"; } return getTypeSignature().toString(); } diff --git a/core/trino-main/src/test/java/io/trino/operator/scalar/TestLambdaExpression.java b/core/trino-main/src/test/java/io/trino/operator/scalar/TestLambdaExpression.java index fd053148984c..468842f3753a 100644 --- a/core/trino-main/src/test/java/io/trino/operator/scalar/TestLambdaExpression.java +++ b/core/trino-main/src/test/java/io/trino/operator/scalar/TestLambdaExpression.java @@ -22,6 +22,7 @@ import static io.trino.operator.scalar.ApplyFunction.APPLY_FUNCTION; import static io.trino.operator.scalar.InvokeFunction.INVOKE_FUNCTION; +import static io.trino.spi.StandardErrorCode.FUNCTION_NOT_FOUND; import static io.trino.spi.type.BigintType.BIGINT; import static io.trino.spi.type.BooleanType.BOOLEAN; import static io.trino.spi.type.DoubleType.DOUBLE; @@ -167,6 +168,17 @@ public void testTypeCombinations() assertFunction("apply(MAP(ARRAY['abc', 'def'], ARRAY[123, 456]), x -> map_keys(x))", new ArrayType(createVarcharType(3)), ImmutableList.of("abc", "def")); } + @Test + public void testFunctionParameter() + { + assertInvalidFunction("count(x -> x)", FUNCTION_NOT_FOUND, "line 1:1: Unexpected parameters () for function count. Expected: count(), count(T) T"); + assertInvalidFunction("max(x -> x)", FUNCTION_NOT_FOUND, "line 1:1: Unexpected parameters () for function max. Expected: max(E) E:orderable, max(E, bigint) E:orderable"); + assertInvalidFunction("sqrt(x -> x)", FUNCTION_NOT_FOUND, "line 1:1: Unexpected parameters () for function sqrt. Expected: sqrt(double)"); + assertInvalidFunction("sqrt(x -> x, 123, x -> x)", FUNCTION_NOT_FOUND, "line 1:1: Unexpected parameters (, integer, ) for function sqrt. Expected: sqrt(double)"); + assertInvalidFunction("pow(x -> x, 123)", FUNCTION_NOT_FOUND, "line 1:1: Unexpected parameters (, integer) for function pow. Expected: pow(double, double)"); + assertInvalidFunction("pow(123, x -> x)", FUNCTION_NOT_FOUND, "line 1:1: Unexpected parameters (integer, ) for function pow. Expected: pow(double, double)"); + } + private static String quote(String identifier) { return "\"" + identifier.replace("\"", "\"\"") + "\""; diff --git a/core/trino-main/src/test/java/io/trino/operator/scalar/TestTypeOfFunction.java b/core/trino-main/src/test/java/io/trino/operator/scalar/TestTypeOfFunction.java index ec0c147ec891..e99e068b518d 100644 --- a/core/trino-main/src/test/java/io/trino/operator/scalar/TestTypeOfFunction.java +++ b/core/trino-main/src/test/java/io/trino/operator/scalar/TestTypeOfFunction.java @@ -16,6 +16,8 @@ import io.trino.spi.type.VarcharType; import org.testng.annotations.Test; +import static io.trino.spi.StandardErrorCode.FUNCTION_NOT_FOUND; + public class TestTypeOfFunction extends AbstractTestFunctions { @@ -58,4 +60,10 @@ public void testComplex() assertFunction("typeof(sin(2))", VarcharType.VARCHAR, "double"); assertFunction("typeof(2+sin(2)+2.3)", VarcharType.VARCHAR, "double"); } + + @Test + public void testLambda() + { + assertInvalidFunction("typeof(x -> x)", FUNCTION_NOT_FOUND, "line 1:1: Unexpected parameters () for function typeof. Expected: typeof(t) T"); + } } diff --git a/core/trino-main/src/test/java/io/trino/type/TestArrayOperators.java b/core/trino-main/src/test/java/io/trino/type/TestArrayOperators.java index c09f36a85a43..a1e6f8835f2d 100644 --- a/core/trino-main/src/test/java/io/trino/type/TestArrayOperators.java +++ b/core/trino-main/src/test/java/io/trino/type/TestArrayOperators.java @@ -439,7 +439,7 @@ public void testArrayToArrayConcat() assertThatThrownBy(() -> assertFunction("ARRAY [ARRAY [1]] || ARRAY [ARRAY ['x']]", new ArrayType(new ArrayType(INTEGER)), null)) .isInstanceOf(TrinoException.class) - .hasMessage("line 1:19: Unexpected parameters (array(array(integer)), array(array(varchar(1)))) for function concat. Expected: concat(char(x), char(y)) , concat(array(E), E) E, concat(E, array(E)) E, concat(array(E)) E, concat(varchar) , concat(varbinary) "); + .hasMessage("line 1:19: Unexpected parameters (array(array(integer)), array(array(varchar(1)))) for function concat. Expected: concat(char(x), char(y)), concat(array(E), E) E, concat(E, array(E)) E, concat(array(E)) E, concat(varchar), concat(varbinary)"); assertCachedInstanceHasBoundedRetainedSize("ARRAY [1, NULL] || ARRAY [3]"); } @@ -477,7 +477,7 @@ public void testElementArrayConcat() assertThatThrownBy(() -> assertFunction("ARRAY [ARRAY[1]] || ARRAY ['x']", new ArrayType(new ArrayType(INTEGER)), null)) .isInstanceOf(TrinoException.class) - .hasMessage("line 1:18: Unexpected parameters (array(array(integer)), array(varchar(1))) for function concat. Expected: concat(char(x), char(y)) , concat(array(E), E) E, concat(E, array(E)) E, concat(array(E)) E, concat(varchar) , concat(varbinary) "); + .hasMessage("line 1:18: Unexpected parameters (array(array(integer)), array(varchar(1))) for function concat. Expected: concat(char(x), char(y)), concat(array(E), E) E, concat(E, array(E)) E, concat(array(E)) E, concat(varchar), concat(varbinary)"); assertCachedInstanceHasBoundedRetainedSize("ARRAY [1, NULL] || 3"); assertCachedInstanceHasBoundedRetainedSize("3 || ARRAY [1, NULL]");