GideonPotok commented on code in PR #45453: URL: https://github.com/apache/spark/pull/45453#discussion_r1540047223
########## sql/core/benchmarks/CollationBenchmark-results.txt: ########## @@ -0,0 +1,26 @@ +OpenJDK 64-Bit Server VM 17.0.10+7-LTS on Linux 6.5.0-1016-azure +AMD EPYC 7763 64-Core Processor +filter df column with collation: Best Time(ms) Avg Time(ms) Stdev(ms) Rate(M/s) Per Row(ns) Relative +----------------------------------------------------------------------------------------------------------------------------------- +filter df column with collation - UNICODE_CI 403 463 39 0.0 20147470.0 1.0X +filter df column with collation - UNICODE 187 223 37 0.0 9339586.0 2.2X +filter df column with collation - UTF8_BINARY_LCASE 426 434 7 0.0 21300903.4 0.9X +filter df column with collation - UTF8_BINARY 188 199 5 0.0 9403169.1 2.1X + +OpenJDK 64-Bit Server VM 17.0.10+7-LTS on Linux 6.5.0-1016-azure +AMD EPYC 7763 64-Core Processor +collation unit benchmarks: Best Time(ms) Avg Time(ms) Stdev(ms) Rate(M/s) Per Row(ns) Relative +------------------------------------------------------------------------------------------------------------------------ +equalsFunction - UTF8_BINARY 0 0 0 10.4 96.6 1.0X +collator.compare - UTF8_BINARY 4 4 0 0.3 3717.9 0.0X +hashFunction - UTF8_BINARY 0 0 0 42.0 23.8 4.1X +equalsFunction - UTF8_BINARY_LCASE 5 5 0 0.2 5014.7 0.0X Review Comment: Done! ########## sql/core/src/test/scala/org/apache/spark/sql/execution/benchmark/CollationBenchmark.scala: ########## @@ -0,0 +1,117 @@ +/* + * 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.spark.sql.execution.benchmark + +import org.apache.spark.benchmark.Benchmark +import org.apache.spark.sql.DataFrame +import org.apache.spark.sql.catalyst.util.CollationFactory +import org.apache.spark.sql.functions._ +import org.apache.spark.unsafe.types.UTF8String + +/** + * Benchmark to measure performance for comparisons between collated strings. To run this benchmark: + * {{{ + * 1. without sbt: + * bin/spark-submit --class <this class> + * --jars <spark core test jar>,<spark catalyst test jar> <spark sql test jar> + * 2. build/sbt "sql/Test/runMain org.apache.spark.sql.execution.benchmark.CollationBenchmark" + * 3. generate result: + * SPARK_GENERATE_BENCHMARK_FILES=1 build/sbt "sql/Test/runMain <this class>" + * Results will be written to "benchmarks/CollationBenchmark-results.txt". + * }}} + */ + +object CollationBenchmark extends SqlBasedBenchmark { + private val collationTypes = Seq("UTF8_BINARY_LCASE", "UNICODE", "UTF8_BINARY", "UNICODE_CI") + + def generateSeqInput(n: Long): Seq[UTF8String] = { + val input = Seq("ABC", "ABC", "aBC", "aBC", "abc", "abc", "DEF", "DEF", "def", + "def", "GHI", "ghi", + "JKL", "jkl", "MNO", "mno", "PQR", "pqr", "STU", "stu", "VWX", "vwx", "YZ", + "ABC", "ABC", "aBC", "aBC", "abc", "abc", "DEF", "DEF", "def", "def", "GHI", "ghi", + "JKL", "jkl", "MNO", "mno", "PQR", "pqr", "STU", "stu", "VWX", "vwx", "YZ") + .map(UTF8String.fromString) + val inputLong: Seq[UTF8String] = (0L until n).map(i => input(i.toInt % input.size)) + inputLong + } + + private def getDataFrame(strings: Seq[String]): DataFrame = { + val asPairs = strings.sliding(2, 1).toSeq.map { + case Seq(s1, s2) => (s1, s2) + } + val d = spark.createDataFrame(asPairs).toDF("s1", "s2") + d + } + + private def generateDataframeInput(l: Long): DataFrame = { + getDataFrame(generateSeqInput(l).map(_.toString)) + } + + def benchmarkUTFString(collationTypes: Seq[String], utf8Strings: Seq[UTF8String]): Unit = { + val sublistStrings = utf8Strings + + val benchmark = new Benchmark("collation unit benchmarks", utf8Strings.size, output = output) + collationTypes.foreach(collationType => { + val collation = CollationFactory.fetchCollation(collationType) + benchmark.addCase(s"equalsFunction - $collationType") { _ => + sublistStrings.foreach(s1 => + utf8Strings.foreach(s => + collation.equalsFunction(s, s1).booleanValue() + ) + ) + } + benchmark.addCase(s"collator.compare - $collationType") { _ => + sublistStrings.foreach(s1 => + utf8Strings.foreach(s => + collation.comparator.compare(s, s1) + ) + ) + } + benchmark.addCase(s"hashFunction - $collationType") { _ => + sublistStrings.foreach(_ => + utf8Strings.foreach(s => + collation.hashFunction.applyAsLong(s) + ) + ) + } + } + ) + benchmark.run() + } + + def benchmarkFilterEqual(collationTypes: Seq[String], + dfUncollated: DataFrame): Unit = { + val benchmark = + new Benchmark("filter df column with collation", dfUncollated.count(), output = output) + collationTypes.foreach(collationType => { + val dfCollated = dfUncollated.selectExpr( + s"collate(s2, '$collationType') as k2_$collationType", + s"collate(s1, '$collationType') as k1_$collationType") + benchmark.addCase(s"filter df column with collation - $collationType") { _ => + dfCollated.where(col(s"k1_$collationType") === col(s"k2_$collationType")) + .queryExecution.executedPlan.executeCollect() Review Comment: K. 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. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org