Search in sources :

Example 6 with UdfMetadata

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));
}
Also used : BasicSqlType(org.apache.calcite.sql.type.BasicSqlType) SqlCallBinding(org.apache.calcite.sql.SqlCallBinding) SamzaSqlUdfMethod(org.apache.samza.sql.udfs.SamzaSqlUdfMethod) Method(java.lang.reflect.Method) MapConfig(org.apache.samza.config.MapConfig) UdfMetadata(org.apache.samza.sql.interfaces.UdfMetadata) Test(org.junit.Test)

Example 7 with UdfMetadata

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));
}
Also used : BasicSqlType(org.apache.calcite.sql.type.BasicSqlType) SqlCallBinding(org.apache.calcite.sql.SqlCallBinding) SamzaSqlUdfMethod(org.apache.samza.sql.udfs.SamzaSqlUdfMethod) Method(java.lang.reflect.Method) MapConfig(org.apache.samza.config.MapConfig) UdfMetadata(org.apache.samza.sql.interfaces.UdfMetadata) Test(org.junit.Test)

Example 8 with UdfMetadata

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);
}
Also used : BasicSqlType(org.apache.calcite.sql.type.BasicSqlType) SqlCallBinding(org.apache.calcite.sql.SqlCallBinding) SamzaSqlUdfMethod(org.apache.samza.sql.udfs.SamzaSqlUdfMethod) Method(java.lang.reflect.Method) MapConfig(org.apache.samza.config.MapConfig) UdfMetadata(org.apache.samza.sql.interfaces.UdfMetadata) Test(org.junit.Test)

Example 9 with UdfMetadata

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));
}
Also used : BasicSqlType(org.apache.calcite.sql.type.BasicSqlType) SqlCallBinding(org.apache.calcite.sql.SqlCallBinding) SamzaSqlUdfMethod(org.apache.samza.sql.udfs.SamzaSqlUdfMethod) Method(java.lang.reflect.Method) MapConfig(org.apache.samza.config.MapConfig) UdfMetadata(org.apache.samza.sql.interfaces.UdfMetadata) Test(org.junit.Test)

Aggregations

UdfMetadata (org.apache.samza.sql.interfaces.UdfMetadata)9 Method (java.lang.reflect.Method)7 MapConfig (org.apache.samza.config.MapConfig)7 Test (org.junit.Test)7 SqlCallBinding (org.apache.calcite.sql.SqlCallBinding)6 SamzaSqlUdfMethod (org.apache.samza.sql.udfs.SamzaSqlUdfMethod)6 BasicSqlType (org.apache.calcite.sql.type.BasicSqlType)5 Config (org.apache.samza.config.Config)2 ReflectionBasedUdfResolver (org.apache.samza.sql.udf.ReflectionBasedUdfResolver)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)1 SqlOperandCountRange (org.apache.calcite.sql.SqlOperandCountRange)1