Skip to content

Commit

Permalink
Spark 3.3: Fix custom options (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
pan3793 committed Apr 27, 2023
1 parent dbee774 commit 63c9ded
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import xenon.clickhouse.exception.CHException
import xenon.clickhouse.spec._

import java.time.{LocalDateTime, ZoneId}
import java.util.{HashMap => JHashMap}
import scala.collection.JavaConverters._

trait ClickHouseHelper extends Logging {
Expand All @@ -47,9 +48,10 @@ trait ClickHouseHelper extends Logging {
def buildNodeSpec(options: CaseInsensitiveStringMap): NodeSpec = {
val clientOpts = options.asScala
.filterKeys(_.startsWith(CATALOG_PROP_OPTION_PREFIX))
.map { case (k, v) => k.substring(CATALOG_PROP_OPTION_PREFIX.length) -> v }
.toMap
.filterKeys { key =>
val clientOpt = key.substring(CATALOG_PROP_OPTION_PREFIX.length)
val ignore = CATALOG_PROP_IGNORE_OPTIONS.contains(clientOpt)
val ignore = CATALOG_PROP_IGNORE_OPTIONS.contains(key)
if (ignore) {
log.warn(s"Ignore configuration $key.")
}
Expand All @@ -64,7 +66,7 @@ trait ClickHouseHelper extends Logging {
username = options.getOrDefault(CATALOG_PROP_USER, "default"),
password = options.getOrDefault(CATALOG_PROP_PASSWORD, ""),
database = options.getOrDefault(CATALOG_PROP_DATABASE, "default"),
options = clientOpts.asJava
options = new JHashMap(clientOpts.asJava)
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed 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
*
* https://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.spark.sql.clickhouse

import org.apache.spark.sql.util.CaseInsensitiveStringMap
import org.scalatest.funsuite.AnyFunSuite
import xenon.clickhouse.ClickHouseHelper

import scala.collection.JavaConverters._

class ClickHouseHelperSuite extends AnyFunSuite with ClickHouseHelper {

test("buildNodeSpec") {
val nodeSpec = buildNodeSpec(
new CaseInsensitiveStringMap(Map(
"database" -> "testing",
"option.database" -> "production",
"option.ssl" -> "true"
).asJava)
)
assert(nodeSpec.database === "testing")
assert(nodeSpec.options.get("ssl") === "true")
}
}

0 comments on commit 63c9ded

Please sign in to comment.