Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.spark.sql.execution

import java.sql.{Date, Timestamp}
import java.time.{Duration, Period}

import org.json4s.DefaultFormats
import org.json4s.JsonDSL._
Expand All @@ -43,6 +44,8 @@ abstract class BaseScriptTransformationSuite extends SparkPlanTest with SQLTestU
import testImplicits._
import ScriptTransformationIOSchema._

protected def defaultSerDe(): String

protected val uncaughtExceptionHandler = new TestUncaughtExceptionHandler

private var defaultUncaughtExceptionHandler: Thread.UncaughtExceptionHandler = _
Expand Down Expand Up @@ -599,6 +602,37 @@ abstract class BaseScriptTransformationSuite extends SparkPlanTest with SQLTestU
'e.cast("string")).collect())
}
}

test("SPARK-35220: DayTimeIntervalType/YearMonthIntervalType show different " +
"between hive serde and row format delimited\t") {
assume(TestUtils.testCommandAvailable("/bin/bash"))
withTempView("v") {
val df = Seq(
(Duration.ofDays(1), Period.ofMonths(10))
).toDF("a", "b")
df.createTempView("v")

if (defaultSerDe == "hive-serde") {
checkAnswer(sql(
"""
|SELECT TRANSFORM(a, b)
| USING 'cat' AS (a, b)
|FROM v
|""".stripMargin),
identity,
Row("1 00:00:00.000000000", "0-10") :: Nil)
} else {
checkAnswer(sql(
"""
|SELECT TRANSFORM(a, b)
| USING 'cat' AS (a, b)
|FROM v
|""".stripMargin),
identity,
Row("INTERVAL '1 00:00:00' DAY TO SECOND", "INTERVAL '0-10' YEAR TO MONTH") :: Nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the spark-sql shell and df.show have different formats for intervals?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the spark-sql shell and df.show have different formats for intervals?

Yea, have this problem too, since spark sql follow hive format. What should I to do next?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is interval format the only difference between hive format and spark cast?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is interval format the only difference between hive format and spark cast?

Yea, ANSI_STYLE and HIVE_STYLE

Copy link
Contributor

@cloud-fan cloud-fan Apr 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should have a new Expression ToHiveString and use it in df.show and TRANSFORM, so that they are consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should have a new Expression ToHiveString and use it in df.show and TRANSFORM, so that they are consistent.

Yea, create a ticket https://issues.apache.org/jira/browse/SPARK-35228

}
}
}
}

case class ExceptionInjectingOperator(child: SparkPlan) extends UnaryExecNode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import org.apache.spark.sql.test.SharedSparkSession
class SparkScriptTransformationSuite extends BaseScriptTransformationSuite with SharedSparkSession {
import testImplicits._

override protected def defaultSerDe(): String = "row-format-delimited"

override def createScriptTransformationExec(
script: String,
output: Seq[Attribute],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class HiveScriptTransformationSuite extends BaseScriptTransformationSuite with T

import ScriptTransformationIOSchema._

override protected def defaultSerDe(): String = "hive-serde"

override def createScriptTransformationExec(
script: String,
output: Seq[Attribute],
Expand Down