Skip to content

Commit e67ff5d

Browse files
committed
Add explicit tests for aggregate hash maps and other minor fixs.
1 parent b9a4268 commit e67ff5d

File tree

5 files changed

+98
-6
lines changed

5 files changed

+98
-6
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ case class HashAggregateExec(
288288
private var isVectorizedHashMapEnabled: Boolean = false
289289
private var isRowBasedHashMapEnabled: Boolean = false
290290
// auxiliary flag, true if any of two above is true
291-
private var isFastHashMapEnabled: Boolean = false
291+
private var isFastHashMapEnabled: Boolean = isVectorizedHashMapEnabled || isRowBasedHashMapEnabled
292292

293293
// The name for UnsafeRow HashMap
294294
private var hashMapTerm: String = _
@@ -517,18 +517,18 @@ case class HashAggregateExec(
517517
sqlContext.conf.enforceFastAggHashMapImpl match {
518518
case "rowbased" =>
519519
if (!enableRowBasedHashMap(ctx)) {
520-
if (modes.forall(mode => mode == Partial || mode == PartialMerge)) {
521-
logWarning("spark.sql.codegen.aggregate.map.enforce.impl is set to rowbased, but "
520+
if (modes.forall(mode => mode == Partial || mode == PartialMerge) && !Utils.isTesting) {
521+
logWarning("spark.sql.codegen.aggregate.map.enforce.impl is set to rowbased, but"
522522
+ " current version of codegened row-based hashmap does not support this aggregate.")
523523
}
524524
} else {
525525
isRowBasedHashMapEnabled = true
526526
}
527527
case "vectorized" =>
528528
if (!enableVectorizedHashMap(ctx)) {
529-
if (modes.forall(mode => mode == Partial || mode == PartialMerge)) {
530-
logWarning("spark.sql.codegen.aggregate.map.enforce.impl is set to vectorized, but "
531-
+ " current version of codegened row-based hashmap does not support this aggregate.")
529+
if (modes.forall(mode => mode == Partial || mode == PartialMerge) && !Utils.isTesting) {
530+
logWarning("spark.sql.codegen.aggregate.map.enforce.impl is set to vectorized, but"
531+
+ " current version of codegened vectorized hashmap does not support this aggregate.")
532532
}
533533
} else {
534534
isVectorizedHashMapEnabled = true
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.sql
19+
20+
import org.apache.spark.sql.functions._
21+
import org.apache.spark.sql.types.DecimalType
22+
23+
abstract class AggregateHashMapSuite extends DataFrameAggregateSuite {
24+
import testImplicits._
25+
26+
protected def setAggregateHashMapImpl(): Unit
27+
28+
protected override def beforeAll(): Unit = {
29+
setAggregateHashMapImpl()
30+
sparkConf.set("spark.sql.codegen.fallback", "false")
31+
super.beforeAll()
32+
}
33+
34+
test("SQL decimal test") {
35+
checkAnswer(
36+
decimalData.groupBy('a cast DecimalType(10, 2)).agg(avg('b cast DecimalType(10, 2))),
37+
Seq(Row(new java.math.BigDecimal(1.0), new java.math.BigDecimal(1.5)),
38+
Row(new java.math.BigDecimal(2.0), new java.math.BigDecimal(1.5)),
39+
Row(new java.math.BigDecimal(3.0), new java.math.BigDecimal(1.5))))
40+
}
41+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.sql
19+
20+
class RowBasedAggregateHashMapSuite extends AggregateHashMapSuite {
21+
22+
protected def setAggregateHashMapImpl() {
23+
sparkConf.set("spark.sql.codegen.aggregate.map.enforce.impl", "rowbased")
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.sql
19+
20+
class VectorizedAggregateHashMapSuite extends AggregateHashMapSuite {
21+
22+
protected def setAggregateHashMapImpl() {
23+
sparkConf.set("spark.sql.codegen.aggregate.map.enforce.impl", "vectorized")
24+
}
25+
}

sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestData.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import java.nio.charset.StandardCharsets
2121

2222
import org.apache.spark.rdd.RDD
2323
import org.apache.spark.sql.{DataFrame, SparkSession, SQLContext, SQLImplicits}
24+
import org.apache.spark.sql.types.Decimal
2425

2526
/**
2627
* A collection of sample data used in SQL tests.

0 commit comments

Comments
 (0)