use of org.apache.samza.sql.interfaces.UdfMetadata in project samza by apache.
the class CheckerTest method testCheckOperandTypesShouldReturnTrueWhenArgumentCheckIsDisabled.
@Test
public void testCheckOperandTypesShouldReturnTrueWhenArgumentCheckIsDisabled() throws NoSuchMethodException {
Method udfMethod = TestUdfWithWrongTypes.class.getMethod("execute", String.class);
UdfMetadata udfMetadata = new UdfMetadata("TestUdfWithWrongTypes", "TestUDFClass", udfMethod, new MapConfig(), ImmutableList.of(SamzaSqlFieldType.INT32), SamzaSqlFieldType.INT64, true);
Checker operandTypeChecker = Checker.getChecker(1, 3, udfMetadata);
SqlCallBinding callBinding = Mockito.mock(SqlCallBinding.class);
Mockito.when(callBinding.getOperandCount()).thenReturn(1);
Mockito.when(callBinding.getOperandType(0)).thenReturn(new BasicSqlType(RelDataTypeSystem.DEFAULT, SqlTypeName.VARCHAR, 12));
assertTrue(operandTypeChecker.checkOperandTypes(callBinding, true));
}
use of org.apache.samza.sql.interfaces.UdfMetadata in project samza by apache.
the class CheckerTest method testCheckOperandTypesShouldReturnTrueOnTypeMatch.
@Test
public void testCheckOperandTypesShouldReturnTrueOnTypeMatch() throws NoSuchMethodException {
Method udfMethod = MyTestPolyUdf.class.getMethod("execute", String.class);
UdfMetadata udfMetadata = new UdfMetadata("MyTestPoly", "Test Polymorphism UDF.", udfMethod, new MapConfig(), ImmutableList.of(SamzaSqlFieldType.STRING), SamzaSqlFieldType.INT32, false);
Checker operandTypeChecker = Checker.getChecker(1, 3, udfMetadata);
SqlCallBinding callBinding = Mockito.mock(SqlCallBinding.class);
Mockito.when(callBinding.getOperandCount()).thenReturn(1);
Mockito.when(callBinding.getOperandType(0)).thenReturn(new BasicSqlType(RelDataTypeSystem.DEFAULT, SqlTypeName.VARCHAR, 12));
assertTrue(operandTypeChecker.checkOperandTypes(callBinding, true));
}
use of org.apache.samza.sql.interfaces.UdfMetadata in project samza by apache.
the class CheckerTest method testCheckOperandTypesShouldFailOnTypeMisMatch.
@Test(expected = SamzaSqlValidatorException.class)
public void testCheckOperandTypesShouldFailOnTypeMisMatch() throws NoSuchMethodException {
Method udfMethod = TestUdfWithWrongTypes.class.getMethod("execute", String.class);
UdfMetadata udfMetadata = new UdfMetadata("TestUdfWithWrongTypes", "TestUDFClass", udfMethod, new MapConfig(), ImmutableList.of(SamzaSqlFieldType.INT32), SamzaSqlFieldType.INT64, false);
Checker operandTypeChecker = Checker.getChecker(1, 3, udfMetadata);
SqlCallBinding callBinding = Mockito.mock(SqlCallBinding.class);
Mockito.when(callBinding.getOperandCount()).thenReturn(1);
Mockito.when(callBinding.getOperandType(0)).thenReturn(new BasicSqlType(RelDataTypeSystem.DEFAULT, SqlTypeName.VARCHAR, 12));
operandTypeChecker.checkOperandTypes(callBinding, true);
}
use of org.apache.samza.sql.interfaces.UdfMetadata in project samza by apache.
the class CheckerTest method testCheckOperandTypesShouldReturnFalseWhenThrowOnFailureIsFalse.
@Test
public void testCheckOperandTypesShouldReturnFalseWhenThrowOnFailureIsFalse() throws NoSuchMethodException {
Method udfMethod = MyTestPolyUdf.class.getMethod("execute", String.class);
UdfMetadata udfMetadata = new UdfMetadata("MyTestPoly", "Test Polymorphism UDF.", udfMethod, new MapConfig(), ImmutableList.of(SamzaSqlFieldType.STRING), SamzaSqlFieldType.INT32, false);
Checker operandTypeChecker = Checker.getChecker(1, 3, udfMetadata);
SqlCallBinding callBinding = Mockito.mock(SqlCallBinding.class);
Mockito.when(callBinding.getOperandCount()).thenReturn(1);
Mockito.when(callBinding.getOperandType(0)).thenReturn(new BasicSqlType(RelDataTypeSystem.DEFAULT, SqlTypeName.VARCHAR, 12));
assertTrue(operandTypeChecker.checkOperandTypes(callBinding, false));
}
Aggregations