Kontinuation commented on code in PR #1520:
URL: https://github.com/apache/sedona/pull/1520#discussion_r1677782681


##########
common/src/main/java/org/apache/sedona/common/utils/RandomPointsBuilderSeed.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.utils;
+
+import java.util.Random;
+import org.locationtech.jts.geom.*;
+import org.locationtech.jts.shape.random.RandomPointsBuilder;
+
+public class RandomPointsBuilderSeed extends RandomPointsBuilder {
+  double seed;
+  int counter = 0;
+  Random rand;
+
+  public RandomPointsBuilderSeed(GeometryFactory geometryFactory, double seed) 
{

Review Comment:
   Why the seed parameter is `double` but not `long`?



##########
spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala:
##########
@@ -1437,6 +1439,60 @@ case class ST_ForceRHR(inputExpressions: Seq[Expression])
   }
 }
 
+case class ST_GeneratePoints(inputExpressions: Seq[Expression], randomSeed: 
Option[Long] = None)
+    extends Expression
+    with Nondeterministic
+    with ExpectsInputTypes
+    with CodegenFallback
+    with ExpressionWithRandomSeed {
+
+  def this(inputExpressions: Seq[Expression]) = this(inputExpressions, 
Some(0L))
+
+  def seedExpression: Expression = 
randomSeed.map(Literal.apply).getOrElse(Literal(0L))
+
+  @transient private[this] var random: Random = _
+
+  protected def withNewChildrenInternal(newChildren: IndexedSeq[Expression]) = 
{
+    copy(inputExpressions = newChildren)
+  }
+
+  private val nArgs = children.length
+
+  override protected def initializeInternal(partitionIndex: Int): Unit = 
random = new Random(
+    randomSeed.getOrElse(0L) + partitionIndex)
+
+  override protected def evalInternal(input: InternalRow): Any = {
+    val geom = children.head.toGeometry(input)
+    val numPoints = children(1).eval(input).asInstanceOf[Int]
+    if (nArgs == 3) {
+      val seed = children(2).eval(input).asInstanceOf[Int]
+      return GeometrySerializer.serialize(Functions.generatePoints(geom, 
numPoints, seed))
+    }
+    GeometrySerializer.serialize(Functions.generatePoints(geom, numPoints))
+  }

Review Comment:
   We should construct an instance of `RandomPointsBuilderSeed` in the 
`initializeInternal` function, and call    `setExtent`, `setNumPoints`, 
`getGeometry` methods using that instance in `evalInternal`.



##########
common/src/main/java/org/apache/sedona/common/utils/RandomPointsBuilderSeed.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.utils;
+
+import java.util.Random;
+import org.locationtech.jts.geom.*;
+import org.locationtech.jts.shape.random.RandomPointsBuilder;
+
+public class RandomPointsBuilderSeed extends RandomPointsBuilder {
+  double seed;
+  int counter = 0;

Review Comment:
   Why do we need this counter?



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