birTiwana commented on a change in pull request #10920: URL: https://github.com/apache/druid/pull/10920#discussion_r637396152
########## File path: extensions-core/spark-extensions/src/test/scala/org/apache/druid/spark/v2/DruidDataSourceV2Suite.scala ########## @@ -0,0 +1,147 @@ +/* + * 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.druid.spark.v2 + +import org.apache.druid.java.util.common.StringUtils +import org.apache.druid.spark.configuration.DruidConfigurationKeys +import org.apache.druid.spark.mixins.TryWithResources +import org.apache.druid.spark.{MAPPER, SparkFunSuite} +import org.apache.druid.timeline.DataSegment +import org.apache.spark.sql.{DataFrame, Row, SaveMode} +import org.apache.spark.sql.sources.v2.DataSourceOptions +import org.scalatest.matchers.should.Matchers + +import scala.collection.JavaConverters.{collectionAsScalaIterableConverter, mapAsJavaMapConverter, + seqAsJavaListConverter} + +class DruidDataSourceV2Suite extends SparkFunSuite with Matchers Review comment: I was also able to test successfully loading segment files from S3 as deep storage. But did not test with any S3 encryption protocols yet. Here is a code snippet.. ` import java.util.UUID import org.apache.druid.jackson.DefaultObjectMapper import org.apache.druid.timeline.DataSegment import org.apache.druid.timeline.DataSegment.PruneSpecsHolder import org.apache.druid.timeline.partition.{NumberedShardSpec, ShardSpec} import org.apache.spark.sql.SparkSession import org.apache.spark.sql.types.{LongType, StringType, StructField, StructType} import org.apache.spark.{SparkConf, SparkContext} import org.joda.time.Interval import scala.collection.JavaConversions.seqAsJavaList object Working { private val localSparkContext = new ThreadLocal[SparkContext] private val localSparkSession = new ThreadLocal[SparkSession] private val MAPPER = new DefaultObjectMapper() def sparkSession: SparkSession = localSparkSession.get() val dataSource: String = "......." private def setupSparkContextAndSession(): Unit = { val sparkConf = new SparkConf(loadDefaults = true) sparkConf.setAppName(UUID.randomUUID.toString).setMaster("local") localSparkContext.set(new SparkContext(sparkConf)) localSparkContext.get().hadoopConfiguration.set("fs.s3n.awsAccessKeyId", "......") localSparkContext.get().hadoopConfiguration.set("fs.s3n.awsSecretAccessKey", "........") localSparkSession.set(SparkSession.builder.getOrCreate()) } def main(args: Array[String]): Unit = { setupSparkContextAndSession() val shardSpec: ShardSpec = new NumberedShardSpec(0, 1) val interval: Interval = Interval.parse("2016-06-28T00:00:00.000Z/2016-06-29T00:00:00.000Z") val loadSpec: java.util.Map[String, AnyRef] = new java.util.HashMap[String, AnyRef] loadSpec.put("type", "s3_zip") loadSpec.put("bucket", "..........") loadSpec.put("key", "......./index.zip") loadSpec.put("S3Schema", "s3n") val dimensions: List[String] = List[String]("added,flags") val metrics: List[String] = List[String]() val binaryVersion: Integer = 9 val version: String = "2021-05-20T16:37:22.549Z" val dataSegment: DataSegment = new DataSegment(dataSource, interval, version, loadSpec, dimensions, metrics, shardSpec, null, binaryVersion, 1170L, PruneSpecsHolder.DEFAULT) val segments: Seq[DataSegment] = Seq[DataSegment](dataSegment) val segmentsString = MAPPER.writeValueAsString(seqAsJavaList(segments)) val schema: StructType = StructType(Seq[StructField]( StructField("__time", LongType, nullable = true), StructField("added", LongType, nullable = true), StructField("flags", StringType, nullable = true) )) val readDf = sparkSession .read .format("org.apache.druid.spark.v2.DruidDataSourceV2") .schema(schema) .options(Map("segments" -> segmentsString)) .load() readDf.toJSON.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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
