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 @@ -168,10 +168,6 @@ public static TColumnValue toTColumnValue(TypeDescriptor typeDescriptor, Object
case TIMESTAMP_TYPE:
// SPARK-31859, SPARK-31861: converted to string already in SparkExecuteStatementOperation
return stringValue((String)value);
case INTERVAL_YEAR_MONTH_TYPE:
return stringValue((HiveIntervalYearMonth) value);
case INTERVAL_DAY_TIME_TYPE:
return stringValue((HiveIntervalDayTime) value);
case DECIMAL_TYPE:
String plainStr = value == null ? null : ((BigDecimal)value).toPlainString();
return stringValue(plainStr);
Expand All @@ -183,6 +179,8 @@ public static TColumnValue toTColumnValue(TypeDescriptor typeDescriptor, Object
case STRUCT_TYPE:
case UNION_TYPE:
case USER_DEFINED_TYPE:
case INTERVAL_YEAR_MONTH_TYPE:
case INTERVAL_DAY_TIME_TYPE:
return stringValue((String)value);
case NULL_TYPE:
return stringValue((String)value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ private[hive] class SparkExecuteStatementOperation(
(from.getAs[CalendarInterval](ordinal), CalendarIntervalType),
false,
timeFormatters)
case _: ArrayType | _: StructType | _: MapType | _: UserDefinedType[_] =>
case _: ArrayType | _: StructType | _: MapType | _: UserDefinedType[_] |
YearMonthIntervalType | DayTimeIntervalType =>
to += toHiveString((from.get(ordinal), dataTypes(ordinal)), false, timeFormatters)
}
}
Expand Down Expand Up @@ -377,6 +378,8 @@ object SparkExecuteStatementOperation {
val attrTypeString = field.dataType match {
case NullType => "void"
case CalendarIntervalType => StringType.catalogString
case YearMonthIntervalType => "interval_year_month"
case DayTimeIntervalType => "interval_day_time"
case other => other.catalogString
}
new FieldSchema(field.name, attrTypeString, field.getComment.getOrElse(""))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private[hive] object SparkGetTypeInfoUtil {
TINYINT_TYPE, SMALLINT_TYPE, INT_TYPE, BIGINT_TYPE,
FLOAT_TYPE, DOUBLE_TYPE, DECIMAL_TYPE,
DATE_TYPE, TIMESTAMP_TYPE,
ARRAY_TYPE, MAP_TYPE, STRUCT_TYPE, CHAR_TYPE, VARCHAR_TYPE)
ARRAY_TYPE, MAP_TYPE, STRUCT_TYPE, CHAR_TYPE, VARCHAR_TYPE,
INTERVAL_YEAR_MONTH_TYPE, INTERVAL_DAY_TIME_TYPE)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.apache.spark.sql.hive.thriftserver
import java.sql.{Date, Timestamp}
import java.util.{List => JList, Properties}

import org.apache.hadoop.hive.common.`type`.HiveIntervalDayTime
import org.apache.hive.jdbc.{HiveConnection, HiveQueryResultSet}
import org.apache.hive.service.auth.PlainSaslHelper
import org.apache.hive.service.cli.GetInfoType
Expand Down Expand Up @@ -458,5 +459,17 @@ class SparkThriftServerProtocolVersionsSuite extends HiveThriftServer2TestBase {
}
}
}

test(s"SPARK-35017: $version get day-time interval type") {
Copy link
Member Author

Choose a reason for hiding this comment

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

I tested only day-time interval because constructing of year-month interval in SQL is not possible at the moment. I created the JIRA for that: SPARK-35018

Copy link
Member Author

Choose a reason for hiding this comment

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

The PR #32240 adds a test for year-month intervals.

testExecuteStatementWithProtocolVersion(
version, "SELECT date'2021-01-01' - date'2020-12-31' AS dt") { rs =>
assert(rs.next())
assert(rs.getObject(1) === new HiveIntervalDayTime(1, 0, 0, 0, 0))
val metaData = rs.getMetaData
assert(metaData.getColumnName(1) === "dt")
assert(metaData.getColumnTypeName(1) === "interval_day_time")
assert(metaData.getColumnType(1) === java.sql.Types.OTHER)
}
}
}
}