Search in sources :

Example 6 with SqlPrimitiveType

use of io.confluent.ksql.schema.ksql.types.SqlPrimitiveType in project ksql by confluentinc.

the class SqlTypeWalkerTest method shouldVisitDouble.

@Test
public void shouldVisitDouble() {
    // Given:
    final SqlPrimitiveType type = SqlTypes.DOUBLE;
    when(visitor.visitDouble(any())).thenReturn("Expected");
    // When:
    final String result = SqlTypeWalker.visit(type, visitor);
    // Then:
    verify(visitor).visitDouble(same(type));
    assertThat(result, is("Expected"));
}
Also used : SqlPrimitiveType(io.confluent.ksql.schema.ksql.types.SqlPrimitiveType) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 7 with SqlPrimitiveType

use of io.confluent.ksql.schema.ksql.types.SqlPrimitiveType in project ksql by confluentinc.

the class SqlTypeWalkerTest method shouldVisitString.

@Test
public void shouldVisitString() {
    // Given:
    final SqlPrimitiveType type = SqlTypes.STRING;
    when(visitor.visitString(any())).thenReturn("Expected");
    // When:
    final String result = SqlTypeWalker.visit(type, visitor);
    // Then:
    verify(visitor).visitString(same(type));
    assertThat(result, is("Expected"));
}
Also used : SqlPrimitiveType(io.confluent.ksql.schema.ksql.types.SqlPrimitiveType) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 8 with SqlPrimitiveType

use of io.confluent.ksql.schema.ksql.types.SqlPrimitiveType in project ksql by confluentinc.

the class SqlTypeWalkerTest method shouldStartWalkingFromField.

@Test
public void shouldStartWalkingFromField() {
    // Given:
    final SqlPrimitiveType type = SqlTypes.BOOLEAN;
    final Field field = mock(Field.class);
    when(field.type()).thenReturn(type);
    when(visitor.visitBoolean(any())).thenReturn("Expected");
    when(visitor.visitField(any(), any())).thenReturn(22);
    // When:
    final Integer result = SqlTypeWalker.visit(field, visitor);
    // Then:
    verify(visitor).visitBoolean(same(type));
    verify(visitor).visitField(same(field), eq("Expected"));
    assertThat(result, is(22));
}
Also used : Field(io.confluent.ksql.schema.ksql.types.SqlStruct.Field) SqlPrimitiveType(io.confluent.ksql.schema.ksql.types.SqlPrimitiveType) Test(org.junit.Test)

Example 9 with SqlPrimitiveType

use of io.confluent.ksql.schema.ksql.types.SqlPrimitiveType in project ksql by confluentinc.

the class SqlTypeWalkerTest method shouldVisitPrimitives.

@Test
public void shouldVisitPrimitives() {
    // Given:
    visitor = new Visitor<String, Integer>() {

        @Override
        public String visitPrimitive(final SqlPrimitiveType type) {
            return "Expected";
        }
    };
    primitiveTypes().forEach(type -> {
        // When:
        final String result = SqlTypeWalker.visit(type, visitor);
        // Then:
        assertThat(result, is("Expected"));
    });
}
Also used : SqlPrimitiveType(io.confluent.ksql.schema.ksql.types.SqlPrimitiveType) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 10 with SqlPrimitiveType

use of io.confluent.ksql.schema.ksql.types.SqlPrimitiveType in project ksql by confluentinc.

the class UdafAggregateFunctionFactory method buildAllParams.

private List<SqlArgument> buildAllParams(final List<SqlArgument> argTypeList, final AggregateFunctionInitArguments initArgs) {
    if (initArgs.args().isEmpty()) {
        return argTypeList;
    }
    final List<SqlArgument> allParams = new ArrayList<>(argTypeList.size() + initArgs.args().size());
    allParams.addAll(argTypeList);
    for (final Object arg : initArgs.args()) {
        if (arg == null) {
            allParams.add(null);
            continue;
        }
        final SqlBaseType baseType = SchemaConverters.javaToSqlConverter().toSqlType(arg.getClass());
        try {
            // Only primitive types currently supported:
            final SqlPrimitiveType primitiveType = SqlPrimitiveType.of(baseType);
            allParams.add(SqlArgument.of(primitiveType));
        } catch (final Exception e) {
            throw new KsqlFunctionException("Only primitive init arguments are supported by UDAF " + getName() + ", but got " + arg, e);
        }
    }
    return allParams;
}
Also used : SqlArgument(io.confluent.ksql.schema.ksql.SqlArgument) SqlPrimitiveType(io.confluent.ksql.schema.ksql.types.SqlPrimitiveType) SqlBaseType(io.confluent.ksql.schema.ksql.types.SqlBaseType) ArrayList(java.util.ArrayList) KsqlException(io.confluent.ksql.util.KsqlException)

Aggregations

SqlPrimitiveType (io.confluent.ksql.schema.ksql.types.SqlPrimitiveType)10 Test (org.junit.Test)9 Matchers.containsString (org.hamcrest.Matchers.containsString)8 TimestampColumn (io.confluent.ksql.execution.timestamp.TimestampColumn)1 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)1 SqlArgument (io.confluent.ksql.schema.ksql.SqlArgument)1 SqlBaseType (io.confluent.ksql.schema.ksql.types.SqlBaseType)1 Field (io.confluent.ksql.schema.ksql.types.SqlStruct.Field)1 KsqlException (io.confluent.ksql.util.KsqlException)1 ArrayList (java.util.ArrayList)1