use of com.datastax.dse.driver.internal.core.data.geometry.DefaultLineString in project dsbulk by datastax.
the class CodecUtilsTest method should_parse_line_string.
@Test
void should_parse_line_string() {
LineString lineString = new DefaultLineString(new DefaultPoint(30, 10), new DefaultPoint(10, 30), new DefaultPoint(40, 40));
assertThat(CodecUtils.parseLineString(null)).isNull();
assertThat(CodecUtils.parseLineString("")).isNull();
assertThat(CodecUtils.parseLineString("LINESTRING (30 10, 10 30, 40 40)")).isEqualTo(lineString);
assertThat(CodecUtils.parseLineString("'LINESTRING (30 10, 10 30, 40 40)'")).isEqualTo(lineString);
assertThat(CodecUtils.parseLineString("{\"type\":\"LineString\",\"coordinates\":[[30.0,10.0],[10.0,30.0],[40.0,40.0]]}")).isEqualTo(lineString);
assertThat(CodecUtils.parseLineString("AQIAAAADAAAAAAAAAAAAPkAAAAAAAAAkQAAAAAAAACRAAAAAAAAAPkAAAAAAAABEQAAAAAAAAERA")).isEqualTo(lineString);
assertThat(CodecUtils.parseLineString("0x0102000000030000000000000000003e40000000000000244000000000000024400000000000003e4000000000000044400000000000004440")).isEqualTo(lineString);
assertThatThrownBy(() -> CodecUtils.parseLineString("not a valid line string")).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Invalid line string literal");
}
use of com.datastax.dse.driver.internal.core.data.geometry.DefaultLineString in project pulsar-sink by datastax.
the class StructEndToEndCCMIT method struct_value_only.
@Test
void struct_value_only() throws ParseException {
String withDateRange = hasDateRange ? "daterangecol=value.daterange, " : "";
String withGeotypes = ccm.getClusterType() == DSE ? "pointcol=value.point, linestringcol=value.linestring, polygoncol=value.polygon, " : "";
taskConfigs.add(makeConnectorProperties("bigintcol=value.bigint, " + "booleancol=value.boolean, " + "doublecol=value.double, " + "floatcol=value.float, " + "intcol=value.int, " + "textcol=value.text, " + withGeotypes + withDateRange + "blobcol=value.blob"));
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("double").type(SchemaType.DOUBLE);
builder.field("float").type(SchemaType.FLOAT);
builder.field("int").type(SchemaType.INT32);
builder.field("text").type(SchemaType.STRING);
builder.field("blob").type(SchemaType.BYTES);
builder.field("point").type(SchemaType.STRING);
builder.field("linestring").type(SchemaType.STRING);
builder.field("polygon").type(SchemaType.STRING);
builder.field("daterange").type(SchemaType.STRING);
Schema schema = org.apache.pulsar.client.api.Schema.generic(builder.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("text", baseValue.toString()).put("blob", blobValue).put("point", "POINT (32.0 64.0)").put("linestring", "LINESTRING (32.0 64.0, 48.5 96.5)").put("polygon", "POLYGON ((0.0 0.0, 20.0 0.0, 25.0 25.0, 0.0 25.0, 0.0 0.0))").put("daterange", "[* TO 2014-12-01]");
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);
if (ccm.getClusterType() == DSE) {
assertThat(row.get("pointcol", GenericType.of(Point.class))).isEqualTo(new DefaultPoint(32.0, 64.0));
assertThat(row.get("linestringcol", GenericType.of(LineString.class))).isEqualTo(new DefaultLineString(new DefaultPoint(32.0, 64.0), new DefaultPoint(48.5, 96.5)));
assertThat(row.get("polygoncol", GenericType.of(Polygon.class))).isEqualTo(new DefaultPolygon(new DefaultPoint(0, 0), new DefaultPoint(20, 0), new DefaultPoint(25, 25), new DefaultPoint(0, 25), new DefaultPoint(0, 0)));
}
if (hasDateRange) {
assertThat(row.get("daterangecol", GenericType.of(DateRange.class))).isEqualTo(DateRange.parse("[* TO 2014-12-01]"));
}
}
Aggregations