Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geo: Switch generated WKT to upper case #50285

Merged
merged 3 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference/ingest/processors/circle.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ The response from the above index request:
"_seq_no": 22,
"_primary_term": 1,
"_source": {
"circle": "polygon ((30.000365257263184 10.0, 30.000111397193788 10.00034284530941, 29.999706043744222 10.000213571721195, 29.999706043744222 9.999786428278805, 30.000111397193788 9.99965715469059, 30.000365257263184 10.0))"
"circle": "POLYGON ((30.000365257263184 10.0, 30.000111397193788 10.00034284530941, 29.999706043744222 10.000213571721195, 29.999706043744222 9.999786428278805, 30.000111397193788 9.99965715469059, 30.000365257263184 10.0))"
}
}
--------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,17 +586,17 @@ private static String getWKTName(Geometry geometry) {
return geometry.visit(new GeometryVisitor<String, RuntimeException>() {
@Override
public String visit(Circle circle) {
return "circle";
return "CIRCLE";
}

@Override
public String visit(GeometryCollection<?> collection) {
return "geometrycollection";
return "GEOMETRYCOLLECTION";
}

@Override
public String visit(Line line) {
return "linestring";
return "LINESTRING";
}

@Override
Expand All @@ -606,32 +606,32 @@ public String visit(LinearRing ring) {

@Override
public String visit(MultiLine multiLine) {
return "multilinestring";
return "MULTILINESTRING";
}

@Override
public String visit(MultiPoint multiPoint) {
return "multipoint";
return "MULTIPOINT";
}

@Override
public String visit(MultiPolygon multiPolygon) {
return "multipolygon";
return "MULTIPOLYGON";
}

@Override
public String visit(Point point) {
return "point";
return "POINT";
}

@Override
public String visit(Polygon polygon) {
return "polygon";
return "POLYGON";
}

@Override
public String visit(Rectangle rectangle) {
return "bbox";
return "BBOX";
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ protected Circle createTestInstance(boolean hasAlt) {

public void testBasicSerialization() throws IOException, ParseException {
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
assertEquals("circle (20.0 10.0 15.0)", wkt.toWKT(new Circle(20, 10, 15)));
assertEquals("CIRCLE (20.0 10.0 15.0)", wkt.toWKT(new Circle(20, 10, 15)));
assertEquals(new Circle(20, 10, 15), wkt.fromWKT("circle (20.0 10.0 15.0)"));

assertEquals("circle (20.0 10.0 15.0 25.0)", wkt.toWKT(new Circle(20, 10, 25, 15)));
assertEquals("CIRCLE (20.0 10.0 15.0 25.0)", wkt.toWKT(new Circle(20, 10, 25, 15)));
assertEquals(new Circle(20, 10, 25, 15), wkt.fromWKT("circle (20.0 10.0 15.0 25.0)"));

assertEquals("circle EMPTY", wkt.toWKT(Circle.EMPTY));
assertEquals(Circle.EMPTY, wkt.fromWKT("circle EMPTY)"));
assertEquals("CIRCLE EMPTY", wkt.toWKT(Circle.EMPTY));
assertEquals(Circle.EMPTY, wkt.fromWKT("CIRCLE EMPTY)"));
}

public void testInitValidation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ protected GeometryCollection<Geometry> createTestInstance(boolean hasAlt) {

public void testBasicSerialization() throws IOException, ParseException {
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
assertEquals("geometrycollection (point (20.0 10.0),point EMPTY)",
assertEquals("GEOMETRYCOLLECTION (POINT (20.0 10.0),POINT EMPTY)",
wkt.toWKT(new GeometryCollection<Geometry>(Arrays.asList(new Point(20, 10), Point.EMPTY))));

assertEquals(new GeometryCollection<Geometry>(Arrays.asList(new Point(20, 10), Point.EMPTY)),
wkt.fromWKT("geometrycollection (point (20.0 10.0),point EMPTY)"));
wkt.fromWKT("GEOMETRYCOLLECTION (POINT (20.0 10.0),POINT EMPTY)"));

assertEquals("geometrycollection EMPTY", wkt.toWKT(GeometryCollection.EMPTY));
assertEquals(GeometryCollection.EMPTY, wkt.fromWKT("geometrycollection EMPTY)"));
assertEquals("GEOMETRYCOLLECTION EMPTY", wkt.toWKT(GeometryCollection.EMPTY));
assertEquals(GeometryCollection.EMPTY, wkt.fromWKT("GEOMETRYCOLLECTION EMPTY)"));
}

@SuppressWarnings("ConstantConditions")
Expand Down
12 changes: 6 additions & 6 deletions libs/geo/src/test/java/org/elasticsearch/geometry/LineTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ protected Line createTestInstance(boolean hasAlt) {

public void testBasicSerialization() throws IOException, ParseException {
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
assertEquals("linestring (3.0 1.0, 4.0 2.0)", wkt.toWKT(new Line(new double[]{3, 4}, new double[]{1, 2})));
assertEquals(new Line(new double[]{3, 4}, new double[]{1, 2}), wkt.fromWKT("linestring (3 1, 4 2)"));
assertEquals("LINESTRING (3.0 1.0, 4.0 2.0)", wkt.toWKT(new Line(new double[]{3, 4}, new double[]{1, 2})));
assertEquals(new Line(new double[]{3, 4}, new double[]{1, 2}), wkt.fromWKT("LINESTRING (3 1, 4 2)"));

assertEquals("linestring (3.0 1.0 5.0, 4.0 2.0 6.0)", wkt.toWKT(new Line(new double[]{3, 4}, new double[]{1, 2},
assertEquals("LINESTRING (3.0 1.0 5.0, 4.0 2.0 6.0)", wkt.toWKT(new Line(new double[]{3, 4}, new double[]{1, 2},
new double[]{5, 6})));
assertEquals(new Line(new double[]{3, 4}, new double[]{1, 2}, new double[]{6, 5}),
wkt.fromWKT("linestring (3 1 6, 4 2 5)"));
wkt.fromWKT("LINESTRING (3 1 6, 4 2 5)"));

assertEquals("linestring EMPTY", wkt.toWKT(Line.EMPTY));
assertEquals(Line.EMPTY, wkt.fromWKT("linestring EMPTY)"));
assertEquals("LINESTRING EMPTY", wkt.toWKT(Line.EMPTY));
assertEquals(Line.EMPTY, wkt.fromWKT("LINESTRING EMPTY)"));
}

public void testInitValidation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ protected MultiLine createTestInstance(boolean hasAlt) {

public void testBasicSerialization() throws IOException, ParseException {
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
assertEquals("multilinestring ((3.0 1.0, 4.0 2.0))", wkt.toWKT(
assertEquals("MULTILINESTRING ((3.0 1.0, 4.0 2.0))", wkt.toWKT(
new MultiLine(Collections.singletonList(new Line(new double[]{3, 4}, new double[]{1, 2})))));
assertEquals(new MultiLine(Collections.singletonList(new Line(new double[]{3, 4}, new double[]{1, 2}))),
wkt.fromWKT("multilinestring ((3 1, 4 2))"));
wkt.fromWKT("MULTILINESTRING ((3 1, 4 2))"));

assertEquals("multilinestring EMPTY", wkt.toWKT(MultiLine.EMPTY));
assertEquals(MultiLine.EMPTY, wkt.fromWKT("multilinestring EMPTY)"));
assertEquals("MULTILINESTRING EMPTY", wkt.toWKT(MultiLine.EMPTY));
assertEquals(MultiLine.EMPTY, wkt.fromWKT("MULTILINESTRING EMPTY)"));
}

public void testValidation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@ protected MultiPoint createTestInstance(boolean hasAlt) {

public void testBasicSerialization() throws IOException, ParseException {
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
assertEquals("multipoint (2.0 1.0)", wkt.toWKT(
assertEquals("MULTIPOINT (2.0 1.0)", wkt.toWKT(
new MultiPoint(Collections.singletonList(new Point(2, 1)))));
assertEquals(new MultiPoint(Collections.singletonList(new Point(2, 1))),
wkt.fromWKT("multipoint (2 1)"));
wkt.fromWKT("MULTIPOINT (2 1)"));

assertEquals("multipoint (2.0 1.0, 3.0 4.0)",
assertEquals("MULTIPOINT (2.0 1.0, 3.0 4.0)",
wkt.toWKT(new MultiPoint(Arrays.asList(new Point(2, 1), new Point(3, 4)))));
assertEquals(new MultiPoint(Arrays.asList(new Point(2, 1), new Point(3, 4))),
wkt.fromWKT("multipoint (2 1, 3 4)"));
wkt.fromWKT("MULTIPOINT (2 1, 3 4)"));

assertEquals("multipoint (2.0 1.0 10.0, 3.0 4.0 20.0)",
assertEquals("MULTIPOINT (2.0 1.0 10.0, 3.0 4.0 20.0)",
wkt.toWKT(new MultiPoint(Arrays.asList(new Point(2, 1, 10), new Point(3, 4, 20)))));
assertEquals(new MultiPoint(Arrays.asList(new Point(2, 1, 10), new Point(3, 4, 20))),
wkt.fromWKT("multipoint (2 1 10, 3 4 20)"));
wkt.fromWKT("MULTIPOINT (2 1 10, 3 4 20)"));

assertEquals("multipoint EMPTY", wkt.toWKT(MultiPoint.EMPTY));
assertEquals(MultiPoint.EMPTY, wkt.fromWKT("multipoint EMPTY)"));
assertEquals("MULTIPOINT EMPTY", wkt.toWKT(MultiPoint.EMPTY));
assertEquals(MultiPoint.EMPTY, wkt.fromWKT("MULTIPOINT EMPTY)"));
}

public void testValidation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ protected MultiPolygon createTestInstance(boolean hasAlt) {

public void testBasicSerialization() throws IOException, ParseException {
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
assertEquals("multipolygon (((3.0 1.0, 4.0 2.0, 5.0 3.0, 3.0 1.0)))",
assertEquals("MULTIPOLYGON (((3.0 1.0, 4.0 2.0, 5.0 3.0, 3.0 1.0)))",
wkt.toWKT(new MultiPolygon(Collections.singletonList(
new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}))))));
assertEquals(new MultiPolygon(Collections.singletonList(
new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1})))),
wkt.fromWKT("multipolygon (((3.0 1.0, 4.0 2.0, 5.0 3.0, 3.0 1.0)))"));
wkt.fromWKT("MULTIPOLYGON (((3.0 1.0, 4.0 2.0, 5.0 3.0, 3.0 1.0)))"));

assertEquals("multipolygon EMPTY", wkt.toWKT(MultiPolygon.EMPTY));
assertEquals(MultiPolygon.EMPTY, wkt.fromWKT("multipolygon EMPTY)"));
assertEquals("MULTIPOLYGON EMPTY", wkt.toWKT(MultiPolygon.EMPTY));
assertEquals(MultiPolygon.EMPTY, wkt.fromWKT("MULTIPOLYGON EMPTY)"));
}

public void testValidation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ protected Point createTestInstance(boolean hasAlt) {

public void testBasicSerialization() throws IOException, ParseException {
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
assertEquals("point (20.0 10.0)", wkt.toWKT(new Point(20, 10)));
assertEquals("POINT (20.0 10.0)", wkt.toWKT(new Point(20, 10)));
assertEquals(new Point(20, 10), wkt.fromWKT("point (20.0 10.0)"));

assertEquals("point (20.0 10.0 100.0)", wkt.toWKT(new Point(20, 10, 100)));
assertEquals(new Point(20, 10, 100), wkt.fromWKT("point (20.0 10.0 100.0)"));
assertEquals("POINT (20.0 10.0 100.0)", wkt.toWKT(new Point(20, 10, 100)));
assertEquals(new Point(20, 10, 100), wkt.fromWKT("POINT (20.0 10.0 100.0)"));

assertEquals("point EMPTY", wkt.toWKT(Point.EMPTY));
assertEquals(Point.EMPTY, wkt.fromWKT("point EMPTY)"));
assertEquals("POINT EMPTY", wkt.toWKT(Point.EMPTY));
assertEquals(Point.EMPTY, wkt.fromWKT("POINT EMPTY)"));
}

public void testInitValidation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@ protected Polygon createTestInstance(boolean hasAlt) {

public void testBasicSerialization() throws IOException, ParseException {
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
assertEquals("polygon ((3.0 1.0, 4.0 2.0, 5.0 3.0, 3.0 1.0))",
assertEquals("POLYGON ((3.0 1.0, 4.0 2.0, 5.0 3.0, 3.0 1.0))",
wkt.toWKT(new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}))));
assertEquals(new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1})),
wkt.fromWKT("polygon ((3 1, 4 2, 5 3, 3 1))"));
wkt.fromWKT("POLYGON ((3 1, 4 2, 5 3, 3 1))"));

assertEquals("polygon ((3.0 1.0 5.0, 4.0 2.0 4.0, 5.0 3.0 3.0, 3.0 1.0 5.0))",
assertEquals("POLYGON ((3.0 1.0 5.0, 4.0 2.0 4.0, 5.0 3.0 3.0, 3.0 1.0 5.0))",
wkt.toWKT(new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}, new double[]{5, 4, 3, 5}))));
assertEquals(new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}, new double[]{5, 4, 3, 5})),
wkt.fromWKT("polygon ((3 1 5, 4 2 4, 5 3 3, 3 1 5))"));
wkt.fromWKT("POLYGON ((3 1 5, 4 2 4, 5 3 3, 3 1 5))"));

