JulianJaffePinterest commented on a change in pull request #10920: URL: https://github.com/apache/druid/pull/10920#discussion_r621865322
########## File path: docs/development/extensions-core/spark.md ########## @@ -0,0 +1,275 @@ +<!-- + ~ 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. + --> + +# Apache Spark Reader and Writer for Druid + +## Reader +The reader reads Druid segments from deep storage into Spark. It locates the segments to read and determines their +schema if not provided by querying the brokers for the relevant metadata but otherwise does not interact with a running +Druid cluster. + +Sample Code: +```scala +val metadataProperties = Map[String, String]( + "metadataDbType" -> "mysql", + "metadataConnectUri" -> "jdbc:mysql://druid.metadata.server:3306/druid", + "metadataUser" -> "druid", + "metadataPassword" -> "diurd" +) + +sparkSession + .read + .format("druid") + .options(Map[String, String]("table" -> "dataSource") ++ metadataProperties) + .load() +``` + +If you know the schema of the Druid data source you're reading from, you can save needing to determine the schema via +calls to the broker with +```scala +sparkSession + .read + .format("druid") + .schema(schema) + .options(Map[String, String]("table" -> "dataSource") ++ metadataProperties) + .load() +``` + +Filters should be applied to the read-in data frame before any [Spark actions](http://spark.apache.org/docs/2.4.7/api/scala/index.html#org.apache.spark.sql.Dataset) Review comment: If a filter is on the time dimension, then we don't need to scan files that don't cover the requested time interval (down the road we could also add support for not fetching unnecessary files if the underlying data source is partitioned by range as well). If the segment file contains data for the requested time period we'll need to fetch it from deep storage but we can still filter out values while we read data into a DataFrame so there's some benefit there as well, at least for what Spark needs to keep in memory. -- 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]
