Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SEDONA-414] Make ST_MakeLine in sedona-spark work with array inputs. #1068

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,10 @@ public void testMakeLine() {
table = table.select(call(Functions.ST_MakeLine.class.getSimpleName(), $("point1"), $("point2")));
Geometry result = (Geometry) first(table).getField(0);
assertEquals("LINESTRING (0 0, 1 1)", result.toString());

table = tableEnv.sqlQuery("SELECT ST_MakeLine(ARRAY[ST_Point(2, 2), ST_Point(3, 3)]) AS line");
result = (Geometry) first(table).getField(0);
assertEquals("LINESTRING (2 2, 3 3)", result.toString());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ case class ST_SubDivideExplode(children: Seq[Expression])
}

case class ST_MakeLine(inputExpressions: Seq[Expression])
extends InferredExpression(InferrableFunction.allowRightNull(Functions.makeLine _)) {
extends InferredExpression(inferrableFunction2(Functions.makeLine), inferrableFunction1(Functions.makeLine)) {

protected def withNewChildrenInternal(newChildren: IndexedSeq[Expression]) = {
copy(inputExpressions = newChildren)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ class dataFrameAPITestScala extends TestBaseScala {
val actualResult = df.take(1)(0).get(0).asInstanceOf[Geometry].toText()
val expectedResult = "LINESTRING (0 0, 1 1)"
assert(actualResult == expectedResult)

val df2 = sparkSession.sql("SELECT ST_MakeLine(ARRAY(ST_Point(0, 0), ST_Point(1, 1), ST_Point(2, 2)))")
val actualResult2 = df2.take(1)(0).get(0).asInstanceOf[Geometry].toText()
assert(actualResult2 == "LINESTRING (0 0, 1 1, 2 2)")
}

it("Passed ST_MakeValid On Invalid Polygon") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,15 @@ class functionTestScala extends TestBaseScala with Matchers with GeometrySample
}

it("Passed ST_MakeLine") {

var testtable = sparkSession.sql(
"SELECT ST_MakeLine(ST_GeomFromText('POINT(1 2)'), ST_GeomFromText('POINT(3 4)'))"
val testtable = sparkSession.sql(
"""SELECT
|ST_MakeLine(ST_GeomFromText('POINT(1 2)'), ST_GeomFromText('POINT(3 4)')),
|ST_MakeLine(ARRAY(ST_Point(5, 6), ST_Point(7, 8), ST_Point(9, 10)))
|""".stripMargin
)
assert(testtable.take(1)(0).get(0).asInstanceOf[Geometry].toText.equals("LINESTRING (1 2, 3 4)"))
val row = testtable.take(1)(0)
assert(row.get(0).asInstanceOf[Geometry].toText.equals("LINESTRING (1 2, 3 4)"))
assert(row.get(1).asInstanceOf[Geometry].toText.equals("LINESTRING (5 6, 7 8, 9 10)"))
}

it("Passed ST_Polygon") {
Expand Down
Loading