use of com.datastax.oss.sink.pulsar.PulsarRecordImpl in project pulsar-sink by datastax.
the class ProvidedQueryCCMIT method should_update_json_using_query_parameter.
@Test
void should_update_json_using_query_parameter() {
ImmutableMap<String, String> extras = ImmutableMap.<String, String>builder().put(queryParameter("types"), String.format("UPDATE %s.types SET listCol = listCol + [1] where bigintcol = :pkey", keyspaceName)).put(deletesDisabled("types")).build();
taskConfigs.add(makeConnectorProperties("pkey=value.pkey, newitem=value.newitem", extras));
RecordSchemaBuilder builder = org.apache.pulsar.client.api.schema.SchemaBuilder.record("MyBean");
builder.field("pkey").type(SchemaType.INT32);
builder.field("newitem").type(SchemaType.INT32);
Schema schema = org.apache.pulsar.client.api.Schema.generic(builder.build(SchemaType.AVRO));
PulsarRecordImpl record = new PulsarRecordImpl("persistent://tenant/namespace/mytopic", null, new GenericRecordImpl().put("pkey", 1234).put("newitem", 1), schema);
PulsarRecordImpl record2 = new PulsarRecordImpl("persistent://tenant/namespace/mytopic", null, new GenericRecordImpl().put("pkey", 1234).put("newitem", 1), schema);
runTaskWithRecords(record, record2);
// Verify that two values were append to listcol
List<Row> results = session.execute("SELECT * FROM types where bigintcol = 1234").all();
assertThat(results.size()).isEqualTo(1);
Row row = results.get(0);
assertThat(row.getLong("bigintcol")).isEqualTo(1234);
assertThat(row.getList("listcol", Integer.class)).isEqualTo(ImmutableList.of(1, 1));
}
use of com.datastax.oss.sink.pulsar.PulsarRecordImpl in project pulsar-sink by datastax.
the class DeleteCCMIT method delete_simple_key.
@Test
void delete_simple_key() {
// First insert a row...
session.execute("INSERT INTO pk_value (my_pk, my_value) VALUES (1234567, true)");
List<Row> results = session.execute("SELECT * FROM pk_value").all();
assertThat(results.size()).isEqualTo(1);
taskConfigs.add(makeConnectorProperties("my_pk=key, my_value=value.my_value", "pk_value", null));
PulsarRecordImpl record = new PulsarRecordImpl("persistent://tenant/namespace/mytopic", "1234567", new GenericRecordImpl(), recordType);
runTaskWithRecords(record);
// Verify that the record was deleted from the database.
results = session.execute("SELECT * FROM pk_value").all();
assertThat(results.size()).isEqualTo(0);
}
use of com.datastax.oss.sink.pulsar.PulsarRecordImpl in project pulsar-sink by datastax.
the class DeleteCCMIT method insert_with_nulls_when_delete_disabled.
@Test
void insert_with_nulls_when_delete_disabled() {
taskConfigs.add(makeConnectorProperties("bigintcol=value.bigint, booleancol=value.boolean, intcol=value.int", "small_simple", ImmutableMap.of(String.format("topic.mytopic.%s.small_simple.deletesEnabled", keyspaceName), "false")));
// Set up records for "mytopic"
GenericRecordImpl value = new GenericRecordImpl().put("bigint", 1234567L).put("int", null).put("boolean", null);
PulsarRecordImpl record = new PulsarRecordImpl("persistent://tenant/namespace/mytopic", null, value, recordType);
runTaskWithRecords(record);
// Verify that the record was inserted into the database with null non-pk values.
List<Row> results = session.execute("SELECT * FROM small_simple").all();
assertThat(results.size()).isEqualTo(1);
Row row = results.get(0);
assertThat(row.get("bigintcol", GenericType.LONG)).isEqualTo(1234567L);
assertThat(row.get("booleancol", GenericType.BOOLEAN)).isNull();
assertThat(row.get("intcol", GenericType.INTEGER)).isNull();
}
use of com.datastax.oss.sink.pulsar.PulsarRecordImpl in project pulsar-sink by datastax.
the class DeleteCCMIT method delete_compound_decode_key_json.
@Test
void delete_compound_decode_key_json() {
// First insert a row...
session.execute("INSERT INTO small_compound (bigintcol, booleancol, intcol) VALUES (1234567, true, 42)");
List<Row> results = session.execute("SELECT * FROM small_compound").all();
assertThat(results.size()).isEqualTo(1);
taskConfigs.add(makeConnectorProperties("bigintcol=key.bigint, booleancol=key.boolean, intcol=key.int", "small_compound", null));
// Set up records for "mytopic", the key contains a json value
String json = "{\"bigint\": 1234567, \"boolean\": true, \"int\": null}";
PulsarRecordImpl record = new PulsarRecordImpl("persistent://tenant/namespace/mytopic", json, new GenericRecordImpl(), recordType);
runTaskWithRecords(record);
// Verify that the record was deleted from the database.
results = session.execute("SELECT * FROM small_compound").all();
assertThat(results.size()).isEqualTo(0);
}
use of com.datastax.oss.sink.pulsar.PulsarRecordImpl in project pulsar-sink by datastax.
the class ConnectorSettingsCCMIT method should_insert_when_using_java_driver_contact_points_setting.
@Test
void should_insert_when_using_java_driver_contact_points_setting() {
Map<String, Object> connectorProperties = makeConnectorPropertiesWithoutContactPointsAndPort("bigintcol=key, listcol=value.field1");
// use single datastax-java-driver prefixed property that carry host:port
connectorProperties.put(withDriverPrefix(DefaultDriverOption.CONTACT_POINTS), getContactPoints().stream().map(a -> {
InetSocketAddress inetSocketAddress = (InetSocketAddress) a.resolve();
return String.format("%s:%d", inetSocketAddress.getHostString(), inetSocketAddress.getPort());
}).collect(Collectors.joining(",")));
taskConfigs.add(connectorProperties);
PulsarRecordImpl record = new PulsarRecordImpl("persistent://tenant/namespace/mytopic", "98761234", new GenericRecordImpl().put("field1", "[42, 37]"), recordType);
record.setRecordSequence(1234L);
runTaskWithRecords(record);
// Verify that the record was inserted properly in the database.
List<Row> results = session.execute("SELECT bigintcol, listcol FROM types").all();
assertThat(results.size()).isEqualTo(1);
Row row = results.get(0);
assertThat(row.getLong("bigintcol")).isEqualTo(98761234L);
assertThat(row.getList("listcol", Integer.class)).isEqualTo(Arrays.asList(42, 37));
}
Aggregations