yuzelin commented on code in PR #20401:
URL: https://github.com/apache/flink/pull/20401#discussion_r938501590


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/endpoint/hive/HiveServer2Endpoint.java:
##########
@@ -422,7 +426,76 @@ public TGetCatalogsResp GetCatalogs(TGetCatalogsReq 
tGetCatalogsReq) throws TExc
 
     @Override
     public TGetSchemasResp GetSchemas(TGetSchemasReq tGetSchemasReq) throws 
TException {
-        throw new UnsupportedOperationException(ERROR_MESSAGE);
+        TGetSchemasResp resp = new TGetSchemasResp();
+        try {
+            SessionHandle sessionHandle = 
toSessionHandle(tGetSchemasReq.getSessionHandle());
+            OperationHandle operationHandle =
+                    service.submitOperation(
+                            sessionHandle,
+                            OperationType.LIST_SCHEMAS,
+                            () -> {
+                                Set<String> schemaNames =
+                                        service
+                                                .listDatabases(
+                                                        sessionHandle,
+                                                        
tGetSchemasReq.getCatalogName())
+                                                .stream()
+                                                .filter(
+                                                        name ->
+                                                                name.matches(
+                                                                        
convertNamePattern(
+                                                                               
 tGetSchemasReq
+                                                                               
         .getSchemaName())))
+                                                .collect(Collectors.toSet());
+
+                                return new ResultSet(
+                                        EOS,
+                                        null,
+                                        GET_SCHEMAS_SCHEMA,
+                                        schemaNames.stream()
+                                                .map(
+                                                        name ->
+                                                                
GenericRowData.of(
+                                                                        
StringData.fromString(name),
+                                                                        
StringData.fromString(
+                                                                               
 tGetSchemasReq
+                                                                               
         .getCatalogName())))
+                                                .collect(Collectors.toList()));
+                            });
+
+            // TODO: Remove this
+            while (!service.getOperationInfo(sessionHandle, operationHandle)
+                    .getStatus()
+                    .isTerminalStatus()) {
+                Thread.sleep(1000);
+            }
+            resp.setStatus(OK_STATUS);
+            resp.setOperationHandle(
+                    toTOperationHandle(sessionHandle, operationHandle, 
OperationType.LIST_SCHEMAS));
+        } catch (Throwable t) {
+            LOG.error("Failed to GetSchemas.", t);
+            resp.setStatus(toTStatus(t));
+        }
+        return resp;
+    }
+
+    /**
+     * Convert wildchars and escape sequence of schema pattern from JDBC 
format to
+     * datanucleous/regex. The schema pattern treats empty string also as 
wildchar. implementation
+     * refers to hive's convertSchemaPattern.
+     */
+    private String convertNamePattern(String schemaName) {

Review Comment:
   Renamed.



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to