You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2021/02/24 05:52:54 UTC
[GitHub] [druid] JulianJaffePinterest opened a new pull request #10920: Spark Direct Readers and Writers for Druid.
JulianJaffePinterest opened a new pull request #10920:
URL: https://github.com/apache/druid/pull/10920
<!-- Thanks for trying to help us make Apache Druid be the best it can be! Please fill out as much of the following information as is possible (where relevant, and remove it when irrelevant) to help make the intention and scope of this PR clear in order to ease review. -->
Implements #9780
### Description
See #9780 and linked discussions for more context. This PR adds a new extension, `spark-extensions`, containing Spark direct readers and writers for Druid. Usage is documented in the `README`.
In my opinion, this process has demonstrated that there is not a sufficient constituency to support these connectors in Druid but I'm opening this PR both to make these changes easier to find and because you miss 100% of the shots you don't take 😉.
<!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
<hr>
This PR has:
- [x] been self-reviewed.
- [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
- [x] added documentation for new or modified features or behaviors.
- [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
- [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/licenses.yaml)
- [x] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
- [x] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
- [ ] added integration tests.
- [x] been tested in a test Druid cluster.
<!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist above are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
<hr>
##### Key changed/added classes in this PR
* `extensions-core/spark-extensions`
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] samarthjain commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
samarthjain commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r626086242
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/clients/DruidClient.scala
##########
@@ -0,0 +1,188 @@
+/*
+ * 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.clients
+
+import com.fasterxml.jackson.core.`type`.TypeReference
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.common.net.HostAndPort
+import org.apache.druid.java.util.common.{ISE, Intervals, JodaUtils, StringUtils}
+import org.apache.druid.java.util.http.client.response.{StringFullResponseHandler,
+ StringFullResponseHolder}
+import org.apache.druid.java.util.http.client.{HttpClient, Request}
+import org.apache.druid.query.Druids
+import org.apache.druid.query.metadata.metadata.{ColumnAnalysis, SegmentAnalysis,
+ SegmentMetadataQuery}
+import org.apache.druid.spark.MAPPER
+import org.apache.druid.spark.configuration.{Configuration, DruidConfigurationKeys}
+import org.apache.druid.spark.mixins.Logging
+import org.jboss.netty.handler.codec.http.{HttpMethod, HttpResponseStatus}
+import org.joda.time.{Duration, Interval}
+
+import java.net.URL
+import java.util.{List => JList}
+import javax.ws.rs.core.MediaType
+import scala.collection.JavaConverters.{asScalaBufferConverter, mapAsJavaMapConverter,
+ mapAsScalaMapConverter, seqAsJavaListConverter}
+
+/**
+ * Going with SegmentMetadataQueries despite the significant overhead because there's no other way
+ * to get accurate information about Druid columns.
+ *
+ * This is pulled pretty directly from the druid-hadoop-input-format project on GitHub. There is
+ * likely substantial room for improvement.
+ *
+ * @param httpClient
+ * @param hostAndPort
+ */
+class DruidClient(
+ val httpClient: HttpClient,
+ val hostAndPort: HostAndPort
+ ) extends Logging {
+ private val RetryCount = 5
Review comment:
Does it make sense to have these settings configurable?
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/configuration/DruidConfigurationKeys.scala
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.configuration
+
+import org.apache.spark.sql.sources.v2.DataSourceOptions
+
+object DruidConfigurationKeys {
+ // Shadowing DataSourceOptions.TABLE_KEY here so other classes won't need unnecessary imports
+ val tableKey: String = DataSourceOptions.TABLE_KEY
+
+ // Metadata Client Configs
+ val metadataPrefix: String = "metadata"
+ val metadataDbTypeKey: String = "dbType"
+ val metadataHostKey: String = "host"
+ val metadataPortKey: String = "port"
+ val metadataConnectUriKey: String = "connectUri"
+ val metadataUserKey: String = "user"
+ val metadataPasswordKey: String = "password"
+ val metadataDbcpPropertiesKey: String = "dbcpProperties"
+ val metadataBaseNameKey: String = "baseName"
+ private[spark] val metadataHostDefaultKey: (String, String) = (metadataHostKey, "localhost")
+ private[spark] val metadataPortDefaultKey: (String, Int) = (metadataPortKey, 1527)
+ private[spark] val metadataBaseNameDefaultKey: (String, String) = (metadataBaseNameKey, "druid")
+
+ // Druid Client Configs
+ val brokerPrefix: String = "broker"
+ val brokerHostKey: String = "host"
+ val brokerPortKey: String = "port"
+ private[spark] val brokerHostDefaultKey: (String, String) = (brokerHostKey, "localhost")
+ private[spark] val brokerPortDefaultKey: (String, Int) = (brokerPortKey, 8082)
+
+ // Common configs
+ val useCompactSketchesKey: String = "useCompactSketches" // Default: false
Review comment:
What is the purpose of this config?
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/v2/writer/DruidDataWriter.scala
##########
@@ -0,0 +1,304 @@
+/*
+ * 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.writer
+
+import com.fasterxml.jackson.core.`type`.TypeReference
+import org.apache.druid.data.input.MapBasedInputRow
+import org.apache.druid.java.util.common.io.Closer
+import org.apache.druid.java.util.common.parsers.TimestampParser
+import org.apache.druid.java.util.common.{DateTimes, FileUtils, Intervals}
+import org.apache.druid.segment.column.ValueType
+import org.apache.druid.segment.data.{BitmapSerdeFactory, CompressionFactory, CompressionStrategy,
+ ConciseBitmapSerdeFactory, RoaringBitmapSerdeFactory}
+import org.apache.druid.segment.incremental.{IncrementalIndex, IncrementalIndexSchema,
+ OnheapIncrementalIndex}
+import org.apache.druid.segment.indexing.DataSchema
+import org.apache.druid.segment.loading.DataSegmentPusher
+import org.apache.druid.segment.writeout.OnHeapMemorySegmentWriteOutMediumFactory
+import org.apache.druid.segment.{IndexSpec, IndexableAdapter, QueryableIndexIndexableAdapter}
+import org.apache.druid.spark.MAPPER
+import org.apache.druid.spark.configuration.{DruidConfigurationKeys, DruidDataWriterConfig}
+import org.apache.druid.spark.mixins.Logging
+import org.apache.druid.spark.registries.{ComplexMetricRegistry, SegmentWriterRegistry,
+ ShardSpecRegistry}
+import org.apache.druid.spark.utils.NullHandlingUtils
+import org.apache.druid.spark.v2.{INDEX_IO, INDEX_MERGER_V9}
+import org.apache.druid.timeline.DataSegment
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.UnsafeArrayData
+import org.apache.spark.sql.sources.v2.writer.{DataWriter, WriterCommitMessage}
+import org.apache.spark.sql.types.ArrayType
+
+import java.io.Closeable
+import java.util.{List => JList}
+import scala.collection.JavaConverters.{asScalaBufferConverter, mapAsJavaMapConverter,
+ seqAsJavaListConverter}
+import scala.collection.mutable
+import scala.collection.mutable.ArrayBuffer
+
+/**
+ * A DruidDataWriter does the actual work of writing a partition of a dataframe to files Druid
+ * knows how to read. Users should not use this class directly but should instead call write() on their dataframe
+ * (e.g. df.write.format("druid").options(Map[String, String](...)).save()).
+ *
+ * TODO: Describe the writing logic (creating the map from bucket to flushed indexers (i.e. adapters
+ * and the current open index), how indices are merged and pushed to deep storage, partition number
+ * /counts concerns, etc.
+ *
+ * @param config An object holding necessary configuration settings for the writer passed along
+ * from the driver.
+ */
+class DruidDataWriter(config: DruidDataWriterConfig) extends DataWriter[InternalRow] with Logging {
+ NullHandlingUtils.initializeDruidNullHandling(config.useDefaultNullHandling)
+
+ private val tmpPersistDir = FileUtils.createTempDir("persist")
+ private val tmpMergeDir = FileUtils.createTempDir("merge")
+ private val closer = Closer.create()
+ closer.register(
+ new Closeable {
+ override def close(): Unit = {
+ FileUtils.deleteDirectory(tmpMergeDir)
+ FileUtils.deleteDirectory(tmpPersistDir)
+ }
+ }
+ )
+
+ private val dataSchema: DataSchema =
+ MAPPER.readValue[DataSchema](config.dataSchemaSerialized,
+ new TypeReference[DataSchema] {})
+ private val dimensions: JList[String] =
+ dataSchema.getDimensionsSpec.getDimensions.asScala.map(_.getName).asJava
+ private val tsColumn: String = dataSchema.getTimestampSpec.getTimestampColumn
+ private val tsColumnIndex = config.schema.fieldIndex(tsColumn)
+ private val timestampParser = TimestampParser
+ .createObjectTimestampParser(dataSchema.getTimestampSpec.getTimestampFormat)
+
+ private val partitionMap = config.partitionMap.map(_(config.partitionId))
+ .getOrElse(Map[String, String]("partitionId" -> config.partitionId.toString))
+
+ private val indexSpecConf = config.properties.dive(DruidConfigurationKeys.indexSpecPrefix)
+ private val indexSpec: IndexSpec = new IndexSpec(
+ DruidDataWriter.getBitmapSerde(
+ indexSpecConf.get(DruidConfigurationKeys.bitmapTypeDefaultKey),
+ indexSpecConf.getBoolean(
+ DruidConfigurationKeys.compressRunOnSerializationKey,
+ RoaringBitmapSerdeFactory.DEFAULT_COMPRESS_RUN_ON_SERIALIZATION)
+ ),
+ DruidDataWriter.getCompressionStrategy(
+ indexSpecConf.get(
+ DruidConfigurationKeys.dimensionCompressionKey,
+ CompressionStrategy.DEFAULT_COMPRESSION_STRATEGY.toString)
+ ),
+ DruidDataWriter.getCompressionStrategy(
+ indexSpecConf.get(
+ DruidConfigurationKeys.metricCompressionKey,
+ CompressionStrategy.DEFAULT_COMPRESSION_STRATEGY.toString)
+ ),
+ DruidDataWriter.getLongEncodingStrategy(
+ indexSpecConf.get(
+ DruidConfigurationKeys.longEncodingKey,
+ CompressionFactory.DEFAULT_LONG_ENCODING_STRATEGY.toString
+ )
+ )
+ )
+
+ private val complexColumnTypes = {
+ dataSchema.getAggregators.toSeq.filter(_.getType == ValueType.COMPLEX).map(_.getComplexTypeName)
+ }
+
+ if (complexColumnTypes.nonEmpty) {
+ // Callers will need to explicitly register any complex metrics not known to ComplexMetricRegistry by default
+ complexColumnTypes.foreach {
+ ComplexMetricRegistry.registerByName(_, config.writeCompactSketches)
+ }
+ }
+ ComplexMetricRegistry.registerSerdes()
+
+ private val pusher: DataSegmentPusher = SegmentWriterRegistry.getSegmentPusher(
+ config.deepStorageType, config.properties
+ )
+
+ // TODO: rewrite this without using IncrementalIndex, because IncrementalIndex bears a lot of overhead
+ // to support concurrent querying, that is not needed in Spark
+ // We may have rows for multiple intervals here, so we need to keep a map of segment start time to
+ // flushed adapters and currently incrementing indexers.
+ private val bucketToIndexMap: mutable.Map[Long,
+ (ArrayBuffer[IndexableAdapter], IncrementalIndex[_])
+ ] = mutable.HashMap[Long, (ArrayBuffer[IndexableAdapter], IncrementalIndex[_])]()
+ .withDefault(bucket => (ArrayBuffer.empty[IndexableAdapter], createInterval(bucket)))
+
+ override def write(row: InternalRow): Unit = {
+ val timestamp = timestampParser
+ .apply(row.get(tsColumnIndex, config.schema(tsColumnIndex).dataType)).getMillis
+ val bucket = getBucketForRow(timestamp)
+ // Scala MutableMaps don't have a computeIfAbsent equivalent, so this is either a logical no-op or it creates the
+ // entry following the function defined in the map's .withDefault declaration
+ bucketToIndexMap(bucket) = bucketToIndexMap(bucket)
+ var index = bucketToIndexMap(bucket)._2
+
+ // Check index, flush if too many rows in memory and recreate
+ if (index.size() == config.rowsPerPersist) {
+ val adapters = bucketToIndexMap(bucket)._1 :+ flushIndex(index)
+ index.close()
+ bucketToIndexMap(bucket) = (adapters, createInterval(bucket))
+ index = bucketToIndexMap(bucket)._2
+ }
+ index.add(
+ index.formatRow(
+ new MapBasedInputRow(
+ timestamp,
+ dimensions,
+ // Convert to Java types that Druid knows how to handle
+ config.schema
+ .map(field => field.name -> (field.dataType, row.get(config.schema.indexOf(field), field.dataType))).toMap
+ .mapValues {
+ case (_, traversable: Traversable[_]) => traversable.toSeq.asJava
+ case (dataType, unsafe: UnsafeArrayData) =>
+ (0 until unsafe.numElements()).map(unsafe.get(_, dataType.asInstanceOf[ArrayType].elementType)).asJava
+ case (_, x) => x
+ }.asJava
+ )
+ )
+ )
+ }
+
+ private[v2] def createInterval(startMillis: Long): IncrementalIndex[_] = {
+ // Using OnHeapIncrementalIndex to minimize changes when migrating from IncrementalIndex. In the future, this should
+ // be optimized further. See https://github.com/apache/druid/issues/10321 for more information.
+ new OnheapIncrementalIndex.Builder()
+ .setIndexSchema(
+ new IncrementalIndexSchema.Builder()
+ .withDimensionsSpec(dataSchema.getDimensionsSpec)
+ .withQueryGranularity(
+ dataSchema.getGranularitySpec.getQueryGranularity
+ )
+ .withMetrics(dataSchema.getAggregators: _*)
+ .withTimestampSpec(dataSchema.getTimestampSpec)
+ .withMinTimestamp(startMillis)
+ .withRollup(dataSchema.getGranularitySpec.isRollup)
+ .build()
+ )
+ .setMaxRowCount(config.rowsPerPersist)
+ .build()
+ }
+
+ private[v2] def flushIndex(index: IncrementalIndex[_]): IndexableAdapter = {
+ new QueryableIndexIndexableAdapter(
+ closer.register(
+ INDEX_IO.loadIndex(
+ INDEX_MERGER_V9
+ .persist(
+ index,
+ index.getInterval,
+ tmpPersistDir,
+ indexSpec,
+ OnHeapMemorySegmentWriteOutMediumFactory.instance()
+ )
+ )
+ )
+ )
+ }
+
+ private[v2] def getBucketForRow(ts: Long): Long = {
+ dataSchema.getGranularitySpec.getSegmentGranularity.bucketStart(DateTimes.utc(ts)).getMillis
+ }
+
+ override def commit(): WriterCommitMessage = {
+ // Return segment locations on deep storage
+ val specs = bucketToIndexMap.values.map { case (adapters, index) =>
+ if (!index.isEmpty) {
+ adapters += flushIndex(index)
+ index.close()
+ }
+ if (adapters.nonEmpty) {
+ // TODO: Merge adapters up to a total number of rows, and then split into new segments.
+ // The tricky piece will be determining the partition number for multiple segments (interpolate 0?)
+ val finalStaticIndexer = INDEX_MERGER_V9
+ val file = finalStaticIndexer.merge(
+ adapters.asJava,
+ true,
+ dataSchema.getAggregators,
+ tmpMergeDir,
+ indexSpec,
+ -1 // TODO: Make maxColumnsToMerge configurable
+ )
+ val allDimensions: JList[String] = adapters
+ .map(_.getDimensionNames)
+ .foldLeft(Set[String]())(_ ++ _.asScala)
+ .toList
+ .asJava
+ val interval = adapters.map(_.getDataInterval)
+ .reduce((l, r) => Intervals.utc(
+ Math.min(l.getStartMillis, r.getStartMillis), Math.max(l.getEndMillis, r.getEndMillis)
+ ))
+ val shardSpec = ShardSpecRegistry.createShardSpec(
+ config.shardSpec,
+ partitionMap)
+ val dataSegmentTemplate = new DataSegment(
+ config.dataSource,
+ dataSchema.getGranularitySpec.getSegmentGranularity.bucket(DateTimes.utc(interval.getStartMillis)),
+ config.version,
+ null, // scalastyle:ignore null
+ allDimensions,
+ dataSchema.getAggregators.map(_.getName).toList.asJava,
+ shardSpec,
+ -1,
+ 0L
+ )
+ val finalDataSegment = pusher.push(file, dataSegmentTemplate, true)
+ Seq(MAPPER.writeValueAsString(finalDataSegment))
+ } else {
+ Seq.empty
+ }
+ }.toSeq.flatten
+ closer.close()
Review comment:
Should this be in a try-with-resources like block you have added in this PR?
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/clients/DruidClient.scala
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.clients
+
+import com.fasterxml.jackson.core.`type`.TypeReference
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.common.net.HostAndPort
+import org.apache.druid.java.util.common.{ISE, StringUtils}
+import org.apache.druid.java.util.http.client.response.{StringFullResponseHandler,
+ StringFullResponseHolder}
+import org.apache.druid.java.util.http.client.{HttpClient, Request}
+import org.apache.druid.query.Druids
+import org.apache.druid.query.metadata.metadata.{ColumnAnalysis, SegmentAnalysis,
+ SegmentMetadataQuery}
+import org.apache.druid.spark.MAPPER
+import org.apache.druid.spark.configuration.{Configuration, DruidConfigurationKeys}
+import org.apache.druid.spark.mixins.Logging
+import org.jboss.netty.handler.codec.http.{HttpMethod, HttpResponseStatus}
+import org.joda.time.{Duration, Interval}
+
+import java.net.URL
+import java.util.{List => JList}
+import javax.ws.rs.core.MediaType
+import scala.collection.JavaConverters.{asScalaBufferConverter, mapAsJavaMapConverter,
+ mapAsScalaMapConverter, seqAsJavaListConverter}
+
+/**
+ * Going with SegmentMetadataQueries despite the significant overhead because there's no other way
+ * to get accurate information about Druid columns.
+ *
+ * This is pulled pretty directly from the druid-hadoop-input-format project on GitHub. There is
+ * likely substantial room for improvement.
+ *
+ * @param httpClient
+ * @param objectMapper
+ * @param hostAndPort
+ */
+class DruidClient(
+ val httpClient: HttpClient,
+ val objectMapper: ObjectMapper,
+ val hostAndPort: HostAndPort
+ ) extends Logging {
+ private val RETRY_COUNT = 5
+ private val RETRY_WAIT_SECONDS = 5
+ private val TIMEOUT_MILLISECONDS = 300000
+ private val druidBaseQueryURL: HostAndPort => String =
+ (hostAndPort: HostAndPort) => s"http://$hostAndPort/druid/v2/"
+
+ /**
+ * The SQL system catalog tables are incorrect for multivalue columns and don't have accurate
+ * type info, so we need to fall back to segmentMetadataQueries. Given a DATASOURCE and a range
+ * of INTERVALS to query over, return a map from column name to a tuple of
+ * (columnType, hasMultipleValues). Note that this is a very expensive operation over large
+ * numbers of segments. If possible, this method should only be called with the most granular
+ * starting and ending intervals instead of over a larger interval.
+ *
+ * @param dataSource The Druid dataSource to fetch the schema for.
+ * @param intervals The intervals to return the schema for.
+ * @return A map from column name to data type and whether or not the column is multi-value
+ * for the schema of DATASOURCE.
+ */
+ def getSchema(dataSource: String, intervals: List[Interval]): Map[String, (String, Boolean)] = {
+ val body = Druids.newSegmentMetadataQueryBuilder()
+ .dataSource(dataSource)
+ .intervals(intervals.asJava)
+ .analysisTypes(SegmentMetadataQuery.AnalysisType.SIZE)
+ .merge(true)
+ .context(Map[String, AnyRef](
+ "timeout" -> Int.box(TIMEOUT_MILLISECONDS)
+ ).asJava)
+ .build()
+ val response = sendRequestWithRetry(
+ druidBaseQueryURL(hostAndPort), RETRY_COUNT, Option(objectMapper.writeValueAsBytes(body))
+ )
+ val segments =
+ objectMapper.readValue[JList[SegmentAnalysis]](
+ response.getContent, new TypeReference[JList[SegmentAnalysis]]() {})
+ if (segments.size() == 0) {
+ throw new ISE(
+ s"No segments found for intervals [${intervals.mkString(",")}] on $dataSource"
+ )
+ }
+ // Since we're setting merge to true, there should only be one item in the list
+ if (segments.size() > 1) {
+ logWarn("Segment metadata response had more than one row, problem?")
+ }
+ segments.asScala.head.getColumns.asScala.map{ case (name: String, col: ColumnAnalysis) =>
Review comment:
Does it make sense to fail the operation if there is an error reported in the response? At a minimum, we should log a warning to let the user know that we are falling back to using "String" as datatype for a column since, possibly, data types are different for a column across segments in the requested interval.
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] juhoautio-rovio commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
juhoautio-rovio commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-876330460
@JulianJaffePinterest thanks.
> I'd love any suggestions you might have on improving the documentation
I would expect to see the most common implicit partitioner method used in the sample code for Writer https://github.com/JulianJaffePinterest/druid/blob/spark_druid_connector/docs/development/extensions-core/spark.md#writer
I suppose that would simply mean including the sample from your comment https://github.com/apache/druid/pull/10920#issuecomment-849417236 above: the one about `Using the new partitioners and the ergonomic approach to passing the a partition map to the writer`.
I would also expect a table that lists the provided partitioners + the corresponding implicit methods for using them conveniently.
----
> They are actually mentioned in the extension docs
Do you mean the doc section [Partitioning & PartitionMaps](https://github.com/JulianJaffePinterest/druid/blob/spark_druid_connector/docs/development/extensions-core/spark.md#partitioning--partitionmaps)?
One partitioner class name is mentioned in this section: `HashedNumberedSegmentPartitioner` – what about others?
It also has this remark:
> see the provided partitioners for examples
Is it just my mistake to not find where those are listed? If I should be looking at some other doc, could there be at least a link to that?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-948484532
Hey @jihoonson, I had some unexpected and unfortunate personal/familial crises to deal with these past few months. While they're not entirely in the rear-view mirror, I should have more time again to push this to the finish line. I've opened #11823 with the next chunk of code (the reading half of the connector). Please let me know if you think the PR is still too big; I couldn't find a good place to split it that wouldn't require a reviewer to know the rest of the code anyway.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-993161134
Calling `.partitionBy` on a `DataFrameWriter` (what you get when you call `.write()` on a DataFrame`) doesn't do anything for a v2 data source that doesn't have a managed catalog, which Druid does not (see #11929 for a recent example). The [docs](https://github.com/apache/druid/blob/8392f87236d4a9795aa4e2867eea18cdf0aeb8ec/docs/operations/spark.md#writer) have a more in-depth discussion of partitioning, but the short version is that you'll either need to partition your dataframe before calling `.write()` on it or use one of the `DruidDataFrame` wrapper's convenience methods (for example,
```scala
import org.apache.druid.spark.DruidDataFrame
df.partitionAndWrite("__time", "millis", "DAY", 200000).format("druid").mode(SaveMode.Overwrite).options(map).save()
```
or in Java
```java
import org.apache.druid.spark.package$.MODULE$.DruidDataFrame
DruidDataFrame(dataset).partitionAndWrite("__time", "millis", "DAY", 200000).format("druid").mode(SaveMode.Overwrite).options(map).save();
```)
If you don't want to use implicits/wrapper classes, you can also use the partitioner directly:
```java
SingleDimensionPartitioner partitioner = new SingleDimensionPartitioner(dataset);
Dataset<Row> partitionedDataSet = partitioner.partition("__time", "millis", "DAY", 200000, "dim1", true);
partitionedDataset.write().format("druid").mode(SaveMode.Overwrite).options(map).save();
```
Also, are you setting `writer.version` in your options map? I'm surprised to see the segments differ in version between each partition. That's what's causing the partitions to overshadow each other.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] wangxiaobaidu11 commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
wangxiaobaidu11 commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-984461681
hi @JulianJaffePinterest, I hope you can get out of your sad mood soon and take good care of yourself! Last month I tested your code. I met a problem described below:
`21/12/02 15:19:40 ERROR Executor: Exception in task 0.0 in stage 0.0 (TID 0)
noc.com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve type id 'thetaSketch' as a subtype of `org.apache.druid.query.aggregation.AggregatorFactory`: known type ids = [cardinality, count, doubleAny, doubleFirst, doubleLast, doubleMax, doubleMean, doubleMin, doubleSum, filtered, floatAny, floatFirst, floatLast, floatMax, floatMin, floatSum, grouping, histogram, hyperUnique, javascript, longAny, longFirst, longLast, longMax, longMin, longSum, stringAny, stringFirst, stringFirstFold, stringLast, stringLastFold]
at [Source: (String)"[
{ "type": "count", "name": "count" },
{ "type": "longSum", "name": "sum_metric1", "fieldName": "sum_metric1" },
{ "type": "longSum", "name": "sum_metric2", "fieldName": "sum_metric2" },
{ "type": "doubleSum", "name": "sum_metric3", "fieldName": "sum_metric3" },
{ "type": "floatSum", "name": "sum_metric4", "fieldName": "sum_metric4" },
{ "type": "thetaSketch", "name": "uniq_id1", "fieldName": "uniq_id1", "isInputThetaSketch": true }
]"; line: 7, column: 13] (through reference chain: java.lang.Object[][5])
at noc.com.fasterxml.jackson.databind.exc.InvalidTypeIdException.from(InvalidTypeIdException.java:43)
at noc.com.fasterxml.jackson.databind.DeserializationContext.invalidTypeIdException(DeserializationContext.java:1761)
at noc.com.fasterxml.jackson.databind.DeserializationContext.handleUnknownTypeId(DeserializationContext.java:1268)
at noc.com.fasterxml.jackson.databind.jsontype.impl.TypeDeserializerBase._handleUnknownTypeId(TypeDeserializerBase.java:290)
at noc.com.fasterxml.jackson.databind.jsontype.impl.TypeDeserializerBase._findDeserializer(TypeDeserializerBase.java:162)
at noc.com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:113)
at noc.com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:97)
at noc.com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserializeWithType(AbstractDeserializer.java:254)
at noc.com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:197)
at noc.com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:21)
at noc.com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4218)
at noc.com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3214)
at noc.com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3197)
at org.apache.druid.spark.v2.writer.DruidDataWriterFactory$.createDataSchemaFromConfiguration(DruidDataWriterFactory.scala:99)
at org.apache.druid.spark.v2.writer.DruidDataWriterFactory.createDataWriter(DruidDataWriterFactory.scala:70)
at org.apache.spark.sql.execution.datasources.v2.DataWritingSparkTask$.run(WriteToDataSourceV2Exec.scala:113)
at org.apache.spark.sql.execution.datasources.v2.WriteToDataSourceV2Exec.$anonfun$doExecute$2(WriteToDataSourceV2Exec.scala:67)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:90)
at org.apache.spark.scheduler.Task.run(Task.scala:121)
at org.apache.spark.executor.Executor$TaskRunner.$anonfun$run$3(Executor.scala:411)
at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1360)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:414)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
21/12/02 15:19:40 WARN TaskSetManager: Lost task 0.0 in stage 0.0 (TID 0, localhost, executor driver): noc.com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve type id 'thetaSketch' as a subtype of `org.apache.druid.query.aggregation.AggregatorFactory`: known type ids = [cardinality, count, doubleAny, doubleFirst, doubleLast, doubleMax, doubleMean, doubleMin, doubleSum, filtered, floatAny, floatFirst, floatLast, floatMax, floatMin, floatSum, grouping, histogram, hyperUnique, javascript, longAny, longFirst, longLast, longMax, longMin, longSum, stringAny, stringFirst, stringFirstFold, stringLast, stringLastFold]
at [Source: (String)"[
{ "type": "count", "name": "count" },
{ "type": "longSum", "name": "sum_metric1", "fieldName": "sum_metric1" },
{ "type": "longSum", "name": "sum_metric2", "fieldName": "sum_metric2" },
{ "type": "doubleSum", "name": "sum_metric3", "fieldName": "sum_metric3" },
{ "type": "floatSum", "name": "sum_metric4", "fieldName": "sum_metric4" },
{ "type": "thetaSketch", "name": "uniq_id1", "fieldName": "uniq_id1", "isInputThetaSketch": true }
]"; line: 7, column: 13] (through reference chain: java.lang.Object[][5])
at noc.com.fasterxml.jackson.databind.exc.InvalidTypeIdException.from(InvalidTypeIdException.java:43)
at noc.com.fasterxml.jackson.databind.DeserializationContext.invalidTypeIdException(DeserializationContext.java:1761)
at noc.com.fasterxml.jackson.databind.DeserializationContext.handleUnknownTypeId(DeserializationContext.java:1268)
at noc.com.fasterxml.jackson.databind.jsontype.impl.TypeDeserializerBase._handleUnknownTypeId(TypeDeserializerBase.java:290)
at noc.com.fasterxml.jackson.databind.jsontype.impl.TypeDeserializerBase._findDeserializer(TypeDeserializerBase.java:162)
at noc.com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:113)
at noc.com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:97)
at noc.com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserializeWithType(AbstractDeserializer.java:254)
at noc.com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:197)
at noc.com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:21)
at noc.com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4218)
at noc.com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3214)
at noc.com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3197)
at org.apache.druid.spark.v2.writer.DruidDataWriterFactory$.createDataSchemaFromConfiguration(DruidDataWriterFactory.scala:99)
at org.apache.druid.spark.v2.writer.DruidDataWriterFactory.createDataWriter(DruidDataWriterFactory.scala:70)
at org.apache.spark.sql.execution.datasources.v2.DataWritingSparkTask$.run(WriteToDataSourceV2Exec.scala:113)
at org.apache.spark.sql.execution.datasources.v2.WriteToDataSourceV2Exec.$anonfun$doExecute$2(WriteToDataSourceV2Exec.scala:67)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:90)
at org.apache.spark.scheduler.Task.run(Task.scala:121)
at org.apache.spark.executor.Executor$TaskRunner.$anonfun$run$3(Executor.scala:411)
at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1360)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:414)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
`
> Hey @jihoonson, I had some unexpected and unfortunate personal/familial crises to deal with these past few months. While they're not entirely in the rear-view mirror, I should have more time again to push this to the finish line. I've opened #11823 with the next chunk of code (the reading half of the connector). Please let me know if you think the PR is still too big; I couldn't find a good place to split it that wouldn't require a reviewer to know the rest of the code anyway.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] birTiwana commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
birTiwana commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r634460646
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/clients/DruidMetadataClient.scala
##########
@@ -0,0 +1,171 @@
+/*
+ * 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.clients
+
+import com.fasterxml.jackson.core.`type`.TypeReference
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.common.base.Suppliers
+import org.apache.druid.indexer.SQLMetadataStorageUpdaterJobHandler
+import org.apache.druid.java.util.common.StringUtils
+import org.apache.druid.metadata.{MetadataStorageConnectorConfig, MetadataStorageTablesConfig,
+ PasswordProvider, SQLMetadataConnector}
+import org.apache.druid.spark.MAPPER
+import org.apache.druid.spark.configuration.{Configuration, DruidConfigurationKeys}
+import org.apache.druid.spark.mixins.Logging
+import org.apache.druid.spark.registries.SQLConnectorRegistry
+import org.apache.druid.timeline.DataSegment
+import org.skife.jdbi.v2.{DBI, Handle}
+
+import java.io.ByteArrayInputStream
+import java.util.Properties
+import scala.collection.JavaConverters.{asScalaBufferConverter, mapAsJavaMapConverter}
+
+class DruidMetadataClient(
+ metadataDbType: String,
+ host: String,
+ port: Int,
+ connectUri: String,
+ user: String,
+ passwordProviderSer: String,
+ dbcpMap: Properties,
+ base: String = "druid"
+ ) extends Logging {
+ private lazy val druidMetadataTableConfig = MetadataStorageTablesConfig.fromBase(base)
+ private lazy val dbcpProperties = new Properties()
+ dbcpProperties.putAll(dbcpMap)
Review comment:
These 2 lines can be combined into one.
`private lazy val dbcpProperties = new Properties(dbcpMap)`
Without this I am getting a build failure when trying to build this PR locally:
`[ERROR] /Users/btiwana/Downloads/druid-spark/druid/extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/utils/DruidMetadataClient.scala:52: error: ambiguous reference to overloaded definition,
[ERROR] both method putAll in class Properties of type (x$1: java.util.Map[_, _])Unit
[ERROR] and method putAll in class Hashtable of type (x$1: java.util.Map[_ <: Object, _ <: Object])Unit
[ERROR] match argument types (java.util.Properties)
[ERROR] dbcpProperties.putAll(dbcpMap)
[ERROR] ^
[ERROR] one error found
`
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] birTiwana commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
birTiwana commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r635283172
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/clients/DruidMetadataClient.scala
##########
@@ -0,0 +1,171 @@
+/*
+ * 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.clients
+
+import com.fasterxml.jackson.core.`type`.TypeReference
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.common.base.Suppliers
+import org.apache.druid.indexer.SQLMetadataStorageUpdaterJobHandler
+import org.apache.druid.java.util.common.StringUtils
+import org.apache.druid.metadata.{MetadataStorageConnectorConfig, MetadataStorageTablesConfig,
+ PasswordProvider, SQLMetadataConnector}
+import org.apache.druid.spark.MAPPER
+import org.apache.druid.spark.configuration.{Configuration, DruidConfigurationKeys}
+import org.apache.druid.spark.mixins.Logging
+import org.apache.druid.spark.registries.SQLConnectorRegistry
+import org.apache.druid.timeline.DataSegment
+import org.skife.jdbi.v2.{DBI, Handle}
+
+import java.io.ByteArrayInputStream
+import java.util.Properties
+import scala.collection.JavaConverters.{asScalaBufferConverter, mapAsJavaMapConverter}
+
+class DruidMetadataClient(
+ metadataDbType: String,
+ host: String,
+ port: Int,
+ connectUri: String,
+ user: String,
+ passwordProviderSer: String,
+ dbcpMap: Properties,
+ base: String = "druid"
+ ) extends Logging {
+ private lazy val druidMetadataTableConfig = MetadataStorageTablesConfig.fromBase(base)
+ private lazy val dbcpProperties = new Properties()
+ dbcpProperties.putAll(dbcpMap)
Review comment:
I am simply doing `mvn clean package -pl extensions-core/spark-extensions` . This actually seems like a scala version mismatch issue for me. I am using `2.13.5` but I think the expectation is to use `2.12.11` or `2.12.10` instead? Adding some stack trace here:
`[INFO] --- scala-maven-plugin:3.2.2:compile (scala-compile-first) @ druid-spark-extensions ---
[WARNING] Expected all dependencies to require Scala version: 2.12.11
[WARNING] com.fasterxml.jackson.module:jackson-module-scala_2.12:2.10.2 requires scala version: 2.12.10
[WARNING] Multiple versions of scala libraries detected!
[INFO] /Users/btiwana/Downloads/druid-spark/druid/extensions-core/spark-extensions/src/main/scala:-1: info: compiling
[INFO] Compiling 29 source files to /Users/btiwana/Downloads/druid-spark/druid/extensions-core/spark-extensions/target/classes at 1621433638727
[ERROR] /Users/btiwana/Downloads/druid-spark/druid/extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/utils/DruidMetadataClient.scala:52: error: ambiguous reference to overloaded definition,
[ERROR] both method putAll in class Properties of type (x$1: java.util.Map[_, _])Unit
[ERROR] and method putAll in class Hashtable of type (x$1: java.util.Map[_ <: Object, _ <: Object])Unit
[ERROR] match argument types (java.util.Properties)
[ERROR] dbcpProperties.putAll(dbcpMap)
[ERROR] ^
[ERROR] one error found
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 29.832 s
[INFO] Finished at: 2021-05-19T07:14:04-07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.2.2:compile (scala-compile-first) on project druid-spark-extensions: wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
`
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest edited a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest edited a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-993161134
Calling `.partitionBy` on a `DataFrameWriter` (what you get when you call `.write()` on a DataFrame`) doesn't do anything for a v2 data source that doesn't have a managed catalog, which Druid does not (see #11929 for a recent example). The [docs](https://github.com/apache/druid/blob/8392f87236d4a9795aa4e2867eea18cdf0aeb8ec/docs/operations/spark.md#writer) have a more in-depth discussion of partitioning, but the short version is that you'll either need to partition your dataframe before calling `.write()` on it or use one of the `DruidDataFrame` wrapper's convenience methods (for example,
```scala
import org.apache.druid.spark.DruidDataFrame
df.partitionAndWrite("__time", "millis", "DAY", 200000).format("druid").mode(SaveMode.Overwrite).options(map).save()
```
or in Java
```java
import org.apache.druid.spark.package$.MODULE$.DruidDataFrame
DruidDataFrame(dataset).partitionAndWrite("__time", "millis", "DAY", 200000).format("druid").mode(SaveMode.Overwrite).options(map).save();
```
)
If you don't want to use implicits/wrapper classes, you can also use the partitioner directly:
```java
SingleDimensionPartitioner partitioner = new SingleDimensionPartitioner(dataset);
Dataset<Row> partitionedDataSet = partitioner.partition("__time", "millis", "DAY", 200000, "dim1", true);
partitionedDataset.write().format("druid").mode(SaveMode.Overwrite).options(map).save();
```
Also, are you setting `writer.version` in your options map? I'm surprised to see the segments differ in version between each partition. That's what's causing the partitions to overshadow each other.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] wangxiaobaidu11 edited a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
wangxiaobaidu11 edited a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-990912600
> @wangxiaobaidu11 you don't need to make changes to the druid spark code for your use case - you can call `AggregatorFactoryRegistry.register("longUnique", new LongUniqueAggregatorFactory("", "", 0)` from within your own spark app. That's definitely still ugly since the AggregatorFactory instance is unnecessary, but as mentioned in my previous comment this won't be the case for long. If instantiating an instance is a problem, there is one other temporary work-around: because all `AggregatorFactoryRegistry` does under the hood is register subtypes, you can use the public package method `registerSubType`. In your case, you would call `org.apache.druid.spark.registerSubtype(new NamedType(classOf[LongUniqueAggregatorFactory], "longUnique"))` from your spark app. (You can statically that method if you'd like, leaving just `registerSubtype(...)`)
@JulianJaffePinterest Thanks!I will update it . I have another question.
①when i set:

