Search in sources :

Example 16 with SchemaBuilder

use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.

the class GenericRowValueTypeEnforcerTest method testEnforceLongAndEnforceLongOne.

@Test
public void testEnforceLongAndEnforceLongOne() {
    SchemaBuilder schemaBuilder = SchemaBuilder.struct().field("long", SchemaBuilder.int64());
    GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
    assertEquals(0L, genericRowValueTypeEnforcer.enforceFieldType(0, 0));
}
Also used : SchemaBuilder(org.apache.kafka.connect.data.SchemaBuilder) Test(org.junit.Test)

Example 17 with SchemaBuilder

use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.

the class GenericRowValueTypeEnforcerTest method testEnforceIntegerAndEnforceIntegerThree.

@Test
public void testEnforceIntegerAndEnforceIntegerThree() {
    SchemaBuilder schemaBuilder = SchemaBuilder.struct().field("int", SchemaBuilder.int32());
    GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
    assertEquals(361, genericRowValueTypeEnforcer.enforceFieldType(0, 361L));
}
Also used : SchemaBuilder(org.apache.kafka.connect.data.SchemaBuilder) Test(org.junit.Test)

Example 18 with SchemaBuilder

use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.

the class GenericRowValueTypeEnforcerTest method testEnforceDoubleReturningDoubleWhereByteValueIsNegative.

@Test
public void testEnforceDoubleReturningDoubleWhereByteValueIsNegative() {
    SchemaBuilder schemaBuilder = SchemaBuilder.struct().field("double", SchemaBuilder.float64());
    GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
    assertEquals((-1.0), genericRowValueTypeEnforcer.enforceFieldType(0, -1));
}
Also used : SchemaBuilder(org.apache.kafka.connect.data.SchemaBuilder) Test(org.junit.Test)

Example 19 with SchemaBuilder

use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.

the class GenericRowValueTypeEnforcerTest method testEnforceIntegerThrowsNumberFormatExceptionOnInvalidString.

@Test
public void testEnforceIntegerThrowsNumberFormatExceptionOnInvalidString() {
    SchemaBuilder schemaBuilder = SchemaBuilder.struct().field("int", SchemaBuilder.int32());
    GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
    try {
        genericRowValueTypeEnforcer.enforceFieldType(0, "Wzhq'Rrv?s=O");
        fail("Expecting exception: NumberFormatException");
    } catch (NumberFormatException e) {
        assertEquals(NumberFormatException.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
Also used : SchemaBuilder(org.apache.kafka.connect.data.SchemaBuilder) Test(org.junit.Test)

Example 20 with SchemaBuilder

use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.

the class AstBuilder method getResultDatasource.

private StructuredDataSource getResultDatasource(Select select, Table into) {
    SchemaBuilder dataSource = SchemaBuilder.struct().name(into.toString());
    for (SelectItem selectItem : select.getSelectItems()) {
        if (selectItem instanceof SingleColumn) {
            SingleColumn singleColumn = (SingleColumn) selectItem;
            String fieldName = singleColumn.getAlias().get();
            dataSource = dataSource.field(fieldName, Schema.BOOLEAN_SCHEMA);
        }
    }
    KsqlTopic ksqlTopic = new KsqlTopic(into.getName().toString(), into.getName().toString(), null);
    StructuredDataSource resultStream = new KsqlStream("AstBuilder-Into", into.getName().toString(), dataSource.schema(), dataSource.fields().get(0), null, ksqlTopic);
    return resultStream;
}
Also used : StructuredDataSource(io.confluent.ksql.metastore.StructuredDataSource) KsqlStream(io.confluent.ksql.metastore.KsqlStream) SelectItem(io.confluent.ksql.parser.tree.SelectItem) SchemaBuilder(org.apache.kafka.connect.data.SchemaBuilder) SingleColumn(io.confluent.ksql.parser.tree.SingleColumn) KsqlTopic(io.confluent.ksql.metastore.KsqlTopic)

Aggregations

SchemaBuilder (org.apache.kafka.connect.data.SchemaBuilder)84 Test (org.junit.Test)40 Schema (org.apache.kafka.connect.data.Schema)36 Struct (org.apache.kafka.connect.data.Struct)21 Field (org.apache.kafka.connect.data.Field)13 SourceRecord (org.apache.kafka.connect.source.SourceRecord)13 Test (org.junit.jupiter.api.Test)8 ConnectSchema (org.apache.kafka.connect.data.ConnectSchema)6 BigDecimal (java.math.BigDecimal)5 Date (java.util.Date)5 Requirements.requireStruct (org.apache.kafka.connect.transforms.util.Requirements.requireStruct)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 DataException (org.apache.kafka.connect.errors.DataException)4 KsqlStream (io.confluent.ksql.metastore.KsqlStream)3 KsqlTopic (io.confluent.ksql.metastore.KsqlTopic)3 Expression (io.confluent.ksql.parser.tree.Expression)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 SelectItem (io.confluent.ksql.parser.tree.SelectItem)2 SingleColumn (io.confluent.ksql.parser.tree.SingleColumn)2