wuchong commented on code in PR #20334:
URL: https://github.com/apache/flink/pull/20334#discussion_r936663070


##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/SqlGatewayServiceITCase.java:
##########
@@ -587,6 +592,20 @@ public void testRequestNonExistOperation() {
         }
     }
 
+    @Test
+    public void testGetOperationSchemaWhenOperationGetError() throws Exception 
{
+        runGetOperationSchemaUntilOperationIsReadyOrError(
+                () -> {
+                    throw new SqlGatewayException("Artificial Exception.");
+                },
+                task ->
+                        assertThatThrownBy(task::get)
+                                .satisfies(
+                                        anyCauseMatches(
+                                                IllegalStateException.class,
+                                                "The result schema is 
available when the Operation is in FINISHED state but the current status is 
ERROR.")));

Review Comment:
   nit: throws the root cause of the operation error if the status is ERROR? 



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/endpoint/hive/HiveServer2Endpoint.java:
##########
@@ -390,7 +396,35 @@ public TGetTypeInfoResp GetTypeInfo(TGetTypeInfoReq 
tGetTypeInfoReq) throws TExc
 
     @Override
     public TGetCatalogsResp GetCatalogs(TGetCatalogsReq tGetCatalogsReq) 
throws TException {
-        throw new UnsupportedOperationException(ERROR_MESSAGE);
+        TGetCatalogsResp resp = new TGetCatalogsResp();
+        try {
+            SessionHandle sessionHandle = 
toSessionHandle(tGetCatalogsReq.getSessionHandle());
+            Set<String> catalogNames = service.listCatalogs(sessionHandle);

Review Comment:
   Should we call this in `service.submitOperation`? Because `CatalogManager` 
is not thread safe. 



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/endpoint/hive/HiveServer2Endpoint.java:
##########
@@ -390,7 +396,35 @@ public TGetTypeInfoResp GetTypeInfo(TGetTypeInfoReq 
tGetTypeInfoReq) throws TExc
 
     @Override
     public TGetCatalogsResp GetCatalogs(TGetCatalogsReq tGetCatalogsReq) 
throws TException {
-        throw new UnsupportedOperationException(ERROR_MESSAGE);
+        TGetCatalogsResp resp = new TGetCatalogsResp();
+        try {
+            SessionHandle sessionHandle = 
toSessionHandle(tGetCatalogsReq.getSessionHandle());
+            Set<String> catalogNames = service.listCatalogs(sessionHandle);
+            OperationHandle operationHandle =
+                    service.submitOperation(
+                            sessionHandle,
+                            OperationType.LIST_CATALOGS,
+                            () ->
+                                    new ResultSet(
+                                            EOS,
+                                            null,
+                                            GET_CATALOGS_SCHEMA,
+                                            catalogNames.stream()
+                                                    .map(
+                                                            name ->
+                                                                    
GenericRowData.of(
+                                                                            
StringData.fromString(
+                                                                               
     name)))
+                                                    
.collect(Collectors.toList())));

Review Comment:
   Maybe we can extract this as util (convert `Collection<String>` into 
`List<RowData>`). I think this can be reused in many places. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to