②spark runtime info:
`21/12/10 16:09:45 INFO DruidDataSourceWriter: Committing the following segments: DataSegment{binaryVersion=9, id=test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.601Z, loadSpec={type=>hdfs, path=>hdfs://xxxx/xxxx/xxx/xxxxxx/segments/test_spark_druid_cube_v4/20200101T000000.000Z_20200102T000000.000Z/2021-12-10T08_09_41.601Z/3_5427a1c2-6405-4516-83b1-2dd17bfff433_index.zip}, dimensions=[dim1, dim2, id1, id2], metrics=[count, sum_metric1, sum_metric2, sum_metric3, sum_metric4, uniq_id1_unique], shardSpec=NumberedShardSpec{partitionNum=0, partitions=1}, lastCompactionState=null, size=3390}, DataSegment{binaryVersion=9, id=test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.443Z, loadSpec={type=>hdfs, path=>hdfs://xxxx/xxxx/xxx/xxxxxx/segments/test_spark_druid_cube_v4/20200101T000000.000Z_20200102T000000.000Z/2021-12-10T08_09_41.443Z/1_c5be6b7e-76a6-44dd-9c53-f189950cb54d_index.zip}, dimensions=[d
im1, dim2, id1, id2], metrics=[count, sum_metric1, sum_metric2, sum_metric3, sum_metric4, uniq_id1_unique], shardSpec=NumberedShardSpec{partitionNum=0, partitions=1}, lastCompactionState=null, size=3390}, DataSegment{binaryVersion=9, id=test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.767Z, loadSpec={type=>hdfs, path=>hdfs://xxxx/xxxx/xxx/xxxxxx/segments/test_spark_druid_cube_v4/20200101T000000.000Z_20200102T000000.000Z/2021-12-10T08_09_41.767Z/2_04fc7ed4-4131-4856-b60d-95c7b409251c_index.zip}, dimensions=[dim1, dim2, id1, id2], metrics=[count, sum_metric1, sum_metric2, sum_metric3, sum_metric4, uniq_id1_unique], shardSpec=NumberedShardSpec{partitionNum=0, partitions=1}, lastCompactionState=null, size=3390}, DataSegment{binaryVersion=9, id=test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.336Z, loadSpec={type=>hdfs, path=>hdfs://xxxx/xxxx/xxx/xxxxxx/segments/test_spark_druid_cube_v4/20200101T0
00000.000Z_20200102T000000.000Z/2021-12-10T08_09_41.336Z/0_918c926a-5738-4a19-a58b-8a3024ee01ad_index.zip}, dimensions=[dim1, dim2, id1, id2], metrics=[count, sum_metric1, sum_metric2, sum_metric3, sum_metric4, uniq_id1_unique], shardSpec=NumberedShardSpec{partitionNum=0, partitions=1}, lastCompactionState=null, size=3390}, DataSegment{binaryVersion=9, id=test_spark_druid_cube_v4_2020-01-02T00:00:00.000Z_2020-01-03T00:00:00.000Z_2021-12-10T08:09:41.299Z, loadSpec={type=>hdfs, path=>hdfs://xxxx/xxxx/xxx/xxxxxx/segments/test_spark_druid_cube_v4/20200102T000000.000Z_20200103T000000.000Z/2021-12-10T08_09_41.299Z/5_c62528cf-4377-4fa4-98da-df09dcc8e359_index.zip}, dimensions=[dim1, dim2, id1, id2], metrics=[count, sum_metric1, sum_metric2, sum_metric3, sum_metric4, uniq_id1_unique], shardSpec=NumberedShardSpec{partitionNum=0, partitions=1}, lastCompactionState=null, size=3390}, DataSegment{binaryVersion=9, id=test_spark_druid_cube_v4_2020-01-02T00:00:00.000Z_2020-01-03T00:00:00.000Z_2021-
12-10T08:09:41.835Z, loadSpec={type=>hdfs, path=>hdfs://xxxx/xxxx/xxx/xxxxxx/segments/test_spark_druid_cube_v4/20200102T000000.000Z_20200103T000000.000Z/2021-12-10T08_09_41.835Z/4_176e1242-cb5f-4745-bae3-0e9bb47b6c62_index.zip}, dimensions=[dim1, dim2, id1, id2], metrics=[count, sum_metric1, sum_metric2, sum_metric3, sum_metric4, uniq_id1_unique], shardSpec=NumberedShardSpec{partitionNum=0, partitions=1}, lastCompactionState=null, size=3466}
21/12/10 16:09:45 INFO SQLMetadataStorageUpdaterJobHandler: Published test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.601Z
21/12/10 16:09:45 INFO SQLMetadataStorageUpdaterJobHandler: Published test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.443Z
21/12/10 16:09:45 INFO SQLMetadataStorageUpdaterJobHandler: Published test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.767Z
21/12/10 16:09:45 INFO SQLMetadataStorageUpdaterJobHandler: Published test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.336Z
21/12/10 16:09:45 INFO SQLMetadataStorageUpdaterJobHandler: Published test_spark_druid_cube_v4_2020-01-02T00:00:00.000Z_2020-01-03T00:00:00.000Z_2021-12-10T08:09:41.299Z
21/12/10 16:09:45 INFO SQLMetadataStorageUpdaterJobHandler: Published test_spark_druid_cube_v4_2020-01-02T00:00:00.000Z_2020-01-03T00:00:00.000Z_2021-12-10T08:09:41.835Z
21/12/10 16:09:45 INFO WriteToDataSourceV2Exec: Data source writer org.apache.druid.spark.v2.writer.DruidDataSourceWriter@1d1c63af committed.`
③ the same date is covered,but I didn't want that to happen
`21/12/10 16:09:45 WARN SegmentRationalizer: More than one version detected for interval 2020-01-01T00:00:00.000Z/2020-01-02T00:00:00.000Z on dataSource test_spark_druid_cube_v4! Some segments will be overshadowed!
21/12/10 16:09:45 WARN SegmentRationalizer: More than one version detected for interval 2020-01-02T00:00:00.000Z/2020-01-03T00:00:00.000Z on dataSource test_spark_druid_cube_v4! Some segments will be overshadowed!`

