You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sedona.apache.org by "zhangfengcdt (via GitHub)" <gi...@apache.org> on 2025/01/29 00:33:02 UTC

[PR] [SEDONA-704] Add the STAC datasource reader [sedona]

zhangfengcdt opened a new pull request, #1775:
URL: https://github.com/apache/sedona/pull/1775

   ## Did you read the Contributor Guide?
   
   - Yes, I have read the [Contributor Rules](https://sedona.apache.org/latest-snapshot/community/rule/) and [Contributor Development Guide](https://sedona.apache.org/latest-snapshot/community/develop/)
   
   ## Is this PR related to a JIRA ticket?
   
   - Yes, the URL of the associated JIRA ticket is https://issues.apache.org/jira/browse/SEDONA-XXX. The PR name follows the format `[SEDONA-XXX] my subject`.
   
   ## What changes were proposed in this PR?
   This PR adds an STAC (SpatioTemporal Asset Catalog) collection reader to Sedona. The reader will fetch STAC items and load them into a Sedona DataFrame. The data can be sourced from static JSON files, GeoParquet, or external services, such as Earth Search by Element84.
   
   ## How was this patch tested?
   Unit tests under: org.apache.spark.sql.sedona_sql.io.stac
   
   ## Did this PR include necessary documentation updates?
   
   - Yes, I have updated the documentation.
   


-- 
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: dev-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SEDONA-704] Add the STAC datasource reader [sedona]

Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu merged PR #1775:
URL: https://github.com/apache/sedona/pull/1775


-- 
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: dev-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SEDONA-704] Add the STAC datasource reader [sedona]

Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu commented on code in PR #1775:
URL: https://github.com/apache/sedona/pull/1775#discussion_r1934663903


