use of org.locationtech.geowave.core.index.IndexDimensionHint in project geowave by locationtech.
the class BasicDataTypeAdapterTest method testInheritedAnnotatedObjectBasedDataAdapter.
@Test
public void testInheritedAnnotatedObjectBasedDataAdapter() {
BasicDataTypeAdapter<InheritedAnnotatedTestType> adapter = BasicDataTypeAdapter.newAdapter("myType", InheritedAnnotatedTestType.class, "alternateName");
assertEquals("myType", adapter.getTypeName());
assertEquals(InheritedAnnotatedTestType.class, adapter.getDataClass());
assertEquals(5, adapter.getFieldDescriptors().length);
assertNotNull(adapter.getFieldDescriptor("alternateName"));
assertTrue(String.class.isAssignableFrom(adapter.getFieldDescriptor("alternateName").bindingClass()));
assertTrue(adapter.getFieldDescriptor("alternateName").indexHints().contains(new IndexDimensionHint("a")));
assertNotNull(adapter.getFieldDescriptor("doubleField"));
assertTrue(Double.class.isAssignableFrom(adapter.getFieldDescriptor("doubleField").bindingClass()));
assertNotNull(adapter.getFieldDescriptor("intField"));
assertTrue(Integer.class.isAssignableFrom(adapter.getFieldDescriptor("intField").bindingClass()));
assertNotNull(adapter.getFieldDescriptor("boolField"));
assertTrue(Boolean.class.isAssignableFrom(adapter.getFieldDescriptor("boolField").bindingClass()));
assertTrue(adapter.getFieldDescriptor("boolField").indexHints().contains(new IndexDimensionHint("a")));
assertTrue(adapter.getFieldDescriptor("boolField").indexHints().contains(new IndexDimensionHint("b")));
assertTrue(adapter.getFieldDescriptor("boolField").indexHints().contains(new IndexDimensionHint("c")));
assertNotNull(adapter.getFieldDescriptor("extraField"));
assertTrue(Double.class.isAssignableFrom(adapter.getFieldDescriptor("extraField").bindingClass()));
final byte[] adapterBytes = PersistenceUtils.toBinary(adapter);
adapter = (BasicDataTypeAdapter) PersistenceUtils.fromBinary(adapterBytes);
assertEquals("myType", adapter.getTypeName());
assertEquals(InheritedAnnotatedTestType.class, adapter.getDataClass());
assertEquals(5, adapter.getFieldDescriptors().length);
assertNotNull(adapter.getFieldDescriptor("alternateName"));
assertTrue(String.class.isAssignableFrom(adapter.getFieldDescriptor("alternateName").bindingClass()));
assertTrue(adapter.getFieldDescriptor("alternateName").indexHints().contains(new IndexDimensionHint("a")));
assertNotNull(adapter.getFieldDescriptor("doubleField"));
assertTrue(Double.class.isAssignableFrom(adapter.getFieldDescriptor("doubleField").bindingClass()));
assertNotNull(adapter.getFieldDescriptor("intField"));
assertTrue(Integer.class.isAssignableFrom(adapter.getFieldDescriptor("intField").bindingClass()));
assertNotNull(adapter.getFieldDescriptor("boolField"));
assertTrue(Boolean.class.isAssignableFrom(adapter.getFieldDescriptor("boolField").bindingClass()));
assertTrue(adapter.getFieldDescriptor("boolField").indexHints().contains(new IndexDimensionHint("a")));
assertTrue(adapter.getFieldDescriptor("boolField").indexHints().contains(new IndexDimensionHint("b")));
assertTrue(adapter.getFieldDescriptor("boolField").indexHints().contains(new IndexDimensionHint("c")));
assertNotNull(adapter.getFieldDescriptor("extraField"));
assertTrue(Double.class.isAssignableFrom(adapter.getFieldDescriptor("extraField").bindingClass()));
final InheritedAnnotatedTestType testEntry = new InheritedAnnotatedTestType("id1", 2.5, 8, true, "ignored", 5.3);
assertEquals("id1", adapter.getFieldValue(testEntry, "alternateName"));
assertEquals(2.5, (double) adapter.getFieldValue(testEntry, "doubleField"), 0.001);
assertEquals(8, adapter.getFieldValue(testEntry, "intField"));
assertTrue((boolean) adapter.getFieldValue(testEntry, "boolField"));
assertEquals(5.3, (double) adapter.getFieldValue(testEntry, "extraField"), 0.001);
final Object[] fields = new Object[5];
for (int i = 0; i < fields.length; i++) {
switch(adapter.getFieldDescriptors()[i].fieldName()) {
case "alternateName":
fields[i] = "id1";
break;
case "doubleField":
fields[i] = 2.5;
break;
case "intField":
fields[i] = 8;
break;
case "boolField":
fields[i] = true;
break;
case "extraField":
fields[i] = 5.3;
break;
}
}
final InheritedAnnotatedTestType builtEntry = adapter.buildObject("id1", fields);
assertEquals("id1", adapter.getFieldValue(builtEntry, "alternateName"));
assertEquals(2.5, (double) adapter.getFieldValue(builtEntry, "doubleField"), 0.001);
assertEquals(8, adapter.getFieldValue(builtEntry, "intField"));
assertTrue((boolean) adapter.getFieldValue(builtEntry, "boolField"));
assertEquals(5.3, (double) adapter.getFieldValue(builtEntry, "extraField"), 0.001);
assertNull(builtEntry.ignoredField);
}
use of org.locationtech.geowave.core.index.IndexDimensionHint in project geowave by locationtech.
the class BasicDataTypeAdapterTest method testInheritedAnnotatedObjectBasedDataAdapterSeparateDataID.
@Test
public void testInheritedAnnotatedObjectBasedDataAdapterSeparateDataID() {
BasicDataTypeAdapter<InheritedAnnotatedTestType> adapter = BasicDataTypeAdapter.newAdapter("myType", InheritedAnnotatedTestType.class, "alternateName", true);
assertEquals("myType", adapter.getTypeName());
assertEquals(InheritedAnnotatedTestType.class, adapter.getDataClass());
assertEquals(4, adapter.getFieldDescriptors().length);
assertNull(adapter.getFieldDescriptor("alternateName"));
assertNotNull(adapter.getDataIDFieldDescriptor());
assertTrue(String.class.isAssignableFrom(adapter.getDataIDFieldDescriptor().bindingClass()));
assertTrue(adapter.getDataIDFieldDescriptor().indexHints().contains(new IndexDimensionHint("a")));
assertNotNull(adapter.getFieldDescriptor("doubleField"));
assertTrue(Double.class.isAssignableFrom(adapter.getFieldDescriptor("doubleField").bindingClass()));
assertNotNull(adapter.getFieldDescriptor("intField"));
assertTrue(Integer.class.isAssignableFrom(adapter.getFieldDescriptor("intField").bindingClass()));
assertNotNull(adapter.getFieldDescriptor("boolField"));
assertTrue(Boolean.class.isAssignableFrom(adapter.getFieldDescriptor("boolField").bindingClass()));
assertTrue(adapter.getFieldDescriptor("boolField").indexHints().contains(new IndexDimensionHint("a")));
assertTrue(adapter.getFieldDescriptor("boolField").indexHints().contains(new IndexDimensionHint("b")));
assertTrue(adapter.getFieldDescriptor("boolField").indexHints().contains(new IndexDimensionHint("c")));
assertNotNull(adapter.getFieldDescriptor("extraField"));
assertTrue(Double.class.isAssignableFrom(adapter.getFieldDescriptor("extraField").bindingClass()));
final byte[] adapterBytes = PersistenceUtils.toBinary(adapter);
adapter = (BasicDataTypeAdapter) PersistenceUtils.fromBinary(adapterBytes);
assertEquals("myType", adapter.getTypeName());
assertEquals(InheritedAnnotatedTestType.class, adapter.getDataClass());
assertEquals(4, adapter.getFieldDescriptors().length);
assertNull(adapter.getFieldDescriptor("alternateName"));
assertNotNull(adapter.getDataIDFieldDescriptor());
assertTrue(String.class.isAssignableFrom(adapter.getDataIDFieldDescriptor().bindingClass()));
assertTrue(adapter.getDataIDFieldDescriptor().indexHints().contains(new IndexDimensionHint("a")));
assertNotNull(adapter.getFieldDescriptor("doubleField"));
assertTrue(Double.class.isAssignableFrom(adapter.getFieldDescriptor("doubleField").bindingClass()));
assertNotNull(adapter.getFieldDescriptor("intField"));
assertTrue(Integer.class.isAssignableFrom(adapter.getFieldDescriptor("intField").bindingClass()));
assertNotNull(adapter.getFieldDescriptor("boolField"));
assertTrue(Boolean.class.isAssignableFrom(adapter.getFieldDescriptor("boolField").bindingClass()));
assertTrue(adapter.getFieldDescriptor("boolField").indexHints().contains(new IndexDimensionHint("a")));
assertTrue(adapter.getFieldDescriptor("boolField").indexHints().contains(new IndexDimensionHint("b")));
assertTrue(adapter.getFieldDescriptor("boolField").indexHints().contains(new IndexDimensionHint("c")));
assertNotNull(adapter.getFieldDescriptor("extraField"));
assertTrue(Double.class.isAssignableFrom(adapter.getFieldDescriptor("extraField").bindingClass()));
final InheritedAnnotatedTestType testEntry = new InheritedAnnotatedTestType("id1", 2.5, 8, true, "ignored", 5.3);
assertEquals("id1", adapter.getFieldValue(testEntry, "alternateName"));
assertEquals(2.5, (double) adapter.getFieldValue(testEntry, "doubleField"), 0.001);
assertEquals(8, adapter.getFieldValue(testEntry, "intField"));
assertTrue((boolean) adapter.getFieldValue(testEntry, "boolField"));
assertEquals(5.3, (double) adapter.getFieldValue(testEntry, "extraField"), 0.001);
final Object[] fields = new Object[4];
for (int i = 0; i < fields.length; i++) {
switch(adapter.getFieldDescriptors()[i].fieldName()) {
case "doubleField":
fields[i] = 2.5;
break;
case "intField":
fields[i] = 8;
break;
case "boolField":
fields[i] = true;
break;
case "extraField":
fields[i] = 5.3;
break;
}
}
final InheritedAnnotatedTestType builtEntry = adapter.buildObject("id1", fields);
assertEquals("id1", adapter.getFieldValue(builtEntry, "alternateName"));
assertEquals(2.5, (double) adapter.getFieldValue(builtEntry, "doubleField"), 0.001);
assertEquals(8, adapter.getFieldValue(builtEntry, "intField"));
assertTrue((boolean) adapter.getFieldValue(builtEntry, "boolField"));
assertEquals(5.3, (double) adapter.getFieldValue(builtEntry, "extraField"), 0.001);
assertNull(builtEntry.ignoredField);
}
use of org.locationtech.geowave.core.index.IndexDimensionHint in project geowave by locationtech.
the class BasicDataTypeAdapterTest method testAnnotatedObjectBasedDataAdapterSeparateDataID.
@Test
public void testAnnotatedObjectBasedDataAdapterSeparateDataID() {
BasicDataTypeAdapter<AnnotatedTestType> adapter = BasicDataTypeAdapter.newAdapter("myType", AnnotatedTestType.class, "alternateName", true);
assertEquals("myType", adapter.getTypeName());
assertEquals(AnnotatedTestType.class, adapter.getDataClass());
assertEquals(3, adapter.getFieldDescriptors().length);
assertNull(adapter.getFieldDescriptor("alternateName"));
assertNotNull(adapter.getDataIDFieldDescriptor());
assertTrue(String.class.isAssignableFrom(adapter.getDataIDFieldDescriptor().bindingClass()));
assertTrue(adapter.getDataIDFieldDescriptor().indexHints().contains(new IndexDimensionHint("a")));
assertNotNull(adapter.getFieldDescriptor("doubleField"));
assertTrue(Double.class.isAssignableFrom(adapter.getFieldDescriptor("doubleField").bindingClass()));
assertNotNull(adapter.getFieldDescriptor("intField"));
assertTrue(Integer.class.isAssignableFrom(adapter.getFieldDescriptor("intField").bindingClass()));
assertNotNull(adapter.getFieldDescriptor("boolField"));
assertTrue(Boolean.class.isAssignableFrom(adapter.getFieldDescriptor("boolField").bindingClass()));
assertTrue(adapter.getFieldDescriptor("boolField").indexHints().contains(new IndexDimensionHint("a")));
assertTrue(adapter.getFieldDescriptor("boolField").indexHints().contains(new IndexDimensionHint("b")));
assertTrue(adapter.getFieldDescriptor("boolField").indexHints().contains(new IndexDimensionHint("c")));
final byte[] adapterBytes = PersistenceUtils.toBinary(adapter);
adapter = (BasicDataTypeAdapter) PersistenceUtils.fromBinary(adapterBytes);
assertEquals("myType", adapter.getTypeName());
assertEquals(AnnotatedTestType.class, adapter.getDataClass());
assertEquals(3, adapter.getFieldDescriptors().length);
assertNull(adapter.getFieldDescriptor("alternateName"));
assertNotNull(adapter.getDataIDFieldDescriptor());
assertTrue(String.class.isAssignableFrom(adapter.getDataIDFieldDescriptor().bindingClass()));
assertTrue(adapter.getDataIDFieldDescriptor().indexHints().contains(new IndexDimensionHint("a")));
assertNotNull(adapter.getFieldDescriptor("doubleField"));
assertTrue(Double.class.isAssignableFrom(adapter.getFieldDescriptor("doubleField").bindingClass()));
assertNotNull(adapter.getFieldDescriptor("intField"));
assertTrue(Integer.class.isAssignableFrom(adapter.getFieldDescriptor("intField").bindingClass()));
assertNotNull(adapter.getFieldDescriptor("boolField"));
assertTrue(Boolean.class.isAssignableFrom(adapter.getFieldDescriptor("boolField").bindingClass()));
assertTrue(adapter.getFieldDescriptor("boolField").indexHints().contains(new IndexDimensionHint("a")));
assertTrue(adapter.getFieldDescriptor("boolField").indexHints().contains(new IndexDimensionHint("b")));
assertTrue(adapter.getFieldDescriptor("boolField").indexHints().contains(new IndexDimensionHint("c")));
final AnnotatedTestType testEntry = new AnnotatedTestType("id1", 2.5, 8, true, "ignored");
assertEquals("id1", adapter.getFieldValue(testEntry, "alternateName"));
assertEquals(2.5, (double) adapter.getFieldValue(testEntry, "doubleField"), 0.001);
assertEquals(8, adapter.getFieldValue(testEntry, "intField"));
assertTrue((boolean) adapter.getFieldValue(testEntry, "boolField"));
final Object[] fields = new Object[3];
for (int i = 0; i < fields.length; i++) {
switch(adapter.getFieldDescriptors()[i].fieldName()) {
case "doubleField":
fields[i] = 2.5;
break;
case "intField":
fields[i] = 8;
break;
case "boolField":
fields[i] = true;
break;
}
}
final AnnotatedTestType builtEntry = adapter.buildObject("id1", fields);
assertEquals("id1", adapter.getFieldValue(builtEntry, "alternateName"));
assertEquals(2.5, (double) adapter.getFieldValue(builtEntry, "doubleField"), 0.001);
assertEquals(8, adapter.getFieldValue(builtEntry, "intField"));
assertTrue((boolean) adapter.getFieldValue(builtEntry, "boolField"));
assertNull(builtEntry.ignoredField);
}
use of org.locationtech.geowave.core.index.IndexDimensionHint in project geowave by locationtech.
the class SpatialAnnotatedFieldDescriptorBuilder method buildFieldDescriptor.
@Override
public FieldDescriptor<?> buildFieldDescriptor(Field field) {
if (field.isAnnotationPresent(GeoWaveSpatialField.class)) {
final GeoWaveSpatialField fieldAnnotation = field.getAnnotation(GeoWaveSpatialField.class);
final String fieldName;
if (fieldAnnotation.name().isEmpty()) {
fieldName = field.getName();
} else {
fieldName = fieldAnnotation.name();
}
final String[] indexHints = fieldAnnotation.indexHints();
final SpatialFieldDescriptorBuilder<?> builder = new SpatialFieldDescriptorBuilder<>(BasicDataTypeAdapter.normalizeClass(field.getType()));
for (final String hint : indexHints) {
builder.indexHint(new IndexDimensionHint(hint));
}
if (!fieldAnnotation.crs().isEmpty()) {
try {
builder.crs(CRS.decode(fieldAnnotation.crs()));
} catch (FactoryException e) {
throw new RuntimeException("Unable to decode CRS: " + fieldAnnotation.crs(), e);
}
}
if (fieldAnnotation.spatialIndexHint()) {
builder.spatialIndexHint();
}
if (fieldAnnotation.latitudeIndexHint()) {
builder.latitudeIndexHint();
}
if (fieldAnnotation.longitudeIndexHint()) {
builder.longitudeIndexHint();
}
return builder.fieldName(fieldName).build();
}
throw new RuntimeException("Field is missing GeoWaveSpatialField annotation.");
}
use of org.locationtech.geowave.core.index.IndexDimensionHint in project geowave by locationtech.
the class SpatialFieldDescriptorTest method testFieldDescriptor.
@Test
public void testFieldDescriptor() throws NoSuchAuthorityCodeException, FactoryException {
final SpatialFieldDescriptor<String> testDescriptor = new SpatialFieldDescriptorBuilder<>(String.class).fieldName("testFieldName").indexHint(new IndexDimensionHint("testDimensionHint")).crs(CRS.decode("EPSG:3857")).build();
assertEquals("testFieldName", testDescriptor.fieldName());
assertEquals(String.class, testDescriptor.bindingClass());
assertEquals(1, testDescriptor.indexHints().size());
assertEquals(CRS.decode("EPSG:3857"), testDescriptor.crs());
assertTrue(testDescriptor.indexHints().contains(new IndexDimensionHint("testDimensionHint")));
final byte[] fieldDescriptorBytes = PersistenceUtils.toBinary(testDescriptor);
final SpatialFieldDescriptor<?> deserialized = (SpatialFieldDescriptor<?>) PersistenceUtils.fromBinary(fieldDescriptorBytes);
assertEquals("testFieldName", deserialized.fieldName());
assertEquals(String.class, deserialized.bindingClass());
assertEquals(1, deserialized.indexHints().size());
assertEquals(CRS.decode("EPSG:3857"), testDescriptor.crs());
assertTrue(deserialized.indexHints().contains(new IndexDimensionHint("testDimensionHint")));
}
Aggregations