Search in sources :

Example 1 with DefaultPoint

use of com.datastax.dse.driver.internal.core.data.geometry.DefaultPoint 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");
}
Also used : DefaultLineString(com.datastax.dse.driver.internal.core.data.geometry.DefaultLineString) LineString(com.datastax.dse.driver.api.core.data.geometry.LineString) DefaultLineString(com.datastax.dse.driver.internal.core.data.geometry.DefaultLineString) DefaultPoint(com.datastax.dse.driver.internal.core.data.geometry.DefaultPoint) Test(org.junit.jupiter.api.Test)

Example 2 with DefaultPoint

use of com.datastax.dse.driver.internal.core.data.geometry.DefaultPoint in project nosqlbench by nosqlbench.

the class PolygonOnGrid method apply.

@Override
public Polygon apply(long value) {
    int row = rowfunc.applyAsInt(value);
    int column = colfunc.applyAsInt(value + 33);
    double left = x_topleft + (column * xwidth);
    double top = y_topleft - (row * yheight);
    double right = left + xwidth;
    double bottom = top - yheight;
    com.datastax.dse.driver.api.core.data.geometry.Polygon polygon = new DefaultPolygon(new DefaultPoint(left, bottom), new DefaultPoint(left, top), new DefaultPoint(right, top), new DefaultPoint(right, bottom));
    return polygon;
}
Also used : Polygon(com.datastax.dse.driver.api.core.data.geometry.Polygon) DefaultPolygon(com.datastax.dse.driver.internal.core.data.geometry.DefaultPolygon) DefaultPoint(com.datastax.dse.driver.internal.core.data.geometry.DefaultPoint) DefaultPoint(com.datastax.dse.driver.internal.core.data.geometry.DefaultPoint)

Example 3 with DefaultPoint

use of com.datastax.dse.driver.internal.core.data.geometry.DefaultPoint 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]"));
    }
}
Also used : DefaultLineString(com.datastax.dse.driver.internal.core.data.geometry.DefaultLineString) 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) LineString(com.datastax.dse.driver.api.core.data.geometry.LineString) DefaultLineString(com.datastax.dse.driver.internal.core.data.geometry.DefaultLineString) Point(com.datastax.dse.driver.api.core.data.geometry.Point) DefaultPoint(com.datastax.dse.driver.internal.core.data.geometry.DefaultPoint) ByteBuffer(java.nio.ByteBuffer) DefaultPolygon(com.datastax.dse.driver.internal.core.data.geometry.DefaultPolygon) DateRange(com.datastax.dse.driver.api.core.data.time.DateRange) LineString(com.datastax.dse.driver.api.core.data.geometry.LineString) DefaultLineString(com.datastax.dse.driver.internal.core.data.geometry.DefaultLineString) GenericRecordImpl(com.datastax.oss.sink.pulsar.GenericRecordImpl) Row(com.datastax.oss.driver.api.core.cql.Row) DefaultPoint(com.datastax.dse.driver.internal.core.data.geometry.DefaultPoint) DefaultPolygon(com.datastax.dse.driver.internal.core.data.geometry.DefaultPolygon) Polygon(com.datastax.dse.driver.api.core.data.geometry.Polygon) Test(org.junit.jupiter.api.Test)

Example 4 with DefaultPoint

use of com.datastax.dse.driver.internal.core.data.geometry.DefaultPoint in project dsbulk by datastax.

the class CodecUtilsTest method should_parse_polygon.

