Search in sources :

Example 6 with PulsarRecordImpl

use of com.datastax.oss.sink.pulsar.PulsarRecordImpl in project pulsar-sink by datastax.

the class StructEndToEndCCMIT method struct_optional_fields_missing.

@Test
void struct_optional_fields_missing() {
    taskConfigs.add(makeConnectorProperties("bigintcol=value.bigint, intcol=value.int, doublecol=value.double"));
    RecordSchemaBuilder builderRoot = org.apache.pulsar.client.api.schema.SchemaBuilder.record("MyBean");
    builderRoot.field("bigint").type(SchemaType.INT64).optional();
    builderRoot.field("boolean").type(SchemaType.BOOLEAN).optional();
    builderRoot.field("double").type(SchemaType.DOUBLE).optional();
    builderRoot.field("float").type(SchemaType.FLOAT).optional();
    builderRoot.field("int").type(SchemaType.INT32).optional();
    builderRoot.field("text").type(SchemaType.STRING).optional();
    builderRoot.field("blob").type(SchemaType.BYTES).optional();
    GenericSchema schema = org.apache.pulsar.client.api.Schema.generic(builderRoot.build(SchemaType.AVRO));
    Long baseValue = 98761234L;
    GenericRecordImpl value = new GenericRecordImpl().put("bigint", baseValue).put("int", baseValue.intValue());
    runTaskWithRecords(new PulsarRecordImpl("persistent://tenant/namespace/mytopic", null, value, schema));
    // Verify that the record was inserted properly in the database.
    List<Row> results = session.execute("SELECT * FROM types").all();
    assertThat(results.size()).isEqualTo(1);
    Row row = results.get(0);
    assertThat(row.getLong("bigintcol")).isEqualTo(baseValue);
    assertThat(row.getInt("intcol")).isEqualTo(baseValue.intValue());
}
Also used : RecordSchemaBuilder(org.apache.pulsar.client.api.schema.RecordSchemaBuilder) PulsarRecordImpl(com.datastax.oss.sink.pulsar.PulsarRecordImpl) GenericSchema(org.apache.pulsar.client.api.schema.GenericSchema) GenericRecordImpl(com.datastax.oss.sink.pulsar.GenericRecordImpl) Row(com.datastax.oss.driver.api.core.cql.Row) Test(org.junit.jupiter.api.Test)

Example 7 with PulsarRecordImpl

use of com.datastax.oss.sink.pulsar.PulsarRecordImpl in project pulsar-sink by datastax.

the class StructEndToEndCCMIT method struct_optional_fields_with_values.

@Test
void struct_optional_fields_with_values() {
    taskConfigs.add(makeConnectorProperties("bigintcol=value.bigint, " + "booleancol=value.boolean, " + "doublecol=value.double, " + "floatcol=value.float, " + "intcol=value.int, " + "textcol=value.text, " + "blobcol=value.blob"));
    RecordSchemaBuilder builderRoot = org.apache.pulsar.client.api.schema.SchemaBuilder.record("MyBean");
    builderRoot.field("bigint").type(SchemaType.INT64).optional();
    builderRoot.field("boolean").type(SchemaType.BOOLEAN).optional();
    builderRoot.field("double").type(SchemaType.DOUBLE).optional();
    builderRoot.field("float").type(SchemaType.FLOAT).optional();
    builderRoot.field("int").type(SchemaType.INT32).optional();
    builderRoot.field("text").type(SchemaType.STRING).optional();
    builderRoot.field("blob").type(SchemaType.BYTES).optional();
    GenericSchema schema = org.apache.pulsar.client.api.Schema.generic(builderRoot.build(SchemaType.AVRO));
    byte[] blobValue = new byte[] { 12, 22, 32 };
    Long baseValue = 98761234L;
    GenericRecordImpl value = new GenericRecordImpl().put("bigint", baseValue).put("boolean", (baseValue.intValue() & 1) == 1).put("double", (double) baseValue + 0.123).put("float", baseValue.floatValue() + 0.987f).put("int", baseValue.intValue()).put("smallint", baseValue.shortValue()).put("text", baseValue.toString()).put("blob", blobValue);
    runTaskWithRecords(new PulsarRecordImpl("persistent://tenant/namespace/mytopic", null, value, schema));
    // Verify that the record was inserted properly in the database.
    List<Row> results = session.execute("SELECT * FROM types").all();
    assertThat(results.size()).isEqualTo(1);
    Row row = results.get(0);
    assertThat(row.getLong("bigintcol")).isEqualTo(baseValue);
    assertThat(row.getBoolean("booleancol")).isEqualTo((baseValue.intValue() & 1) == 1);
    assertThat(row.getDouble("doublecol")).isEqualTo((double) baseValue + 0.123);
    assertThat(row.getFloat("floatcol")).isEqualTo(baseValue.floatValue() + 0.987f);
    assertThat(row.getInt("intcol")).isEqualTo(baseValue.intValue());
    assertThat(row.getString("textcol")).isEqualTo(baseValue.toString());
    ByteBuffer blobcol = row.getByteBuffer("blobcol");
    assertThat(blobcol).isNotNull();
    assertThat(Bytes.getArray(blobcol)).isEqualTo(blobValue);
}
Also used : RecordSchemaBuilder(org.apache.pulsar.client.api.schema.RecordSchemaBuilder) PulsarRecordImpl(com.datastax.oss.sink.pulsar.PulsarRecordImpl) GenericSchema(org.apache.pulsar.client.api.schema.GenericSchema) GenericRecordImpl(com.datastax.oss.sink.pulsar.GenericRecordImpl) Row(com.datastax.oss.driver.api.core.cql.Row) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 8 with PulsarRecordImpl

