This is an automated email from the ASF dual-hosted git repository.

starocean999 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 4ef95faf3a1 [Enhancement] (nereids)implement showCharsetCommand in 
nereids (#43155)
4ef95faf3a1 is described below

commit 4ef95faf3a1c0fae68ca8b98eb7a297832517cb5
Author: Sridhar R Manikarnike <sridhar.n...@gmail.com>
AuthorDate: Mon Dec 16 16:05:55 2024 +0530

    [Enhancement] (nereids)implement showCharsetCommand in nereids (#43155)
    
    Issue Number: close #42749
---
 .../antlr4/org/apache/doris/nereids/DorisParser.g4 |  2 +-
 .../doris/nereids/parser/LogicalPlanBuilder.java   |  7 +++
 .../apache/doris/nereids/trees/plans/PlanType.java |  1 +
 .../trees/plans/commands/ShowCharsetCommand.java   | 67 ++++++++++++++++++++++
 .../trees/plans/visitor/CommandVisitor.java        |  5 ++
 .../nereids_p0/show/test_show_charset_command.out  |  4 ++
 .../show/test_show_charset_command.groovy          | 30 ++++++++++
 7 files changed, 115 insertions(+), 1 deletion(-)

diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
index bc91a667eda..3d797988046 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
@@ -234,6 +234,7 @@ supportedShowStatement
     | SHOW DYNAMIC PARTITION TABLES ((FROM | IN) 
database=multipartIdentifier)?     #showDynamicPartition
     | SHOW EVENTS ((FROM | IN) database=multipartIdentifier)? wildWhere?       
     #showEvents
     | SHOW LAST INSERT                                                         
     #showLastInsert 
+    | SHOW ((CHAR SET) | CHARSET)                                              
     #showCharset
     | SHOW DELETE ((FROM | IN) database=multipartIdentifier)?                  
     #showDelete
     | SHOW ALL? GRANTS                                                         
     #showGrants
     | SHOW GRANTS FOR userIdentify                                             
     #showGrantsForUser
@@ -331,7 +332,6 @@ unsupportedShowStatement
     | SHOW CATALOG name=identifier                                             
     #showCatalog
     | SHOW FULL? (COLUMNS | FIELDS) (FROM | IN) tableName=multipartIdentifier
         ((FROM | IN) database=multipartIdentifier)? wildWhere?                 
     #showColumns
-    | SHOW ((CHAR SET) | CHARSET) wildWhere?                                   
     #showCharset
     | SHOW COUNT LEFT_PAREN ASTERISK RIGHT_PAREN (WARNINGS | ERRORS)           
     #showWaringErrorCount
     | SHOW LOAD WARNINGS ((((FROM | IN) database=multipartIdentifier)?
         wildWhere? limitClause?) | (ON url=STRING_LITERAL))                    
     #showLoadWarings
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index 94c2757e560..921e3014c90 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -239,6 +239,7 @@ import 
org.apache.doris.nereids.DorisParser.SetVariableWithTypeContext;
 import org.apache.doris.nereids.DorisParser.ShowAuthorsContext;
 import org.apache.doris.nereids.DorisParser.ShowBackendsContext;
 import org.apache.doris.nereids.DorisParser.ShowBrokerContext;
+import org.apache.doris.nereids.DorisParser.ShowCharsetContext;
 import org.apache.doris.nereids.DorisParser.ShowCollationContext;
 import org.apache.doris.nereids.DorisParser.ShowConfigContext;
 import org.apache.doris.nereids.DorisParser.ShowConstraintContext;
@@ -550,6 +551,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.SetUserPropertiesCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowAuthorsCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowBackendsCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowBrokerCommand;
+import org.apache.doris.nereids.trees.plans.commands.ShowCharsetCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowCollationCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowConfigCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowConstraintsCommand;
@@ -4795,6 +4797,11 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
         return new CreateFileCommand(stripQuotes(ctx.name.getText()), dbName, 
properties);
     }
 
+    @Override
+    public LogicalPlan visitShowCharset(ShowCharsetContext ctx) {
+        return new ShowCharsetCommand();
+    }
+
     @Override
     public LogicalPlan visitShowFrontends(ShowFrontendsContext ctx) {
         String detail = (ctx.name != null) ? ctx.name.getText() : null;
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
index 26b8ed4c0c9..060dc859fef 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
@@ -205,6 +205,7 @@ public enum PlanType {
     SHOW_BACKENDS_COMMAND,
     SHOW_BLOCK_RULE_COMMAND,
     SHOW_BROKER_COMMAND,
+    SHOW_CHARSET_COMMAND,
     SHOW_COLLATION_COMMAND,
     SHOW_CONFIG_COMMAND,
     SHOW_CREATE_CATALOG_COMMAND,
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommand.java
new file mode 100644
index 00000000000..bce34695281
--- /dev/null
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommand.java
@@ -0,0 +1,67 @@
+// 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.doris.nereids.trees.plans.commands;
+
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.ShowResultSet;
+import org.apache.doris.qe.ShowResultSetMetaData;
+import org.apache.doris.qe.StmtExecutor;
+
+import com.google.common.collect.Lists;
+
+import java.util.List;
+
+/**
+ * Represents the command for SHOW CHARSETG
+ */
+public class ShowCharsetCommand extends ShowCommand {
+    private static final ShowResultSetMetaData CHARSET_META_DATA =
+            ShowResultSetMetaData.builder()
+                    .addColumn(new Column("Charset", 
ScalarType.createVarchar(20)))
+                    .addColumn(new Column("Description", 
ScalarType.createVarchar(60)))
+                    .addColumn(new Column("Default collation", 
ScalarType.createVarchar(20)))
+                    .addColumn(new Column("Maxlen", 
ScalarType.createVarchar(10)))
+                    .build();
+
+    public ShowCharsetCommand() {
+        super(PlanType.SHOW_CHARSET_COMMAND);
+    }
+
+    @Override
+    public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) 
throws Exception {
+        List<List<String>> rows = Lists.newArrayList();
+        List<String> row = Lists.newArrayList();
+        // | utf8mb4 | UTF-8 Unicode | utf8mb4_general_ci | 4|
+        row.add(ctx.getSessionVariable().getCharsetServer());
+        row.add("UTF-8 Unicode");
+        row.add(ctx.getSessionVariable().getCollationConnection());
+        row.add("4");
+        rows.add(row);
+
+        return new ShowResultSet(CHARSET_META_DATA, rows);
+    }
+
+    @Override
+    public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+        return visitor.visitShowCharsetCommand(this, context);
+    }
+}
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
index efb81ae7ee0..dc01cdd6d76 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
@@ -85,6 +85,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.SetUserPropertiesCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowAuthorsCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowBackendsCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowBrokerCommand;
+import org.apache.doris.nereids.trees.plans.commands.ShowCharsetCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowCollationCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowConfigCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowConstraintsCommand;
@@ -578,6 +579,10 @@ public interface CommandVisitor<R, C> {
         return visitCommand(showReplicaDistributedCommand, context);
     }
 
+    default R visitShowCharsetCommand(ShowCharsetCommand showCharsetCommand, C 
context) {
+        return visitCommand(showCharsetCommand, context);
+    }
+
     default R visitDropWorkloadPolicyCommand(DropWorkloadPolicyCommand 
dropWorkloadPolicyCommand, C context) {
         return visitCommand(dropWorkloadPolicyCommand, context);
     }
diff --git a/regression-test/data/nereids_p0/show/test_show_charset_command.out 
b/regression-test/data/nereids_p0/show/test_show_charset_command.out
new file mode 100644
index 00000000000..dd9ca552bf7
--- /dev/null
+++ b/regression-test/data/nereids_p0/show/test_show_charset_command.out
@@ -0,0 +1,4 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !cmd --
+utf8mb4        UTF-8 Unicode   utf8mb4_0900_bin        4
+
diff --git 
a/regression-test/suites/nereids_p0/show/test_show_charset_command.groovy 
b/regression-test/suites/nereids_p0/show/test_show_charset_command.groovy
new file mode 100644
index 00000000000..30ad3631b94
--- /dev/null
+++ b/regression-test/suites/nereids_p0/show/test_show_charset_command.groovy
@@ -0,0 +1,30 @@
+// 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.
+
+suite("test_show_charset_command", "query,charset") {
+    try {
+        // Execute the SHOW CHARSET command and verify the output
+        checkNereidsExecute("SHOW CHARSET")
+        qt_cmd("SHOW CHARSET")
+
+    } catch (Exception e) {
+        // Log any exceptions that occur during testing
+        log.error("Failed to execute SHOW CHARSET command", e)
+        throw e
+    }
+}
+


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to