use of com.datastax.dse.driver.internal.core.data.geometry.DefaultPolygon 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;
}
use of com.datastax.dse.driver.internal.core.data.geometry.DefaultPolygon 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]"));
}
}
use of com.datastax.dse.driver.internal.core.data.geometry.DefaultPolygon 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");
}
Aggregations