diff --git a/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/endpoint/hive/HiveServer2Endpoint.java b/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/endpoint/hive/HiveServer2Endpoint.java index 0260503368baf..ecbdc75b7311e 100644 --- a/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/endpoint/hive/HiveServer2Endpoint.java +++ b/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/endpoint/hive/HiveServer2Endpoint.java @@ -376,6 +376,8 @@ public TGetInfoResp GetInfo(TGetInfoReq tGetInfoReq) throws TException { resp.setInfoValue(tInfoValue); } catch (Throwable t) { LOG.error("Failed to GetInfo.", t); + // InfoValue must be set because the hive service requires it. + resp.setInfoValue(TGetInfoValue.lenValue(0)); resp.setStatus(toTStatus(t)); } return resp; diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/endpoint/hive/HiveServer2EndpointITCase.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/endpoint/hive/HiveServer2EndpointITCase.java index 0f782e1e8cced..b3d4294309711 100644 --- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/endpoint/hive/HiveServer2EndpointITCase.java +++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/endpoint/hive/HiveServer2EndpointITCase.java @@ -67,6 +67,9 @@ import org.apache.hive.service.rpc.thrift.TExecuteStatementResp; import org.apache.hive.service.rpc.thrift.TFetchOrientation; import org.apache.hive.service.rpc.thrift.TFetchResultsReq; +import org.apache.hive.service.rpc.thrift.TGetInfoReq; +import org.apache.hive.service.rpc.thrift.TGetInfoResp; +import org.apache.hive.service.rpc.thrift.TGetInfoType; import org.apache.hive.service.rpc.thrift.TGetOperationStatusReq; import org.apache.hive.service.rpc.thrift.TOpenSessionReq; import org.apache.hive.service.rpc.thrift.TOpenSessionResp; @@ -595,6 +598,28 @@ public void testGetInfo() throws Exception { } } + @Test + public void testUnknownGetInfoType() throws Exception { + TCLIService.Client client = createClient(); + TOpenSessionReq openSessionReq = new TOpenSessionReq(); + TOpenSessionResp openSessionResp = client.OpenSession(openSessionReq); + TSessionHandle tSessionHandle = openSessionResp.getSessionHandle(); + + // send GetInfoReq using a GetInfoType which is unknown to HiveServer2 endpoint + TGetInfoReq getInfoReq = + new TGetInfoReq(tSessionHandle, TGetInfoType.CLI_MAX_IDENTIFIER_LEN); + TGetInfoResp getInfoResp = client.GetInfo(getInfoReq); + assertThat(getInfoResp.getStatus().getStatusCode()).isEqualTo(TStatusCode.ERROR_STATUS); + + try (Connection connection = ENDPOINT_EXTENSION.getConnection()) { + DatabaseMetaData metaData = connection.getMetaData(); + connection.createStatement().execute("CREATE SCHEMA test;"); + + assertThat(collectAndCompact(metaData.getSchemas("hive", null), 2)) + .contains(Arrays.asList("test", "hive")); + } + } + @Test public void testExecuteStatementInSyncMode() throws Exception { TCLIService.Client client = createClient();