jiayuasu commented on code in PR #1520: URL: https://github.com/apache/sedona/pull/1520#discussion_r1681724635
########## common/src/main/java/org/apache/sedona/common/Functions.java: ########## @@ -1812,6 +1812,24 @@ private static Geometry[] convertGeometryToArray(Geometry geom) { return array; } + public static Geometry generatePoints(Geometry geom, int numPoints, long seed) { + RandomPointsBuilderSeed pointsBuilder = new RandomPointsBuilderSeed(geom.getFactory(), seed); + pointsBuilder.setExtent(geom); + pointsBuilder.setNumPoints(numPoints); + return pointsBuilder.getGeometry(); + } + + public static Geometry generatePoints(Geometry geom, int numPoints) { + return generatePoints(geom, numPoints, 0); + } + + public static Geometry generatePoints(Geometry geom, int numPoints, Random random) { Review Comment: Why is there another overloaded function that takes `Random` as input? ########## 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: Why is this needed? This if condition seems to be repeating the same condition in `Functions` -- 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-unsubscr...@sedona.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org