④ I expect result which is combined segments,How do I set partition
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] wangxiaobaidu11 edited a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
wangxiaobaidu11 edited a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-990912600
> @wangxiaobaidu11 you don't need to make changes to the druid spark code for your use case - you can call `AggregatorFactoryRegistry.register("longUnique", new LongUniqueAggregatorFactory("", "", 0)` from within your own spark app. That's definitely still ugly since the AggregatorFactory instance is unnecessary, but as mentioned in my previous comment this won't be the case for long. If instantiating an instance is a problem, there is one other temporary work-around: because all `AggregatorFactoryRegistry` does under the hood is register subtypes, you can use the public package method `registerSubType`. In your case, you would call `org.apache.druid.spark.registerSubtype(new NamedType(classOf[LongUniqueAggregatorFactory], "longUnique"))` from your spark app. (You can statically that method if you'd like, leaving just `registerSubtype(...)`)
Thanks!I will update it . I have another question.
①when i set:

②spark runtime info:
`21/12/10 16:09:45 INFO DruidDataSourceWriter: Committing the following segments: DataSegment{binaryVersion=9, id=test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.601Z, loadSpec={type=>hdfs, path=>hdfs://ns-fed/user/olap/druid-index-test-02/segments/test_spark_druid_cube_v4/20200101T000000.000Z_20200102T000000.000Z/2021-12-10T08_09_41.601Z/3_5427a1c2-6405-4516-83b1-2dd17bfff433_index.zip}, dimensions=[dim1, dim2, id1, id2], metrics=[count, sum_metric1, sum_metric2, sum_metric3, sum_metric4, uniq_id1_unique], shardSpec=NumberedShardSpec{partitionNum=0, partitions=1}, lastCompactionState=null, size=3390}, DataSegment{binaryVersion=9, id=test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.443Z, loadSpec={type=>hdfs, path=>hdfs://ns-fed/user/olap/druid-index-test-02/segments/test_spark_druid_cube_v4/20200101T000000.000Z_20200102T000000.000Z/2021-12-10T08_09_41.443Z/1_c5be6b7e-76a6-44dd-9c53-f18995
0cb54d_index.zip}, dimensions=[dim1, dim2, id1, id2], metrics=[count, sum_metric1, sum_metric2, sum_metric3, sum_metric4, uniq_id1_unique], shardSpec=NumberedShardSpec{partitionNum=0, partitions=1}, lastCompactionState=null, size=3390}, DataSegment{binaryVersion=9, id=test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.767Z, loadSpec={type=>hdfs, path=>hdfs://ns-fed/user/olap/druid-index-test-02/segments/test_spark_druid_cube_v4/20200101T000000.000Z_20200102T000000.000Z/2021-12-10T08_09_41.767Z/2_04fc7ed4-4131-4856-b60d-95c7b409251c_index.zip}, dimensions=[dim1, dim2, id1, id2], metrics=[count, sum_metric1, sum_metric2, sum_metric3, sum_metric4, uniq_id1_unique], shardSpec=NumberedShardSpec{partitionNum=0, partitions=1}, lastCompactionState=null, size=3390}, DataSegment{binaryVersion=9, id=test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.336Z, loadSpec={type=>hdfs, path=>hdfs://ns-fed/user/olap/
druid-index-test-02/segments/test_spark_druid_cube_v4/20200101T000000.000Z_20200102T000000.000Z/2021-12-10T08_09_41.336Z/0_918c926a-5738-4a19-a58b-8a3024ee01ad_index.zip}, dimensions=[dim1, dim2, id1, id2], metrics=[count, sum_metric1, sum_metric2, sum_metric3, sum_metric4, uniq_id1_unique], shardSpec=NumberedShardSpec{partitionNum=0, partitions=1}, lastCompactionState=null, size=3390}, DataSegment{binaryVersion=9, id=test_spark_druid_cube_v4_2020-01-02T00:00:00.000Z_2020-01-03T00:00:00.000Z_2021-12-10T08:09:41.299Z, loadSpec={type=>hdfs, path=>hdfs://ns-fed/user/olap/druid-index-test-02/segments/test_spark_druid_cube_v4/20200102T000000.000Z_20200103T000000.000Z/2021-12-10T08_09_41.299Z/5_c62528cf-4377-4fa4-98da-df09dcc8e359_index.zip}, dimensions=[dim1, dim2, id1, id2], metrics=[count, sum_metric1, sum_metric2, sum_metric3, sum_metric4, uniq_id1_unique], shardSpec=NumberedShardSpec{partitionNum=0, partitions=1}, lastCompactionState=null, size=3390}, DataSegment{binaryVersion=9, id=
test_spark_druid_cube_v4_2020-01-02T00:00:00.000Z_2020-01-03T00:00:00.000Z_2021-12-10T08:09:41.835Z, loadSpec={type=>hdfs, path=>hdfs://ns-fed/user/olap/druid-index-test-02/segments/test_spark_druid_cube_v4/20200102T000000.000Z_20200103T000000.000Z/2021-12-10T08_09_41.835Z/4_176e1242-cb5f-4745-bae3-0e9bb47b6c62_index.zip}, dimensions=[dim1, dim2, id1, id2], metrics=[count, sum_metric1, sum_metric2, sum_metric3, sum_metric4, uniq_id1_unique], shardSpec=NumberedShardSpec{partitionNum=0, partitions=1}, lastCompactionState=null, size=3466}
21/12/10 16:09:45 INFO SQLMetadataStorageUpdaterJobHandler: Published test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.601Z
21/12/10 16:09:45 INFO SQLMetadataStorageUpdaterJobHandler: Published test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.443Z
21/12/10 16:09:45 INFO SQLMetadataStorageUpdaterJobHandler: Published test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.767Z
21/12/10 16:09:45 INFO SQLMetadataStorageUpdaterJobHandler: Published test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.336Z
21/12/10 16:09:45 INFO SQLMetadataStorageUpdaterJobHandler: Published test_spark_druid_cube_v4_2020-01-02T00:00:00.000Z_2020-01-03T00:00:00.000Z_2021-12-10T08:09:41.299Z
21/12/10 16:09:45 INFO SQLMetadataStorageUpdaterJobHandler: Published test_spark_druid_cube_v4_2020-01-02T00:00:00.000Z_2020-01-03T00:00:00.000Z_2021-12-10T08:09:41.835Z
21/12/10 16:09:45 INFO WriteToDataSourceV2Exec: Data source writer org.apache.druid.spark.v2.writer.DruidDataSourceWriter@1d1c63af committed.`
③ the same date is covered,but I didn't want that to happen
`21/12/10 16:09:45 WARN SegmentRationalizer: More than one version detected for interval 2020-01-01T00:00:00.000Z/2020-01-02T00:00:00.000Z on dataSource test_spark_druid_cube_v4! Some segments will be overshadowed!
21/12/10 16:09:45 WARN SegmentRationalizer: More than one version detected for interval 2020-01-02T00:00:00.000Z/2020-01-03T00:00:00.000Z on dataSource test_spark_druid_cube_v4! Some segments will be overshadowed!`

④ I expect result which is combined segments,How do I set partition
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] wangxiaobaidu11 edited a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
wangxiaobaidu11 edited a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-990912600
> @wangxiaobaidu11 you don't need to make changes to the druid spark code for your use case - you can call `AggregatorFactoryRegistry.register("longUnique", new LongUniqueAggregatorFactory("", "", 0)` from within your own spark app. That's definitely still ugly since the AggregatorFactory instance is unnecessary, but as mentioned in my previous comment this won't be the case for long. If instantiating an instance is a problem, there is one other temporary work-around: because all `AggregatorFactoryRegistry` does under the hood is register subtypes, you can use the public package method `registerSubType`. In your case, you would call `org.apache.druid.spark.registerSubtype(new NamedType(classOf[LongUniqueAggregatorFactory], "longUnique"))` from your spark app. (You can statically that method if you'd like, leaving just `registerSubtype(...)`)
Thanks!I will update it . I have another question.
①when i set:

②spark runtime info:
`21/12/10 16:09:45 INFO DruidDataSourceWriter: Committing the following segments: DataSegment{binaryVersion=9, id=test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.601Z, loadSpec={type=>hdfs, path=>hdfs://xxxx/xxxx/xxx/xxxxxx/segments/test_spark_druid_cube_v4/20200101T000000.000Z_20200102T000000.000Z/2021-12-10T08_09_41.601Z/3_5427a1c2-6405-4516-83b1-2dd17bfff433_index.zip}, dimensions=[dim1, dim2, id1, id2], metrics=[count, sum_metric1, sum_metric2, sum_metric3, sum_metric4, uniq_id1_unique], shardSpec=NumberedShardSpec{partitionNum=0, partitions=1}, lastCompactionState=null, size=3390}, DataSegment{binaryVersion=9, id=test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.443Z, loadSpec={type=>hdfs, path=>hdfs://xxxx/xxxx/xxx/xxxxxx/segments/test_spark_druid_cube_v4/20200101T000000.000Z_20200102T000000.000Z/2021-12-10T08_09_41.443Z/1_c5be6b7e-76a6-44dd-9c53-f189950cb54d_index.zip}, dimensions=[d
im1, dim2, id1, id2], metrics=[count, sum_metric1, sum_metric2, sum_metric3, sum_metric4, uniq_id1_unique], shardSpec=NumberedShardSpec{partitionNum=0, partitions=1}, lastCompactionState=null, size=3390}, DataSegment{binaryVersion=9, id=test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.767Z, loadSpec={type=>hdfs, path=>hdfs://xxxx/xxxx/xxx/xxxxxx/segments/test_spark_druid_cube_v4/20200101T000000.000Z_20200102T000000.000Z/2021-12-10T08_09_41.767Z/2_04fc7ed4-4131-4856-b60d-95c7b409251c_index.zip}, dimensions=[dim1, dim2, id1, id2], metrics=[count, sum_metric1, sum_metric2, sum_metric3, sum_metric4, uniq_id1_unique], shardSpec=NumberedShardSpec{partitionNum=0, partitions=1}, lastCompactionState=null, size=3390}, DataSegment{binaryVersion=9, id=test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.336Z, loadSpec={type=>hdfs, path=>hdfs://xxxx/xxxx/xxx/xxxxxx/segments/test_spark_druid_cube_v4/20200101T0
00000.000Z_20200102T000000.000Z/2021-12-10T08_09_41.336Z/0_918c926a-5738-4a19-a58b-8a3024ee01ad_index.zip}, dimensions=[dim1, dim2, id1, id2], metrics=[count, sum_metric1, sum_metric2, sum_metric3, sum_metric4, uniq_id1_unique], shardSpec=NumberedShardSpec{partitionNum=0, partitions=1}, lastCompactionState=null, size=3390}, DataSegment{binaryVersion=9, id=test_spark_druid_cube_v4_2020-01-02T00:00:00.000Z_2020-01-03T00:00:00.000Z_2021-12-10T08:09:41.299Z, loadSpec={type=>hdfs, path=>hdfs://xxxx/xxxx/xxx/xxxxxx/segments/test_spark_druid_cube_v4/20200102T000000.000Z_20200103T000000.000Z/2021-12-10T08_09_41.299Z/5_c62528cf-4377-4fa4-98da-df09dcc8e359_index.zip}, dimensions=[dim1, dim2, id1, id2], metrics=[count, sum_metric1, sum_metric2, sum_metric3, sum_metric4, uniq_id1_unique], shardSpec=NumberedShardSpec{partitionNum=0, partitions=1}, lastCompactionState=null, size=3390}, DataSegment{binaryVersion=9, id=test_spark_druid_cube_v4_2020-01-02T00:00:00.000Z_2020-01-03T00:00:00.000Z_2021-
12-10T08:09:41.835Z, loadSpec={type=>hdfs, path=>hdfs://xxxx/xxxx/xxx/xxxxxx/segments/test_spark_druid_cube_v4/20200102T000000.000Z_20200103T000000.000Z/2021-12-10T08_09_41.835Z/4_176e1242-cb5f-4745-bae3-0e9bb47b6c62_index.zip}, dimensions=[dim1, dim2, id1, id2], metrics=[count, sum_metric1, sum_metric2, sum_metric3, sum_metric4, uniq_id1_unique], shardSpec=NumberedShardSpec{partitionNum=0, partitions=1}, lastCompactionState=null, size=3466}
21/12/10 16:09:45 INFO SQLMetadataStorageUpdaterJobHandler: Published test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.601Z
21/12/10 16:09:45 INFO SQLMetadataStorageUpdaterJobHandler: Published test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.443Z
21/12/10 16:09:45 INFO SQLMetadataStorageUpdaterJobHandler: Published test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.767Z
21/12/10 16:09:45 INFO SQLMetadataStorageUpdaterJobHandler: Published test_spark_druid_cube_v4_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2021-12-10T08:09:41.336Z
21/12/10 16:09:45 INFO SQLMetadataStorageUpdaterJobHandler: Published test_spark_druid_cube_v4_2020-01-02T00:00:00.000Z_2020-01-03T00:00:00.000Z_2021-12-10T08:09:41.299Z
21/12/10 16:09:45 INFO SQLMetadataStorageUpdaterJobHandler: Published test_spark_druid_cube_v4_2020-01-02T00:00:00.000Z_2020-01-03T00:00:00.000Z_2021-12-10T08:09:41.835Z
21/12/10 16:09:45 INFO WriteToDataSourceV2Exec: Data source writer org.apache.druid.spark.v2.writer.DruidDataSourceWriter@1d1c63af committed.`
③ the same date is covered,but I didn't want that to happen
`21/12/10 16:09:45 WARN SegmentRationalizer: More than one version detected for interval 2020-01-01T00:00:00.000Z/2020-01-02T00:00:00.000Z on dataSource test_spark_druid_cube_v4! Some segments will be overshadowed!
21/12/10 16:09:45 WARN SegmentRationalizer: More than one version detected for interval 2020-01-02T00:00:00.000Z/2020-01-03T00:00:00.000Z on dataSource test_spark_druid_cube_v4! Some segments will be overshadowed!`

