jeyhunkarimov commented on code in PR #23612:
URL: https://github.com/apache/flink/pull/23612#discussion_r1408794805


##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/ShowDatabasesOperation.java:
##########
@@ -20,26 +20,108 @@
 
 import org.apache.flink.annotation.Internal;
 import org.apache.flink.table.api.internal.TableResultInternal;
+import org.apache.flink.table.functions.SqlLikeUtils;
 
+import java.util.Arrays;
+
+import static java.util.Objects.requireNonNull;
 import static 
org.apache.flink.table.api.internal.TableResultUtils.buildStringArrayResult;
 
 /** Operation to describe a SHOW DATABASES statement. */
 @Internal
 public class ShowDatabasesOperation implements ShowOperation {
 
+    private final String preposition;
+    private final String catalogName;
+    private final LikeType likeType;
+    private final String likePattern;
+    private final boolean notLike;
+
+    public ShowDatabasesOperation() {
+        // "SHOW DATABASES" command with all options being default
+        this.preposition = null;
+        this.catalogName = null;
+        this.likeType = null;
+        this.likePattern = null;
+        this.notLike = false;
+    }
+
+    public ShowDatabasesOperation(String likeType, String likePattern, boolean 
notLike) {
+        this.preposition = null;
+        this.catalogName = null;
+        if (likeType != null) {
+            this.likeType = LikeType.of(likeType);
+            this.likePattern = requireNonNull(likePattern, "Like pattern must 
not be null");
+            this.notLike = notLike;
+        } else {
+            this.likeType = null;
+            this.likePattern = null;
+            this.notLike = false;
+        }
+    }
+
+    public ShowDatabasesOperation(
+            String preposition,
+            String catalogName,
+            String likeType,
+            String likePattern,
+            boolean notLike) {
+        this.preposition = preposition;
+        this.catalogName = catalogName;
+        if (likeType != null) {
+            this.likeType = LikeType.of(likeType);
+            this.likePattern = requireNonNull(likePattern, "Like pattern must 
not be null");
+            this.notLike = notLike;
+        } else {
+            this.likeType = null;
+            this.likePattern = null;
+            this.notLike = false;
+        }
+    }
+
     @Override
     public String asSummaryString() {
-        return "SHOW DATABASES";
+        StringBuilder builder = new StringBuilder();
+        builder.append("SHOW DATABASES");
+        if (preposition != null) {
+            builder.append(String.format(" %s %s", preposition, catalogName));
+        }
+        if (likeType != null) {
+            if (notLike) {
+                builder.append(String.format(" NOT %s '%s'", likeType.name(), 
likePattern));
+            } else {
+                builder.append(String.format(" %s '%s'", likeType.name(), 
likePattern));
+            }
+        }
+        return builder.toString();
     }
 
     @Override
     public TableResultInternal execute(Context ctx) {
+        String cName =
+                catalogName == null ? 
ctx.getCatalogManager().getCurrentCatalog() : catalogName;
         String[] databases =
-                ctx.getCatalogManager()
-                        
.getCatalogOrThrowException(ctx.getCatalogManager().getCurrentCatalog())
-                        .listDatabases().stream()
+                
ctx.getCatalogManager().getCatalogOrThrowException(cName).listDatabases().stream()
                         .sorted()
                         .toArray(String[]::new);
+
+        if (likeType != null) {
+            databases =
+                    Arrays.stream(databases)

Review Comment:
   done



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