// Auto closing in coerce mode
assertEquals(new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1})),
wkt.fromWKT("polygon ((3 1, 4 2, 5 3))"));
wkt.fromWKT("POLYGON ((3 1, 4 2, 5 3))"));
assertEquals(new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}, new double[]{5, 4, 3, 5})),
wkt.fromWKT("polygon ((3 1 5, 4 2 4, 5 3 3))"));
wkt.fromWKT("POLYGON ((3 1 5, 4 2 4, 5 3 3))"));
assertEquals(new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}),
Collections.singletonList(new LinearRing(new double[]{0.5, 2.5, 2.0, 0.5}, new double[]{1.5, 1.5, 1.0, 1.5}))),
wkt.fromWKT("polygon ((3 1, 4 2, 5 3, 3 1), (0.5 1.5, 2.5 1.5, 2.0 1.0))"));
wkt.fromWKT("POLYGON ((3 1, 4 2, 5 3, 3 1), (0.5 1.5, 2.5 1.5, 2.0 1.0))"));

assertEquals("polygon EMPTY", wkt.toWKT(Polygon.EMPTY));
assertEquals(Polygon.EMPTY, wkt.fromWKT("polygon EMPTY)"));
assertEquals("POLYGON EMPTY", wkt.toWKT(Polygon.EMPTY));
assertEquals(Polygon.EMPTY, wkt.fromWKT("POLYGON EMPTY)"));
}

