Hive Server 2 CHAR(N) patch

Adds support for CHAR(N) to hive server 2.

Change-Id: I125e58ccab247e76b1a22b54daceee67a122e852
Reviewed-on: http://gerrit.sjc.cloudera.com:8080/4433
Tested-by: jenkins
Reviewed-by: Lenni Kuff <lskuff@cloudera.com>
This commit is contained in:
Victor Bittorf
2014-09-19 14:13:32 -07:00
committed by Nong Li
parent 8a75e759cb
commit b10743a89f
3 changed files with 34 additions and 2 deletions

View File

@@ -74,6 +74,7 @@ void impala::TColumnValueToHS2TColumn(const TColumnValue& col_val,
case TPrimitiveType::TIMESTAMP:
case TPrimitiveType::NULL_TYPE:
case TPrimitiveType::STRING:
case TPrimitiveType::CHAR:
case TPrimitiveType::VARCHAR:
case TPrimitiveType::DECIMAL:
is_null = !col_val.__isset.string_val;
@@ -148,6 +149,15 @@ void impala::ExprValueToHS2TColumn(const void* value, const TColumnType& type,
}
nulls = &column->stringVal.nulls;
break;
case TPrimitiveType::CHAR:
column->stringVal.values.push_back("");
if (value != NULL) {
ColumnType char_type = ColumnType::CreateCharType(type.types[0].scalar_type.len);
column->stringVal.values.back().assign(
StringValue::CharSlotToPtr(value, char_type), char_type.len);
}
nulls = &column->stringVal.nulls;
break;
case TPrimitiveType::DECIMAL: {
// HiveServer2 requires decimal to be presented as string.
column->stringVal.values.push_back("");
@@ -225,6 +235,7 @@ void impala::TColumnValueToHS2TColumnValue(const TColumnValue& col_val,
case TPrimitiveType::STRING:
case TPrimitiveType::TIMESTAMP:
case TPrimitiveType::VARCHAR:
case TPrimitiveType::CHAR:
// HiveServer2 requires timestamp to be presented as string. Note that the .thrift
// spec says it should be a BIGINT; AFAICT Hive ignores that and produces a string.
hs2_col_val->__isset.stringVal = true;
@@ -298,7 +309,16 @@ void impala::ExprValueToHS2TColumnValue(const void* value, const TColumnType& ty
if (not_null) {
const StringValue* string_val = reinterpret_cast<const StringValue*>(value);
hs2_col_val->stringVal.value.assign(static_cast<char*>(string_val->ptr),
string_val->len);
string_val->len);
}
break;
case TPrimitiveType::CHAR:
hs2_col_val->__isset.stringVal = true;
hs2_col_val->stringVal.__isset.value = not_null;
if (not_null) {
ColumnType char_type = ColumnType::CreateCharType(type.types[0].scalar_type.len);
hs2_col_val->stringVal.value.assign(
StringValue::CharSlotToPtr(value, char_type), char_type.len);
}
break;
case TPrimitiveType::TIMESTAMP:

View File

@@ -242,6 +242,7 @@ class ImpalaServer::HS2ColumnarResultSet : public ImpalaServer::QueryResultSet {
case TPrimitiveType::DECIMAL:
case TPrimitiveType::STRING:
case TPrimitiveType::VARCHAR:
case TPrimitiveType::CHAR:
to->stringVal.values.insert(to->stringVal.values.end(),
from->stringVal.values.begin() + start_idx,
from->stringVal.values.begin() + start_idx + rows_added);
@@ -313,6 +314,7 @@ class ImpalaServer::HS2ColumnarResultSet : public ImpalaServer::QueryResultSet {
case TPrimitiveType::NULL_TYPE:
case TPrimitiveType::DECIMAL:
case TPrimitiveType::VARCHAR:
case TPrimitiveType::CHAR:
case TPrimitiveType::STRING:
column.__isset.stringVal = true;
break;

View File

@@ -121,11 +121,21 @@ class TestFetch(HS2TestSuite):
assert result == ("1234, 2222, 1.2345678900, "
"0.12345678900000000000000000000000000000, 12345.78900, 1\n")
# VARCHAR (TODO: CHAR)
# VARCHAR
fetch_results_resp = self.__query_and_fetch("SELECT CAST('str' AS VARCHAR(3))")
num_rows, result = self.__column_results_to_string(fetch_results_resp.results.columns)
assert result == "str\n"
# CHAR not inlined
fetch_results_resp = self.__query_and_fetch("SELECT CAST('car' AS CHAR(140))")
num_rows, result = self.__column_results_to_string(fetch_results_resp.results.columns)
assert result == "car" + (" " * 137) + "\n"
# CHAR inlined
fetch_results_resp = self.__query_and_fetch("SELECT CAST('car' AS CHAR(5))")
num_rows, result = self.__column_results_to_string(fetch_results_resp.results.columns)
assert result == "car \n"
@needs_session(TCLIService.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V1)
def test_execute_select_v1(self):
"""Test that a simple select statement works in the row-oriented protocol"""