use of com.datastax.oss.sink.pulsar.PulsarRecordImpl in project pulsar-sink by datastax.

the class StructEndToEndCCMIT method single_record_multiple_tables.

@Test
void single_record_multiple_tables() {
    taskConfigs.add(makeConnectorProperties("bigintcol=value.bigint, booleancol=value.boolean, intcol=value.int", ImmutableMap.of(String.format("topic.mytopic.%s.small_simple.mapping", keyspaceName), "bigintcol=value.bigint, intcol=value.int")));
    // Set up records for "mytopic"
    RecordSchemaBuilder builder = org.apache.pulsar.client.api.schema.SchemaBuilder.record("MyBean");
    builder.field("bigint").type(SchemaType.INT64);
    builder.field("boolean").type(SchemaType.BOOLEAN);
    builder.field("int").type(SchemaType.INT32);
    Schema schema = org.apache.pulsar.client.api.Schema.generic(builder.build(SchemaType.AVRO));
    GenericRecordImpl value = new GenericRecordImpl().put("bigint", 1234567L).put("boolean", true).put("int", 5725);
    PulsarRecordImpl record = new PulsarRecordImpl("persistent://tenant/namespace/mytopic", null, value, schema);
    runTaskWithRecords(record);
    // Verify that a record was inserted in each of small_simple and types tables.
    {
        List<Row> results = session.execute("SELECT * FROM small_simple").all();
        assertThat(results.size()).isEqualTo(1);
        Row row = results.get(0);
        assertThat(row.getLong("bigintcol")).isEqualTo(1234567L);
        assertThat(row.get("booleancol", GenericType.BOOLEAN)).isNull();
        assertThat(row.getInt("intcol")).isEqualTo(5725);
    }
    {
        List<Row> results = session.execute("SELECT * FROM types").all();
        assertThat(results.size()).isEqualTo(1);
        Row row = results.get(0);
        assertThat(row.getLong("bigintcol")).isEqualTo(1234567L);
        assertThat(row.getBoolean("booleancol")).isTrue();
        assertThat(row.getInt("intcol")).isEqualTo(5725);
    }
}
Also used : RecordSchemaBuilder(org.apache.pulsar.client.api.schema.RecordSchemaBuilder) PulsarRecordImpl(com.datastax.oss.sink.pulsar.PulsarRecordImpl) GenericSchema(org.apache.pulsar.client.api.schema.GenericSchema) Schema(org.apache.pulsar.client.api.Schema) GenericRecordImpl(com.datastax.oss.sink.pulsar.GenericRecordImpl) List(java.util.List) Row(com.datastax.oss.driver.api.core.cql.Row) Test(org.junit.jupiter.api.Test)

Example 9 with PulsarRecordImpl

use of com.datastax.oss.sink.pulsar.PulsarRecordImpl in project pulsar-sink by datastax.

the class StructEndToEndCCMIT method multiple_records_multiple_topics.

@Test
void multiple_records_multiple_topics() {
    taskConfigs.add(makeConnectorProperties("bigintcol=value.bigint, doublecol=value.double", ImmutableMap.of(String.format("topic.yourtopic.%s.types.mapping", keyspaceName), "bigintcol=key, intcol=value.int")));
    // Set up records for "mytopic"
    RecordSchemaBuilder builder = org.apache.pulsar.client.api.schema.SchemaBuilder.record("MyBean");
    builder.field("bigint").type(SchemaType.INT64);
    builder.field("double").type(SchemaType.DOUBLE);
    Schema recordTypeUtd = org.apache.pulsar.client.api.Schema.generic(builder.build(SchemaType.AVRO));
    GenericRecordImpl value1 = new GenericRecordImpl().put("bigint", 1234567L).put("double", 42.0);
    GenericRecordImpl value2 = new GenericRecordImpl().put("bigint", 9876543L).put("double", 21.0);
    PulsarRecordImpl record1 = new PulsarRecordImpl("persistent://tenant/namespace/mytopic", null, value1, recordTypeUtd);
    PulsarRecordImpl record2 = new PulsarRecordImpl("persistent://tenant/namespace/mytopic", null, value2, recordTypeUtd);
    // Set up a record for "yourtopic"
    PulsarRecordImpl record3 = new PulsarRecordImpl("persistent://tenant/namespace/yourtopic", "5555", new GenericRecordImpl().put("int", 3333), recordType);
    runTaskWithRecords(record1, record2, record3);
    // Verify that the record was inserted properly in the database.
    List<Row> results = session.execute("SELECT bigintcol, doublecol, intcol FROM types").all();
    assertThat(results.size()).isEqualTo(3);
    for (Row row : results) {
        if (row.getLong("bigintcol") == 1234567L) {
            assertThat(row.getDouble("doublecol")).isEqualTo(42.0);
            assertThat(row.getObject("intcol")).isNull();
        } else if (row.getLong("bigintcol") == 9876543L) {
            assertThat(row.getDouble("doublecol")).isEqualTo(21.0);
            assertThat(row.getObject("intcol")).isNull();
        } else if (row.getLong("bigintcol") == 5555L) {
            assertThat(row.getObject("doublecol")).isNull();
            assertThat(row.getInt("intcol")).isEqualTo(3333);
        }
    }
}
Also used : RecordSchemaBuilder(org.apache.pulsar.client.api.schema.RecordSchemaBuilder) PulsarRecordImpl(com.datastax.oss.sink.pulsar.PulsarRecordImpl) GenericSchema(org.apache.pulsar.client.api.schema.GenericSchema) Schema(org.apache.pulsar.client.api.Schema) GenericRecordImpl(com.datastax.oss.sink.pulsar.GenericRecordImpl) Row(com.datastax.oss.driver.api.core.cql.Row) Test(org.junit.jupiter.api.Test)

