Skip to content

Commit 0e75965

Browse files
committed
int_to_binary
1 parent acee970 commit 0e75965

File tree

2 files changed

+16
-34
lines changed

2 files changed

+16
-34
lines changed

spark/src/main/scala/org/apache/comet/expressions/CometCast.scala

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,8 @@ object CometCast extends CometExpressionSerde[Cast] with CometExprShim {
276276
Compatible()
277277
case DataTypes.FloatType | DataTypes.DoubleType | _: DecimalType =>
278278
Compatible()
279-
case DataTypes.BinaryType =>
280-
if (evalMode == CometEvalMode.LEGACY) {
281-
Compatible()
282-
} else {
283-
Unsupported(
284-
Some(s"Spark does not support byte to binary conversion in ${evalMode} eval mode"))
285-
}
279+
case DataTypes.BinaryType if (evalMode == CometEvalMode.LEGACY) =>
280+
Compatible()
286281
case _ =>
287282
unsupported(DataTypes.ByteType, toType)
288283
}
@@ -295,13 +290,8 @@ object CometCast extends CometExpressionSerde[Cast] with CometExprShim {
295290
Compatible()
296291
case DataTypes.FloatType | DataTypes.DoubleType | _: DecimalType =>
297292
Compatible()
298-
case DataTypes.BinaryType =>
299-
if (evalMode == CometEvalMode.LEGACY) {
300-
Compatible()
301-
} else {
302-
Unsupported(
303-
Some(s"Spark does not support short to binary conversion in ${evalMode} eval mode"))
304-
}
293+
case DataTypes.BinaryType if (evalMode == CometEvalMode.LEGACY) =>
294+
Compatible()
305295
case _ =>
306296
unsupported(DataTypes.ShortType, toType)
307297
}
@@ -316,13 +306,7 @@ object CometCast extends CometExpressionSerde[Cast] with CometExprShim {
316306
Compatible()
317307
case _: DecimalType =>
318308
Compatible()
319-
case DataTypes.BinaryType =>
320-
if (evalMode == CometEvalMode.LEGACY) {
321-
Compatible()
322-
} else {
323-
Unsupported(
324-
Some(s"Spark does not support int to binary conversion in ${evalMode} eval mode"))
325-
}
309+
case DataTypes.BinaryType if (evalMode == CometEvalMode.LEGACY) => Compatible()
326310
case _ =>
327311
unsupported(DataTypes.IntegerType, toType)
328312
}
@@ -337,13 +321,7 @@ object CometCast extends CometExpressionSerde[Cast] with CometExprShim {
337321
Compatible()
338322
case _: DecimalType =>
339323
Compatible()
340-
case DataTypes.BinaryType =>
341-
if (evalMode == CometEvalMode.LEGACY) {
342-
Compatible()
343-
} else {
344-
Unsupported(
345-
Some(s"Spark does not support long to binary conversion in ${evalMode} eval mode"))
346-
}
324+
case DataTypes.BinaryType if (evalMode == CometEvalMode.LEGACY) => Compatible()
347325
case _ =>
348326
unsupported(DataTypes.LongType, toType)
349327
}

spark/src/test/scala/org/apache/comet/CometCastSuite.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
212212
castTest(
213213
generateBytes(),
214214
DataTypes.BinaryType,
215-
hasIncompatibleType = usingParquetExecWithIncompatTypes, testAnsi = false, testTry = false)
215+
hasIncompatibleType = usingParquetExecWithIncompatTypes,
216+
testAnsi = false,
217+
testTry = false)
216218
}
217219

218220
ignore("cast ByteType to TimestampType") {
@@ -287,7 +289,9 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
287289
castTest(
288290
generateShorts(),
289291
DataTypes.BinaryType,
290-
hasIncompatibleType = usingParquetExecWithIncompatTypes, testAnsi = false, testTry = false)
292+
hasIncompatibleType = usingParquetExecWithIncompatTypes,
293+
testAnsi = false,
294+
testTry = false)
291295
}
292296

293297
ignore("cast ShortType to TimestampType") {
@@ -397,7 +401,7 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
397401

398402
test("cast LongType to BinaryType") {
399403
// Spark does not support ANSI or Try mode
400-
castTest(generateLongs(), DataTypes.BinaryType , testAnsi = false, testTry = false)
404+
castTest(generateLongs(), DataTypes.BinaryType, testAnsi = false, testTry = false)
401405
}
402406

403407
ignore("cast LongType to TimestampType") {
@@ -1348,7 +1352,7 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
13481352
checkSparkAnswerAndOperator(df)
13491353
}
13501354

1351-
if (testTry){
1355+
if (testTry) {
13521356
// try_cast() should always return null for invalid inputs
13531357
val df2 =
13541358
data.select(col("a"), col("a").try_cast(toType)).orderBy(col("a"))
@@ -1414,9 +1418,9 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
14141418
}
14151419

14161420
// try_cast() should always return null for invalid inputs
1417-
if (testTry){
1421+
if (testTry) {
14181422
val df2 =
1419-
data.select(col("a"), col("a").cast(toType)).orderBy(col("a"))
1423+
data.select(col("a"), col("a").try_cast(toType)).orderBy(col("a"))
14201424
if (hasIncompatibleType) {
14211425
checkSparkAnswer(df2)
14221426
} else {

0 commit comments

Comments
 (0)