Search in sources :

Example 1 with SchemaBuilder

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

the class GenericRowValueTypeEnforcerTest method testEnforceIntegerOnValidString.

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

Example 2 with SchemaBuilder

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

the class GenericRowValueTypeEnforcerTest method testEnforceLongReturningLongWhereByteValueIsNegative.

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

Example 3 with SchemaBuilder

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

the class GenericRowValueTypeEnforcerTest method testEnforceLongOnValidString.

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

Example 4 with SchemaBuilder

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

the class GenericRowValueTypeEnforcerTest method testEnforceDoubleThrowsNumberFormatExceptionOnInvalidCharSequence.

@Test(expected = NumberFormatException.class)
public void testEnforceDoubleThrowsNumberFormatExceptionOnInvalidCharSequence() {
    SchemaBuilder schemaBuilder = SchemaBuilder.struct().field("double", SchemaBuilder.float64());
    GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
    genericRowValueTypeEnforcer.enforceFieldType(0, new StringBuilder("not a double"));
}
Also used : SchemaBuilder(org.apache.kafka.connect.data.SchemaBuilder) Test(org.junit.Test)

Example 5 with SchemaBuilder

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

the class GenericRowValueTypeEnforcerTest method testEnforceBooleanReturningBooleanWhereBooleanValueIsFalse.

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

Aggregations

SchemaBuilder (org.apache.kafka.connect.data.SchemaBuilder)88 Schema (org.apache.kafka.connect.data.Schema)40 Test (org.junit.Test)40 Struct (org.apache.kafka.connect.data.Struct)23 Field (org.apache.kafka.connect.data.Field)13 SourceRecord (org.apache.kafka.connect.source.SourceRecord)13 Test (org.junit.jupiter.api.Test)9 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