-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support float/double castings for ORC reading [databricks] #6319
Support float/double castings for ORC reading [databricks] #6319
Conversation
* Impl: float/double -> double/float, bool, int8/16/32/64, timestamp * There are some precision issue when casting float/double to string * IT Test: need a function float_gen with range [a, b] Signed-off-by: sinkinben <sinkinben@outlook.com>
Signed-off-by: sinkinben <sinkinben@outlook.com>
Signed-off-by: sinkinben <sinkinben@outlook.com>
# TODO: merge test_casting_from_float and test_casting_from_double into one test | ||
# TODO: Need a float_gen with range [a, b], if float/double >= 1e13, then float/double -> timestamp will overflow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these TODO comments still need addressing in this PR, or require follow-on issues to be filed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these TODO comments still need addressing in this PR, or require follow-on issues to be filed?
Yep, I plan to address these TODOs in this PR.
assert_gpu_and_cpu_are_equal_collect( | ||
lambda spark: spark.read.schema(schema_str).orc(orc_path) | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: too many blank lines between tests. I believe the convention is to have 2, although we do not do this consistently in our tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Signed-off-by: sinkinben <sinkinben@outlook.com>
Signed-off-by: sinkinben <sinkinben@outlook.com>
For the precision problem of And in sql-cast, it's controlled by a conf: lazy val isCastFloatToStringEnabled: Boolean = get(ENABLE_CAST_FLOAT_TO_STRING)
val ENABLE_CAST_FLOAT_TO_STRING = conf("spark.rapids.sql.castFloatToString.enabled")
.doc("Casting from floating point types to string on the GPU returns results that have " +
"a different precision than the default results of Spark.")
.booleanConf
.createWithDefault(true) In private def recursiveTagExprForGpuCheck(...) {
...
case (_: FloatType | _: DoubleType, _: StringType) if !conf.isCastFloatToStringEnabled =>
willNotWorkOnGpu("the GPU will use different precision than Java's toString method when " +
"converting floating point data types to strings and this can produce results that " +
"differ from the default behavior in Spark. To enable this operation on the GPU, set" +
s" ${RapidsConf.ENABLE_CAST_FLOAT_TO_STRING} to true.")
} I think we can handle the precision problem of |
…ading. Signed-off-by: sinkinben <sinkinben@outlook.com>
sql-plugin/src/main/scala/com/nvidia/spark/rapids/GpuOrcScan.scala
Outdated
Show resolved
Hide resolved
sql-plugin/src/main/scala/com/nvidia/spark/rapids/GpuOrcScan.scala
Outdated
Show resolved
Hide resolved
sql-plugin/src/main/scala/com/nvidia/spark/rapids/GpuOrcScan.scala
Outdated
Show resolved
Hide resolved
sql-plugin/src/main/scala/com/nvidia/spark/rapids/RapidsConf.scala
Outdated
Show resolved
Hide resolved
* Fixed bug when all elements in ColumnVector are null * Updated IT tests Signed-off-by: sinkinben <sinkinben@outlook.com>
Signed-off-by: sinkinben <sinkinben@outlook.com>
@@ -864,6 +864,16 @@ object RapidsConf { | |||
.booleanConf | |||
.createWithDefault(true) | |||
|
|||
val ENABLE_ORC_FLOAT_TYPES_TO_STRING = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some docs to this that indicate what will happen if we run into this situation. For most configs when we are in this kind of a situation we fall back to the CPU, but here we will throw an exception and the job will fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have updated this in config.md
.
// We let a conf 'spark.rapids.sql.format.orc.floatTypesToString.enable' to control it's | ||
// enable or not. | ||
case (DType.FLOAT32 | DType.FLOAT64, DType.STRING) => | ||
GpuCast.castFloatingTypeToString(col) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please file a follow on issue for us to go back an see what we can do to fix this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please file a follow on issue for us to go back an see what we can do to fix this?
Ok, after merging this, I will file an issue to describe this problem.
|
||
# When casting float/double to double/float, we need to compare values of GPU with CPU | ||
# in an approximate way. | ||
@pytest.mark.approximate_float |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we off if we don't do this? It feels odd that we would get a different answer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we off if we don't do this? It feels odd that we would get a different answer.
Yep, it's okay to remove approximate_float
, we can still pass the test.
But I think we should pay attention to the method of comparing float types numbers whether if they are equal.
For example,
scala> var k = (3.14).toFloat
var k: Float = 3.14
scala> k.toDouble
val res3: Double = 3.140000104904175
I don't know whether if the conversion float -> double
in GPU is same as CPU.
We should check two float types numbers if they're equal via abs(val1 - val2) < EPSLION
, where EPSILON
is the allowable accuracy error.
…STRING Signed-off-by: sinkinben <sinkinben@outlook.com>
Signed-off-by: sinkinben <sinkinben@outlook.com>
Signed-off-by: sinkinben <sinkinben@outlook.com>
build |
Close #6291, (which is sub-issue of #6149 ).
To implement casting
float/double
to{bool, integer types, double/float, string, timestamp}
.double
is also known asfloat64
. Integer types includeint8/16/32/64
.Implementation
float/double -> {bool, int8/16/32/64}
2. Convert the ColumnVector to Long type
3. Down cast long to the target integral type.
float <-> double
ColumnView.castTo
.2. When casting
double -> float
, ifdouble
value is greater thanFLOAT_MAX
, then mark this value withInfinite
.float/double -> string
2. Added a config item
spark.rapids.sql.format.orc.floatTypesToString.enable
(default value is true) to control whether if we can castfloat/double -> string
while reading ORC.float/double -> timestamp
float/double
values are in seconds.2. If
ROUND(val * 1000) > LONG_MAX
, replace it with null, e.g.val = 1e20
. Otherwise, keep these values, and convert them into milli-seonds vector.3. Multiply 1000, convert them into micro-seconds vector. Pay attention to long(INT64) overflow here, since timestamp is stored in
INT64
.