##########
spark/common/src/test/scala/org/apache/spark/sql/sedona_sql/io/stac/StacDataSourceTest.scala:
##########
@@ -0,0 +1,210 @@
+/*
+ * 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.spark.sql.sedona_sql.io.stac
+
+import org.apache.sedona.sql.TestBaseScala
+import org.apache.spark.sql.sedona_sql.UDT.{GeometryUDT, RasterUDT}
+import org.apache.spark.sql.types.{ArrayType, DoubleType, MapType, StringType, StructField, StructType, TimestampType}
+import org.scalatest.BeforeAndAfterAll
+
+import java.util.TimeZone
+
+class StacDataSourceTest extends TestBaseScala {
+
+  val STAC_COLLECTION_LOCAL: String = resourceFolder + "datasource_stac/collection.json"
+  val STAC_ITEM_LOCAL: String = resourceFolder + "geojson/core-item.json"
+
+  val STAC_COLLECTION_REMOTE: List[String] = List(
+    "https://earth-search.aws.element84.com/v1/collections/sentinel-2-pre-c1-l2a",
+    "https://storage.googleapis.com/cfo-public/vegetation/collection.json",
+    "https://storage.googleapis.com/cfo-public/wildfire/collection.json",
+    "https://earthdatahub.destine.eu/api/stac/v1/collections/copernicus-dem",
+    "https://planetarycomputer.microsoft.com/api/stac/v1/collections/naip")
+
+  it("basic df load from local file should work") {
+    val dfStac = sparkSession.read.format("stac").load(STAC_COLLECTION_LOCAL)
+    dfStac.show(false)

Review Comment:
   Please remove `.show()`



-- 
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-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SEDONA-704] Add the STAC datasource reader [sedona]

Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu commented on code in PR #1775:
URL: https://github.com/apache/sedona/pull/1775#discussion_r1934665302


##########
spark/common/src/test/scala/org/apache/spark/sql/sedona_sql/io/stac/StacTableTest.scala:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.spark.sql.sedona_sql.io.stac
+
+import org.apache.spark.sql.sedona_sql.io.stac.StacTable.{SCHEMA_GEOPARQUET, addAssetStruct, addAssetsStruct}
+import org.apache.spark.sql.types.{ArrayType, MapType, StringType, StructField, StructType}
+import org.scalatest.funsuite.AnyFunSuite
+
+class StacTableTest extends AnyFunSuite {
+
+  def printSchema(schema: StructType): Unit = {
+    def printFields(fields: Array[StructField], indent: String): Unit = {
+      fields.foreach { field =>
+        println(
+          s"$indent- ${field.name}: ${field.dataType.simpleString} (nullable = ${field.nullable})")
+        field.dataType match {
+          case structType: StructType => printFields(structType.fields, indent + "  ")
+          case arrayType: ArrayType =>
+            println(s"$indent  - elementType: ${arrayType.elementType.simpleString}")
+            arrayType.elementType match {
+              case structType: StructType => printFields(structType.fields, indent + "    ")
+              case _ => // Do nothing
+            }
+          case mapType: MapType =>
+            println(s"$indent  - keyType: ${mapType.keyType.simpleString}")
+            println(s"$indent  - valueType: ${mapType.valueType.simpleString}")
+            mapType.valueType match {
+              case structType: StructType => printFields(structType.fields, indent + "    ")
+              case _ => // Do nothing
+            }
+          case _ => // Do nothing
+        }
+      }
+    }
+    printFields(schema.fields, "")
+  }
+
+  test("addAssetStruct should add a new asset to an existing assets struct") {
+    val initialSchema = StructType(
+      Seq(
+        StructField("id", StringType, nullable = false),
+        StructField(
+          "assets",
+          StructType(Seq(StructField(
+            "image",
+            StructType(Seq(
+              StructField("href", StringType, nullable = true),
+              StructField("roles", ArrayType(StringType), nullable = true),
+              StructField("title", StringType, nullable = true),
+              StructField("type", StringType, nullable = true))),
+            nullable = true))),
+          nullable = true)))
+
+    val updatedSchema = addAssetStruct(initialSchema, "thumbnail")
+
+    assert(updatedSchema.fieldNames.contains("assets"))
+    val assetsField = updatedSchema("assets").dataType.asInstanceOf[StructType]
+    assert(assetsField.fieldNames.contains("thumbnail"))
+  }
+
+  test("addAssetStruct should create assets struct if it doesn't exist") {
+    val initialSchema = StructType(Seq(StructField("id", StringType, nullable = false)))
+
+    val updatedSchema1 = addAssetStruct(initialSchema, "image")
+    val updatedSchema2 = addAssetStruct(updatedSchema1, "rast")
+
+    assert(updatedSchema2.fieldNames.contains("assets"))
+    val assetsField = updatedSchema2("assets").dataType.asInstanceOf[StructType]
+    assert(assetsField.fieldNames.contains("image"))
+    assert(assetsField.fieldNames.contains("rast"))
+  }
+
+  test("addAssetStruct should not modify other fields") {
+    val initialSchema = SCHEMA_GEOPARQUET
+
+    val updatedSchema = addAssetsStruct(initialSchema, Array("thumbnail", "preview"))
+    printSchema(updatedSchema)

Review Comment:
   please don't print output in tests



-- 
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-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SEDONA-704] Add the STAC datasource reader [sedona]

Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu commented on code in PR #1775:
URL: https://github.com/apache/sedona/pull/1775#discussion_r1934664147


##########
spark/common/src/test/scala/org/apache/spark/sql/sedona_sql/io/stac/StacDataSourceTest.scala:
##########
@@ -0,0 +1,210 @@
+/*
+ * 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.spark.sql.sedona_sql.io.stac
+
+import org.apache.sedona.sql.TestBaseScala
+import org.apache.spark.sql.sedona_sql.UDT.{GeometryUDT, RasterUDT}
+import org.apache.spark.sql.types.{ArrayType, DoubleType, MapType, StringType, StructField, StructType, TimestampType}
+import org.scalatest.BeforeAndAfterAll
+
+import java.util.TimeZone
+
+class StacDataSourceTest extends TestBaseScala {
+
+  val STAC_COLLECTION_LOCAL: String = resourceFolder + "datasource_stac/collection.json"
+  val STAC_ITEM_LOCAL: String = resourceFolder + "geojson/core-item.json"
+
+  val STAC_COLLECTION_REMOTE: List[String] = List(
+    "https://earth-search.aws.element84.com/v1/collections/sentinel-2-pre-c1-l2a",
+    "https://storage.googleapis.com/cfo-public/vegetation/collection.json",
+    "https://storage.googleapis.com/cfo-public/wildfire/collection.json",
+    "https://earthdatahub.destine.eu/api/stac/v1/collections/copernicus-dem",
+    "https://planetarycomputer.microsoft.com/api/stac/v1/collections/naip")
+
+  it("basic df load from local file should work") {
+    val dfStac = sparkSession.read.format("stac").load(STAC_COLLECTION_LOCAL)
+    dfStac.show(false)
+  }
+
+  it("basic df load from remote service endpoints should work") {
+    STAC_COLLECTION_REMOTE.foreach { endpoint =>
+      val dfStac = sparkSession.read.format("stac").load(endpoint)
+      assertSchema(dfStac.schema)
+    }
+  }
+
+  it("normal select SQL without any filter") {
+    val dfStac = sparkSession.read.format("stac").load(STAC_COLLECTION_LOCAL)
+    dfStac.createOrReplaceTempView("STACTBL")
+
+    val dfSelect =
+      sparkSession.sql("SELECT id, datetime as dt, geometry, bbox FROM STACTBL")
+
+    assert(dfSelect.schema.fieldNames.contains("id"))
+    assert(dfSelect.schema.fieldNames.contains("dt"))
+    assert(dfSelect.schema.fieldNames.contains("geometry"))
+    assert(dfSelect.schema.fieldNames.contains("bbox"))
+
+    val rowCount = dfSelect.count()
+    assert(rowCount == 6)
+  }
+
+  it("select SQL with filter on datetime") {
+    val dfStac = sparkSession.read.format("stac").load(STAC_COLLECTION_LOCAL)
+    dfStac.createOrReplaceTempView("STACTBL")
+
+    val dfSelect = sparkSession.sql(
+      "SELECT id, datetime as dt, geometry, bbox " +
+        "FROM STACTBL " +
+        "WHERE datetime BETWEEN '2020-01-01T00:00:00Z' AND '2020-12-13T00:00:00Z'")
+
+    dfSelect.explain(true)

Review Comment:
   Please remove `explain()`



-- 
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-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org