Skip to content

Commit

Permalink
Improve TestMySqlFunctionNamespaceManager
Browse files Browse the repository at this point in the history
- Update error message.
- Update method names.
- Add test cases.
  • Loading branch information
caithagoras0 committed Apr 8, 2020
1 parent d4fc345 commit a8de10f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void createFunction(SqlInvokedFunction function, boolean replace)
}
checkFieldLength("Function name", functionName.getFunctionName(), MAX_FUNCTION_NAME_LENGTH);
checkFieldLength(
"Parameter types",
"Parameter type list",
function.getFunctionId().getArgumentTypes().stream()
.map(TypeSignature::toString)
.collect(joining(",")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,6 @@ public void testListFunction()
assertListFunctions(function1.withVersion(1), function2.withVersion(1));
}

private static SqlInvokedFunction constructTestFunction(QualifiedFunctionName functionName)
{
return new SqlInvokedFunction(
functionName,
ImmutableList.of(new SqlParameter("x", parseTypeSignature(DOUBLE))),
parseTypeSignature(DOUBLE),
"power tower",
RoutineCharacteristics.builder().setDeterminism(DETERMINISTIC).build(),
"pow(x, x)",
Optional.empty());
}

@Test
public void testCreateFunction()
{
Expand Down Expand Up @@ -215,49 +203,43 @@ public void testCreateFunctionFailedVersioned()
}

@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Schema name exceeds max length of 128.*")
public void testCreateFunctionSchemaNameTooLong()
public void testSchemaNameTooLong()
{
QualifiedFunctionName functionName = QualifiedFunctionName.of(new CatalogSchemaName(TEST_CATALOG, dummyString(129)), "tangent");
createFunction(getFunctionTangent(functionName), false);
createFunction(createFunctionTangent(functionName), false);
}

@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Function name exceeds max length of 256.*")
public void testCreateFunctionFunctionNameTooLong()
public void testFunctionNameTooLong()
{
QualifiedFunctionName functionName = QualifiedFunctionName.of(new CatalogSchemaName(TEST_CATALOG, TEST_SCHEMA), dummyString(257));
createFunction(getFunctionTangent(functionName), false);
createFunction(createFunctionTangent(functionName), false);
}

@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Parameter types exceeds max length of 500.*")
public void testCreateFunctionFunctionIdTooLong()
@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Parameter type list exceeds max length of 500.*")
public void testParameterTypeListTooLong()
{
List<SqlParameter> parameters = nCopies(72, new SqlParameter("x", parseTypeSignature(DOUBLE)));
createFunction(
new SqlInvokedFunction(
FUNCTION_TANGENT.getFunctionId().getFunctionName(),
parameters,
FUNCTION_TANGENT.getSignature().getReturnType(),
FUNCTION_TANGENT.getDescription(),
FUNCTION_TANGENT.getRoutineCharacteristics(),
FUNCTION_TANGENT.getBody(),
Optional.empty()),
false);
createFunction(createFunctionTangent(parameters), false);
}

public void testLongParameterTypeList()
{
List<SqlParameter> parameters = nCopies(71, new SqlParameter("x", parseTypeSignature(DOUBLE)));
createFunction(createFunctionTangent(parameters), false);
}

@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Return type exceeds max length of 256.*")
public void testCreateFunctionTypeNameTooLong()
public void testReturnTypeTooLong()
{
TypeSignature returnType = parseTypeSignature(dummyString(257));
createFunction(
new SqlInvokedFunction(
TANGENT,
FUNCTION_TANGENT.getParameters(),
returnType,
FUNCTION_TANGENT.getDescription(),
FUNCTION_TANGENT.getRoutineCharacteristics(),
FUNCTION_TANGENT.getBody(),
Optional.empty()),
false);
createFunction(createFunctionTangent(returnType), false);
}

public void testLongReturnType()
{
TypeSignature returnType = parseTypeSignature(dummyString(256));
createFunction(createFunctionTangent(returnType), false);
}

@Test
Expand Down Expand Up @@ -474,7 +456,19 @@ private static String dummyString(int length)
return Joiner.on("").join(nCopies(length, "x"));
}

private static SqlInvokedFunction getFunctionTangent(QualifiedFunctionName functionName)
private static SqlInvokedFunction constructTestFunction(QualifiedFunctionName functionName)
{
return new SqlInvokedFunction(
functionName,
ImmutableList.of(new SqlParameter("x", parseTypeSignature(DOUBLE))),
parseTypeSignature(DOUBLE),
"power tower",
RoutineCharacteristics.builder().setDeterminism(DETERMINISTIC).build(),
"pow(x, x)",
Optional.empty());
}

private static SqlInvokedFunction createFunctionTangent(QualifiedFunctionName functionName)
{
return new SqlInvokedFunction(
functionName,
Expand All @@ -485,4 +479,28 @@ private static SqlInvokedFunction getFunctionTangent(QualifiedFunctionName funct
FUNCTION_TANGENT.getBody(),
Optional.empty());
}

private static SqlInvokedFunction createFunctionTangent(List<SqlParameter> parameters)
{
return new SqlInvokedFunction(
FUNCTION_TANGENT.getFunctionId().getFunctionName(),
parameters,
FUNCTION_TANGENT.getSignature().getReturnType(),
FUNCTION_TANGENT.getDescription(),
FUNCTION_TANGENT.getRoutineCharacteristics(),
FUNCTION_TANGENT.getBody(),
Optional.empty());
}

private static SqlInvokedFunction createFunctionTangent(TypeSignature returnType)
{
return new SqlInvokedFunction(
TANGENT,
FUNCTION_TANGENT.getParameters(),
returnType,
FUNCTION_TANGENT.getDescription(),
FUNCTION_TANGENT.getRoutineCharacteristics(),
FUNCTION_TANGENT.getBody(),
Optional.empty());
}
}

0 comments on commit a8de10f

Please sign in to comment.