Copilot commented on code in PR #3062:
URL: https://github.com/apache/sedona/pull/3062#discussion_r3441146328


##########
flink/src/main/java/org/apache/sedona/flink/expressions/GeographyConstructors.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.flink.expressions;
+
+import org.apache.flink.table.annotation.DataTypeHint;
+import org.apache.flink.table.functions.ScalarFunction;
+import org.apache.sedona.common.S2Geography.Geography;
+import org.apache.sedona.common.geography.Constructors;
+import org.apache.sedona.flink.GeographyTypeSerializer;

Review Comment:
   `GeographyConstructors` is in the same package as 
`org.apache.sedona.flink.expressions.Constructors`, so importing 
`org.apache.sedona.common.geography.Constructors` here risks a simple-name 
collision and can break compilation / make it unclear which `Constructors` is 
being referenced. In the existing Flink expressions code, common constructors 
are referenced via fully-qualified names to avoid this (see 
`flink/.../expressions/Constructors.java`).



##########
flink/src/test/java/org/apache/sedona/flink/GeographyConstructorTest.java:
##########
@@ -0,0 +1,177 @@
+/*
+ * 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.flink;
+
+import static org.apache.flink.table.api.Expressions.$;
+import static org.apache.flink.table.api.Expressions.call;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Collections;
+import java.util.List;
+import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
+import org.apache.flink.api.common.typeinfo.PrimitiveArrayTypeInfo;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.java.typeutils.RowTypeInfo;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.types.Row;
+import org.apache.sedona.common.S2Geography.Geography;
+import org.apache.sedona.common.geography.Constructors;
+import org.apache.sedona.flink.expressions.GeographyConstructors;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.io.WKBWriter;
+import org.locationtech.jts.io.WKTReader;
+
+public class GeographyConstructorTest extends TestBase {
+
+  @BeforeClass
+  public static void onceExecutedBeforeAll() {
+    initialize();
+  }
+
+  /** Build a single-row, single-column source table. */
+  private Table sourceTable(String colName, Object value, TypeInformation<?> 
colType) {
+    List<Row> data = Collections.singletonList(Row.of(value));
+    RowTypeInfo typeInfo =
+        new RowTypeInfo(new TypeInformation<?>[] {colType}, new String[] 
{colName});
+    DataStream<Row> ds = env.fromCollection(data).returns(typeInfo);
+    return tableEnv.fromDataStream(ds);
+  }
+
+  private Geography evalGeog(Table source, String func, String inputCol) {
+    Table out = source.select(call(func, $(inputCol)).as("geog"));
+    return first(out).getFieldAs("geog");
+  }
+
+  @Test
+  public void testGeogFromWKT() throws Exception {
+    Table src = sourceTable("wkt", "POINT (1 2)", 
BasicTypeInfo.STRING_TYPE_INFO);
+    Geography result =
+        evalGeog(src, 
GeographyConstructors.ST_GeogFromWKT.class.getSimpleName(), "wkt");
+    assertEquals(Constructors.geogFromWKT("POINT (1 2)", 0).toEWKT(), 
result.toEWKT());
+  }
+
+  @Test
+  public void testGeogFromWKTWithSrid() throws Exception {
+    Table src = sourceTable("wkt", "POINT (1 2)", 
BasicTypeInfo.STRING_TYPE_INFO);
+    Table out =
+        src.select(
+            call(
+                    GeographyConstructors.ST_GeogFromWKT.class.getSimpleName(),
+                    $("wkt"),
+                    org.apache.flink.table.api.Expressions.lit(4326))
+                .as("geog"));
+    Geography result = first(out).getFieldAs("geog");
+    assertEquals(4326, result.getSRID());
+    assertEquals(Constructors.geogFromWKT("POINT (1 2)", 4326).toEWKT(), 
result.toEWKT());
+  }
+
+  @Test
+  public void testGeogFromText() throws Exception {
+    Table src = sourceTable("wkt", "LINESTRING (0 0, 1 1, 2 2)", 
BasicTypeInfo.STRING_TYPE_INFO);
+    Geography result =
+        evalGeog(src, 
GeographyConstructors.ST_GeogFromText.class.getSimpleName(), "wkt");
+    assertEquals(
+        Constructors.geogFromWKT("LINESTRING (0 0, 1 1, 2 2)", 0).toEWKT(), 
result.toEWKT());
+  }
+
+  @Test
+  public void testGeogFromEWKT() throws Exception {
+    Table src = sourceTable("ewkt", "SRID=4326;POINT (1 2)", 
BasicTypeInfo.STRING_TYPE_INFO);
+    Geography result =
+        evalGeog(src, 
GeographyConstructors.ST_GeogFromEWKT.class.getSimpleName(), "ewkt");
+    assertEquals(4326, result.getSRID());
+    assertEquals(Constructors.geogFromEWKT("SRID=4326;POINT (1 2)").toEWKT(), 
result.toEWKT());
+  }
+
+  @Test
+  public void testGeogCollFromText() throws Exception {
+    String wkt = "GEOMETRYCOLLECTION (POINT (1 2), LINESTRING (0 0, 1 1))";
+    Table src = sourceTable("wkt", wkt, BasicTypeInfo.STRING_TYPE_INFO);
+    Geography result =
+        evalGeog(src, 
GeographyConstructors.ST_GeogCollFromText.class.getSimpleName(), "wkt");
+    assertEquals(Constructors.geogCollFromText(wkt, 0).toEWKT(), 
result.toEWKT());
+  }
+
+  @Test
+  public void testGeogFromWKB() throws Exception {
+    Geometry point = new WKTReader().read("POINT (1 2)");
+    byte[] wkb = new WKBWriter().write(point);
+    Table src = sourceTable("wkb", wkb, 
PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO);
+    Geography result =
+        evalGeog(src, 
GeographyConstructors.ST_GeogFromWKB.class.getSimpleName(), "wkb");
+    assertEquals(Constructors.geogFromWKB(wkb, 0).toEWKT(), result.toEWKT());
+  }
+
+  @Test
+  public void testGeogFromEWKB() throws Exception {
+    Geometry point = new WKTReader().read("POINT (3 4)");
+    byte[] wkb = new WKBWriter().write(point);
+    Table src = sourceTable("wkb", wkb, 
PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO);
+    Geography result =
+        evalGeog(src, 
GeographyConstructors.ST_GeogFromEWKB.class.getSimpleName(), "wkb");
+    assertEquals(Constructors.geogFromWKB(wkb).toEWKT(), result.toEWKT());
+  }

Review Comment:
   `testGeogFromEWKB` currently writes plain WKB (no SRID flag), so it doesn't 
actually validate EWKB SRID extraction end-to-end. As written, the test would 
still pass even if `ST_GeogFromEWKB` incorrectly ignored embedded SRID.



-- 
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]

Reply via email to