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


##########
spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala:
##########
@@ -1435,6 +1436,58 @@ case class ST_ForceRHR(inputExpressions: Seq[Expression])
   }
 }
 
+case class ST_GeneratePoints(inputExpressions: Seq[Expression], randomSeed: 
Long)
+    extends Expression
+    with CodegenFallback
+    with ExpectsInputTypes
+    with Nondeterministic {
+
+  def this(inputExpressions: Seq[Expression]) = this(inputExpressions, 
Utils.random.nextLong())
+
+  @transient private[this] var random: java.util.Random = _
+
+  private val nArgs = children.length
+
+  override protected def initializeInternal(partitionIndex: Int): Unit = 
random =
+    new java.util.Random(randomSeed + partitionIndex)
+
+  override protected def evalInternal(input: InternalRow): Any = {
+    val geom = children.head.toGeometry(input)
+    val numPoints = children(1).eval(input).asInstanceOf[Int]
+    val generatedPoints = if (nArgs == 3) {
+      val seed = children(2).eval(input).asInstanceOf[Int]
+      if (seed > 0) {
+        Functions.generatePoints(geom, numPoints, seed)
+      } else {
+        Functions.generatePoints(geom, numPoints, random)

Review Comment:
   This is for generating consistent random streams even if seed is 0.



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