You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@sedona.apache.org by "ZhuochengShang (via GitHub)" <gi...@apache.org> on 2025/08/08 23:19:52 UTC

[PR] [GH-]add test for ST_GeogFromWKB(byte array) [sedona]

ZhuochengShang opened a new pull request, #2256:
URL: https://github.com/apache/sedona/pull/2256

   ## What changes were proposed in this PR?
   
   Constructor test for ST_GeogFromWKB
   Datframe API test for ST_GeogFromWKB
   


-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GH-2255]add test for ST_GeogFromWKB(byte array) [sedona]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2256:
URL: https://github.com/apache/sedona/pull/2256#discussion_r2264157807


##########
spark/common/src/test/scala/org/apache/sedona/sql/geography/ConstructorsTest.scala:
##########
@@ -73,4 +73,31 @@ class ConstructorsTest extends TestBaseScala {
       "GEOMETRYCOLLECTION (POINT (50 50), LINESTRING (20 30, 40 60, 80 90), POLYGON ((35 15, 45 15, 40 25, 35 15), (30 10, 40 20, 30 20, 30 10)))"
     assert(expected.equals(actual))
   }
+
+  it("Passed ST_GeogFromWKB") {
+    // RAW binary array
+    val wkbSeq = Seq[Array[Byte]](
+      Array[Byte](1, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, -124, -42, 0, -64, 0, 0, 0, 0, -128, -75,
+        -42, -65, 0, 0, 0, 96, -31, -17, -9, -65, 0, 0, 0, -128, 7, 93, -27, -65))
+    val rawWkbDf = wkbSeq.toDF("wkb")
+    rawWkbDf.createOrReplaceTempView("rawWKBTable")
+    val geometries = {
+      sparkSession.sql("SELECT ST_GeogFromWKB(rawWKBTable.wkb) as countyshape from rawWKBTable")
+    }
+    val expectedGeom =
+      "LINESTRING (-2.1047439575195317 -0.35482788085937506, -1.4960645437240603 -0.6676061153411864)"
+    assert(
+      geometries
+        .first()
+        .getAs[Geography](0)
+        .toString(new PrecisionModel(1e16))
+        .equals(expectedGeom))
+    // null input
+    val nullGeom = sparkSession.sql("SELECT ST_GeogFromWKB(null)")
+    assert(nullGeom.first().isNullAt(0))
+    // Fail on wrong input type
+    intercept[Exception] {
+      sparkSession.sql("SELECT ST_S2GeogFromWKB(0)").collect()

Review Comment:
   The test is calling ST_S2GeogFromWKB instead of ST_GeogFromWKB. This appears to be a copy-paste error since the test is intended to validate ST_GeogFromWKB with wrong input type.
   ```suggestion
         sparkSession.sql("SELECT ST_GeogFromWKB(0)").collect()
   ```



##########
common/src/test/java/org/apache/sedona/common/Geography/ConstructorsTest.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sedona.common.Geography;
+
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.geometry.S2LatLng;
+import com.google.common.geometry.S2Point;
+import org.apache.sedona.common.S2Geography.Geography;
+import org.apache.sedona.common.S2Geography.SinglePointGeography;
+import org.apache.sedona.common.S2Geography.WKBWriter;
+import org.apache.sedona.common.geography.Constructors;
+import org.junit.Test;
+import org.locationtech.jts.io.ParseException;
+
+public class ConstructorsTest {
+
+  @Test
+  public void geogFromWKB() throws ParseException {
+    S2Point pt = S2LatLng.fromDegrees(45, -64).toPoint();
+    SinglePointGeography geog = new SinglePointGeography(pt);
+
+    // Test WKB without SRID
+    WKBWriter wkbWriter = new WKBWriter();
+    byte[] wkb = wkbWriter.write(geog);
+
+    Geography result = Constructors.geogFromWKB(wkb);
+    assertEquals(geog.toString(), result.toString());
+    assertEquals(0, result.getSRID());
+    assertEquals(0, result.getSRID());
+
+    // Test specifying SRID
+    result = Constructors.geogFromWKB(wkb, 1000);
+    assertEquals(geog.toString(), result.toString());
+    assertEquals(1000, result.getSRID());
+    assertEquals(1000, result.getSRID());

Review Comment:
   This assertion is duplicated on the next line. The duplicate assertion should be removed.
   ```suggestion
   
       // Test specifying SRID
       result = Constructors.geogFromWKB(wkb, 1000);
       assertEquals(geog.toString(), result.toString());
       assertEquals(1000, result.getSRID());
   ```



##########
common/src/test/java/org/apache/sedona/common/Geography/ConstructorsTest.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sedona.common.Geography;
+
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.geometry.S2LatLng;
+import com.google.common.geometry.S2Point;
+import org.apache.sedona.common.S2Geography.Geography;
+import org.apache.sedona.common.S2Geography.SinglePointGeography;
+import org.apache.sedona.common.S2Geography.WKBWriter;
+import org.apache.sedona.common.geography.Constructors;
+import org.junit.Test;
+import org.locationtech.jts.io.ParseException;
+
+public class ConstructorsTest {
+
+  @Test
+  public void geogFromWKB() throws ParseException {
+    S2Point pt = S2LatLng.fromDegrees(45, -64).toPoint();
+    SinglePointGeography geog = new SinglePointGeography(pt);
+
+    // Test WKB without SRID
+    WKBWriter wkbWriter = new WKBWriter();
+    byte[] wkb = wkbWriter.write(geog);
+
+    Geography result = Constructors.geogFromWKB(wkb);
+    assertEquals(geog.toString(), result.toString());
+    assertEquals(0, result.getSRID());
+    assertEquals(0, result.getSRID());
+
+    // Test specifying SRID
+    result = Constructors.geogFromWKB(wkb, 1000);
+    assertEquals(geog.toString(), result.toString());
+    assertEquals(1000, result.getSRID());
+    assertEquals(1000, result.getSRID());

Review Comment:
   This assertion is duplicated on the next line. The duplicate assertion should be removed.
   ```suggestion
   
   ```



##########
common/src/test/java/org/apache/sedona/common/Geography/ConstructorsTest.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sedona.common.Geography;
+
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.geometry.S2LatLng;
+import com.google.common.geometry.S2Point;
+import org.apache.sedona.common.S2Geography.Geography;
+import org.apache.sedona.common.S2Geography.SinglePointGeography;
+import org.apache.sedona.common.S2Geography.WKBWriter;
+import org.apache.sedona.common.geography.Constructors;
+import org.junit.Test;
+import org.locationtech.jts.io.ParseException;
+
+public class ConstructorsTest {
+
+  @Test
+  public void geogFromWKB() throws ParseException {
+    S2Point pt = S2LatLng.fromDegrees(45, -64).toPoint();
+    SinglePointGeography geog = new SinglePointGeography(pt);
+
+    // Test WKB without SRID
+    WKBWriter wkbWriter = new WKBWriter();
+    byte[] wkb = wkbWriter.write(geog);
+
+    Geography result = Constructors.geogFromWKB(wkb);
+    assertEquals(geog.toString(), result.toString());
+    assertEquals(0, result.getSRID());
+    assertEquals(0, result.getSRID());
+
+    // Test specifying SRID
+    result = Constructors.geogFromWKB(wkb, 1000);
+    assertEquals(geog.toString(), result.toString());
+    assertEquals(1000, result.getSRID());
+    assertEquals(1000, result.getSRID());
+
+    // Test EWKB with SRID
+    wkbWriter = new WKBWriter(2, true);
+    geog.setSRID(2000);
+    wkb = wkbWriter.write(geog);
+    result = Constructors.geogFromWKB(wkb);
+    assertEquals(geog.toString(), result.toString());
+    assertEquals(2000, result.getSRID());
+    assertEquals(2000, result.getSRID());
+
+    // Test overriding SRID
+    result = Constructors.geogFromWKB(wkb, 3000);
+    assertEquals(geog.toString(), result.toString());
+    assertEquals(3000, result.getSRID());
+    assertEquals(3000, result.getSRID());
+    result = Constructors.geogFromWKB(wkb, 0);
+    assertEquals(geog.toString(), result.toString());
+    assertEquals(0, result.getSRID());
+    assertEquals(0, result.getSRID());

Review Comment:
   This assertion is duplicated on the next line. The duplicate assertion should be removed.
   ```suggestion
   
       // Test overriding SRID
       result = Constructors.geogFromWKB(wkb, 3000);
       assertEquals(geog.toString(), result.toString());
       assertEquals(3000, result.getSRID());
       result = Constructors.geogFromWKB(wkb, 0);
       assertEquals(geog.toString(), result.toString());
       assertEquals(0, result.getSRID());
   ```



##########
spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/st_constructors.scala:
##########
@@ -102,11 +102,11 @@ object st_constructors {
     wrapExpression[ST_GeogFromText](wkt, srid)
   def ST_GeogFromText(wkt: String, srid: Int): Column = wrapExpression[ST_GeogFromText](wkt, srid)
 
-  def ST_GeogFromWKB(wkt: Column): Column = wrapExpression[ST_GeogFromWKB](wkt, 0)
-  def ST_GeogFromWKB(wkt: String): Column = wrapExpression[ST_GeogFromWKB](wkt, 0)
-  def ST_GeogFromWKB(wkt: Column, srid: Column): Column =
-    wrapExpression[ST_GeogFromWKT](wkt, srid)
-  def ST_GeogFromWKB(wkt: String, srid: Int): Column = wrapExpression[ST_GeogFromWKB](wkt, srid)
+  def ST_GeogFromWKB(wkb: Column): Column = wrapExpression[ST_GeogFromWKB](wkb, 0)
+  def ST_GeogFromWKB(wkb: String): Column = wrapExpression[ST_GeogFromWKB](wkb, 0)
+  def ST_GeogFromWKB(wkb: Column, srid: Column): Column =
+    wrapExpression[ST_GeogFromWKT](wkb, srid)

Review Comment:
   This method should wrap ST_GeogFromWKB instead of ST_GeogFromWKT. The expression type doesn't match the method name ST_GeogFromWKB.
   ```suggestion
       wrapExpression[ST_GeogFromWKB](wkb, srid)
   ```



##########
common/src/test/java/org/apache/sedona/common/Geography/ConstructorsTest.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sedona.common.Geography;
+
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.geometry.S2LatLng;
+import com.google.common.geometry.S2Point;
+import org.apache.sedona.common.S2Geography.Geography;
+import org.apache.sedona.common.S2Geography.SinglePointGeography;
+import org.apache.sedona.common.S2Geography.WKBWriter;
+import org.apache.sedona.common.geography.Constructors;
+import org.junit.Test;
+import org.locationtech.jts.io.ParseException;
+
+public class ConstructorsTest {
+
+  @Test
+  public void geogFromWKB() throws ParseException {
+    S2Point pt = S2LatLng.fromDegrees(45, -64).toPoint();
+    SinglePointGeography geog = new SinglePointGeography(pt);
+
+    // Test WKB without SRID
+    WKBWriter wkbWriter = new WKBWriter();
+    byte[] wkb = wkbWriter.write(geog);
+
+    Geography result = Constructors.geogFromWKB(wkb);
+    assertEquals(geog.toString(), result.toString());
+    assertEquals(0, result.getSRID());
+    assertEquals(0, result.getSRID());
+
+    // Test specifying SRID
+    result = Constructors.geogFromWKB(wkb, 1000);
+    assertEquals(geog.toString(), result.toString());
+    assertEquals(1000, result.getSRID());
+    assertEquals(1000, result.getSRID());
+
+    // Test EWKB with SRID
+    wkbWriter = new WKBWriter(2, true);
+    geog.setSRID(2000);
+    wkb = wkbWriter.write(geog);
+    result = Constructors.geogFromWKB(wkb);
+    assertEquals(geog.toString(), result.toString());
+    assertEquals(2000, result.getSRID());
+    assertEquals(2000, result.getSRID());
+
+    // Test overriding SRID
+    result = Constructors.geogFromWKB(wkb, 3000);
+    assertEquals(geog.toString(), result.toString());
+    assertEquals(3000, result.getSRID());
+    assertEquals(3000, result.getSRID());
+    result = Constructors.geogFromWKB(wkb, 0);
+    assertEquals(geog.toString(), result.toString());
+    assertEquals(0, result.getSRID());
+    assertEquals(0, result.getSRID());

Review Comment:
   This assertion is duplicated on the next line. The duplicate assertion should be removed.
   ```suggestion
   
   ```



##########
common/src/test/java/org/apache/sedona/common/Geography/ConstructorsTest.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sedona.common.Geography;
+
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.geometry.S2LatLng;
+import com.google.common.geometry.S2Point;
+import org.apache.sedona.common.S2Geography.Geography;
+import org.apache.sedona.common.S2Geography.SinglePointGeography;
+import org.apache.sedona.common.S2Geography.WKBWriter;
+import org.apache.sedona.common.geography.Constructors;
+import org.junit.Test;
+import org.locationtech.jts.io.ParseException;
+
+public class ConstructorsTest {
+
+  @Test
+  public void geogFromWKB() throws ParseException {
+    S2Point pt = S2LatLng.fromDegrees(45, -64).toPoint();
+    SinglePointGeography geog = new SinglePointGeography(pt);
+
+    // Test WKB without SRID
+    WKBWriter wkbWriter = new WKBWriter();
+    byte[] wkb = wkbWriter.write(geog);
+
+    Geography result = Constructors.geogFromWKB(wkb);
+    assertEquals(geog.toString(), result.toString());
+    assertEquals(0, result.getSRID());
+    assertEquals(0, result.getSRID());
+
+    // Test specifying SRID
+    result = Constructors.geogFromWKB(wkb, 1000);
+    assertEquals(geog.toString(), result.toString());
+    assertEquals(1000, result.getSRID());
+    assertEquals(1000, result.getSRID());
+
+    // Test EWKB with SRID
+    wkbWriter = new WKBWriter(2, true);
+    geog.setSRID(2000);
+    wkb = wkbWriter.write(geog);
+    result = Constructors.geogFromWKB(wkb);
+    assertEquals(geog.toString(), result.toString());
+    assertEquals(2000, result.getSRID());
+    assertEquals(2000, result.getSRID());

Review Comment:
   This assertion is duplicated on the next line. The duplicate assertion should be removed.
   ```suggestion
   
   ```



-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GH-2255]add test for ST_GeogFromWKB(byte array) [sedona]

Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu commented on code in PR #2256:
URL: https://github.com/apache/sedona/pull/2256#discussion_r2264155714


##########
spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/st_constructors.scala:
##########
@@ -102,11 +102,11 @@ object st_constructors {
     wrapExpression[ST_GeogFromText](wkt, srid)
   def ST_GeogFromText(wkt: String, srid: Int): Column = wrapExpression[ST_GeogFromText](wkt, srid)
 
-  def ST_GeogFromWKB(wkt: Column): Column = wrapExpression[ST_GeogFromWKB](wkt, 0)
-  def ST_GeogFromWKB(wkt: String): Column = wrapExpression[ST_GeogFromWKB](wkt, 0)
-  def ST_GeogFromWKB(wkt: Column, srid: Column): Column =
-    wrapExpression[ST_GeogFromWKT](wkt, srid)
-  def ST_GeogFromWKB(wkt: String, srid: Int): Column = wrapExpression[ST_GeogFromWKB](wkt, srid)
+  def ST_GeogFromWKB(wkb: Column): Column = wrapExpression[ST_GeogFromWKB](wkb, 0)
+  def ST_GeogFromWKB(wkb: String): Column = wrapExpression[ST_GeogFromWKB](wkb, 0)

Review Comment:
   Why is this using String type? I thought we always use Binary for WKB?



-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GH-2255]add test for ST_GeogFromWKB(byte array) [sedona]

Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu commented on code in PR #2256:
URL: https://github.com/apache/sedona/pull/2256#discussion_r2264469765


##########
spark/common/src/test/scala/org/apache/sedona/sql/geography/ConstructorsTest.scala:
##########
@@ -73,4 +73,31 @@ class ConstructorsTest extends TestBaseScala {
       "GEOMETRYCOLLECTION (POINT (50 50), LINESTRING (20 30, 40 60, 80 90), POLYGON ((35 15, 45 15, 40 25, 35 15), (30 10, 40 20, 30 20, 30 10)))"
     assert(expected.equals(actual))
   }
+
+  it("Passed ST_GeogFromWKB") {
+    // RAW binary array
+    val wkbSeq = Seq[Array[Byte]](
+      Array[Byte](1, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, -124, -42, 0, -64, 0, 0, 0, 0, -128, -75,
+        -42, -65, 0, 0, 0, 96, -31, -17, -9, -65, 0, 0, 0, -128, 7, 93, -27, -65))
+    val rawWkbDf = wkbSeq.toDF("wkb")
+    rawWkbDf.createOrReplaceTempView("rawWKBTable")
+    val geometries = {
+      sparkSession.sql("SELECT ST_GeogFromWKB(rawWKBTable.wkb) as countyshape from rawWKBTable")
+    }
+    val expectedGeom =
+      "LINESTRING (-2.1047439575195317 -0.35482788085937506, -1.4960645437240603 -0.6676061153411864)"
+    assert(
+      geometries
+        .first()
+        .getAs[Geography](0)
+        .toString(new PrecisionModel(1e16))
+        .equals(expectedGeom))
+    // null input
+    val nullGeom = sparkSession.sql("SELECT ST_GeogFromWKB(null)")
+    assert(nullGeom.first().isNullAt(0))
+    // Fail on wrong input type
+    intercept[Exception] {
+      sparkSession.sql("SELECT ST_GeogFromWKB(0)").collect()

Review Comment:
   Please make sure this only intercept the corresponding wrong input type exception instead of all exception. Otherwise it has no use.
   
   For example, the old code throws a real exception which shouldn't be intercepted.
   
   If it is not possible to do so, please remove this intercept completely as it has no use



-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GH-2255]add test for ST_GeogFromWKB(byte array) [sedona]

Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu merged PR #2256:
URL: https://github.com/apache/sedona/pull/2256


-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GH-2255]add test for ST_GeogFromWKB(byte array) [sedona]

Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu commented on code in PR #2256:
URL: https://github.com/apache/sedona/pull/2256#discussion_r2264155458


##########
spark/common/src/test/scala/org/apache/sedona/sql/geography/ConstructorsTest.scala:
##########
@@ -73,4 +73,31 @@ class ConstructorsTest extends TestBaseScala {
       "GEOMETRYCOLLECTION (POINT (50 50), LINESTRING (20 30, 40 60, 80 90), POLYGON ((35 15, 45 15, 40 25, 35 15), (30 10, 40 20, 30 20, 30 10)))"
     assert(expected.equals(actual))
   }
+
+  it("Passed ST_GeogFromWKB") {
+    // RAW binary array
+    val wkbSeq = Seq[Array[Byte]](
+      Array[Byte](1, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, -124, -42, 0, -64, 0, 0, 0, 0, -128, -75,
+        -42, -65, 0, 0, 0, 96, -31, -17, -9, -65, 0, 0, 0, -128, 7, 93, -27, -65))
+    val rawWkbDf = wkbSeq.toDF("wkb")
+    rawWkbDf.createOrReplaceTempView("rawWKBTable")
+    val geometries = {
+      sparkSession.sql("SELECT ST_GeogFromWKB(rawWKBTable.wkb) as countyshape from rawWKBTable")
+    }
+    val expectedGeom =
+      "LINESTRING (-2.1047439575195317 -0.35482788085937506, -1.4960645437240603 -0.6676061153411864)"
+    assert(
+      geometries
+        .first()
+        .getAs[Geography](0)
+        .toString(new PrecisionModel(1e16))
+        .equals(expectedGeom))
+    // null input
+    val nullGeom = sparkSession.sql("SELECT ST_GeogFromWKB(null)")
+    assert(nullGeom.first().isNullAt(0))
+    // Fail on wrong input type
+    intercept[Exception] {
+      sparkSession.sql("SELECT ST_S2GeogFromWKB(0)").collect()

Review Comment:
   Why is this `ST_S2GeogFromWKB`?



-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org