You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/08/01 06:56:50 UTC

[GitHub] [flink] yuzelin opened a new pull request, #20401: List schemas

yuzelin opened a new pull request, #20401:
URL: https://github.com/apache/flink/pull/20401

   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   Implement getSchemas in the HiveServer2 Endpoint.
   
   
   ## Brief change log
   
     - Implement listDatabases in the SqlGatewayService.
     - Implement GetSchemas in the HiveServer2 Endpoint.
   
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - Added list all databases in the  `SqlGatewayServiceITCase`.
     - Use jdbc to fetch all schemas (matching name pattern) within given catalog  in the `HiveServer2EndpointITCase`.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (yes / **no**)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (**yes** / no)
     - The serializers: (yes / **no** / don't know)
     - The runtime per-record code paths (performance sensitive): (yes / **no** / don't know)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (yes / **no** / don't know)
     - The S3 file system connector: (yes / **no** / don't know)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (**yes** / no)
     - If yes, how is the feature documented? (not applicable / docs / **JavaDocs** / not documented)
   


-- 
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-unsubscribe@flink.apache.org

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


[GitHub] [flink] yuzelin commented on a diff in pull request #20401: [FLINK-28630][sql-gateway][hive] Allow to getSchemas in the HiveServer2 Endpoint.

Posted by GitBox <gi...@apache.org>.
yuzelin commented on code in PR #20401:
URL: https://github.com/apache/flink/pull/20401#discussion_r938507937


##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/endpoint/hive/HiveServer2EndpointITCase.java:
##########
@@ -211,6 +213,49 @@ public void testGetCatalogs() throws Exception {
         }
     }
 
+    @Test
+    public void testGetSchemas() throws Exception {
+        try (Connection connection = ENDPOINT_EXTENSION.getConnection()) {
+            connection.createStatement().execute("CREATE SCHEMA schema1");

Review Comment:
   Improved by introducing a common initDefaultTestConnection method to build test database.



-- 
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-unsubscribe@flink.apache.org

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


[GitHub] [flink] yuzelin commented on a diff in pull request #20401: [FLINK-28630][sql-gateway][hive] Allow to getSchemas in the HiveServer2 Endpoint.

Posted by GitBox <gi...@apache.org>.
yuzelin commented on code in PR #20401:
URL: https://github.com/apache/flink/pull/20401#discussion_r938511152


##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/SqlGatewayServiceITCase.java:
##########
@@ -316,6 +317,32 @@ public void testListCatalogs() {
         assertThat(service.listCatalogs(sessionHandle)).contains("cat1", "cat2");
     }
 
+    @Test
+    public void testListDatabases() throws Exception {
+        SessionEnvironment environment =
+                SessionEnvironment.newBuilder()
+                        .setSessionEndpointVersion(MockedEndpointVersion.V1)
+                        .registerCatalog("cat", new GenericInMemoryCatalog("cat"))
+                        .build();

Review Comment:
   Fixed.



-- 
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-unsubscribe@flink.apache.org

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


[GitHub] [flink] yuzelin commented on a diff in pull request #20401: [FLINK-28630][sql-gateway][hive] Allow to getSchemas in the HiveServer2 Endpoint.

Posted by GitBox <gi...@apache.org>.
yuzelin commented on code in PR #20401:
URL: https://github.com/apache/flink/pull/20401#discussion_r938492387


##########
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(

Review Comment:
   Make it better by introducing new util class OperationExecutorFactory and method packData.



-- 
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-unsubscribe@flink.apache.org

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


[GitHub] [flink] fsk119 commented on a diff in pull request #20401: [FLINK-28630][sql-gateway][hive] Allow to getSchemas in the HiveServer2 Endpoint.

Posted by GitBox <gi...@apache.org>.
fsk119 commented on code in PR #20401:
URL: https://github.com/apache/flink/pull/20401#discussion_r938387937


##########
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())

Review Comment:
   tGetSchemasReq.getCatalogName() may be null. 
   If null, I think we can use the current catalog name.



##########
flink-table/flink-sql-gateway-api/src/main/java/org/apache/flink/table/gateway/api/SqlGatewayService.java:
##########
@@ -198,4 +198,15 @@ ResultSet fetchResults(
      * @return names of the registered catalogs.
      */
     Set<String> listCatalogs(SessionHandle sessionHandle) throws SqlGatewayException;
+
+    /**
+     * Return all available schemas' name matching {@param databaseNamePattern} in the given

Review Comment:
   We don't allow users to specify databaseNamePattern here.
   



##########
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.
+     */

Review Comment:
   ```
   /**
      * Convert SQL 'like' pattern to a Java regular expression.
      *
      * Underscores (_) are converted to '.' and percent signs (%) are converted to '.*'.
      *  
      * @param pattern the SQL pattern to convert
      * @return the equivalent Java regular expression of the pattern
      */
   ```



##########
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);
+            }

Review Comment:
   Remove this



##########
flink-table/flink-sql-gateway-api/src/main/java/org/apache/flink/table/gateway/api/session/SessionEnvironment.java:
##########
@@ -41,6 +41,7 @@ public class SessionEnvironment {
     private final @Nullable String sessionName;
     private final EndpointVersion version;
     private final Map<String, Catalog> registeredCatalogs;
+

Review Comment:
   remove this change.



##########
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(

Review Comment:
   It's better we can reuse or extend the `StringRowDataUtils`



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/endpoint/hive/HiveServer2Schemas.java:
##########
@@ -35,4 +36,16 @@ public class HiveServer2Schemas {
                                     .withComment("Catalog name. NULL if not applicable.")),
                     Collections.emptyList(),
                     null);
+
+    /** Schema for {@link HiveServer2Endpoint#GetSchemas}. */
+    public static final ResolvedSchema GET_SCHEMAS_SCHEMA =
+            new ResolvedSchema(
+                    Collections.unmodifiableList(

Review Comment:
   I think we can remove Collections.unmodifiedList? It's trivial to wrap this again.



##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/endpoint/hive/HiveServer2EndpointITCase.java:
##########
@@ -211,6 +213,49 @@ public void testGetCatalogs() throws Exception {
         }
     }
 
+    @Test
+    public void testGetSchemas() throws Exception {
+        try (Connection connection = ENDPOINT_EXTENSION.getConnection()) {
+            connection.createStatement().execute("CREATE SCHEMA schema1");

Review Comment:
   reuse the same statement



##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/SqlGatewayServiceITCase.java:
##########
@@ -316,6 +317,32 @@ public void testListCatalogs() {
         assertThat(service.listCatalogs(sessionHandle)).contains("cat1", "cat2");
     }
 
+    @Test
+    public void testListDatabases() throws Exception {
+        SessionEnvironment environment =
+                SessionEnvironment.newBuilder()
+                        .setSessionEndpointVersion(MockedEndpointVersion.V1)
+                        .registerCatalog("cat", new GenericInMemoryCatalog("cat"))
+                        .build();

Review Comment:
   `.setDefaultCatalog("cat")`



##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/service/operation/OperationExecutor.java:
##########
@@ -104,8 +105,15 @@ public Set<String> listCatalogs() {
         return getTableEnvironment().getCatalogManager().listCatalogs();
     }
 
+
+    public Set<String> listDatabases(String catalogName) {
+        return Collections.unmodifiableSet(
+                new HashSet<>(getTableEnvironment().getCatalogManager().listSchemas(catalogName)));
+    }
+
     // --------------------------------------------------------------------------------------------
 
+

Review Comment:
   remove this



##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/service/operation/OperationExecutor.java:
##########
@@ -104,8 +105,15 @@ public Set<String> listCatalogs() {
         return getTableEnvironment().getCatalogManager().listCatalogs();
     }
 
+
+    public Set<String> listDatabases(String catalogName) {
+        return Collections.unmodifiableSet(
+                new HashSet<>(getTableEnvironment().getCatalogManager().listSchemas(catalogName)));

Review Comment:
   listSchema is different from the listDatabases. `listSchemas` also includes the temporary object here but `listDatabases` doesn't.  We should keep the meaning and the actual implementation is the same here.



##########
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:
   rename schemaName to pattern



-- 
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-unsubscribe@flink.apache.org

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


[GitHub] [flink] fsk119 commented on a diff in pull request #20401: [FLINK-28630][sql-gateway][hive] Allow to getSchemas in the HiveServer2 Endpoint.

Posted by GitBox <gi...@apache.org>.
fsk119 commented on code in PR #20401:
URL: https://github.com/apache/flink/pull/20401#discussion_r938676333


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/endpoint/hive/HiveServer2Endpoint.java:
##########
@@ -429,46 +416,20 @@ public TGetSchemasResp GetSchemas(TGetSchemasReq tGetSchemasReq) throws TExcepti
         TGetSchemasResp resp = new TGetSchemasResp();
         try {
             SessionHandle sessionHandle = toSessionHandle(tGetSchemasReq.getSessionHandle());
+            String catalogName = tGetSchemasReq.getCatalogName();
+            if (catalogName == null || catalogName.equals("")) {
+                catalogName = service.getCurrentCatalog(sessionHandle);
+            }

Review Comment:
   Move into the executor. It should be executed when get the opertaion lock



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/endpoint/hive/util/OperationExecutorFactory.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.endpoint.hive.util;
+
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.StringData;
+import org.apache.flink.table.gateway.api.SqlGatewayService;
+import org.apache.flink.table.gateway.api.results.ResultSet;
+import org.apache.flink.table.gateway.api.session.SessionHandle;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.table.endpoint.hive.HiveServer2Schemas.GET_CATALOGS_SCHEMA;
+import static org.apache.flink.table.endpoint.hive.HiveServer2Schemas.GET_SCHEMAS_SCHEMA;
+import static org.apache.flink.table.gateway.api.results.ResultSet.ResultType.EOS;
+
+/** Factory to create the operation executor. */
+public class OperationExecutorFactory {
+
+    public static Callable<ResultSet> createGetCatalogsExecutor(
+            SqlGatewayService service, SessionHandle sessionHandle) {
+        return () -> executeGetCatalogs(service, sessionHandle);
+    }
+
+    public static Callable<ResultSet> createGetSchemasExecutor(
+            SqlGatewayService service,
+            SessionHandle sessionHandle,
+            String catalogName,
+            String schemaName) {
+        return () -> executeGetSchemas(service, sessionHandle, catalogName, schemaName);
+    }
+
+    private static ResultSet executeGetCatalogs(
+            SqlGatewayService service, SessionHandle sessionHandle) {
+        Set<String> catalogNames = service.listCatalogs(sessionHandle);
+        return new ResultSet(
+                EOS,
+                null,
+                GET_CATALOGS_SCHEMA,
+                catalogNames.stream()
+                        .map(OperationExecutorFactory::packData)
+                        .collect(Collectors.toList()));
+    }
+
+    private static ResultSet executeGetSchemas(
+            SqlGatewayService service,
+            SessionHandle sessionHandle,
+            String catalogName,
+            String schemaName) {
+        Set<String> schemaNames =
+                filterStringSetBy(service.listDatabases(sessionHandle, catalogName), schemaName);
+
+        return new ResultSet(
+                EOS,
+                null,
+                GET_SCHEMAS_SCHEMA,
+                schemaNames.stream()
+                        .map(name -> packData(name, catalogName))
+                        .collect(Collectors.toList()));
+    }
+
+    // -------------------------------------
+    // useful methods
+    // -------------------------------------
+
+    /**
+     * Covert SQL 'like' pattern to a Java regular expression. Underscores (_) are converted to '.'
+     * and percent signs (%) are converted to '.*'. Note: escape characters are removed.
+     *
+     * @param pattern the SQL pattern to convert.
+     * @return the equivalent Java regular expression of the pattern.
+     */
+    private static String convertNamePattern(String pattern) {
+        if ((pattern == null) || pattern.isEmpty()) {
+            pattern = "%";
+        }
+        String wStr = ".*";
+        return pattern.replaceAll("([^\\\\])%", "$1" + wStr)
+                .replaceAll("\\\\%", "%")
+                .replaceAll("^%", wStr)
+                .replaceAll("([^\\\\])_", "$1.")
+                .replaceAll("\\\\_", "_")
+                .replaceAll("^_", ".");
+    }
+
+    public static Set<String> filterStringSetBy(Set<String> set, String pattern) {
+        return set.stream()
+                .filter(name -> name.matches(convertNamePattern(pattern)))
+                .collect(Collectors.toSet());

Review Comment:
   It's better to reuse the same `Pattern`. It's time wasted to recompile. Please cc 
   
   https://stackoverflow.com/questions/2469244/whats-the-difference-between-string-matches-and-matcher-matches



##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/endpoint/hive/HiveServer2EndpointITCase.java:
##########
@@ -216,44 +217,74 @@ public void testGetCatalogs() throws Exception {
     @Test
     public void testGetSchemas() throws Exception {
         try (Connection connection = ENDPOINT_EXTENSION.getConnection()) {
-            connection.createStatement().execute("CREATE SCHEMA schema1");
-            connection.createStatement().execute("CREATE SCHEMA schema2");
-            connection.createStatement().execute("CREATE SCHEMA different");
-
+            initDefaultTestConnection(connection);
             // test all
-            java.sql.ResultSet resultAll = connection.getMetaData().getSchemas("hive", null);
-            assertSchemaEquals(
-                    ResolvedSchema.of(
-                            Column.physical("TABLE_SCHEMA", DataTypes.STRING()),
-                            Column.physical("TABLE_CAT", DataTypes.STRING())),
-                    resultAll.getMetaData());
+            testGetSchemasAll(connection);
+            // test schema pattern parameter
+            testGetSchemasWithPattern(connection);
+        }
+    }
 
-            List<List<String>> actual = new ArrayList<>();
-            while (resultAll.next()) {
-                actual.add(Arrays.asList(resultAll.getString(1), resultAll.getString(2)));
-            }
-            assertThat(new HashSet<>(actual))
-                    .isEqualTo(
-                            new HashSet<>(
-                                    Arrays.asList(
-                                            Arrays.asList("default", "hive"),
-                                            Arrays.asList("schema1", "hive"),
-                                            Arrays.asList("schema2", "hive"),
-                                            Arrays.asList("different", "hive"))));
+    private void testGetSchemasAll(Connection connection) throws Exception {

Review Comment:
   I think we can resuse most of codes between `testGetSchemasAll` and `testGetSchemasWithPattern`



##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/endpoint/hive/HiveServer2EndpointITCase.java:
##########
@@ -216,44 +217,74 @@ public void testGetCatalogs() throws Exception {
     @Test
     public void testGetSchemas() throws Exception {
         try (Connection connection = ENDPOINT_EXTENSION.getConnection()) {
-            connection.createStatement().execute("CREATE SCHEMA schema1");
-            connection.createStatement().execute("CREATE SCHEMA schema2");
-            connection.createStatement().execute("CREATE SCHEMA different");
-
+            initDefaultTestConnection(connection);
             // test all
-            java.sql.ResultSet resultAll = connection.getMetaData().getSchemas("hive", null);
-            assertSchemaEquals(
-                    ResolvedSchema.of(
-                            Column.physical("TABLE_SCHEMA", DataTypes.STRING()),
-                            Column.physical("TABLE_CAT", DataTypes.STRING())),
-                    resultAll.getMetaData());
+            testGetSchemasAll(connection);
+            // test schema pattern parameter
+            testGetSchemasWithPattern(connection);

Review Comment:
   It's better to split into two tests if they are irrelevant.



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/endpoint/hive/util/OperationExecutorFactory.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.endpoint.hive.util;
+
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.StringData;
+import org.apache.flink.table.gateway.api.SqlGatewayService;
+import org.apache.flink.table.gateway.api.results.ResultSet;
+import org.apache.flink.table.gateway.api.session.SessionHandle;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.table.endpoint.hive.HiveServer2Schemas.GET_CATALOGS_SCHEMA;
+import static org.apache.flink.table.endpoint.hive.HiveServer2Schemas.GET_SCHEMAS_SCHEMA;
+import static org.apache.flink.table.gateway.api.results.ResultSet.ResultType.EOS;
+
+/** Factory to create the operation executor. */
+public class OperationExecutorFactory {
+
+    public static Callable<ResultSet> createGetCatalogsExecutor(
+            SqlGatewayService service, SessionHandle sessionHandle) {
+        return () -> executeGetCatalogs(service, sessionHandle);
+    }
+
+    public static Callable<ResultSet> createGetSchemasExecutor(
+            SqlGatewayService service,
+            SessionHandle sessionHandle,
+            String catalogName,
+            String schemaName) {
+        return () -> executeGetSchemas(service, sessionHandle, catalogName, schemaName);
+    }
+
+    private static ResultSet executeGetCatalogs(
+            SqlGatewayService service, SessionHandle sessionHandle) {
+        Set<String> catalogNames = service.listCatalogs(sessionHandle);
+        return new ResultSet(
+                EOS,
+                null,
+                GET_CATALOGS_SCHEMA,
+                catalogNames.stream()
+                        .map(OperationExecutorFactory::packData)
+                        .collect(Collectors.toList()));
+    }
+
+    private static ResultSet executeGetSchemas(
+            SqlGatewayService service,
+            SessionHandle sessionHandle,
+            String catalogName,
+            String schemaName) {
+        Set<String> schemaNames =
+                filterStringSetBy(service.listDatabases(sessionHandle, catalogName), schemaName);
+
+        return new ResultSet(
+                EOS,
+                null,
+                GET_SCHEMAS_SCHEMA,
+                schemaNames.stream()
+                        .map(name -> packData(name, catalogName))
+                        .collect(Collectors.toList()));
+    }
+
+    // -------------------------------------
+    // useful methods
+    // -------------------------------------
+
+    /**
+     * Covert SQL 'like' pattern to a Java regular expression. Underscores (_) are converted to '.'
+     * and percent signs (%) are converted to '.*'. Note: escape characters are removed.
+     *
+     * @param pattern the SQL pattern to convert.
+     * @return the equivalent Java regular expression of the pattern.
+     */
+    private static String convertNamePattern(String pattern) {
+        if ((pattern == null) || pattern.isEmpty()) {
+            pattern = "%";
+        }
+        String wStr = ".*";
+        return pattern.replaceAll("([^\\\\])%", "$1" + wStr)
+                .replaceAll("\\\\%", "%")
+                .replaceAll("^%", wStr)
+                .replaceAll("([^\\\\])_", "$1.")
+                .replaceAll("\\\\_", "_")
+                .replaceAll("^_", ".");
+    }
+
+    public static Set<String> filterStringSetBy(Set<String> set, String pattern) {
+        return set.stream()
+                .filter(name -> name.matches(convertNamePattern(pattern)))
+                .collect(Collectors.toSet());
+    }
+
+    private static GenericRowData packData(List<Object> data) {

Review Comment:
   It seems `packData(List<Object> data)` and `packData(Object... data)` are the same. We can combine into one.



-- 
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-unsubscribe@flink.apache.org

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


[GitHub] [flink] fsk119 closed pull request #20401: [FLINK-28630][sql-gateway][hive] Allow to getSchemas in the HiveServer2 Endpoint.

Posted by GitBox <gi...@apache.org>.
fsk119 closed pull request #20401: [FLINK-28630][sql-gateway][hive] Allow to getSchemas in the HiveServer2 Endpoint.
URL: https://github.com/apache/flink/pull/20401


-- 
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-unsubscribe@flink.apache.org

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


[GitHub] [flink] yuzelin commented on a diff in pull request #20401: [FLINK-28630][sql-gateway][hive] Allow to getSchemas in the HiveServer2 Endpoint.

Posted by GitBox <gi...@apache.org>.
yuzelin commented on code in PR #20401:
URL: https://github.com/apache/flink/pull/20401#discussion_r938492798


##########
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);
+            }

Review Comment:
   Removed.



-- 
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-unsubscribe@flink.apache.org

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


[GitHub] [flink] yuzelin commented on a diff in pull request #20401: [FLINK-28630][sql-gateway][hive] Allow to getSchemas in the HiveServer2 Endpoint.

Posted by GitBox <gi...@apache.org>.
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-unsubscribe@flink.apache.org

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


[GitHub] [flink] flinkbot commented on pull request #20401: List schemas

Posted by GitBox <gi...@apache.org>.
flinkbot commented on PR #20401:
URL: https://github.com/apache/flink/pull/20401#issuecomment-1200809838

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "aa9876830b3c9de01efaa484510db48df8d4b664",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "aa9876830b3c9de01efaa484510db48df8d4b664",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * aa9876830b3c9de01efaa484510db48df8d4b664 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
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-unsubscribe@flink.apache.org

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


[GitHub] [flink] yuzelin commented on a diff in pull request #20401: [FLINK-28630][sql-gateway][hive] Allow to getSchemas in the HiveServer2 Endpoint.

Posted by GitBox <gi...@apache.org>.
yuzelin commented on code in PR #20401:
URL: https://github.com/apache/flink/pull/20401#discussion_r938483915


##########
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())

Review Comment:
   1. Add SqlGatewayService#getCurrentCatalog & test case.
   2. Add null check for catalogName, and, if null, set catalogName = getCurrentCatalog.



-- 
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-unsubscribe@flink.apache.org

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


[GitHub] [flink] yuzelin commented on a diff in pull request #20401: [FLINK-28630][sql-gateway][hive] Allow to getSchemas in the HiveServer2 Endpoint.

Posted by GitBox <gi...@apache.org>.
yuzelin commented on code in PR #20401:
URL: https://github.com/apache/flink/pull/20401#discussion_r938508495


##########
flink-table/flink-sql-gateway-api/src/main/java/org/apache/flink/table/gateway/api/SqlGatewayService.java:
##########
@@ -198,4 +198,15 @@ ResultSet fetchResults(
      * @return names of the registered catalogs.
      */
     Set<String> listCatalogs(SessionHandle sessionHandle) throws SqlGatewayException;
+
+    /**
+     * Return all available schemas' name matching {@param databaseNamePattern} in the given

Review Comment:
   Fixed.



-- 
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-unsubscribe@flink.apache.org

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


[GitHub] [flink] yuzelin commented on a diff in pull request #20401: [FLINK-28630][sql-gateway][hive] Allow to getSchemas in the HiveServer2 Endpoint.

Posted by GitBox <gi...@apache.org>.
yuzelin commented on code in PR #20401:
URL: https://github.com/apache/flink/pull/20401#discussion_r938509598


##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/service/operation/OperationExecutor.java:
##########
@@ -104,8 +105,15 @@ public Set<String> listCatalogs() {
         return getTableEnvironment().getCatalogManager().listCatalogs();
     }
 
+
+    public Set<String> listDatabases(String catalogName) {
+        return Collections.unmodifiableSet(
+                new HashSet<>(getTableEnvironment().getCatalogManager().listSchemas(catalogName)));

Review Comment:
   Fixed.



-- 
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-unsubscribe@flink.apache.org

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


[GitHub] [flink] yuzelin commented on a diff in pull request #20401: [FLINK-28630][sql-gateway][hive] Allow to getSchemas in the HiveServer2 Endpoint.

Posted by GitBox <gi...@apache.org>.
yuzelin commented on code in PR #20401:
URL: https://github.com/apache/flink/pull/20401#discussion_r938509312


##########
flink-table/flink-sql-gateway-api/src/main/java/org/apache/flink/table/gateway/api/session/SessionEnvironment.java:
##########
@@ -41,6 +41,7 @@ public class SessionEnvironment {
     private final @Nullable String sessionName;
     private final EndpointVersion version;
     private final Map<String, Catalog> registeredCatalogs;
+

Review Comment:
   Removed.



-- 
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-unsubscribe@flink.apache.org

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


[GitHub] [flink] yuzelin commented on a diff in pull request #20401: [FLINK-28630][sql-gateway][hive] Allow to getSchemas in the HiveServer2 Endpoint.

Posted by GitBox <gi...@apache.org>.
yuzelin commented on code in PR #20401:
URL: https://github.com/apache/flink/pull/20401#discussion_r938500275


##########
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.
+     */

Review Comment:
   Changed.



-- 
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-unsubscribe@flink.apache.org

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


[GitHub] [flink] yuzelin commented on a diff in pull request #20401: [FLINK-28630][sql-gateway][hive] Allow to getSchemas in the HiveServer2 Endpoint.

Posted by GitBox <gi...@apache.org>.
yuzelin commented on code in PR #20401:
URL: https://github.com/apache/flink/pull/20401#discussion_r938501841


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/endpoint/hive/HiveServer2Schemas.java:
##########
@@ -35,4 +36,16 @@ public class HiveServer2Schemas {
                                     .withComment("Catalog name. NULL if not applicable.")),
                     Collections.emptyList(),
                     null);
+
+    /** Schema for {@link HiveServer2Endpoint#GetSchemas}. */
+    public static final ResolvedSchema GET_SCHEMAS_SCHEMA =
+            new ResolvedSchema(
+                    Collections.unmodifiableList(

Review Comment:
   Removed.



-- 
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-unsubscribe@flink.apache.org

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