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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
