Skip to content

Commit

Permalink
Fix error message for function calls with lambda arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Jan 16, 2022
1 parent 9448c2f commit 0a13667
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static List<TypeSignatureProvider> fromTypeSignatures(List<? extends Type
public String toString()
{
if (hasDependency) {
return super.toString();
return "<function>";
}
return getTypeSignature().toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 (<function>) for function count. Expected: count(), count(T) T");
assertInvalidFunction("max(x -> x)", FUNCTION_NOT_FOUND, "line 1:1: Unexpected parameters (<function>) 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 (<function>) for function sqrt. Expected: sqrt(double)");
assertInvalidFunction("sqrt(x -> x, 123, x -> x)", FUNCTION_NOT_FOUND, "line 1:1: Unexpected parameters (<function>, integer, <function>) for function sqrt. Expected: sqrt(double)");
assertInvalidFunction("pow(x -> x, 123)", FUNCTION_NOT_FOUND, "line 1:1: Unexpected parameters (<function>, integer) for function pow. Expected: pow(double, double)");
assertInvalidFunction("pow(123, x -> x)", FUNCTION_NOT_FOUND, "line 1:1: Unexpected parameters (integer, <function>) for function pow. Expected: pow(double, double)");
}

private static String quote(String identifier)
{
return "\"" + identifier.replace("\"", "\"\"") + "\"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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 (<function>) for function typeof. Expected: typeof(t) T");
}
}

0 comments on commit 0a13667

Please sign in to comment.