birTiwana commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r634795152



##########
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
+  with DruidDataSourceV2TestUtils with TryWithResources {
+  test("sparkSession.read(\"druid\") should correctly read segments into a 
dataFrame") {
+    val expected = sparkSession.createDataFrame(Seq(
+      // Reading from segments will not sort the resulting dataframe by time 
across segments, only within it
+      Row.fromSeq(Seq(1577836800000L, List("dim1"), "1", "1", "2", 1L, 1L, 3L, 
4.2, 1.7F, idOneSketch)),
+      Row.fromSeq(Seq(1577862000000L, List("dim2"), "1", "1", "2", 1L, 4L, 2L, 
5.1, 8.9F, idOneSketch)),
+      Row.fromSeq(Seq(1577851200000L, List("dim1"), "1", "1", "2", 1L, 3L, 1L, 
0.2, 0.0F, idOneSketch)),
+      Row.fromSeq(Seq(1577876400000L, List("dim2"), "2", "1", "2", 1L, 1L, 5L, 
8.0, 4.15F, idOneSketch)),
+      Row.fromSeq(Seq(1577962800000L, List("dim1", "dim3"), "2", "3", "7", 1L, 
2L, 4L, 11.17, 3.7F, idThreeSketch)),
+      Row.fromSeq(Seq(1577988000000L, List("dim2"), "3", "2", "1", 1L, 1L, 7L, 
0.0, 19.0F, idTwoSketch))
+    ).asJava, schema)
+
+    val segmentsString = MAPPER.writeValueAsString(
+      List[DataSegment](firstSegment, secondSegment, thirdSegment).asJava
+    )
+
+    val df = sparkSession
+      .read
+      .format("druid")

Review comment:
       I tried to run these test cases locally using Intellij's scala plugin 
but they are failing with the same error that I mentioned in my comment earlier 
regarding "druid" not being a correct DataSource:
   
   `2021-05-18T14:23:04,851 INFO [ScalaTest-run-running-DruidDataSourceV2Suite] 
org.apache.spark.sql.internal.SharedState - Setting 
hive.metastore.warehouse.dir ('null') to the value of spark.sql.warehouse.dir 
('file:/Users/btiwana/Downloads/druid-spark/druid/extensions-core/spark-extensions/spark-warehouse').
   2021-05-18T14:23:04,852 INFO [ScalaTest-run-running-DruidDataSourceV2Suite] 
org.apache.spark.sql.internal.SharedState - Warehouse path is 
'file:/Users/btiwana/Downloads/druid-spark/druid/extensions-core/spark-extensions/spark-warehouse'.
   2021-05-18T14:23:04,855 INFO [ScalaTest-run-running-DruidDataSourceV2Suite] 
org.apache.spark.sql.execution.streaming.state.StateStoreCoordinatorRef - 
Registered StateStoreCoordinator endpoint
   
   
   Failed to find data source: druid. Please find packages at 
http://spark.apache.org/third-party-projects.html
   java.lang.ClassNotFoundException: Failed to find data source: druid. Please 
find packages at http://spark.apache.org/third-party-projects.html
        at 
org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:660)
        at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:245)
        at 
org.apache.druid.spark.v2.DruidDataSourceV2Suite.$anonfun$new$2(DruidDataSourceV2Suite.scala:77)
        at 
scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
        at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
        at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
        at org.scalatest.Transformer.apply(Transformer.scala:22)
        at org.scalatest.Transformer.apply(Transformer.scala:20)
        at 
org.scalatest.funsuite.AnyFunSuiteLike$$anon$1.apply(AnyFunSuiteLike.scala:189)
        at org.scalatest.TestSuite.withFixture(TestSuite.scala:196)
        at org.scalatest.TestSuite.withFixture$(TestSuite.scala:195)
        at 
org.scalatest.funsuite.AnyFunSuite.withFixture(AnyFunSuite.scala:1562)
        at 
org.scalatest.funsuite.AnyFunSuiteLike.invokeWithFixture$1(AnyFunSuiteLike.scala:187)
        at 
org.scalatest.funsuite.AnyFunSuiteLike.$anonfun$runTest$1(AnyFunSuiteLike.scala:199)
        at org.scalatest.SuperEngine.runTestImpl(Engine.scala:306)
        at 
org.scalatest.funsuite.AnyFunSuiteLike.runTest(AnyFunSuiteLike.scala:199)
        at 
org.scalatest.funsuite.AnyFunSuiteLike.runTest$(AnyFunSuiteLike.scala:181)
        at 
org.apache.druid.spark.SparkFunSuite.org$scalatest$BeforeAndAfterEach$$super$runTest(SparkFunSuite.scala:34)
        at 
org.scalatest.BeforeAndAfterEach.runTest(BeforeAndAfterEach.scala:234)
        at 
org.scalatest.BeforeAndAfterEach.runTest$(BeforeAndAfterEach.scala:227)
        at org.apache.druid.spark.SparkFunSuite.runTest(SparkFunSuite.scala:34)
        at 
org.scalatest.funsuite.AnyFunSuiteLike.$anonfun$runTests$1(AnyFunSuiteLike.scala:232)
        at 
org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:413)
        at scala.collection.immutable.List.foreach(List.scala:392)
        at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)
        at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:396)
        at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:475)
        at 
org.scalatest.funsuite.AnyFunSuiteLike.runTests(AnyFunSuiteLike.scala:232)
        at 
org.scalatest.funsuite.AnyFunSuiteLike.runTests$(AnyFunSuiteLike.scala:231)
        at org.scalatest.funsuite.AnyFunSuite.runTests(AnyFunSuite.scala:1562)
        at org.scalatest.Suite.run(Suite.scala:1112)
        at org.scalatest.Suite.run$(Suite.scala:1094)
        at 
org.scalatest.funsuite.AnyFunSuite.org$scalatest$funsuite$AnyFunSuiteLike$$super$run(AnyFunSuite.scala:1562)
        at 
org.scalatest.funsuite.AnyFunSuiteLike.$anonfun$run$1(AnyFunSuiteLike.scala:236)
        at org.scalatest.SuperEngine.runImpl(Engine.scala:535)
        at org.scalatest.funsuite.AnyFunSuiteLike.run(AnyFunSuiteLike.scala:236)
        at 
org.scalatest.funsuite.AnyFunSuiteLike.run$(AnyFunSuiteLike.scala:235)
        at org.scalatest.funsuite.AnyFunSuite.run(AnyFunSuite.scala:1562)
        at org.scalatest.tools.SuiteRunner.run(SuiteRunner.scala:45)
        at 
org.scalatest.tools.Runner$.$anonfun$doRunRunRunDaDoRunRun$13(Runner.scala:1320)
        at 
org.scalatest.tools.Runner$.$anonfun$doRunRunRunDaDoRunRun$13$adapted(Runner.scala:1314)
        at scala.collection.immutable.List.foreach(List.scala:392)
        at org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:1314)
        at 
org.scalatest.tools.Runner$.$anonfun$runOptionallyWithPassFailReporter$24(Runner.scala:993)
        at 
org.scalatest.tools.Runner$.$anonfun$runOptionallyWithPassFailReporter$24$adapted(Runner.scala:971)
        at 
org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:1480)
        at 
org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:971)
        at org.scalatest.tools.Runner$.run(Runner.scala:798)
        at org.scalatest.tools.Runner.run(Runner.scala)
        at 
org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.runScalaTest2(ScalaTestRunner.java:133)
        at 
org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.main(ScalaTestRunner.java:27)
   Caused by: java.lang.ClassNotFoundException: druid.DefaultSource
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
        at 
org.apache.spark.sql.execution.datasources.DataSource$.$anonfun$lookupDataSource$5(DataSource.scala:634)
        at scala.util.Try$.apply(Try.scala:213)
        at 
org.apache.spark.sql.execution.datasources.DataSource$.$anonfun$lookupDataSource$4(DataSource.scala:634)
        at scala.util.Failure.orElse(Try.scala:224)
        at 
org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:634)
        ... 51 more
   
   `
   
   I think we are missing a step of adding druid as a data source to spark.
   




-- 
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]

Reply via email to