Search in sources :

Example 6 with BasicSqlType

use of org.apache.calcite.sql.type.BasicSqlType 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 7 with BasicSqlType

use of org.apache.calcite.sql.type.BasicSqlType 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 8 with BasicSqlType

use of org.apache.calcite.sql.type.BasicSqlType 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

BasicSqlType (org.apache.calcite.sql.type.BasicSqlType)8 Test (org.junit.Test)7 Method (java.lang.reflect.Method)5 SqlCallBinding (org.apache.calcite.sql.SqlCallBinding)5 MapConfig (org.apache.samza.config.MapConfig)5 UdfMetadata (org.apache.samza.sql.interfaces.UdfMetadata)5 SamzaSqlUdfMethod (org.apache.samza.sql.udfs.SamzaSqlUdfMethod)5 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 RexNode (org.apache.calcite.rex.RexNode)2 ArraySqlType (org.apache.calcite.sql.type.ArraySqlType)2 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)2 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 SqlLiteral (org.apache.calcite.sql.SqlLiteral)1