@Test
void should_parse_polygon() {
    Polygon polygon = new DefaultPolygon(new DefaultPoint(30, 10), new DefaultPoint(10, 20), new DefaultPoint(20, 40), new DefaultPoint(40, 40));
    assertThat(CodecUtils.parsePolygon(null)).isNull();
    assertThat(CodecUtils.parsePolygon("")).isNull();
    assertThat(CodecUtils.parsePolygon("POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))")).isEqualTo(polygon);
    assertThat(CodecUtils.parsePolygon("'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))'")).isEqualTo(polygon);
    assertThat(CodecUtils.parsePolygon("{\"type\":\"Polygon\",\"coordinates\":[[[30.0,10.0],[10.0,20.0],[20.0,40.0],[40.0,40.0],[30.0,10.0]]]}")).isEqualTo(polygon);
    assertThat(CodecUtils.parsePolygon("AQMAAAABAAAABQAAAAAAAAAAAD5AAAAAAAAAJEAAAAAAAABEQAAAAAAAAERAAAAAAAAANEAAAAAAAABEQAAAAAAAACRAAAAAAAAANEAAAAAAAAA+QAAAAAAAACRA")).isEqualTo(polygon);
    assertThat(CodecUtils.parsePolygon("0x010300000001000000050000000000000000003e4000000000000024400000000000004440000000000000444" + "000000000000034400000000000004440000000000000244000000000000034400000000000003e400000000000002440")).isEqualTo(polygon);
    assertThatThrownBy(() -> CodecUtils.parsePolygon("not a valid polygon")).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Invalid polygon literal");
}
Also used : DefaultPolygon(com.datastax.dse.driver.internal.core.data.geometry.DefaultPolygon) DefaultPolygon(com.datastax.dse.driver.internal.core.data.geometry.DefaultPolygon) Polygon(com.datastax.dse.driver.api.core.data.geometry.Polygon) DefaultPoint(com.datastax.dse.driver.internal.core.data.geometry.DefaultPoint) Test(org.junit.jupiter.api.Test)

Example 5 with DefaultPoint

use of com.datastax.dse.driver.internal.core.data.geometry.DefaultPoint in project dsbulk by datastax.

the class CodecUtilsTest method should_parse_point.

@Test
void should_parse_point() {
    assertThat(CodecUtils.parsePoint(null)).isNull();
    assertThat(CodecUtils.parsePoint("")).isNull();
    assertThat(CodecUtils.parsePoint("POINT (-1.1 -2.2)")).isEqualTo(new DefaultPoint(-1.1d, -2.2d));
    assertThat(CodecUtils.parsePoint("'POINT (-1.1 -2.2)'")).isEqualTo(new DefaultPoint(-1.1d, -2.2d));
    assertThat(CodecUtils.parsePoint("{\"type\":\"Point\",\"coordinates\":[-1.1,-2.2]}")).isEqualTo(new DefaultPoint(-1.1d, -2.2d));
    assertThat(CodecUtils.parsePoint("AQEAAACamZmZmZnxv5qZmZmZmQHA")).isEqualTo(new DefaultPoint(-1.1d, -2.2d));
    assertThat(CodecUtils.parsePoint("0x01010000009a9999999999f1bf9a999999999901c0")).isEqualTo(new DefaultPoint(-1.1d, -2.2d));
    assertThatThrownBy(() -> CodecUtils.parsePoint("not a valid point")).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Invalid point literal");
}
Also used : DefaultPoint(com.datastax.dse.driver.internal.core.data.geometry.DefaultPoint) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultPoint (com.datastax.dse.driver.internal.core.data.geometry.DefaultPoint)5 Test (org.junit.jupiter.api.Test)4 Polygon (com.datastax.dse.driver.api.core.data.geometry.Polygon)3 DefaultPolygon (com.datastax.dse.driver.internal.core.data.geometry.DefaultPolygon)3 LineString (com.datastax.dse.driver.api.core.data.geometry.LineString)2 DefaultLineString (com.datastax.dse.driver.internal.core.data.geometry.DefaultLineString)2 Point (com.datastax.dse.driver.api.core.data.geometry.Point)1 DateRange (com.datastax.dse.driver.api.core.data.time.DateRange)1 Row (com.datastax.oss.driver.api.core.cql.Row)1 GenericRecordImpl (com.datastax.oss.sink.pulsar.GenericRecordImpl)1 PulsarRecordImpl (com.datastax.oss.sink.pulsar.PulsarRecordImpl)1 ByteBuffer (java.nio.ByteBuffer)1 Schema (org.apache.pulsar.client.api.Schema)1 GenericSchema (org.apache.pulsar.client.api.schema.GenericSchema)1 RecordSchemaBuilder (org.apache.pulsar.client.api.schema.RecordSchemaBuilder)1