④ I expect result which is combined segments,How do I set partition
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r614555850
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/clients/DruidClient.scala
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.clients
+
+import com.fasterxml.jackson.core.`type`.TypeReference
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.common.net.HostAndPort
+import org.apache.druid.java.util.common.{ISE, StringUtils}
+import org.apache.druid.java.util.http.client.response.{StringFullResponseHandler,
+ StringFullResponseHolder}
+import org.apache.druid.java.util.http.client.{HttpClient, Request}
+import org.apache.druid.query.Druids
+import org.apache.druid.query.metadata.metadata.{ColumnAnalysis, SegmentAnalysis,
+ SegmentMetadataQuery}
+import org.apache.druid.spark.MAPPER
+import org.apache.druid.spark.configuration.{Configuration, DruidConfigurationKeys}
+import org.apache.druid.spark.mixins.Logging
+import org.jboss.netty.handler.codec.http.{HttpMethod, HttpResponseStatus}
+import org.joda.time.{Duration, Interval}
+
+import java.net.URL
+import java.util.{List => JList}
+import javax.ws.rs.core.MediaType
+import scala.collection.JavaConverters.{asScalaBufferConverter, mapAsJavaMapConverter,
+ mapAsScalaMapConverter, seqAsJavaListConverter}
+
+/**
+ * Going with SegmentMetadataQueries despite the significant overhead because there's no other way
+ * to get accurate information about Druid columns.
+ *
+ * This is pulled pretty directly from the druid-hadoop-input-format project on GitHub. There is
+ * likely substantial room for improvement.
+ *
+ * @param httpClient
+ * @param objectMapper
+ * @param hostAndPort
+ */
+class DruidClient(
+ val httpClient: HttpClient,
+ val objectMapper: ObjectMapper,
+ val hostAndPort: HostAndPort
+ ) extends Logging {
+ private val RETRY_COUNT = 5
+ private val RETRY_WAIT_SECONDS = 5
+ private val TIMEOUT_MILLISECONDS = 300000
+ private val druidBaseQueryURL: HostAndPort => String =
+ (hostAndPort: HostAndPort) => s"http://$hostAndPort/druid/v2/"
+
+ /**
+ * The SQL system catalog tables are incorrect for multivalue columns and don't have accurate
+ * type info, so we need to fall back to segmentMetadataQueries. Given a DATASOURCE and a range
+ * of INTERVALS to query over, return a map from column name to a tuple of
+ * (columnType, hasMultipleValues). Note that this is a very expensive operation over large
+ * numbers of segments. If possible, this method should only be called with the most granular
+ * starting and ending intervals instead of over a larger interval.
+ *
+ * @param dataSource The Druid dataSource to fetch the schema for.
+ * @param intervals The intervals to return the schema for.
+ * @return A map from column name to data type and whether or not the column is multi-value
+ * for the schema of DATASOURCE.
+ */
+ def getSchema(dataSource: String, intervals: List[Interval]): Map[String, (String, Boolean)] = {
+ val body = Druids.newSegmentMetadataQueryBuilder()
+ .dataSource(dataSource)
+ .intervals(intervals.asJava)
+ .analysisTypes(SegmentMetadataQuery.AnalysisType.SIZE)
+ .merge(true)
+ .context(Map[String, AnyRef](
+ "timeout" -> Int.box(TIMEOUT_MILLISECONDS)
+ ).asJava)
+ .build()
+ val response = sendRequestWithRetry(
+ druidBaseQueryURL(hostAndPort), RETRY_COUNT, Option(objectMapper.writeValueAsBytes(body))
+ )
+ val segments =
+ objectMapper.readValue[JList[SegmentAnalysis]](
+ response.getContent, new TypeReference[JList[SegmentAnalysis]]() {})
+ if (segments.size() == 0) {
+ throw new ISE(
+ s"No segments found for intervals [${intervals.mkString(",")}] on $dataSource"
+ )
+ }
+ // Since we're setting merge to true, there should only be one item in the list
+ if (segments.size() > 1) {
+ logWarn("Segment metadata response had more than one row, problem?")
+ }
+ segments.asScala.head.getColumns.asScala.map{ case (name: String, col: ColumnAnalysis) =>
Review comment:
To the second part of your question, the reason we don't just take the last segment in an interval and use its schema is because the latest segment may happen to not have multiple values for a particular column where other segments do, or a column may be all null for the latest segment and so not show up in the Segment Metadata. We query the full range of the requested interval and then merge to handle these cases, which does open up the merging problem if types change. At least in my Druid experience, the first two cases are much more frequent than the third case.
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] birTiwana commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
birTiwana commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-843217694
@JulianJaffePinterest I have tried to create a jar file from your PR branch and copied it to my spark code. I am using it to read a druid data source using the following code (I have retrieved the segments directly via the DruidMetaClient ):
`val readDf = sparkSession
.read
.format("druid")
.options(Map("segments" -> segmentsString))
.load()`
but I keep on hitting the error:
`icationMaster.runDriver(ApplicationMaster.scala:472)
at org.apache.spark.deploy.yarn.ApplicationMaster.org$apache$spark$deploy$yarn$ApplicationMaster$$runImpl(ApplicationMaster.scala:308)
at org.apache.spark.deploy.yarn.ApplicationMaster$$anonfun$run$1.apply$mcV$sp(ApplicationMaster.scala:248)
at org.apache.spark.deploy.yarn.ApplicationMaster$$anonfun$run$1.apply(ApplicationMaster.scala:248)
at org.apache.spark.deploy.yarn.ApplicationMaster$$anonfun$run$1.apply(ApplicationMaster.scala:248)
at org.apache.spark.deploy.yarn.ApplicationMaster$$anon$3.run(ApplicationMaster.scala:783)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1926)
at org.apache.spark.deploy.yarn.ApplicationMaster.doAsUser(ApplicationMaster.scala:782)
at org.apache.spark.deploy.yarn.ApplicationMaster.run(ApplicationMaster.scala:247)
at org.apache.spark.deploy.yarn.ApplicationMaster$.main(ApplicationMaster.scala:807)
at org.apache.spark.deploy.yarn.ApplicationMaster.main(ApplicationMaster.scala)
Caused by: 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:675)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:213)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:186)
at LoadData$.main(LoadData.scala:80)
at LoadData.main(LoadData.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.spark.deploy.yarn.ApplicationMaster$$anon$2.run(ApplicationMaster.scala:688)
Caused by: java.lang.ClassNotFoundException: druid.DefaultSource
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$20$$anonfun$apply$12.apply(DataSource.scala:652)
at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$20$$anonfun$apply$12.apply(DataSource.scala:652)
at scala.util.Try$.apply(Try.scala:192)
at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$20.apply(DataSource.scala:652)
at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$20.apply(DataSource.scala:652)
at scala.util.Try.orElse(Try.scala:84)
at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:652)
... 9 more`
Not sure what I am missing here exactly but I did not see a test case for this in your PR as well.
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-988646390
@wangxiaobaidu11 thank you for your kind wishes. The issue you've encountered is an artifact of pulling out some custom code and updating logic to match mainline Druid changes from newer versions. In your case, you can call `AggregatorFactoryRegistry.register("thetaSketch", new SketchAggregatorFactory("", "", 2, 0))` on the driver before writing (note that for historical reasons you need to pass an AggregatorFactory instance and not just the class). In the piecemeal writer code for review that is waiting on #11823, this is done automatically for you. #11823 has been approved pending a broken test in the unrelated code I'm running down, so I hope to have the writer code up soon. If I can find a few minutes I'll put up a repo with the up-to-date connector code and compatibility with older Druid versions as well.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] wangxiaobaidu11 commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
wangxiaobaidu11 commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-992404912
> @wangxiaobaidu11 you can control the number of partitions by partitioning your dataframe prior to calling `.write()` on the dataframe. There's a brief discussion in the [docs](https://github.com/apache/druid/blob/8392f87236d4a9795aa4e2867eea18cdf0aeb8ec/docs/operations/spark.md) about partitioning; I'm happy to add more/clarify/etc. as needed. Can you share more details about how you're configuring and calling the writer?
` Dataset<Row> dataset = sparkSession.createDataFrame(list, schema);
dataset.write().partitionBy("__time").format("druid").mode(SaveMode.Overwrite).options(map).save();`
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-876321790
@juhoautio-rovio thanks for beta-testing the documentation 😉! If the implicit wrappers were to be added to the documentation, where you hope to find them? (They are actually mentioned in the extension docs, but obviously not clearly enough given that you couldn't find them. I'd love any suggestions you might have on improving 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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] jihoonson commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
jihoonson commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-951574636
@JulianJaffePinterest sorry to hear that. I hope things have gotten better. Also, thank you for making #11823. I will take a look.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] samarthjain commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
samarthjain commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-883602572
FWIW, this looks good to me now, @JulianJaffePinterest . But as @jihoonson suggested, in the interest of getting more reviews, let's work on getting smaller pieces reviewed using PRs against your branch.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-870340789
@samarthjain Done! I also updated LICENSE and NOTICE for the new dependencies
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] wangxiaobaidu11 edited a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
wangxiaobaidu11 edited a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-984461681
hi @JulianJaffePinterest, I hope you can get out of your sad mood soon and take good care of yourself! Last month I tested your code. I met a problem described below:
when run “dataset.write().format("druid").mode(SaveMode.Overwrite).options(map).save();“
`21/12/02 15:19:40 ERROR Executor: Exception in task 0.0 in stage 0.0 (TID 0)
noc.com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve type id 'thetaSketch' as a subtype of `org.apache.druid.query.aggregation.AggregatorFactory`: known type ids = [cardinality, count, doubleAny, doubleFirst, doubleLast, doubleMax, doubleMean, doubleMin, doubleSum, filtered, floatAny, floatFirst, floatLast, floatMax, floatMin, floatSum, grouping, histogram, hyperUnique, javascript, longAny, longFirst, longLast, longMax, longMin, longSum, stringAny, stringFirst, stringFirstFold, stringLast, stringLastFold]
at [Source: (String)"[
{ "type": "count", "name": "count" },
{ "type": "longSum", "name": "sum_metric1", "fieldName": "sum_metric1" },
{ "type": "longSum", "name": "sum_metric2", "fieldName": "sum_metric2" },
{ "type": "doubleSum", "name": "sum_metric3", "fieldName": "sum_metric3" },
{ "type": "floatSum", "name": "sum_metric4", "fieldName": "sum_metric4" },
{ "type": "thetaSketch", "name": "uniq_id1", "fieldName": "uniq_id1", "isInputThetaSketch": true }
]"; line: 7, column: 13] (through reference chain: java.lang.Object[][5])
at noc.com.fasterxml.jackson.databind.exc.InvalidTypeIdException.from(InvalidTypeIdException.java:43)
at noc.com.fasterxml.jackson.databind.DeserializationContext.invalidTypeIdException(DeserializationContext.java:1761)
at noc.com.fasterxml.jackson.databind.DeserializationContext.handleUnknownTypeId(DeserializationContext.java:1268)
at noc.com.fasterxml.jackson.databind.jsontype.impl.TypeDeserializerBase._handleUnknownTypeId(TypeDeserializerBase.java:290)
at noc.com.fasterxml.jackson.databind.jsontype.impl.TypeDeserializerBase._findDeserializer(TypeDeserializerBase.java:162)
at noc.com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:113)
at noc.com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:97)
at noc.com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserializeWithType(AbstractDeserializer.java:254)
at noc.com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:197)
at noc.com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:21)
at noc.com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4218)
at noc.com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3214)
at noc.com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3197)
at org.apache.druid.spark.v2.writer.DruidDataWriterFactory$.createDataSchemaFromConfiguration(DruidDataWriterFactory.scala:99)
at org.apache.druid.spark.v2.writer.DruidDataWriterFactory.createDataWriter(DruidDataWriterFactory.scala:70)
at org.apache.spark.sql.execution.datasources.v2.DataWritingSparkTask$.run(WriteToDataSourceV2Exec.scala:113)
at org.apache.spark.sql.execution.datasources.v2.WriteToDataSourceV2Exec.$anonfun$doExecute$2(WriteToDataSourceV2Exec.scala:67)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:90)
at org.apache.spark.scheduler.Task.run(Task.scala:121)
at org.apache.spark.executor.Executor$TaskRunner.$anonfun$run$3(Executor.scala:411)
at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1360)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:414)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
21/12/02 15:19:40 WARN TaskSetManager: Lost task 0.0 in stage 0.0 (TID 0, localhost, executor driver): noc.com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve type id 'thetaSketch' as a subtype of `org.apache.druid.query.aggregation.AggregatorFactory`: known type ids = [cardinality, count, doubleAny, doubleFirst, doubleLast, doubleMax, doubleMean, doubleMin, doubleSum, filtered, floatAny, floatFirst, floatLast, floatMax, floatMin, floatSum, grouping, histogram, hyperUnique, javascript, longAny, longFirst, longLast, longMax, longMin, longSum, stringAny, stringFirst, stringFirstFold, stringLast, stringLastFold]
at [Source: (String)"[
{ "type": "count", "name": "count" },
{ "type": "longSum", "name": "sum_metric1", "fieldName": "sum_metric1" },
{ "type": "longSum", "name": "sum_metric2", "fieldName": "sum_metric2" },
{ "type": "doubleSum", "name": "sum_metric3", "fieldName": "sum_metric3" },
{ "type": "floatSum", "name": "sum_metric4", "fieldName": "sum_metric4" },
{ "type": "thetaSketch", "name": "uniq_id1", "fieldName": "uniq_id1", "isInputThetaSketch": true }
]"; line: 7, column: 13] (through reference chain: java.lang.Object[][5])
at noc.com.fasterxml.jackson.databind.exc.InvalidTypeIdException.from(InvalidTypeIdException.java:43)
at noc.com.fasterxml.jackson.databind.DeserializationContext.invalidTypeIdException(DeserializationContext.java:1761)
at noc.com.fasterxml.jackson.databind.DeserializationContext.handleUnknownTypeId(DeserializationContext.java:1268)
at noc.com.fasterxml.jackson.databind.jsontype.impl.TypeDeserializerBase._handleUnknownTypeId(TypeDeserializerBase.java:290)
at noc.com.fasterxml.jackson.databind.jsontype.impl.TypeDeserializerBase._findDeserializer(TypeDeserializerBase.java:162)
at noc.com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:113)
at noc.com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:97)
at noc.com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserializeWithType(AbstractDeserializer.java:254)
at noc.com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:197)
at noc.com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:21)
at noc.com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4218)
at noc.com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3214)
at noc.com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3197)
at org.apache.druid.spark.v2.writer.DruidDataWriterFactory$.createDataSchemaFromConfiguration(DruidDataWriterFactory.scala:99)
at org.apache.druid.spark.v2.writer.DruidDataWriterFactory.createDataWriter(DruidDataWriterFactory.scala:70)
at org.apache.spark.sql.execution.datasources.v2.DataWritingSparkTask$.run(WriteToDataSourceV2Exec.scala:113)
at org.apache.spark.sql.execution.datasources.v2.WriteToDataSourceV2Exec.$anonfun$doExecute$2(WriteToDataSourceV2Exec.scala:67)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:90)
at org.apache.spark.scheduler.Task.run(Task.scala:121)
at org.apache.spark.executor.Executor$TaskRunner.$anonfun$run$3(Executor.scala:411)
at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1360)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:414)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
`
> Hey @jihoonson, I had some unexpected and unfortunate personal/familial crises to deal with these past few months. While they're not entirely in the rear-view mirror, I should have more time again to push this to the finish line. I've opened #11823 with the next chunk of code (the reading half of the connector). Please let me know if you think the PR is still too big; I couldn't find a good place to split it that wouldn't require a reviewer to know the rest of the code anyway.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r614550669
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/clients/DruidClient.scala
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.clients
+
+import com.fasterxml.jackson.core.`type`.TypeReference
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.common.net.HostAndPort
+import org.apache.druid.java.util.common.{ISE, StringUtils}
+import org.apache.druid.java.util.http.client.response.{StringFullResponseHandler,
+ StringFullResponseHolder}
+import org.apache.druid.java.util.http.client.{HttpClient, Request}
+import org.apache.druid.query.Druids
+import org.apache.druid.query.metadata.metadata.{ColumnAnalysis, SegmentAnalysis,
+ SegmentMetadataQuery}
+import org.apache.druid.spark.MAPPER
+import org.apache.druid.spark.configuration.{Configuration, DruidConfigurationKeys}
+import org.apache.druid.spark.mixins.Logging
+import org.jboss.netty.handler.codec.http.{HttpMethod, HttpResponseStatus}
+import org.joda.time.{Duration, Interval}
+
+import java.net.URL
+import java.util.{List => JList}
+import javax.ws.rs.core.MediaType
+import scala.collection.JavaConverters.{asScalaBufferConverter, mapAsJavaMapConverter,
+ mapAsScalaMapConverter, seqAsJavaListConverter}
+
+/**
+ * Going with SegmentMetadataQueries despite the significant overhead because there's no other way
+ * to get accurate information about Druid columns.
+ *
+ * This is pulled pretty directly from the druid-hadoop-input-format project on GitHub. There is
+ * likely substantial room for improvement.
+ *
+ * @param httpClient
+ * @param objectMapper
+ * @param hostAndPort
+ */
+class DruidClient(
+ val httpClient: HttpClient,
+ val objectMapper: ObjectMapper,
+ val hostAndPort: HostAndPort
+ ) extends Logging {
+ private val RETRY_COUNT = 5
+ private val RETRY_WAIT_SECONDS = 5
+ private val TIMEOUT_MILLISECONDS = 300000
+ private val druidBaseQueryURL: HostAndPort => String =
+ (hostAndPort: HostAndPort) => s"http://$hostAndPort/druid/v2/"
+
+ /**
+ * The SQL system catalog tables are incorrect for multivalue columns and don't have accurate
+ * type info, so we need to fall back to segmentMetadataQueries. Given a DATASOURCE and a range
+ * of INTERVALS to query over, return a map from column name to a tuple of
+ * (columnType, hasMultipleValues). Note that this is a very expensive operation over large
+ * numbers of segments. If possible, this method should only be called with the most granular
+ * starting and ending intervals instead of over a larger interval.
+ *
+ * @param dataSource The Druid dataSource to fetch the schema for.
+ * @param intervals The intervals to return the schema for.
+ * @return A map from column name to data type and whether or not the column is multi-value
+ * for the schema of DATASOURCE.
+ */
+ def getSchema(dataSource: String, intervals: List[Interval]): Map[String, (String, Boolean)] = {
+ val body = Druids.newSegmentMetadataQueryBuilder()
+ .dataSource(dataSource)
+ .intervals(intervals.asJava)
+ .analysisTypes(SegmentMetadataQuery.AnalysisType.SIZE)
+ .merge(true)
+ .context(Map[String, AnyRef](
+ "timeout" -> Int.box(TIMEOUT_MILLISECONDS)
+ ).asJava)
+ .build()
+ val response = sendRequestWithRetry(
+ druidBaseQueryURL(hostAndPort), RETRY_COUNT, Option(objectMapper.writeValueAsBytes(body))
+ )
+ val segments =
+ objectMapper.readValue[JList[SegmentAnalysis]](
+ response.getContent, new TypeReference[JList[SegmentAnalysis]]() {})
+ if (segments.size() == 0) {
+ throw new ISE(
+ s"No segments found for intervals [${intervals.mkString(",")}] on $dataSource"
+ )
+ }
+ // Since we're setting merge to true, there should only be one item in the list
+ if (segments.size() > 1) {
+ logWarn("Segment metadata response had more than one row, problem?")
Review comment:
Yeah, this should error. Good catch.
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] jihoonson commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
jihoonson commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-881756176
> @jihoonson @samarthjain has been reviewing the pr but yes I agree it's too large to effectively review. I'm not sure how to reduce it to pieces though - splitting it into just readers or just writers still means that the first pr is very large (since it would still need all the shared code). Do you have any suggestions there?
@JulianJaffePinterest I don't fully understand how this change is structured as I'm unfamiliar with scala, so it is hard for me to suggest something good based on code structure. An idea is creating a branch for this project and committing changes to there until most of changes are committed. Since you are going to create a PR against a branch, the PR doesn't have to be atomic, but can have incomplete changes or features. This can make each PR smaller. When the branch is ready, you can make another PR to merge the branch into master. This PR can be giant but should be OK because all changes in the branch is already reviewed. This could be an option if you think it will help with review. Note that I tagged "Design Review" for this PR which means this PR requires 3 approvals from committers for its design (user APIs, important interfaces, etc) and 1 approval for code changes. The same committers can review both design and code changes.
> * These APIs are production ready (and are in fact being used in production at multiple organizations). Some of the cross-matrix options (deep storage types, sql metadata types) are more experimental (e.g. I'm unaware of any production users writing to Azure deep storage).
Thanks for the answer. What is most important is not giving a wrong idea to users. Can you please document what matrix options are well tested, so that readers can get some idea about it? BTW, I don't see any new tests in .travis.yml. Unless they are running somewhere else, we should add some.
> @jihoonson IMHO, for a completely new big feature like this, isn't it better to be submitted as 1 PR? If there is something wrong in the future, the git forensic would be much easier.
Every PR is squashed when it is merged into master, so there is only one commit per PR in the master branch. Making some change atomic (that means, one feature is added in one PR instead of being spread across multiple PRs) can help with release, but I'm not sure how else huge PRs can make something easier..
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r640372531
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/clients/DruidClient.scala
##########
@@ -0,0 +1,188 @@
+/*
+ * 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.clients
+
+import com.fasterxml.jackson.core.`type`.TypeReference
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.common.net.HostAndPort
+import org.apache.druid.java.util.common.{ISE, Intervals, JodaUtils, StringUtils}
+import org.apache.druid.java.util.http.client.response.{StringFullResponseHandler,
+ StringFullResponseHolder}
+import org.apache.druid.java.util.http.client.{HttpClient, Request}
+import org.apache.druid.query.Druids
+import org.apache.druid.query.metadata.metadata.{ColumnAnalysis, SegmentAnalysis,
+ SegmentMetadataQuery}
+import org.apache.druid.spark.MAPPER
+import org.apache.druid.spark.configuration.{Configuration, DruidConfigurationKeys}
+import org.apache.druid.spark.mixins.Logging
+import org.jboss.netty.handler.codec.http.{HttpMethod, HttpResponseStatus}
+import org.joda.time.{Duration, Interval}
+
+import java.net.URL
+import java.util.{List => JList}
+import javax.ws.rs.core.MediaType
+import scala.collection.JavaConverters.{asScalaBufferConverter, mapAsJavaMapConverter,
+ mapAsScalaMapConverter, seqAsJavaListConverter}
+
+/**
+ * Going with SegmentMetadataQueries despite the significant overhead because there's no other way
+ * to get accurate information about Druid columns.
+ *
+ * This is pulled pretty directly from the druid-hadoop-input-format project on GitHub. There is
+ * likely substantial room for improvement.
+ *
+ * @param httpClient
+ * @param hostAndPort
+ */
+class DruidClient(
+ val httpClient: HttpClient,
+ val hostAndPort: HostAndPort
+ ) extends Logging {
+ private val RetryCount = 5
Review comment:
Done
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] bcmcmill commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
bcmcmill commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-819220362
Awesome, I have had to resort adding a InitializeForTesting call from the NullHandliing module to the writer class, to ensure that NullHandling was initialized on the executors or else exceptions were thrown. Glad that is properly fixed up now.
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r614545490
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/clients/DruidClient.scala
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.clients
+
+import com.fasterxml.jackson.core.`type`.TypeReference
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.common.net.HostAndPort
+import org.apache.druid.java.util.common.{ISE, StringUtils}
+import org.apache.druid.java.util.http.client.response.{StringFullResponseHandler,
+ StringFullResponseHolder}
+import org.apache.druid.java.util.http.client.{HttpClient, Request}
+import org.apache.druid.query.Druids
+import org.apache.druid.query.metadata.metadata.{ColumnAnalysis, SegmentAnalysis,
+ SegmentMetadataQuery}
+import org.apache.druid.spark.MAPPER
+import org.apache.druid.spark.configuration.{Configuration, DruidConfigurationKeys}
+import org.apache.druid.spark.mixins.Logging
+import org.jboss.netty.handler.codec.http.{HttpMethod, HttpResponseStatus}
+import org.joda.time.{Duration, Interval}
+
+import java.net.URL
+import java.util.{List => JList}
+import javax.ws.rs.core.MediaType
+import scala.collection.JavaConverters.{asScalaBufferConverter, mapAsJavaMapConverter,
+ mapAsScalaMapConverter, seqAsJavaListConverter}
+
+/**
+ * Going with SegmentMetadataQueries despite the significant overhead because there's no other way
+ * to get accurate information about Druid columns.
+ *
+ * This is pulled pretty directly from the druid-hadoop-input-format project on GitHub. There is
+ * likely substantial room for improvement.
+ *
+ * @param httpClient
+ * @param objectMapper
+ * @param hostAndPort
+ */
+class DruidClient(
+ val httpClient: HttpClient,
+ val objectMapper: ObjectMapper,
+ val hostAndPort: HostAndPort
+ ) extends Logging {
+ private val RETRY_COUNT = 5
+ private val RETRY_WAIT_SECONDS = 5
+ private val TIMEOUT_MILLISECONDS = 300000
+ private val druidBaseQueryURL: HostAndPort => String =
+ (hostAndPort: HostAndPort) => s"http://$hostAndPort/druid/v2/"
+
+ /**
+ * The SQL system catalog tables are incorrect for multivalue columns and don't have accurate
+ * type info, so we need to fall back to segmentMetadataQueries. Given a DATASOURCE and a range
+ * of INTERVALS to query over, return a map from column name to a tuple of
+ * (columnType, hasMultipleValues). Note that this is a very expensive operation over large
+ * numbers of segments. If possible, this method should only be called with the most granular
+ * starting and ending intervals instead of over a larger interval.
+ *
+ * @param dataSource The Druid dataSource to fetch the schema for.
+ * @param intervals The intervals to return the schema for.
+ * @return A map from column name to data type and whether or not the column is multi-value
+ * for the schema of DATASOURCE.
+ */
+ def getSchema(dataSource: String, intervals: List[Interval]): Map[String, (String, Boolean)] = {
Review comment:
Intervals are required because the default behavior is unlikely to be what Spark users would expect (e.g. if no time bounds are provided, I would expect to read the whole table in a batch context, not just the last week.) For now, this is only called in [one place](https://github.com/apache/druid/pull/10920/files/331e0c9d088cad3778f3a57432680a1cc607c084#diff-fdc08076d81ecaaf0431bfa58ec51cd8ea8c9efd6aa2ba72faf0eea9928c0ffaR76), which uses `JodaTime.MIN_INSTANT` and `JodaTime.MAX_INSTANT` as the interval bounds if no time filters are provided. This will be an expensive query for large datasources, but until #9707 is implemented I don't know of a better way. I suppose it would make sense to move that default handling into the `getSchema` method here instead though, so I'll make the change.
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] didip commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
didip commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-879597226
@samarthjain Can’t wait to have this merged.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] birTiwana commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-877498085
@samarthjain do you know who maintains the Travis checks on PRs? I'm trying to figure out what's happening with the intelliJ inspections test (it's the only [failing check](https://app.travis-ci.com/github/apache/druid/jobs/523127037) for most of my recent builds). The errors are
```[ERROR] pom.xml:1790 -- Element forkCount is not allowed here #loc
[ERROR] pom.xml:1790 -- Element forkCount is not allowed here #loc
[ERROR] pom.xml:1790 -- Cannot resolve symbol 'forkCount' #loc
[ERROR] pom.xml:1790 -- Cannot resolve symbol 'forkCount' #loc
[ERROR] pom.xml:1791 -- Element reuseForks is not allowed here #loc
[ERROR] pom.xml:1791 -- Element reuseForks is not allowed here #loc
[ERROR] pom.xml:1791 -- Cannot resolve symbol 'reuseForks' #loc
[ERROR] pom.xml:1791 -- Cannot resolve symbol 'reuseForks' #loc
```
which are args being passed to the surefire plugin when the parallel-test profile is set. I haven't made any changes to that profile (or to the base pom beyond adding the new module), and I've even removed the surefire configuration changes I made in the spark extension, but the error remains. I'm pretty sure it's erroneous, since all the other checks are able to execute maven commands. Googling hasn't turned up much beyond a suggestion to check the bundled xml schema used by the inspector so it would be great to talk to someone who knows a little more about what's happening under the hood for this check
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] samarthjain commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
samarthjain commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-871740496
Once @JulianJaffePinterest pushes fixes to take care of Travis failures, I think this is good to be merged upstream.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] wangxiaobaidu11 commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
wangxiaobaidu11 commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-990912600
> @wangxiaobaidu11 you don't need to make changes to the druid spark code for your use case - you can call `AggregatorFactoryRegistry.register("longUnique", new LongUniqueAggregatorFactory("", "", 0)` from within your own spark app. That's definitely still ugly since the AggregatorFactory instance is unnecessary, but as mentioned in my previous comment this won't be the case for long. If instantiating an instance is a problem, there is one other temporary work-around: because all `AggregatorFactoryRegistry` does under the hood is register subtypes, you can use the public package method `registerSubType`. In your case, you would call `org.apache.druid.spark.registerSubtype(new NamedType(classOf[LongUniqueAggregatorFactory], "longUnique"))` from your spark app. (You can statically that method if you'd like, leaving just `registerSubtype(...)`)
Thanks!I will update it . I have another question.
①when i set:

②spark runtime info:

③ the same date is covered,but I didn't want that to happen
`21/12/10 16:09:45 WARN SegmentRationalizer: More than one version detected for interval 2020-01-01T00:00:00.000Z/2020-01-02T00:00:00.000Z on dataSource test_spark_druid_cube_v4! Some segments will be overshadowed!
21/12/10 16:09:45 WARN SegmentRationalizer: More than one version detected for interval 2020-01-02T00:00:00.000Z/2020-01-03T00:00:00.000Z on dataSource test_spark_druid_cube_v4! Some segments will be overshadowed!`

④ I expect result which is combined segments,How do I set partition
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] wangxiaobaidu11 edited a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
wangxiaobaidu11 edited a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-989656307
@JulianJaffePinterest Thanks for your reply. I added my own extension, Long Unique Extension, and I ran the entire Spark writing process to Druid.
I changed some ugly, how do I want to change more elegant.

--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-884060155
Opened #11474 as the first piecemeal PR against `spark_druid_connector`.
Also, for you last point @jihoonson the end-to-end test currently runs alongside the more traditional unit tests when `mvn test` is executed on the module, meaning it already runs automatically.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-879596335
@samarthjain whenever you get a moment it's green 🙂
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-844710045
Ah yes, the scala version for this extension is 2.12.12 - it won't work with 2.13.5. What Spark version are you using?
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] wangxiaobaidu11 commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
wangxiaobaidu11 commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-989656307
Thanks for your reply. I added my own extension, Long Unique Extension, and I ran the entire Spark writing process to Druid.
I changed some ugly, how do I want to change more elegant.

--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest edited a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest edited a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-993161134
Calling `.partitionBy` on a `DataFrameWriter` (what you get when you call `.write()` on a `DataFrame`) doesn't do anything for a v2 data source that doesn't have a managed catalog, which Druid does not (see #11929 for a recent example). The [docs](https://github.com/apache/druid/blob/8392f87236d4a9795aa4e2867eea18cdf0aeb8ec/docs/operations/spark.md#writer) have a more in-depth discussion of partitioning, but the short version is that you'll either need to partition your dataframe before calling `.write()` on it or use one of the `DruidDataFrame` wrapper's convenience methods. For example, in scala
```scala
import org.apache.druid.spark.DruidDataFrame
df.partitionAndWrite("__time", "millis", "DAY", 200000).format("druid").mode(SaveMode.Overwrite).options(map).save()
```
or in Java
```java
import org.apache.druid.spark.package$.MODULE$.DruidDataFrame;
DruidDataFrame(dataset).partitionAndWrite("__time", "millis", "DAY", 200000).format("druid").mode(SaveMode.Overwrite).options(map).save();
```
If you don't want to use implicits/wrapper classes, you can also use the partitioner directly:
```java
SingleDimensionPartitioner partitioner = new SingleDimensionPartitioner(dataset);
Dataset<Row> partitionedDataSet = partitioner.partition("__time", "millis", "DAY", 200000, "dim1", true);
partitionedDataset.write().format("druid").mode(SaveMode.Overwrite).options(map).save();
```
Also, are you setting `writer.version` in your options map? I'm surprised to see the segments differ in version between each partition. That's what's causing the partitions to overshadow each other.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-880138468
No worries @samarthjain 🙂
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-849417236
I've had a number of conversations about these connectors and how to use them. Common pain points are partitioning and user-friendliness, and so I've added three new partitioners, ergonomic ways to use the new partitioners, and a semi-typed way to configure the readers and writers. The improved ergonomics do come at the cost of introducing scala implicits into the project, which I have tried to avoid to ease comprehension for other developers. However, I think the tradeoff here is worth it. See the [extension documentation for more details](https://github.com/JulianJaffePinterest/druid/blob/spark_druid_connector/docs/development/extensions-core/spark.md)
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-883156439
@jihoonson could you create a branch in the druid repo for me please?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-828215936
I pushed up a commit to clean up the documentation as you requested @samarthjain. I also added support for building a library jar suitable for adding to a Spark cluster with `mvn clean package -pl extensions-core/spark-extensions`. To keep the size reasonable I added dependency exclusions to the pom. I haven't yet made sure that we're excluding every dependency possible, but even the obvious first cut trimmed the size by over 60%.
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] samarthjain commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
samarthjain commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r613876723
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/clients/DruidClient.scala
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.clients
+
+import com.fasterxml.jackson.core.`type`.TypeReference
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.common.net.HostAndPort
+import org.apache.druid.java.util.common.{ISE, StringUtils}
+import org.apache.druid.java.util.http.client.response.{StringFullResponseHandler,
+ StringFullResponseHolder}
+import org.apache.druid.java.util.http.client.{HttpClient, Request}
+import org.apache.druid.query.Druids
+import org.apache.druid.query.metadata.metadata.{ColumnAnalysis, SegmentAnalysis,
+ SegmentMetadataQuery}
+import org.apache.druid.spark.MAPPER
+import org.apache.druid.spark.configuration.{Configuration, DruidConfigurationKeys}
+import org.apache.druid.spark.mixins.Logging
+import org.jboss.netty.handler.codec.http.{HttpMethod, HttpResponseStatus}
+import org.joda.time.{Duration, Interval}
+
+import java.net.URL
+import java.util.{List => JList}
+import javax.ws.rs.core.MediaType
+import scala.collection.JavaConverters.{asScalaBufferConverter, mapAsJavaMapConverter,
+ mapAsScalaMapConverter, seqAsJavaListConverter}
+
+/**
+ * Going with SegmentMetadataQueries despite the significant overhead because there's no other way
+ * to get accurate information about Druid columns.
+ *
+ * This is pulled pretty directly from the druid-hadoop-input-format project on GitHub. There is
+ * likely substantial room for improvement.
+ *
+ * @param httpClient
+ * @param objectMapper
+ * @param hostAndPort
+ */
+class DruidClient(
+ val httpClient: HttpClient,
+ val objectMapper: ObjectMapper,
+ val hostAndPort: HostAndPort
+ ) extends Logging {
+ private val RETRY_COUNT = 5
+ private val RETRY_WAIT_SECONDS = 5
+ private val TIMEOUT_MILLISECONDS = 300000
+ private val druidBaseQueryURL: HostAndPort => String =
+ (hostAndPort: HostAndPort) => s"http://$hostAndPort/druid/v2/"
+
+ /**
+ * The SQL system catalog tables are incorrect for multivalue columns and don't have accurate
+ * type info, so we need to fall back to segmentMetadataQueries. Given a DATASOURCE and a range
+ * of INTERVALS to query over, return a map from column name to a tuple of
+ * (columnType, hasMultipleValues). Note that this is a very expensive operation over large
+ * numbers of segments. If possible, this method should only be called with the most granular
+ * starting and ending intervals instead of over a larger interval.
+ *
+ * @param dataSource The Druid dataSource to fetch the schema for.
+ * @param intervals The intervals to return the schema for.
+ * @return A map from column name to data type and whether or not the column is multi-value
+ * for the schema of DATASOURCE.
+ */
+ def getSchema(dataSource: String, intervals: List[Interval]): Map[String, (String, Boolean)] = {
+ val body = Druids.newSegmentMetadataQueryBuilder()
+ .dataSource(dataSource)
+ .intervals(intervals.asJava)
+ .analysisTypes(SegmentMetadataQuery.AnalysisType.SIZE)
+ .merge(true)
+ .context(Map[String, AnyRef](
+ "timeout" -> Int.box(TIMEOUT_MILLISECONDS)
+ ).asJava)
+ .build()
+ val response = sendRequestWithRetry(
+ druidBaseQueryURL(hostAndPort), RETRY_COUNT, Option(objectMapper.writeValueAsBytes(body))
+ )
+ val segments =
+ objectMapper.readValue[JList[SegmentAnalysis]](
+ response.getContent, new TypeReference[JList[SegmentAnalysis]]() {})
+ if (segments.size() == 0) {
+ throw new ISE(
+ s"No segments found for intervals [${intervals.mkString(",")}] on $dataSource"
+ )
+ }
+ // Since we're setting merge to true, there should only be one item in the list
+ if (segments.size() > 1) {
+ logWarn("Segment metadata response had more than one row, problem?")
Review comment:
I am not sure if simply logging a WARN message is enough. I would rather fail the request since this shouldn't happen.
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] abhishekagarwal87 commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
abhishekagarwal87 commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-883326773
> @jihoonson could you create a branch in the druid repo for me please?
@JulianJaffePinterest Here you go - https://github.com/apache/druid/tree/spark_druid_connector
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r671521222
##########
File path: pom.xml
##########
@@ -105,6 +105,7 @@
<protobuf.version>3.11.0</protobuf.version>
<resilience4j.version>1.3.1</resilience4j.version>
<slf4j.version>1.7.12</slf4j.version>
+ <curefire.version>2.22.2</curefire.version>
Review comment:
Indeed. Fixed
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] birTiwana commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
birTiwana commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-846398512
> Ah yes, the scala version for this extension is 2.12.12 - it won't work with 2.13.5. What Spark version are you using?
2.4.5
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest removed a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest removed a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-880398612
An unrelated integration test timed out 🙃. Is there some way to retrigger the CI build or should I just push a dummy commit?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-790469076
I've added some more tests, improved some comments, and added support for configuring non-default multi-value handling and indexing for string dimensions.
I also see that instructions for how to update the licenses and notices have been committed, but I'll wait on doing that until this has a little more traction 😉
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-880398612
An unrelated integration test timed out 🙃. Is there some way to retrigger the CI build or should I just push a dummy commit?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r640373936
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/configuration/DruidConfigurationKeys.scala
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.configuration
+
+import org.apache.spark.sql.sources.v2.DataSourceOptions
+
+object DruidConfigurationKeys {
+ // Shadowing DataSourceOptions.TABLE_KEY here so other classes won't need unnecessary imports
+ val tableKey: String = DataSourceOptions.TABLE_KEY
+
+ // Metadata Client Configs
+ val metadataPrefix: String = "metadata"
+ val metadataDbTypeKey: String = "dbType"
+ val metadataHostKey: String = "host"
+ val metadataPortKey: String = "port"
+ val metadataConnectUriKey: String = "connectUri"
+ val metadataUserKey: String = "user"
+ val metadataPasswordKey: String = "password"
+ val metadataDbcpPropertiesKey: String = "dbcpProperties"
+ val metadataBaseNameKey: String = "baseName"
+ private[spark] val metadataHostDefaultKey: (String, String) = (metadataHostKey, "localhost")
+ private[spark] val metadataPortDefaultKey: (String, Int) = (metadataPortKey, 1527)
+ private[spark] val metadataBaseNameDefaultKey: (String, String) = (metadataBaseNameKey, "druid")
+
+ // Druid Client Configs
+ val brokerPrefix: String = "broker"
+ val brokerHostKey: String = "host"
+ val brokerPortKey: String = "port"
+ private[spark] val brokerHostDefaultKey: (String, String) = (brokerHostKey, "localhost")
+ private[spark] val brokerPortDefaultKey: (String, Int) = (brokerPortKey, 8082)
+
+ // Common configs
+ val useCompactSketchesKey: String = "useCompactSketches" // Default: false
Review comment:
To allows users to work with compact versions of ThetaSketches if desired (for example, if they don't need to update the sketches after reading them)
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-870340789
@samarthjain Done! I also updated LICENSE and NOTICE for the new dependencies
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] bcmcmill commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
bcmcmill commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-814479674
> Is anyone actively reviewing this? If not, I have a bit of a refactor I'd like to push that improves the organization of the code and hopefully makes it easier to follow.
Please post this update.
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest edited a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest edited a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-993161134
Calling `.partitionBy` on a `DataFrameWriter` (what you get when you call `.write()` on a DataFrame`) doesn't do anything for a v2 data source that doesn't have a managed catalog, which Druid does not (see #11929 for a recent example). The [docs](https://github.com/apache/druid/blob/8392f87236d4a9795aa4e2867eea18cdf0aeb8ec/docs/operations/spark.md#writer) have a more in-depth discussion of partitioning, but the short version is that you'll either need to partition your dataframe before calling `.write()` on it or use one of the `DruidDataFrame` wrapper's convenience methods. For example, in scala
```scala
import org.apache.druid.spark.DruidDataFrame
df.partitionAndWrite("__time", "millis", "DAY", 200000).format("druid").mode(SaveMode.Overwrite).options(map).save()
```
or in Java
```java
import org.apache.druid.spark.package$.MODULE$.DruidDataFrame;
DruidDataFrame(dataset).partitionAndWrite("__time", "millis", "DAY", 200000).format("druid").mode(SaveMode.Overwrite).options(map).save();
```
If you don't want to use implicits/wrapper classes, you can also use the partitioner directly:
```java
SingleDimensionPartitioner partitioner = new SingleDimensionPartitioner(dataset);
Dataset<Row> partitionedDataSet = partitioner.partition("__time", "millis", "DAY", 200000, "dim1", true);
partitionedDataset.write().format("druid").mode(SaveMode.Overwrite).options(map).save();
```
Also, are you setting `writer.version` in your options map? I'm surprised to see the segments differ in version between each partition. That's what's causing the partitions to overshadow each other.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] wangxiaobaidu11 edited a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
wangxiaobaidu11 edited a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-990912600
> @wangxiaobaidu11 you don't need to make changes to the druid spark code for your use case - you can call `AggregatorFactoryRegistry.register("longUnique", new LongUniqueAggregatorFactory("", "", 0)` from within your own spark app. That's definitely still ugly since the AggregatorFactory instance is unnecessary, but as mentioned in my previous comment this won't be the case for long. If instantiating an instance is a problem, there is one other temporary work-around: because all `AggregatorFactoryRegistry` does under the hood is register subtypes, you can use the public package method `registerSubType`. In your case, you would call `org.apache.druid.spark.registerSubtype(new NamedType(classOf[LongUniqueAggregatorFactory], "longUnique"))` from your spark app. (You can statically that method if you'd like, leaving just `registerSubtype(...)`)
Thanks!I will update it . I have another question.
①when i set:

②spark runtime info:
``
③ the same date is covered,but I didn't want that to happen
`21/12/10 16:09:45 WARN SegmentRationalizer: More than one version detected for interval 2020-01-01T00:00:00.000Z/2020-01-02T00:00:00.000Z on dataSource test_spark_druid_cube_v4! Some segments will be overshadowed!
21/12/10 16:09:45 WARN SegmentRationalizer: More than one version detected for interval 2020-01-02T00:00:00.000Z/2020-01-03T00:00:00.000Z on dataSource test_spark_druid_cube_v4! Some segments will be overshadowed!`

④ I expect result which is combined segments,How do I set partition
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] wangxiaobaidu11 edited a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
wangxiaobaidu11 edited a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-989656307
@JulianJaffePinterest Thanks for your reply. I added my own extension, Long Unique Extension, and I ran the entire Spark writing process to Druid. Use hdfs for deep storage.
The code I changed is a little ugly, how can I make it more elegant.

--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] wangxiaobaidu11 edited a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
wangxiaobaidu11 edited a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-989656307
@JulianJaffePinterest Thanks for your reply. I added my own extension, Long Unique Extension, and I ran the entire Spark writing process to Druid. Use hdfs for deep storage.
I changed some ugly, how do I want to change more elegant.

--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] birTiwana commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
birTiwana commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-844153216
> org.apache.druid.spark.v2.DruidDataSourceV2
Thanks, this helped. I was building the spark-extensions jar using `mvn clean package -pl extensions-core/spark-extensions`
The copying it to my scala project's lib folder and then packaging the whole project using `sbt assembly`
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] jihoonson commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
jihoonson commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-884653902
> Also, for you last point @jihoonson the end-to-end test currently runs alongside the more traditional unit tests when `mvn test` is executed on the module, meaning it already runs automatically.
Nice, thanks!
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest edited a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest edited a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-849417236
I've had a number of conversations about these connectors and how to use them. Common pain points are partitioning and user-friendliness, and so I've added three new partitioners, ergonomic ways to use the new partitioners, and a semi-typed way to configure the readers and writers. The improved ergonomics do come at the cost of introducing scala implicits into the project, which I have tried to avoid to ease comprehension for other developers. However, I think the tradeoff here is worth it. See the [extension documentation for more details](https://github.com/JulianJaffePinterest/druid/blob/spark_druid_connector/docs/development/extensions-core/spark.md) for more details.
Example usages:
Configuring the reader:
```scala
import org.apache.druid.spark.DruidDataFrameReader
sparkSession
.read
.brokerHost("localhost")
.brokerPort(8082)
.metadataDbType("mysql")
.metadataUri("jdbc:mysql://druid.metadata.server:3306/druid")
.metadataUser("druid")
.metadataPassword("diurd")
.dataSource("dataSource")
.druid()
```
Configuring the writer:
```scala
import org.apache.druid.spark.DruidDataFrameWriter
val deepStorageConfig = new LocalDeepStorageConfig().storageDirectory("/mnt/druid/druid-segments/")
df
.write
.metadataDbType("mysql")
.metadataUri("jdbc:mysql://druid.metadata.server:3306/druid")
.metadataUser("druid")
.metadataPassword("diurd")
.version(1)
.deepStorage(deepStorageConfig)
.mode(SaveMode.Overwrite)
.dataSource("dataSource")
.druid()
```
Using the new partitioners and the ergonomic approach to passing the a partition map to the writer:
```scala
import org.apache.druid.spark.DruidDataFrame
import org.apache.druid.spark.DruidDataFrameWriter
val deepStorageConfig = new LocalDeepStorageConfig().storageDirectory("/mnt/druid/druid-segments/")
df
.rangePartitionerAndWrite(tsCol, tsFormat, granularityString, rowsPerPartition, partitionCol)
.metadataDbType("mysql")
.metadataUri("jdbc:mysql://druid.metadata.server:3306/druid")
.metadataUser("druid")
.metadataPassword("diurd")
.version(1)
.deepStorage(deepStorageConfig)
.mode(SaveMode.Overwrite)
.dataSource("dataSource")
.druid()
```
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] didip commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
didip commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-871738803
Is there any hope that this gets merged? From our perspective, the native ingestion is brittle when put in a dynamic cloud like Kubernetes. Having a Spark-based ingestion would be super.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest edited a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest edited a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-877498085
@samarthjain do you know who maintains the Travis checks on PRs? I'm trying to figure out what's happening with the intelliJ inspections test (it's the only [failing check](https://app.travis-ci.com/github/apache/druid/jobs/523127037) for most of my recent builds). The errors are
```[ERROR] pom.xml:1790 -- Element forkCount is not allowed here #loc
[ERROR] pom.xml:1790 -- Element forkCount is not allowed here #loc
[ERROR] pom.xml:1790 -- Cannot resolve symbol 'forkCount' #loc
[ERROR] pom.xml:1790 -- Cannot resolve symbol 'forkCount' #loc
[ERROR] pom.xml:1791 -- Element reuseForks is not allowed here #loc
[ERROR] pom.xml:1791 -- Element reuseForks is not allowed here #loc
[ERROR] pom.xml:1791 -- Cannot resolve symbol 'reuseForks' #loc
[ERROR] pom.xml:1791 -- Cannot resolve symbol 'reuseForks' #loc
```
which are args being passed to the surefire plugin when the parallel-test profile is set. I haven't made any changes to that profile (or to the base pom beyond adding the new module), and I've even removed the surefire configuration changes I made in the spark extension, but the error remains. I'm pretty sure it's erroneous, since all the other checks are able to execute maven commands. Googling hasn't turned up much beyond a suggestion to check the bundled xml schema used by the inspector so it would be great to talk to someone who knows a little more about what's happening under the hood for this check
Follow up: I solved this problem by explicitly setting the surefire version in the plugin section where the complaining configuration lived, even though the version was already set in the plugin management section.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-817587252
Life intervened as always, so I haven't thought about this for a while. I've just pushed that refactor I mentioned above that improves the package and class layout. The commit also bumps the target Spark and scala patch versions (to 2.4.7 & 2.12.12, respectively) to pull in security fixes, adds more unit tests, and improves the code documentation. Finally, the commit adds two new features: the ability to specify SQL-compliant or Druid default value null handling (via the `reader.useDefaultValueForNull` config option) and experimental support for columnar reads. See the extension documentation for more detail.
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-879632108
@jihoonson @samarthjain has been reviewing the pr but yes I agree it's too large to effectively review. I'm not sure how to reduce it to pieces though - splitting it into just readers or just writers still means that the first pr is very large (since it would still need all the shared code). Do you have any suggestions there?
As to your questions,
- These APIs are production ready (and are in fact being used in production at multiple organizations)
- That makes sense to me from a code organization perspective. I can make that change
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-992041166
@wangxiaobaidu11 you can control the number of partitions by partitioning your dataframe prior to calling `.write()` on the dataframe. There's a brief discussion in the [docs](https://github.com/apache/druid/blob/8392f87236d4a9795aa4e2867eea18cdf0aeb8ec/docs/operations/spark.md) about partitioning; I'm happy to add more/clarify/etc. as needed. Can you share more details about how you're configuring and calling the writer?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-819271642
Added the `writer.useDefaultValueForNull` config option as well to control how nulls are handled while writing.
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-881963079
@jihoonson I don't have the ability to create a branch in this repo to open prs against, but I'm game to try. It's been difficult to get reviews from committers (it took two months and multiple emails to the dev list to get the first review for this diff) and so I'm hesitant to go down a path of needing to hunt reviews for many diffs, but if you think smaller prs will actually get reviews I can do so. (As an aside, if the Druid website's [list of committers](https://druid.apache.org/community/) is accurate only 1 of the last 10 prs tagged "Design Review" actually had approval from three committers in GitHub, so some process improvements may be necessary)
For documenting level of confidence in the various deep storage/metadata options, would you prefer an explicit table in the docs or in-line callouts (the current approach). I haven't updated .travis.yml beyond the checkstyle because the existing travis packages run the static checks and tests for the new module. In addition to unit tests, there's a light end-to-end test as well that writes segments out and then reads the created segments and confirms they match what was written. If there's actually a road for this pr, I can look into writing an integration test that requires an external spark cluster but obviously that won't be run as part of travis.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] samarthjain commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
samarthjain commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r621494295
##########
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
Review comment:
It would be good to also include an example that illustrates how to provide broker url for determining schema.
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-792497055
Is anyone actively reviewing this? If not, I have a bit of a refactor I'd like to push that improves the organization of the code and hopefully makes it easier to follow.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] samarthjain commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
samarthjain commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-869350706
@JulianJaffePinterest - thanks for the updates. This looks good to me now. Could you rebase the PR?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] jihoonson commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
jihoonson commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-879620914
Hi @JulianJaffePinterest, apologize for not having a look earlier and thank you for your patience! I know there are many people out there who want this, so thank you again for making this PR. I haven't gone through all changes because this is a giant PR. I bet none of committers would probably not able to do a careful review for such a giant PR in the near future. Do you think you can split this into smaller PRs? That will actually make the review process faster. I also have 2 comments about this project.
- What is the current state of these APIs? Is it production-ready? Or is it experimental? This should be documented.
- AFAIT, the thing you added is not a Druid extension, but spark APIs to read from or write to Druid, isn't it? If so, I think it makes more sense to place these codes in a new directory under the druid root such as `${DRUID_ROOT}/spark-apis`.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-883156439
@jihoonson could you create a branch in the druid repo for me please?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] jihoonson commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
jihoonson commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-938349997
Hi @JulianJaffePinterest, just want to check how things are going. My previous suggestion for splitting this PR into smaller chunks was based on an assumption that it will not slow down the process. But it seems not working as well as I expected. Our ultimate goal here is merging this cool feature quickly. If you are busy, I totally understand and will support you to merge this PR as quickly as possible without further split.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r621862855
##########
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
Review comment:
Added 👍
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] didip commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
didip commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-880063014
@jihoonson IMHO, for a completely new big feature like this, isn't it better to be submitted as 1 PR? If there is something wrong in the future, the git forensic would be much easier.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] viongpanzi commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
viongpanzi commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r671404168
##########
File path: pom.xml
##########
@@ -105,6 +105,7 @@
<protobuf.version>3.11.0</protobuf.version>
<resilience4j.version>1.3.1</resilience4j.version>
<slf4j.version>1.7.12</slf4j.version>
+ <curefire.version>2.22.2</curefire.version>
Review comment:
should be surefire.version?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest edited a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest edited a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-828215936
I pushed up a commit to clean up the documentation as you requested @samarthjain. I also added support for building a library jar suitable for adding to a Spark cluster with `mvn clean package -pl extensions-core/spark-extensions` (edit 7/14/21: use `mvn clean package -pl spark`). To keep the size reasonable I added dependency exclusions to the pom. I haven't yet made sure that we're excluding every dependency possible, but even the obvious first cut trimmed the size by over 60%.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r635118457
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/clients/DruidMetadataClient.scala
##########
@@ -0,0 +1,171 @@
+/*
+ * 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.clients
+
+import com.fasterxml.jackson.core.`type`.TypeReference
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.common.base.Suppliers
+import org.apache.druid.indexer.SQLMetadataStorageUpdaterJobHandler
+import org.apache.druid.java.util.common.StringUtils
+import org.apache.druid.metadata.{MetadataStorageConnectorConfig, MetadataStorageTablesConfig,
+ PasswordProvider, SQLMetadataConnector}
+import org.apache.druid.spark.MAPPER
+import org.apache.druid.spark.configuration.{Configuration, DruidConfigurationKeys}
+import org.apache.druid.spark.mixins.Logging
+import org.apache.druid.spark.registries.SQLConnectorRegistry
+import org.apache.druid.timeline.DataSegment
+import org.skife.jdbi.v2.{DBI, Handle}
+
+import java.io.ByteArrayInputStream
+import java.util.Properties
+import scala.collection.JavaConverters.{asScalaBufferConverter, mapAsJavaMapConverter}
+
+class DruidMetadataClient(
+ metadataDbType: String,
+ host: String,
+ port: Int,
+ connectUri: String,
+ user: String,
+ passwordProviderSer: String,
+ dbcpMap: Properties,
+ base: String = "druid"
+ ) extends Logging {
+ private lazy val druidMetadataTableConfig = MetadataStorageTablesConfig.fromBase(base)
+ private lazy val dbcpProperties = new Properties()
+ dbcpProperties.putAll(dbcpMap)
Review comment:
Can you share a stack trace or how you triggered this error?
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] wangxiaobaidu11 edited a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
wangxiaobaidu11 edited a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-992404912
> @wangxiaobaidu11 you can control the number of partitions by partitioning your dataframe prior to calling `.write()` on the dataframe. There's a brief discussion in the [docs](https://github.com/apache/druid/blob/8392f87236d4a9795aa4e2867eea18cdf0aeb8ec/docs/operations/spark.md) about partitioning; I'm happy to add more/clarify/etc. as needed. Can you share more details about how you're configuring and calling the writer?
java code
` StructType schema = (new StructType())
.add(new StructField("__time", LongType, true, new Metadata().empty()))
.add(new StructField("dim1", new ArrayType(StringType, false),
true, new Metadata().empty()))
.add(new StructField("dim2", StringType, true, new Metadata().empty()))
.add(new StructField("id1", StringType, true, new Metadata().empty()))
.add(new StructField("id2", StringType, true, new Metadata().empty()))
.add(new StructField("count", LongType, true, new Metadata().empty()))
.add(new StructField("sum_metric1", LongType, true, new Metadata().empty()))
.add(new StructField("sum_metric2", LongType, true, new Metadata().empty()))
.add(new StructField("sum_metric3", DoubleType, true, new Metadata().empty()))
.add(new StructField("sum_metric4", FloatType, true, new Metadata().empty()))
.add(new StructField("uniq_id1", LongType, true, new Metadata().empty()));
Dataset<Row> dataset = sparkSession.createDataFrame(list, schema);
dataset.write().partitionBy("__time").format("druid").mode(SaveMode.Overwrite).options(map).save();`
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest edited a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest edited a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-993161134
Calling `.partitionBy` on a `DataFrameWriter` (what you get when you call `.write()` on a DataFrame`) doesn't do anything for a v2 data source that doesn't have a managed catalog, which Druid does not (see #11929 for a recent example). The [docs](https://github.com/apache/druid/blob/8392f87236d4a9795aa4e2867eea18cdf0aeb8ec/docs/operations/spark.md#writer) have a more in-depth discussion of partitioning, but the short version is that you'll either need to partition your dataframe before calling `.write()` on it or use one of the `DruidDataFrame` wrapper's convenience methods. For example, in scala
```scala
import org.apache.druid.spark.DruidDataFrame
df.partitionAndWrite("__time", "millis", "DAY", 200000).format("druid").mode(SaveMode.Overwrite).options(map).save()
```
or in Java
```java
import org.apache.druid.spark.package$.MODULE$.DruidDataFrame
DruidDataFrame(dataset).partitionAndWrite("__time", "millis", "DAY", 200000).format("druid").mode(SaveMode.Overwrite).options(map).save();
```
If you don't want to use implicits/wrapper classes, you can also use the partitioner directly:
```java
SingleDimensionPartitioner partitioner = new SingleDimensionPartitioner(dataset);
Dataset<Row> partitionedDataSet = partitioner.partition("__time", "millis", "DAY", 200000, "dim1", true);
partitionedDataset.write().format("druid").mode(SaveMode.Overwrite).options(map).save();
```
Also, are you setting `writer.version` in your options map? I'm surprised to see the segments differ in version between each partition. That's what's causing the partitions to overshadow each other.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] samarthjain commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
samarthjain commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r621497291
##########
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:
This might be a gap in my understanding - since the readers are directly loading from deep storage, would they not need to essentially download and scan the entire file to apply predicates?
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] birTiwana commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r640375532
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/clients/DruidMetadataClient.scala
##########
@@ -0,0 +1,171 @@
+/*
+ * 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.clients
+
+import com.fasterxml.jackson.core.`type`.TypeReference
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.common.base.Suppliers
+import org.apache.druid.indexer.SQLMetadataStorageUpdaterJobHandler
+import org.apache.druid.java.util.common.StringUtils
+import org.apache.druid.metadata.{MetadataStorageConnectorConfig, MetadataStorageTablesConfig,
+ PasswordProvider, SQLMetadataConnector}
+import org.apache.druid.spark.MAPPER
+import org.apache.druid.spark.configuration.{Configuration, DruidConfigurationKeys}
+import org.apache.druid.spark.mixins.Logging
+import org.apache.druid.spark.registries.SQLConnectorRegistry
+import org.apache.druid.timeline.DataSegment
+import org.skife.jdbi.v2.{DBI, Handle}
+
+import java.io.ByteArrayInputStream
+import java.util.Properties
+import scala.collection.JavaConverters.{asScalaBufferConverter, mapAsJavaMapConverter}
+
+class DruidMetadataClient(
+ metadataDbType: String,
+ host: String,
+ port: Int,
+ connectUri: String,
+ user: String,
+ passwordProviderSer: String,
+ dbcpMap: Properties,
+ base: String = "druid"
+ ) extends Logging {
+ private lazy val druidMetadataTableConfig = MetadataStorageTablesConfig.fromBase(base)
+ private lazy val dbcpProperties = new Properties()
+ dbcpProperties.putAll(dbcpMap)
+ private lazy val password = if (passwordProviderSer == "") {
+ // Jackson doesn't like deserializing empty strings
+ passwordProviderSer
+ } else {
+ MAPPER.readValue[PasswordProvider](
+ passwordProviderSer, new TypeReference[PasswordProvider] {}
+ ).getPassword
+ }
+
+ private lazy val connectorConfig: MetadataStorageConnectorConfig =
+ new MetadataStorageConnectorConfig
+ {
+ override def isCreateTables: Boolean = false
+ override def getHost: String = host
+ override def getPort: Int = port
+ override def getConnectURI: String = connectUri
+ override def getUser: String = user
+ override def getPassword: String = password
+ override def getDbcpProperties: Properties = dbcpProperties
+ }
+ private lazy val connectorConfigSupplier = Suppliers.ofInstance(connectorConfig)
+ private lazy val metadataTableConfigSupplier = Suppliers.ofInstance(druidMetadataTableConfig)
+ private lazy val connector = buildSQLConnector()
+
+ def getSegmentPayloads(
Review comment:
Yes, if users want to aggregate over the retrieved segments they'll need to do that themselves.
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] samarthjain commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
samarthjain commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r613868557
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/clients/DruidClient.scala
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.clients
+
+import com.fasterxml.jackson.core.`type`.TypeReference
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.common.net.HostAndPort
+import org.apache.druid.java.util.common.{ISE, StringUtils}
+import org.apache.druid.java.util.http.client.response.{StringFullResponseHandler,
+ StringFullResponseHolder}
+import org.apache.druid.java.util.http.client.{HttpClient, Request}
+import org.apache.druid.query.Druids
+import org.apache.druid.query.metadata.metadata.{ColumnAnalysis, SegmentAnalysis,
+ SegmentMetadataQuery}
+import org.apache.druid.spark.MAPPER
+import org.apache.druid.spark.configuration.{Configuration, DruidConfigurationKeys}
+import org.apache.druid.spark.mixins.Logging
+import org.jboss.netty.handler.codec.http.{HttpMethod, HttpResponseStatus}
+import org.joda.time.{Duration, Interval}
+
+import java.net.URL
+import java.util.{List => JList}
+import javax.ws.rs.core.MediaType
+import scala.collection.JavaConverters.{asScalaBufferConverter, mapAsJavaMapConverter,
+ mapAsScalaMapConverter, seqAsJavaListConverter}
+
+/**
+ * Going with SegmentMetadataQueries despite the significant overhead because there's no other way
+ * to get accurate information about Druid columns.
+ *
+ * This is pulled pretty directly from the druid-hadoop-input-format project on GitHub. There is
+ * likely substantial room for improvement.
+ *
+ * @param httpClient
+ * @param objectMapper
+ * @param hostAndPort
+ */
+class DruidClient(
+ val httpClient: HttpClient,
+ val objectMapper: ObjectMapper,
+ val hostAndPort: HostAndPort
+ ) extends Logging {
+ private val RETRY_COUNT = 5
+ private val RETRY_WAIT_SECONDS = 5
+ private val TIMEOUT_MILLISECONDS = 300000
+ private val druidBaseQueryURL: HostAndPort => String =
+ (hostAndPort: HostAndPort) => s"http://$hostAndPort/druid/v2/"
+
+ /**
+ * The SQL system catalog tables are incorrect for multivalue columns and don't have accurate
+ * type info, so we need to fall back to segmentMetadataQueries. Given a DATASOURCE and a range
+ * of INTERVALS to query over, return a map from column name to a tuple of
+ * (columnType, hasMultipleValues). Note that this is a very expensive operation over large
+ * numbers of segments. If possible, this method should only be called with the most granular
+ * starting and ending intervals instead of over a larger interval.
+ *
+ * @param dataSource The Druid dataSource to fetch the schema for.
+ * @param intervals The intervals to return the schema for.
+ * @return A map from column name to data type and whether or not the column is multi-value
+ * for the schema of DATASOURCE.
+ */
+ def getSchema(dataSource: String, intervals: List[Interval]): Map[String, (String, Boolean)] = {
Review comment:
Should intervals be optional? If interval is not provided, the default interval specified by the broker config `druid.query.segmentMetadata.defaultHistory` will be used. https://druid.apache.org/docs/latest/querying/segmentmetadataquery.html#intervals
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r640373257
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/v2/writer/DruidDataWriter.scala
##########
@@ -0,0 +1,304 @@
+/*
+ * 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.writer
+
+import com.fasterxml.jackson.core.`type`.TypeReference
+import org.apache.druid.data.input.MapBasedInputRow
+import org.apache.druid.java.util.common.io.Closer
+import org.apache.druid.java.util.common.parsers.TimestampParser
+import org.apache.druid.java.util.common.{DateTimes, FileUtils, Intervals}
+import org.apache.druid.segment.column.ValueType
+import org.apache.druid.segment.data.{BitmapSerdeFactory, CompressionFactory, CompressionStrategy,
+ ConciseBitmapSerdeFactory, RoaringBitmapSerdeFactory}
+import org.apache.druid.segment.incremental.{IncrementalIndex, IncrementalIndexSchema,
+ OnheapIncrementalIndex}
+import org.apache.druid.segment.indexing.DataSchema
+import org.apache.druid.segment.loading.DataSegmentPusher
+import org.apache.druid.segment.writeout.OnHeapMemorySegmentWriteOutMediumFactory
+import org.apache.druid.segment.{IndexSpec, IndexableAdapter, QueryableIndexIndexableAdapter}
+import org.apache.druid.spark.MAPPER
+import org.apache.druid.spark.configuration.{DruidConfigurationKeys, DruidDataWriterConfig}
+import org.apache.druid.spark.mixins.Logging
+import org.apache.druid.spark.registries.{ComplexMetricRegistry, SegmentWriterRegistry,
+ ShardSpecRegistry}
+import org.apache.druid.spark.utils.NullHandlingUtils
+import org.apache.druid.spark.v2.{INDEX_IO, INDEX_MERGER_V9}
+import org.apache.druid.timeline.DataSegment
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.UnsafeArrayData
+import org.apache.spark.sql.sources.v2.writer.{DataWriter, WriterCommitMessage}
+import org.apache.spark.sql.types.ArrayType
+
+import java.io.Closeable
+import java.util.{List => JList}
+import scala.collection.JavaConverters.{asScalaBufferConverter, mapAsJavaMapConverter,
+ seqAsJavaListConverter}
+import scala.collection.mutable
+import scala.collection.mutable.ArrayBuffer
+
+/**
+ * A DruidDataWriter does the actual work of writing a partition of a dataframe to files Druid
+ * knows how to read. Users should not use this class directly but should instead call write() on their dataframe
+ * (e.g. df.write.format("druid").options(Map[String, String](...)).save()).
+ *
+ * TODO: Describe the writing logic (creating the map from bucket to flushed indexers (i.e. adapters
+ * and the current open index), how indices are merged and pushed to deep storage, partition number
+ * /counts concerns, etc.
+ *
+ * @param config An object holding necessary configuration settings for the writer passed along
+ * from the driver.
+ */
+class DruidDataWriter(config: DruidDataWriterConfig) extends DataWriter[InternalRow] with Logging {
+ NullHandlingUtils.initializeDruidNullHandling(config.useDefaultNullHandling)
+
+ private val tmpPersistDir = FileUtils.createTempDir("persist")
+ private val tmpMergeDir = FileUtils.createTempDir("merge")
+ private val closer = Closer.create()
+ closer.register(
+ new Closeable {
+ override def close(): Unit = {
+ FileUtils.deleteDirectory(tmpMergeDir)
+ FileUtils.deleteDirectory(tmpPersistDir)
+ }
+ }
+ )
+
+ private val dataSchema: DataSchema =
+ MAPPER.readValue[DataSchema](config.dataSchemaSerialized,
+ new TypeReference[DataSchema] {})
+ private val dimensions: JList[String] =
+ dataSchema.getDimensionsSpec.getDimensions.asScala.map(_.getName).asJava
+ private val tsColumn: String = dataSchema.getTimestampSpec.getTimestampColumn
+ private val tsColumnIndex = config.schema.fieldIndex(tsColumn)
+ private val timestampParser = TimestampParser
+ .createObjectTimestampParser(dataSchema.getTimestampSpec.getTimestampFormat)
+
+ private val partitionMap = config.partitionMap.map(_(config.partitionId))
+ .getOrElse(Map[String, String]("partitionId" -> config.partitionId.toString))
+
+ private val indexSpecConf = config.properties.dive(DruidConfigurationKeys.indexSpecPrefix)
+ private val indexSpec: IndexSpec = new IndexSpec(
+ DruidDataWriter.getBitmapSerde(
+ indexSpecConf.get(DruidConfigurationKeys.bitmapTypeDefaultKey),
+ indexSpecConf.getBoolean(
+ DruidConfigurationKeys.compressRunOnSerializationKey,
+ RoaringBitmapSerdeFactory.DEFAULT_COMPRESS_RUN_ON_SERIALIZATION)
+ ),
+ DruidDataWriter.getCompressionStrategy(
+ indexSpecConf.get(
+ DruidConfigurationKeys.dimensionCompressionKey,
+ CompressionStrategy.DEFAULT_COMPRESSION_STRATEGY.toString)
+ ),
+ DruidDataWriter.getCompressionStrategy(
+ indexSpecConf.get(
+ DruidConfigurationKeys.metricCompressionKey,
+ CompressionStrategy.DEFAULT_COMPRESSION_STRATEGY.toString)
+ ),
+ DruidDataWriter.getLongEncodingStrategy(
+ indexSpecConf.get(
+ DruidConfigurationKeys.longEncodingKey,
+ CompressionFactory.DEFAULT_LONG_ENCODING_STRATEGY.toString
+ )
+ )
+ )
+
+ private val complexColumnTypes = {
+ dataSchema.getAggregators.toSeq.filter(_.getType == ValueType.COMPLEX).map(_.getComplexTypeName)
+ }
+
+ if (complexColumnTypes.nonEmpty) {
+ // Callers will need to explicitly register any complex metrics not known to ComplexMetricRegistry by default
+ complexColumnTypes.foreach {
+ ComplexMetricRegistry.registerByName(_, config.writeCompactSketches)
+ }
+ }
+ ComplexMetricRegistry.registerSerdes()
+
+ private val pusher: DataSegmentPusher = SegmentWriterRegistry.getSegmentPusher(
+ config.deepStorageType, config.properties
+ )
+
+ // TODO: rewrite this without using IncrementalIndex, because IncrementalIndex bears a lot of overhead
+ // to support concurrent querying, that is not needed in Spark
+ // We may have rows for multiple intervals here, so we need to keep a map of segment start time to
+ // flushed adapters and currently incrementing indexers.
+ private val bucketToIndexMap: mutable.Map[Long,
+ (ArrayBuffer[IndexableAdapter], IncrementalIndex[_])
+ ] = mutable.HashMap[Long, (ArrayBuffer[IndexableAdapter], IncrementalIndex[_])]()
+ .withDefault(bucket => (ArrayBuffer.empty[IndexableAdapter], createInterval(bucket)))
+
+ override def write(row: InternalRow): Unit = {
+ val timestamp = timestampParser
+ .apply(row.get(tsColumnIndex, config.schema(tsColumnIndex).dataType)).getMillis
+ val bucket = getBucketForRow(timestamp)
+ // Scala MutableMaps don't have a computeIfAbsent equivalent, so this is either a logical no-op or it creates the
+ // entry following the function defined in the map's .withDefault declaration
+ bucketToIndexMap(bucket) = bucketToIndexMap(bucket)
+ var index = bucketToIndexMap(bucket)._2
+
+ // Check index, flush if too many rows in memory and recreate
+ if (index.size() == config.rowsPerPersist) {
+ val adapters = bucketToIndexMap(bucket)._1 :+ flushIndex(index)
+ index.close()
+ bucketToIndexMap(bucket) = (adapters, createInterval(bucket))
+ index = bucketToIndexMap(bucket)._2
+ }
+ index.add(
+ index.formatRow(
+ new MapBasedInputRow(
+ timestamp,
+ dimensions,
+ // Convert to Java types that Druid knows how to handle
+ config.schema
+ .map(field => field.name -> (field.dataType, row.get(config.schema.indexOf(field), field.dataType))).toMap
+ .mapValues {
+ case (_, traversable: Traversable[_]) => traversable.toSeq.asJava
+ case (dataType, unsafe: UnsafeArrayData) =>
+ (0 until unsafe.numElements()).map(unsafe.get(_, dataType.asInstanceOf[ArrayType].elementType)).asJava
+ case (_, x) => x
+ }.asJava
+ )
+ )
+ )
+ }
+
+ private[v2] def createInterval(startMillis: Long): IncrementalIndex[_] = {
+ // Using OnHeapIncrementalIndex to minimize changes when migrating from IncrementalIndex. In the future, this should
+ // be optimized further. See https://github.com/apache/druid/issues/10321 for more information.
+ new OnheapIncrementalIndex.Builder()
+ .setIndexSchema(
+ new IncrementalIndexSchema.Builder()
+ .withDimensionsSpec(dataSchema.getDimensionsSpec)
+ .withQueryGranularity(
+ dataSchema.getGranularitySpec.getQueryGranularity
+ )
+ .withMetrics(dataSchema.getAggregators: _*)
+ .withTimestampSpec(dataSchema.getTimestampSpec)
+ .withMinTimestamp(startMillis)
+ .withRollup(dataSchema.getGranularitySpec.isRollup)
+ .build()
+ )
+ .setMaxRowCount(config.rowsPerPersist)
+ .build()
+ }
+
+ private[v2] def flushIndex(index: IncrementalIndex[_]): IndexableAdapter = {
+ new QueryableIndexIndexableAdapter(
+ closer.register(
+ INDEX_IO.loadIndex(
+ INDEX_MERGER_V9
+ .persist(
+ index,
+ index.getInterval,
+ tmpPersistDir,
+ indexSpec,
+ OnHeapMemorySegmentWriteOutMediumFactory.instance()
+ )
+ )
+ )
+ )
+ }
+
+ private[v2] def getBucketForRow(ts: Long): Long = {
+ dataSchema.getGranularitySpec.getSegmentGranularity.bucketStart(DateTimes.utc(ts)).getMillis
+ }
+
+ override def commit(): WriterCommitMessage = {
+ // Return segment locations on deep storage
+ val specs = bucketToIndexMap.values.map { case (adapters, index) =>
+ if (!index.isEmpty) {
+ adapters += flushIndex(index)
+ index.close()
+ }
+ if (adapters.nonEmpty) {
+ // TODO: Merge adapters up to a total number of rows, and then split into new segments.
+ // The tricky piece will be determining the partition number for multiple segments (interpolate 0?)
+ val finalStaticIndexer = INDEX_MERGER_V9
+ val file = finalStaticIndexer.merge(
+ adapters.asJava,
+ true,
+ dataSchema.getAggregators,
+ tmpMergeDir,
+ indexSpec,
+ -1 // TODO: Make maxColumnsToMerge configurable
+ )
+ val allDimensions: JList[String] = adapters
+ .map(_.getDimensionNames)
+ .foldLeft(Set[String]())(_ ++ _.asScala)
+ .toList
+ .asJava
+ val interval = adapters.map(_.getDataInterval)
+ .reduce((l, r) => Intervals.utc(
+ Math.min(l.getStartMillis, r.getStartMillis), Math.max(l.getEndMillis, r.getEndMillis)
+ ))
+ val shardSpec = ShardSpecRegistry.createShardSpec(
+ config.shardSpec,
+ partitionMap)
+ val dataSegmentTemplate = new DataSegment(
+ config.dataSource,
+ dataSchema.getGranularitySpec.getSegmentGranularity.bucket(DateTimes.utc(interval.getStartMillis)),
+ config.version,
+ null, // scalastyle:ignore null
+ allDimensions,
+ dataSchema.getAggregators.map(_.getName).toList.asJava,
+ shardSpec,
+ -1,
+ 0L
+ )
+ val finalDataSegment = pusher.push(file, dataSegmentTemplate, true)
+ Seq(MAPPER.writeValueAsString(finalDataSegment))
+ } else {
+ Seq.empty
+ }
+ }.toSeq.flatten
+ closer.close()
Review comment:
I think if this throws an exception we should blow up to avoid polluting the Spark cluster's workspace with orphaned filed, but I'm open to alternative approaches.
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-843974756
@birTiwana the problem is that you don't have the `org.apache.spark.sql.sources.DataSourceRegister` resource in your META-INF/services, so the short name resolution isn't working. How are you building the jar?
If you're using `mvn clean package -pl extensions-core/spark-extensions`, try deleting the line in the pom that sets the ServicesResourcesTransformer (`<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>` ). If you don't want to include the resource in your META-INF services, you can also just use the fully qualified name instead: `org.apache.druid.spark.v2.DruidDataSourceV2`
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] birTiwana commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest edited a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest edited a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-879632108
@jihoonson @samarthjain has been reviewing the pr but yes I agree it's too large to effectively review. I'm not sure how to reduce it to pieces though - splitting it into just readers or just writers still means that the first pr is very large (since it would still need all the shared code). Do you have any suggestions there?
As to your questions,
- These APIs are production ready (and are in fact being used in production at multiple organizations). Some of the cross-matrix options (deep storage types, sql metadata types) are more experimental (e.g. I'm unaware of any production users writing to Azure deep storage).
- That makes sense to me from a code organization perspective. I can make that change
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] birTiwana commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
birTiwana commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r637399013
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/clients/DruidMetadataClient.scala
##########
@@ -0,0 +1,171 @@
+/*
+ * 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.clients
+
+import com.fasterxml.jackson.core.`type`.TypeReference
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.common.base.Suppliers
+import org.apache.druid.indexer.SQLMetadataStorageUpdaterJobHandler
+import org.apache.druid.java.util.common.StringUtils
+import org.apache.druid.metadata.{MetadataStorageConnectorConfig, MetadataStorageTablesConfig,
+ PasswordProvider, SQLMetadataConnector}
+import org.apache.druid.spark.MAPPER
+import org.apache.druid.spark.configuration.{Configuration, DruidConfigurationKeys}
+import org.apache.druid.spark.mixins.Logging
+import org.apache.druid.spark.registries.SQLConnectorRegistry
+import org.apache.druid.timeline.DataSegment
+import org.skife.jdbi.v2.{DBI, Handle}
+
+import java.io.ByteArrayInputStream
+import java.util.Properties
+import scala.collection.JavaConverters.{asScalaBufferConverter, mapAsJavaMapConverter}
+
+class DruidMetadataClient(
+ metadataDbType: String,
+ host: String,
+ port: Int,
+ connectUri: String,
+ user: String,
+ passwordProviderSer: String,
+ dbcpMap: Properties,
+ base: String = "druid"
+ ) extends Logging {
+ private lazy val druidMetadataTableConfig = MetadataStorageTablesConfig.fromBase(base)
+ private lazy val dbcpProperties = new Properties()
+ dbcpProperties.putAll(dbcpMap)
+ private lazy val password = if (passwordProviderSer == "") {
+ // Jackson doesn't like deserializing empty strings
+ passwordProviderSer
+ } else {
+ MAPPER.readValue[PasswordProvider](
+ passwordProviderSer, new TypeReference[PasswordProvider] {}
+ ).getPassword
+ }
+
+ private lazy val connectorConfig: MetadataStorageConnectorConfig =
+ new MetadataStorageConnectorConfig
+ {
+ override def isCreateTables: Boolean = false
+ override def getHost: String = host
+ override def getPort: Int = port
+ override def getConnectURI: String = connectUri
+ override def getUser: String = user
+ override def getPassword: String = password
+ override def getDbcpProperties: Properties = dbcpProperties
+ }
+ private lazy val connectorConfigSupplier = Suppliers.ofInstance(connectorConfig)
+ private lazy val metadataTableConfigSupplier = Suppliers.ofInstance(druidMetadataTableConfig)
+ private lazy val connector = buildSQLConnector()
+
+ def getSegmentPayloads(
Review comment:
We are directly getting all the segments here within a time interval. Now let's take a scenario where some metric data with longMax with the same set of dimensions and timestamp is written twice in two different segment files. This is a valid scenarios in case of Kafka based ingestion. If we were to use broker->historical to query this data, then it will do aggregation automatically to select the correct value for us based on the column type. But this won't work here. Are users of this extensions supposed to write such a logic themselves?
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest edited a comment on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest edited a comment on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-849417236
I've had a number of conversations about these connectors and how to use them. Common pain points are partitioning and user-friendliness, and so I've added three new partitioners, ergonomic ways to use the new partitioners, and a semi-typed way to configure the readers and writers. The improved ergonomics do come at the cost of introducing scala implicits into the project, which I have tried to avoid to ease comprehension for other developers. However, I think the tradeoff here is worth it. See the [documentation for more details](https://github.com/JulianJaffePinterest/druid/blob/spark_druid_connector/docs/development/spark.md) for more details.
Example usages:
Configuring the reader:
```scala
import org.apache.druid.spark.DruidDataFrameReader
sparkSession
.read
.brokerHost("localhost")
.brokerPort(8082)
.metadataDbType("mysql")
.metadataUri("jdbc:mysql://druid.metadata.server:3306/druid")
.metadataUser("druid")
.metadataPassword("diurd")
.dataSource("dataSource")
.druid()
```
Configuring the writer:
```scala
import org.apache.druid.spark.DruidDataFrameWriter
val deepStorageConfig = new LocalDeepStorageConfig().storageDirectory("/mnt/druid/druid-segments/")
df
.write
.metadataDbType("mysql")
.metadataUri("jdbc:mysql://druid.metadata.server:3306/druid")
.metadataUser("druid")
.metadataPassword("diurd")
.version(1)
.deepStorage(deepStorageConfig)
.mode(SaveMode.Overwrite)
.dataSource("dataSource")
.druid()
```
Using the new partitioners and the ergonomic approach to passing the a partition map to the writer:
```scala
import org.apache.druid.spark.DruidDataFrame
import org.apache.druid.spark.DruidDataFrameWriter
val deepStorageConfig = new LocalDeepStorageConfig().storageDirectory("/mnt/druid/druid-segments/")
df
.rangePartitionerAndWrite(tsCol, tsFormat, granularityString, rowsPerPartition, partitionCol)
.metadataDbType("mysql")
.metadataUri("jdbc:mysql://druid.metadata.server:3306/druid")
.metadataUser("druid")
.metadataPassword("diurd")
.version(1)
.deepStorage(deepStorageConfig)
.mode(SaveMode.Overwrite)
.dataSource("dataSource")
.druid()
```
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r614550259
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/clients/DruidClient.scala
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.clients
+
+import com.fasterxml.jackson.core.`type`.TypeReference
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.common.net.HostAndPort
+import org.apache.druid.java.util.common.{ISE, StringUtils}
+import org.apache.druid.java.util.http.client.response.{StringFullResponseHandler,
+ StringFullResponseHolder}
+import org.apache.druid.java.util.http.client.{HttpClient, Request}
+import org.apache.druid.query.Druids
+import org.apache.druid.query.metadata.metadata.{ColumnAnalysis, SegmentAnalysis,
+ SegmentMetadataQuery}
+import org.apache.druid.spark.MAPPER
+import org.apache.druid.spark.configuration.{Configuration, DruidConfigurationKeys}
+import org.apache.druid.spark.mixins.Logging
+import org.jboss.netty.handler.codec.http.{HttpMethod, HttpResponseStatus}
+import org.joda.time.{Duration, Interval}
+
+import java.net.URL
+import java.util.{List => JList}
+import javax.ws.rs.core.MediaType
+import scala.collection.JavaConverters.{asScalaBufferConverter, mapAsJavaMapConverter,
+ mapAsScalaMapConverter, seqAsJavaListConverter}
+
+/**
+ * Going with SegmentMetadataQueries despite the significant overhead because there's no other way
+ * to get accurate information about Druid columns.
+ *
+ * This is pulled pretty directly from the druid-hadoop-input-format project on GitHub. There is
+ * likely substantial room for improvement.
+ *
+ * @param httpClient
+ * @param objectMapper
+ * @param hostAndPort
+ */
+class DruidClient(
+ val httpClient: HttpClient,
+ val objectMapper: ObjectMapper,
+ val hostAndPort: HostAndPort
+ ) extends Logging {
+ private val RETRY_COUNT = 5
+ private val RETRY_WAIT_SECONDS = 5
+ private val TIMEOUT_MILLISECONDS = 300000
+ private val druidBaseQueryURL: HostAndPort => String =
+ (hostAndPort: HostAndPort) => s"http://$hostAndPort/druid/v2/"
+
+ /**
+ * The SQL system catalog tables are incorrect for multivalue columns and don't have accurate
+ * type info, so we need to fall back to segmentMetadataQueries. Given a DATASOURCE and a range
+ * of INTERVALS to query over, return a map from column name to a tuple of
+ * (columnType, hasMultipleValues). Note that this is a very expensive operation over large
+ * numbers of segments. If possible, this method should only be called with the most granular
+ * starting and ending intervals instead of over a larger interval.
+ *
+ * @param dataSource The Druid dataSource to fetch the schema for.
+ * @param intervals The intervals to return the schema for.
+ * @return A map from column name to data type and whether or not the column is multi-value
+ * for the schema of DATASOURCE.
+ */
+ def getSchema(dataSource: String, intervals: List[Interval]): Map[String, (String, Boolean)] = {
+ val body = Druids.newSegmentMetadataQueryBuilder()
+ .dataSource(dataSource)
+ .intervals(intervals.asJava)
+ .analysisTypes(SegmentMetadataQuery.AnalysisType.SIZE)
+ .merge(true)
+ .context(Map[String, AnyRef](
+ "timeout" -> Int.box(TIMEOUT_MILLISECONDS)
+ ).asJava)
+ .build()
+ val response = sendRequestWithRetry(
+ druidBaseQueryURL(hostAndPort), RETRY_COUNT, Option(objectMapper.writeValueAsBytes(body))
+ )
+ val segments =
+ objectMapper.readValue[JList[SegmentAnalysis]](
+ response.getContent, new TypeReference[JList[SegmentAnalysis]]() {})
+ if (segments.size() == 0) {
+ throw new ISE(
+ s"No segments found for intervals [${intervals.mkString(",")}] on $dataSource"
+ )
+ }
+ // Since we're setting merge to true, there should only be one item in the list
+ if (segments.size() > 1) {
+ logWarn("Segment metadata response had more than one row, problem?")
+ }
+ segments.asScala.head.getColumns.asScala.map{ case (name: String, col: ColumnAnalysis) =>
Review comment:
[The analysis will error if a dimension has different types across two merged segments](https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/query/metadata/metadata/ColumnAnalysis.java#L138). The [returned column will have type `String` ](https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/query/metadata/metadata/ColumnAnalysis.java#L36) and so we'll silently widen the type to String. It's been a couple years since I wrote this piece, and yeah that is really non-obvious (I had to go code spelunking to figure it out). I'm inclined to add a comment to the code explaining what happens and then leave the current behavior, but I could also see just throwing an error back to the caller and refusing to continue.
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] juhoautio-rovio commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
juhoautio-rovio commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-872550994
@JulianJaffePinterest providing implicits like `.rangePartitionerAndWrite` looks nice indeed. And it looks familiar from what we did as well ;)
You mentioned `.rangePartitionerAndWrite` in https://github.com/apache/druid/pull/10920#issuecomment-849417236 but there doesn't seem to be anything about it in the [extension doc](https://github.com/JulianJaffePinterest/druid/blob/spark_druid_connector/docs/development/extensions-core/spark.md) yet. Would it be good to add? And are there actually more implicits than that (one for each partitioner type)?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] samarthjain commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
samarthjain commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-872396680
@JulianJaffePinterest - looks like there are a few more failures - https://travis-ci.com/github/apache/druid/jobs/520783859
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] samarthjain commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
samarthjain commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-880070097
> @samarthjain whenever you get a moment it's green 🙂
I have been out over the last 2 weeks. Taking a look now.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] tijoparacka commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
tijoparacka commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r702329050
##########
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
Review comment:
@JulianJaffePinterest , appreciate your effort to build something like this. Thank you !! . I am trying to use this spark connector . Just wanted to check if the - spark.md file is merged to sprak-druid-connector branch?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
JulianJaffePinterest commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-883156439
@jihoonson could you create a branch in the druid repo for me please?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] jihoonson commented on pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
jihoonson commented on pull request #10920:
URL: https://github.com/apache/druid/pull/10920#issuecomment-883624912
> > @jihoonson could you create a branch in the druid repo for me please?
>
> @JulianJaffePinterest Here you go - https://github.com/apache/druid/tree/spark_druid_connector
Sorry @JulianJaffePinterest, I missed your comment. @abhishekagarwal87 thank you for creating a branch.
> @jihoonson I don't have the ability to create a branch in this repo to open prs against, but I'm game to try. It's been difficult to get reviews from committers (it took two months and multiple emails to the dev list to get the first review for this diff) and so I'm hesitant to go down a path of needing to hunt reviews for many diffs, but if you think smaller prs will actually get reviews I can do so. (As an aside, if the Druid website's [list of committers](https://druid.apache.org/community/) is accurate only 1 of the last 10 prs tagged "Design Review" actually had approval from three committers in GitHub, so some process improvements may be necessary)
I'm fine with either working on a branch or merging this pr directly. Whatever the fastest way for merging this change would be best to me. Since @samarthjain already reviewed this PR, you need 2 more approvals from committers. So, it's up to you which way you choose. I suggested working on a branch because committers are usually busy and big PRs usually hard to get reviews.
For the design review process, I believe we are doing better than you described. I checked some of last PRs tagged design review, and they do have 3 approvals from committers, including the PR author himself. Perhaps the committer list on our website has gone stale. You can find the most recent list of committers in https://people.apache.org/phonebook.html?unix=druid. (We probably should add this link in our website instead of our own committer list)
> For documenting level of confidence in the various deep storage/metadata options, would you prefer an explicit table in the docs or in-line callouts (the current approach).
Oh, I didn't realize they are called out! Thank you for adding them. Perhaps I didn't read the doc carefully. But it might mean that it could be better if the callout was more obvious or more emphasized. I'm fine with either a table or callouts, but prefer whatever the most explicit way.
> I haven't updated .travis.yml beyond the checkstyle because the existing travis packages run the static checks and tests for the new module. In addition to unit tests, there's a light end-to-end test as well that writes segments out and then reads the created segments and confirms they match what was written. If there's actually a road for this pr, I can look into writing an integration test that requires an external spark cluster but obviously that won't be run as part of travis.
These tests sound really nice. I think it's OK to not have integration tests or not run those unit tests automatically in this PR, but we should do it as soon as possible. Do you have a follow-up plan for this?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] samarthjain commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
samarthjain commented on a change in pull request #10920:
URL: https://github.com/apache/druid/pull/10920#discussion_r613873991
##########
File path: extensions-core/spark-extensions/src/main/scala/org/apache/druid/spark/clients/DruidClient.scala
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.clients
+
+import com.fasterxml.jackson.core.`type`.TypeReference
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.common.net.HostAndPort
+import org.apache.druid.java.util.common.{ISE, StringUtils}
+import org.apache.druid.java.util.http.client.response.{StringFullResponseHandler,
+ StringFullResponseHolder}
+import org.apache.druid.java.util.http.client.{HttpClient, Request}
+import org.apache.druid.query.Druids
+import org.apache.druid.query.metadata.metadata.{ColumnAnalysis, SegmentAnalysis,
+ SegmentMetadataQuery}
+import org.apache.druid.spark.MAPPER
+import org.apache.druid.spark.configuration.{Configuration, DruidConfigurationKeys}
+import org.apache.druid.spark.mixins.Logging
+import org.jboss.netty.handler.codec.http.{HttpMethod, HttpResponseStatus}
+import org.joda.time.{Duration, Interval}
+
+import java.net.URL
+import java.util.{List => JList}
+import javax.ws.rs.core.MediaType
+import scala.collection.JavaConverters.{asScalaBufferConverter, mapAsJavaMapConverter,
+ mapAsScalaMapConverter, seqAsJavaListConverter}
+
+/**
+ * Going with SegmentMetadataQueries despite the significant overhead because there's no other way
+ * to get accurate information about Druid columns.
+ *
+ * This is pulled pretty directly from the druid-hadoop-input-format project on GitHub. There is
+ * likely substantial room for improvement.
+ *
+ * @param httpClient
+ * @param objectMapper
+ * @param hostAndPort
+ */
+class DruidClient(
+ val httpClient: HttpClient,
+ val objectMapper: ObjectMapper,
+ val hostAndPort: HostAndPort
+ ) extends Logging {
+ private val RETRY_COUNT = 5
+ private val RETRY_WAIT_SECONDS = 5
+ private val TIMEOUT_MILLISECONDS = 300000
+ private val druidBaseQueryURL: HostAndPort => String =
+ (hostAndPort: HostAndPort) => s"http://$hostAndPort/druid/v2/"
+
+ /**
+ * The SQL system catalog tables are incorrect for multivalue columns and don't have accurate
+ * type info, so we need to fall back to segmentMetadataQueries. Given a DATASOURCE and a range
+ * of INTERVALS to query over, return a map from column name to a tuple of
+ * (columnType, hasMultipleValues). Note that this is a very expensive operation over large
+ * numbers of segments. If possible, this method should only be called with the most granular
+ * starting and ending intervals instead of over a larger interval.
+ *
+ * @param dataSource The Druid dataSource to fetch the schema for.
+ * @param intervals The intervals to return the schema for.
+ * @return A map from column name to data type and whether or not the column is multi-value
+ * for the schema of DATASOURCE.
+ */
+ def getSchema(dataSource: String, intervals: List[Interval]): Map[String, (String, Boolean)] = {
+ val body = Druids.newSegmentMetadataQueryBuilder()
+ .dataSource(dataSource)
+ .intervals(intervals.asJava)
+ .analysisTypes(SegmentMetadataQuery.AnalysisType.SIZE)
+ .merge(true)
+ .context(Map[String, AnyRef](
+ "timeout" -> Int.box(TIMEOUT_MILLISECONDS)
+ ).asJava)
+ .build()
+ val response = sendRequestWithRetry(
+ druidBaseQueryURL(hostAndPort), RETRY_COUNT, Option(objectMapper.writeValueAsBytes(body))
+ )
+ val segments =
+ objectMapper.readValue[JList[SegmentAnalysis]](
+ response.getContent, new TypeReference[JList[SegmentAnalysis]]() {})
+ if (segments.size() == 0) {
+ throw new ISE(
+ s"No segments found for intervals [${intervals.mkString(",")}] on $dataSource"
+ )
+ }
+ // Since we're setting merge to true, there should only be one item in the list
+ if (segments.size() > 1) {
+ logWarn("Segment metadata response had more than one row, problem?")
+ }
+ segments.asScala.head.getColumns.asScala.map{ case (name: String, col: ColumnAnalysis) =>
Review comment:
I couldn't find it in the docs, but what happens if segments have different schemas. For ex - a dimension maybe a string in one segment and a double in another. Should we set `merge` to `false` and give precedence to the latest segment when determining a column's type and other information.
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] JulianJaffePinterest commented on a change in pull request #10920: Spark Direct Readers and Writers for Druid.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org