public void testInitValidation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ protected Rectangle createTestInstance(boolean hasAlt) {

public void testBasicSerialization() throws IOException, ParseException {
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
assertEquals("bbox (10.0, 20.0, 40.0, 30.0)", wkt.toWKT(new Rectangle(10, 20, 40, 30)));
assertEquals(new Rectangle(10, 20, 40, 30), wkt.fromWKT("bbox (10.0, 20.0, 40.0, 30.0)"));
assertEquals("BBOX (10.0, 20.0, 40.0, 30.0)", wkt.toWKT(new Rectangle(10, 20, 40, 30)));
assertEquals(new Rectangle(10, 20, 40, 30), wkt.fromWKT("BBOX (10.0, 20.0, 40.0, 30.0)"));

assertEquals("bbox EMPTY", wkt.toWKT(Rectangle.EMPTY));
assertEquals(Rectangle.EMPTY, wkt.fromWKT("bbox EMPTY)"));
assertEquals("BBOX EMPTY", wkt.toWKT(Rectangle.EMPTY));
assertEquals(Rectangle.EMPTY, wkt.fromWKT("BBOX EMPTY)"));
}

public void testInitValidation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void testWKTParsing() throws Exception {
XContentBuilder newGeoJson = XContentFactory.jsonBuilder().startObject().field("val");
format.toXContent(new Point(100, 10), newGeoJson, ToXContent.EMPTY_PARAMS);
newGeoJson.endObject();
assertEquals("{\"val\":\"point (100.0 10.0)\"}", Strings.toString(newGeoJson));
assertEquals("{\"val\":\"POINT (100.0 10.0)\"}", Strings.toString(newGeoJson));
}

// Make sure we can parse values outside the normal lat lon boundaries
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugin/sql/qa/src/main/resources/docs/geo.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ selectAsWKT
SELECT city, ST_AsWKT(location) location FROM "geo" WHERE city = 'Amsterdam';

city:s | location:s
Amsterdam |point (4.850311987102032 52.347556999884546)
Amsterdam |POINT (4.850311987102032 52.347556999884546)
// end::aswkt
;

Expand All @@ -24,7 +24,7 @@ selectWKTToSQL
SELECT CAST(ST_WKTToSQL('POINT (10 20)') AS STRING) location;

location:s
point (10.0 20.0)
POINT (10.0 20.0)
// end::wkttosql
;

Expand Down
Loading