-
Notifications
You must be signed in to change notification settings - Fork 28.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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 <[email protected]> Closes #20245 from maropu/SPARK-21213-FOLLOWUP.
- Loading branch information
1 parent
ba891ec
commit 0066d6f
Showing
2 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
sql/core/src/test/scala/org/apache/spark/sql/execution/command/CommandUtilsSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |