wangyum commented on issue #25158: [SPARK-28395][SQL] Division operator support 
integral division
URL: https://github.com/apache/spark/pull/25158#issuecomment-511642418
 
 
   Benchmark and benchmark result:
   ```scala
   cat <<EOF > 
sql/core/src/test/scala/org/apache/spark/sql/execution/benchmark/SPARK_28395_Benchmark.scala
   /*
    * 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.internal.SQLConf
   
   /**
    * To run this benchmark:
    *   build/sbt "sql/test:runMain 
org.apache.spark.sql.execution.benchmark.SPARK_28395_Benchmark"
    */
   object SPARK_28395_Benchmark extends SqlBasedBenchmark {
   
     override def runBenchmarkSuite(mainArgs: Array[String]): Unit = {
   
       val title = "Benchmark SPARK-28395"
       runBenchmark(title) {
         withTempPath { dir =>
           val N = 6000000
           val df = spark.range(4096000)
   
           df.selectExpr("id as id1", "cast(id % 999999 as bigint) as id2")
             .write.mode("overwrite").parquet(dir.getCanonicalPath)
   
           val benchmark = new Benchmark(title, N, minNumIters = 5, output = 
output)
           Seq(false, true).foreach { integralDivision =>
             val name = if (integralDivision) "Integral division" else 
"Fractional division"
             benchmark.addCase(name) { _ =>
               withSQLConf(SQLConf.PREFER_INTEGRAL_DIVISION.key -> 
integralDivision.toString) {
                 spark.read.parquet(dir.getCanonicalPath).selectExpr("id1 / 
id2").collect()
               }
             }
           }
           benchmark.run()
         }
       }
     }
   }
   
   EOF
   ```
   
   ```
   [info] Java HotSpot(TM) 64-Bit Server VM 1.8.0_191-b12 on Mac OS X 10.13.6
   [info] Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
   [info] Benchmark SPARK-28395:                    Best Time(ms)   Avg 
Time(ms)   Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
   [info] 
------------------------------------------------------------------------------------------------------------------------
   [info] Fractional division                                1440           
2100         977          4.2         240.0       1.0X
   [info] Integral division                                  1115           
1252         142          5.4         185.9       1.3X
   ```
   ```
   [info] Java HotSpot(TM) 64-Bit Server VM 1.8.0_211-b12 on Linux 
3.10.0-957.1.3.el7.x86_64
   [info] Intel Core Processor (Broadwell)
   [info] Benchmark SPARK-28395:                    Best Time(ms)   Avg 
Time(ms)   Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
   [info] 
------------------------------------------------------------------------------------------------------------------------
   [info] Fractional division                                1818           
2878         NaN          3.3         303.0       1.0X
   [info] Integral division                                  1352           
1516         169          4.4         225.4       1.3X
   ```

----------------------------------------------------------------
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]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to