Example 10 with PulsarRecordImpl

use of com.datastax.oss.sink.pulsar.PulsarRecordImpl in project pulsar-sink by datastax.

the class StructEndToEndCCMIT method raw_udt_value_from_struct.

@Test
void raw_udt_value_from_struct() {
    taskConfigs.add(makeConnectorProperties("bigintcol=key, udtcol=value"));
    RecordSchemaBuilder builder = org.apache.pulsar.client.api.schema.SchemaBuilder.record("MyBean");
    builder.field("udtmem1").type(SchemaType.INT32);
    builder.field("udtmem2").type(SchemaType.STRING);
    Schema recordTypeUtd = org.apache.pulsar.client.api.Schema.generic(builder.build(SchemaType.AVRO));
    GenericRecordImpl value = new GenericRecordImpl().put("udtmem1", 42).put("udtmem2", "the answer");
    PulsarRecordImpl record = new PulsarRecordImpl("persistent://tenant/namespace/mytopic", "98761234", value, recordTypeUtd);
    runTaskWithRecords(record);
    // Verify that the record was inserted properly in the database.
    List<Row> results = session.execute("SELECT bigintcol, udtcol FROM types").all();
    assertThat(results.size()).isEqualTo(1);
    Row row = results.get(0);
    assertThat(row.getLong("bigintcol")).isEqualTo(98761234L);
    UserDefinedType udt = new UserDefinedTypeBuilder(keyspaceName, "myudt").withField("udtmem1", DataTypes.INT).withField("udtmem2", DataTypes.TEXT).build();
    udt.attach(session.getContext());
    assertThat(row.getUdtValue("udtcol")).isEqualTo(udt.newValue(42, "the answer"));
}
Also used : RecordSchemaBuilder(org.apache.pulsar.client.api.schema.RecordSchemaBuilder) PulsarRecordImpl(com.datastax.oss.sink.pulsar.PulsarRecordImpl) GenericSchema(org.apache.pulsar.client.api.schema.GenericSchema) Schema(org.apache.pulsar.client.api.Schema) UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType) GenericRecordImpl(com.datastax.oss.sink.pulsar.GenericRecordImpl) Row(com.datastax.oss.driver.api.core.cql.Row) UserDefinedTypeBuilder(com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

PulsarRecordImpl (com.datastax.oss.sink.pulsar.PulsarRecordImpl)75 Test (org.junit.jupiter.api.Test)69 Row (com.datastax.oss.driver.api.core.cql.Row)64 GenericRecordImpl (com.datastax.oss.sink.pulsar.GenericRecordImpl)56 RecordSchemaBuilder (org.apache.pulsar.client.api.schema.RecordSchemaBuilder)17 Schema (org.apache.pulsar.client.api.Schema)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 GenericSchema (org.apache.pulsar.client.api.schema.GenericSchema)9 UserDefinedType (com.datastax.oss.driver.api.core.type.UserDefinedType)8 UserDefinedTypeBuilder (com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder)8 GenericRecord (org.apache.pulsar.client.api.schema.GenericRecord)4 Query (com.datastax.oss.simulacron.common.request.Query)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 LineString (com.datastax.dse.driver.api.core.data.geometry.LineString)2 DefaultLineString (com.datastax.dse.driver.internal.core.data.geometry.DefaultLineString)2 ConfigException (com.datastax.oss.common.sink.ConfigException)2 InstanceState (com.datastax.oss.common.sink.state.InstanceState)2 InetSocketAddress (java.net.InetSocketAddress)2 HashMap (java.util.HashMap)2 Point (com.datastax.dse.driver.api.core.data.geometry.Point)1