@Test public void testNormalizeFromObject() throws Exception { Symbol normalized = normalize(FUNCTION_NAME, VALID_OBJECT, DataTypes.OBJECT); assertThat(normalized, instanceOf(Literal.class)); assertThat(normalized.valueType(), is((DataType) DataTypes.GEO_SHAPE)); Map<String, Object> value = ((Literal<Map<String, Object>>) normalized).value(); assertThat(value, hasEntry("type", (Object) "Polygon")); assertThat(value, hasEntry("coordinates", VALID_OBJECT.get("coordinates"))); }
@Test public void testNormalizeFromString() throws Exception { Symbol normalized = normalize(FUNCTION_NAME, VALID_STR, DataTypes.STRING); assertThat(normalized, instanceOf(Literal.class)); assertThat(normalized.valueType(), is((DataType) DataTypes.GEO_SHAPE)); Map<String, Object> value = ((Literal<Map<String, Object>>) normalized).value(); assertThat(value, hasEntry("type", (Object) "Point")); assertThat(value, hasKey("coordinates")); double[] coords = (double[]) value.get("coordinates"); assertThat(coords.length, is(2)); assertThat(coords[0], is(0.0d)); assertThat(coords[1], is(0.1d)); }
@Override public void readFrom(StreamInput in) throws IOException { if (in.readBoolean()) { query = Symbol.fromStream(in); } else { noMatch = in.readBoolean(); } }
@Override public void writeTo(StreamOutput out) throws IOException { if (query != null) { out.writeBoolean(true); Symbol.toStream(query, out); } else { out.writeBoolean(false); out.writeBoolean(noMatch); } }