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 @@ -26,6 +26,9 @@ import org.apache.hive.service.cli.GetInfoType
import org.apache.thrift.protocol.TBinaryProtocol
import org.apache.thrift.transport.TSocket

import org.apache.spark.sql.catalyst.util.NumberConverter
import org.apache.spark.unsafe.types.UTF8String

class SparkThriftServerProtocolVersionsSuite extends HiveThriftJdbcTest {

override def mode: ServerMode.Value = ServerMode.binary
Expand Down Expand Up @@ -215,12 +218,19 @@ class SparkThriftServerProtocolVersionsSuite extends HiveThriftJdbcTest {
}
}

// TODO: enable this test case after SPARK-28474
ignore(s"$version get binary type") {
test(s"$version get binary type") {
testExecuteStatementWithProtocolVersion(version, "SELECT cast('ABC' as binary)") { rs =>
assert(rs.next())
assert(rs.getString(1) === "ABC")
}
testExecuteStatementWithProtocolVersion(version, "SELECT cast(49960 as binary)") { rs =>
assert(rs.next())
assert(rs.getString(1) === UTF8String.fromBytes(NumberConverter.toBinary(49960)).toString)
}
testExecuteStatementWithProtocolVersion(version, "SELECT cast(null as binary)") { rs =>
assert(rs.next())
assert(rs.getString(1) === null)
}
}

test(s"$version get boolean type") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.apache.hive.service.cli.thrift.TI64Value;
import org.apache.hive.service.cli.thrift.TStringValue;

import org.apache.spark.unsafe.types.UTF8String;

/**
* Protocols before HIVE_CLI_SERVICE_PROTOCOL_V6 (used by RowBasedSet)
*
Expand Down Expand Up @@ -195,7 +197,8 @@ public static TColumnValue toTColumnValue(Type type, Object value) {
case DECIMAL_TYPE:
return stringValue(((HiveDecimal)value));
case BINARY_TYPE:
return stringValue((String)value);
String strVal = value == null ? null : UTF8String.fromBytes((byte[])value).toString();
return stringValue(strVal);
Copy link
Member

Choose a reason for hiding this comment

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

@wangyum, #25480 this might be the cause. UTF8String.toString().

new String(getBytes(), StandardCharsets.UTF_8);

It actually reads bytes with UTF-8. IIRC, Java mangles the data if it's not conformed as specified encoding.
For some protocols, it might be unable to recognise those mangled strings back to binary. It might be the cause.

BTW, we should allow arbitrary binary, for instance, for the use case like images.

If you are unable to find the root cause, we can partially revert to the failed protocols for now.

case ARRAY_TYPE:
case MAP_TYPE:
case STRUCT_TYPE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import org.apache.hive.service.rpc.thrift.TI64Value;
import org.apache.hive.service.rpc.thrift.TStringValue;

import org.apache.spark.unsafe.types.UTF8String;

/**
* Protocols before HIVE_CLI_SERVICE_PROTOCOL_V6 (used by RowBasedSet)
*
Expand Down Expand Up @@ -199,7 +201,8 @@ public static TColumnValue toTColumnValue(TypeDescriptor typeDescriptor, Object
case DECIMAL_TYPE:
return stringValue((HiveDecimal)value, typeDescriptor);
case BINARY_TYPE:
return stringValue((String)value);
String strVal = value == null ? null : UTF8String.fromBytes((byte[])value).toString();
return stringValue(strVal);
case ARRAY_TYPE:
case MAP_TYPE:
case STRUCT_TYPE:
Expand Down