You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by li...@apache.org on 2018/01/13 21:39:46 UTC
spark git commit: [SPARK-21213][SQL][FOLLOWUP] Use compatible types
for comparisons in compareAndGetNewStats
Repository: spark
Updated Branches:
refs/heads/master ba891ec99 -> 0066d6f6f
[SPARK-21213][SQL][FOLLOWUP] Use compatible types for comparisons in compareAndGetNewStats
## What changes were proposed in this pull request?
This pr fixed code to compare values in `compareAndGetNewStats`.
The test below fails in the current master;
```
val oldStats2 = CatalogStatistics(sizeInBytes = BigInt(Long.MaxValue) * 2)
val newStats5 = CommandUtils.compareAndGetNewStats(
Some(oldStats2), newTotalSize = BigInt(Long.MaxValue) * 2, None)
assert(newStats5.isEmpty)
```
## How was this patch tested?
Added some tests in `CommandUtilsSuite`.
Author: Takeshi Yamamuro <ya...@apache.org>
Closes #20245 from maropu/SPARK-21213-FOLLOWUP.
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/0066d6f6
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/0066d6f6
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/0066d6f6
Branch: refs/heads/master
Commit: 0066d6f6fa604817468471832968d4339f71c5cb
Parents: ba891ec
Author: Takeshi Yamamuro <ya...@apache.org>
Authored: Sun Jan 14 05:39:38 2018 +0800
Committer: gatorsmile <ga...@gmail.com>
Committed: Sun Jan 14 05:39:38 2018 +0800
----------------------------------------------------------------------
.../sql/execution/command/CommandUtils.scala | 4 +-
.../execution/command/CommandUtilsSuite.scala | 56 ++++++++++++++++++++
2 files changed, 58 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/0066d6f6/sql/core/src/main/scala/org/apache/spark/sql/execution/command/CommandUtils.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/CommandUtils.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/CommandUtils.scala
index 1a0d67f..c270486 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/CommandUtils.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/CommandUtils.scala
@@ -116,8 +116,8 @@ object CommandUtils extends Logging {
oldStats: Option[CatalogStatistics],
newTotalSize: BigInt,
newRowCount: Option[BigInt]): Option[CatalogStatistics] = {
- val oldTotalSize = oldStats.map(_.sizeInBytes.toLong).getOrElse(-1L)
- val oldRowCount = oldStats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L)
+ val oldTotalSize = oldStats.map(_.sizeInBytes).getOrElse(BigInt(-1))
+ val oldRowCount = oldStats.flatMap(_.rowCount).getOrElse(BigInt(-1))
var newStats: Option[CatalogStatistics] = None
if (newTotalSize >= 0 && newTotalSize != oldTotalSize) {
newStats = Some(CatalogStatistics(sizeInBytes = newTotalSize))
http://git-wip-us.apache.org/repos/asf/spark/blob/0066d6f6/sql/core/src/test/scala/org/apache/spark/sql/execution/command/CommandUtilsSuite.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/CommandUtilsSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/CommandUtilsSuite.scala
new file mode 100644
index 0000000..f3e1518
--- /dev/null
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/CommandUtilsSuite.scala
@@ -0,0 +1,56 @@
+/*
+ * 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.command
+
+import org.apache.spark.SparkFunSuite
+import org.apache.spark.sql.catalyst.catalog.CatalogStatistics
+
+class CommandUtilsSuite extends SparkFunSuite {
+
+ test("Check if compareAndGetNewStats returns correct results") {
+ val oldStats1 = CatalogStatistics(sizeInBytes = 10, rowCount = Some(100))
+ val newStats1 = CommandUtils.compareAndGetNewStats(
+ Some(oldStats1), newTotalSize = 10, newRowCount = Some(100))
+ assert(newStats1.isEmpty)
+ val newStats2 = CommandUtils.compareAndGetNewStats(
+ Some(oldStats1), newTotalSize = -1, newRowCount = None)
+ assert(newStats2.isEmpty)
+ val newStats3 = CommandUtils.compareAndGetNewStats(
+ Some(oldStats1), newTotalSize = 20, newRowCount = Some(-1))
+ assert(newStats3.isDefined)
+ newStats3.foreach { stat =>
+ assert(stat.sizeInBytes === 20)
+ assert(stat.rowCount.isEmpty)
+ }
+ val newStats4 = CommandUtils.compareAndGetNewStats(
+ Some(oldStats1), newTotalSize = -1, newRowCount = Some(200))
+ assert(newStats4.isDefined)
+ newStats4.foreach { stat =>
+ assert(stat.sizeInBytes === 10)
+ assert(stat.rowCount.isDefined && stat.rowCount.get === 200)
+ }
+ }
+
+ test("Check if compareAndGetNewStats can handle large values") {
+ // Tests for large values
+ val oldStats2 = CatalogStatistics(sizeInBytes = BigInt(Long.MaxValue) * 2)
+ val newStats5 = CommandUtils.compareAndGetNewStats(
+ Some(oldStats2), newTotalSize = BigInt(Long.MaxValue) * 2, None)
+ assert(newStats5.isEmpty)
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org