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: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
