Search in sources :

Example 6 with SchemaBuilder

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

the class GenericRowValueTypeEnforcerTest method testEnforceDoubleReturningNull.

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

Example 7 with SchemaBuilder

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

the class GenericRowValueTypeEnforcerTest method testEnforceBooleanReturningNull.

@Test
public void testEnforceBooleanReturningNull() {
    SchemaBuilder schemaBuilder = SchemaBuilder.struct().field("boolean", SchemaBuilder.bool());
    GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
    assertNull(genericRowValueTypeEnforcer.enforceFieldType(0, null));
}
Also used : SchemaBuilder(org.apache.kafka.connect.data.SchemaBuilder) Test(org.junit.Test)

Example 8 with SchemaBuilder

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

the class GenericRowValueTypeEnforcerTest method testEnforceDoubleAndEnforceDoubleOne.

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

Example 9 with SchemaBuilder

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

the class GenericRowValueTypeEnforcerTest method testEnforceLong.

@Test
public void testEnforceLong() {
    SchemaBuilder schemaBuilder = SchemaBuilder.struct().field("long", SchemaBuilder.int64());
    GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
    try {
        genericRowValueTypeEnforcer.enforceFieldType(0, Boolean.FALSE);
        fail("Expecting exception: KsqlException");
    } catch (KsqlException e) {
        assertEquals(GenericRowValueTypeEnforcer.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
Also used : SchemaBuilder(org.apache.kafka.connect.data.SchemaBuilder) Test(org.junit.Test)

Example 10 with SchemaBuilder

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

the class GenericRowValueTypeEnforcerTest method testEnforceDoubleReturningDoubleWhereShortValueIsNegative.

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

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