szehon-ho commented on code in PR #54325:
URL: https://github.com/apache/spark/pull/54325#discussion_r2835191301
##########
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/util/Geometry.java:
##########
@@ -154,14 +155,23 @@ public byte[] toEwkb(ByteOrder endianness) {
@Override
public byte[] toWkt() {
- // Once WKT conversion is implemented, it should support various
precisions.
- throw new UnsupportedOperationException("Geometry WKT conversion is not
yet supported.");
+ return toWktInternal().getBytes(StandardCharsets.UTF_8);
Review Comment:
we could make this in Geo base class, but its quite small
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/RandomDataGenerator.scala:
##########
@@ -386,6 +386,51 @@ object RandomDataGenerator {
}
}
}
+ case gt: GeometryType =>
+ val possibleGeometriesWKB = Seq(
Review Comment:
can you comment what these values are?
##########
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/util/Geography.java:
##########
@@ -154,14 +155,20 @@ public byte[] toEwkb(ByteOrder endianness) {
@Override
public byte[] toWkt() {
- // Once WKT conversion is implemented, it should support various
precisions.
- throw new UnsupportedOperationException("Geography WKT conversion is not
yet supported.");
+ return toWktInternal().getBytes(StandardCharsets.UTF_8);
}
@Override
public byte[] toEwkt() {
- // Once EWKT conversion is implemented, it should support various
precisions.
- throw new UnsupportedOperationException("Geography EWKT conversion is not
yet supported.");
+ String ewkt = "SRID=" + srid() + ";" + toWktInternal();
Review Comment:
ok, so all wkt is valid ewkt, and we add extra SRID=... make sense to me.
##########
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/util/Geography.java:
##########
@@ -154,14 +155,20 @@ public byte[] toEwkb(ByteOrder endianness) {
@Override
public byte[] toWkt() {
- // Once WKT conversion is implemented, it should support various
precisions.
- throw new UnsupportedOperationException("Geography WKT conversion is not
yet supported.");
+ return toWktInternal().getBytes(StandardCharsets.UTF_8);
}
@Override
public byte[] toEwkt() {
- // Once EWKT conversion is implemented, it should support various
precisions.
- throw new UnsupportedOperationException("Geography EWKT conversion is not
yet supported.");
+ String ewkt = "SRID=" + srid() + ";" + toWktInternal();
+ return ewkt.getBytes(StandardCharsets.UTF_8);
+ }
+
+ private String toWktInternal() {
+ WkbReader reader = new WkbReader(true);
+ GeometryModel model = reader.read(Arrays.copyOfRange(
+ getBytes(), WKB_OFFSET, getBytes().length));
+ return model.toString();
Review Comment:
i think it would have been cleaner to have explicit toWKT in GeometryModel,
as toString may change. It can be separate from this pr though
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]