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

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


The following commit(s) were added to refs/heads/master by this push:
     new f591098  [Feature] Support fe login using sql tools when no be is 
available. (#6150)
f591098 is described below

commit f591098b080b54b9267eb026ef639e1cf1d7be99
Author: Arthur.Zhang <[email protected]>
AuthorDate: Tue Sep 7 11:51:46 2021 +0800

    [Feature] Support fe login using sql tools when no be is available. (#6150)
    
    When no backend(be) available, eg first time before setup or all be is 
down, we cannot login to fe using most sql tools, eg datagrip, querious.
    
    This is because these tools call `select version()` or  `select 
@@version_comment …` right after login, when there is no backend available, the 
login will fail.
    
    I make this pr to support login when no be available, so we can add backend 
or modify some configuaration using GUI sql tools, especially the first setup 
time.
    
    This pr is working at precondition that,sql tools only query very simple 
information that fe can handle, there is no need to send the request to be.
    
    So I check the query type and BE status, if we can handle the query and no 
BE is available, we will intercept and process in fe.
---
 .../org/apache/doris/qe/AbstractResultSet.java     | 80 +++++++++++++++++++
 ...etaData.java => AbstractResultSetMetaData.java} | 44 +++--------
 .../java/org/apache/doris/qe/CommonResultSet.java  | 36 +++++++++
 .../java/org/apache/doris/qe/ConnectProcessor.java |  5 +-
 .../java/org/apache/doris/qe/GlobalVariable.java   |  4 +-
 .../main/java/org/apache/doris/qe/ResultSet.java   | 90 ++++++++++++++++++++++
 .../org/apache/doris/qe/ResultSetMetaData.java     | 55 +++++++++++++
 .../java/org/apache/doris/qe/ShowResultSet.java    | 62 ++-------------
 .../org/apache/doris/qe/ShowResultSetMetaData.java | 26 +------
 .../java/org/apache/doris/qe/StmtExecutor.java     | 43 ++++++++++-
 .../java/org/apache/doris/rewrite/FEFunctions.java |  7 ++
 11 files changed, 334 insertions(+), 118 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/qe/AbstractResultSet.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/AbstractResultSet.java
new file mode 100644
index 0000000..81fb07c
--- /dev/null
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/AbstractResultSet.java
@@ -0,0 +1,80 @@
+// 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.qe;
+
+import java.util.List;
+
+public abstract class AbstractResultSet implements ResultSet {
+    protected ResultSetMetaData metaData;
+    protected List<List<String>> resultRows;
+    int rowIdx;
+
+    public AbstractResultSet() {
+    }
+
+    public AbstractResultSet(ResultSetMetaData metaData, List<List<String>> 
resultRows) {
+        this.metaData = metaData;
+        this.resultRows = resultRows;
+        rowIdx = -1;
+    }
+
+    @Override
+    public boolean next() {
+        if (rowIdx + 1 >= resultRows.size()) {
+            return false;
+        }
+        rowIdx++;
+        return true;
+    }
+
+    @Override
+    public List<List<String>> getResultRows() {
+        return resultRows;
+    }
+
+    @Override
+    public ResultSetMetaData getMetaData() {
+        return metaData;
+    }
+
+    @Override
+    public String getString(int col) {
+        return resultRows.get(rowIdx).get(col);
+    }
+
+    @Override
+    public byte getByte(int col) {
+        return Byte.valueOf(getString(col));
+    }
+
+    @Override
+    public int getInt(int col) {
+        return Integer.valueOf(getString(col));
+    }
+
+    @Override
+    public long getLong(int col) {
+        return Long.valueOf(getString(col));
+    }
+
+    @Override
+    public short getShort(int col) {
+        return Short.valueOf(getString(col));
+    }
+
+}
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowResultSetMetaData.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/AbstractResultSetMetaData.java
similarity index 64%
copy from 
fe/fe-core/src/main/java/org/apache/doris/qe/ShowResultSetMetaData.java
copy to 
fe/fe-core/src/main/java/org/apache/doris/qe/AbstractResultSetMetaData.java
index cc44aa0..4789fce 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowResultSetMetaData.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/qe/AbstractResultSetMetaData.java
@@ -17,58 +17,36 @@
 
 package org.apache.doris.qe;
 
-// Meta data to describe result set of show statement.
-// Because ResultSetMetaData is complicated, redefine it.
-
-import org.apache.doris.catalog.Column;
-
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
+import org.apache.doris.catalog.Column;
 
 import java.util.List;
 
-public class ShowResultSetMetaData {
-    private List<Column> columns;
+public class AbstractResultSetMetaData implements ResultSetMetaData {
+    private final List<Column> columns;
 
+    public AbstractResultSetMetaData(List<Column> columns) {
+        this.columns = columns;
+    }
+
+    @Override
     public int getColumnCount() {
         return columns.size();
     }
 
+    @Override
     public List<Column> getColumns() {
         return columns;
     }
 
+    @Override
     public Column getColumn(int idx) {
         return columns.get(idx);
     }
 
+    @Override
     public void removeColumn(int idx) {
         Preconditions.checkArgument(idx < columns.size());
         columns.remove(idx);
     }
-
-    public ShowResultSetMetaData(List<Column> columns) {
-        this.columns = columns;
-    }
-
-    public static Builder builder() {
-        return new Builder();
-    }
-
-    public static class Builder {
-        private List<Column> columns;
-
-        public Builder() {
-            columns = Lists.newArrayList();
-        }
-
-        public ShowResultSetMetaData build() {
-            return new ShowResultSetMetaData(columns);
-        }
-
-        public Builder addColumn(Column col) {
-            columns.add(col);
-            return this;
-        }
-    }
 }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/CommonResultSet.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/CommonResultSet.java
new file mode 100644
index 0000000..2735739
--- /dev/null
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/CommonResultSet.java
@@ -0,0 +1,36 @@
+// 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.qe;
+
+import org.apache.doris.catalog.Column;
+
+import java.util.List;
+
+public class CommonResultSet extends AbstractResultSet {
+
+    public CommonResultSet(ResultSetMetaData metaData, List<List<String>> 
resultRows) {
+        super(metaData, resultRows);
+    }
+
+    public static class CommonResultSetMetaData extends 
AbstractResultSetMetaData {
+        public CommonResultSetMetaData(List<Column> columns) {
+            super(columns);
+        }
+    }
+
+}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java
index 7d44cc2..eb85f1a 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java
@@ -17,6 +17,7 @@
 
 package org.apache.doris.qe;
 
+import com.google.common.base.Strings;
 import org.apache.doris.analysis.InsertStmt;
 import org.apache.doris.analysis.KillStmt;
 import org.apache.doris.analysis.SqlParser;
@@ -80,6 +81,8 @@ public class ConnectProcessor {
         this.ctx = context;
     }
 
+
+
     // COM_INIT_DB: change current database of this session.
     private void handleInitDb() {
         String dbName = new String(packetBuf.array(), 1, packetBuf.limit() - 
1);
@@ -392,7 +395,7 @@ public class ConnectProcessor {
             if (resultSet == null) {
                 packet = executor.getOutputPacket();
             } else {
-                executor.sendShowResult(resultSet);
+                executor.sendResult(resultSet);
                 packet = getResultPacket();
                 if (packet == null) {
                     LOG.debug("packet == null");
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/GlobalVariable.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/GlobalVariable.java
index 54441f1..60decf2 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/GlobalVariable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/GlobalVariable.java
@@ -63,7 +63,7 @@ public final class GlobalVariable {
 
     // A string to be executed by the server for each client that connects
     @VariableMgr.VarAttr(name = INIT_CONNECT, flag = VariableMgr.GLOBAL)
-    private volatile static String initConnect = "";
+    public volatile static String initConnect = "";
 
     // A string to be executed by the server for each client that connects
     @VariableMgr.VarAttr(name = SYSTEM_TIME_ZONE, flag = VariableMgr.READ_ONLY)
@@ -71,7 +71,7 @@ public final class GlobalVariable {
 
     // The amount of memory allocated for caching query results
     @VariableMgr.VarAttr(name = QUERY_CACHE_SIZE, flag = VariableMgr.GLOBAL)
-    private volatile static long queryCacheSize = 1048576;
+    public volatile static long queryCacheSize = 1048576;
 
     @VariableMgr.VarAttr(name = DEFAULT_ROWSET_TYPE, flag = VariableMgr.GLOBAL)
     public volatile static String defaultRowsetType = "alpha";
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ResultSet.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/ResultSet.java
new file mode 100644
index 0000000..468aa47
--- /dev/null
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ResultSet.java
@@ -0,0 +1,90 @@
+// 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.qe;
+
+import java.util.List;
+
+/**
+ * Simplified ResultSet implementation
+ */
+public interface ResultSet {
+
+    /**
+     * Moves the cursor froward one row from its current position.
+     *
+     * @return <code>true</code> if the new current row is valid;
+     *<code>false</code> if there are no more rows
+     */
+    boolean next();
+
+    /**
+     * Return result data in list format
+     *
+     * @return A list of list data of rows
+     */
+    List<List<String>> getResultRows();
+
+    /**
+     * Retrieves the number, types and properties of
+     * this <code>ResultSet</code> object's columns.
+     *
+     * @return the description of this <code>ResultSet</code> object's columns
+     */
+    ResultSetMetaData getMetaData();
+
+    /**
+     * Retrieves the value of the designated column in the current row
+     * of this <code>ResultSet</code> object as String
+     * @param col the column index
+     * @return the column value
+     */
+    String getString(int col);
+
+    /**
+     * Retrieves the value of the designated column in the current row
+     * of this <code>ResultSet</code> object as byte
+     * @param col the column index
+     * @return the column value
+     */
+    byte getByte(int col);
+
+    /**
+     * Retrieves the value of the designated column in the current row
+     * of this <code>ResultSet</code> object as short
+     * @param col the column index
+     * @return the column value
+     */
+    short getShort(int col);
+
+    /**
+     * Retrieves the value of the designated column in the current row
+     * of this <code>ResultSet</code> object as int
+     * @param col the column index
+     * @return the column value
+     */
+    int getInt(int col);
+
+    /**
+     * Retrieves the value of the designated column in the current row
+     * of this <code>ResultSet</code> object as long
+     * @param col the column index
+     * @return the column value
+     */
+    long getLong(int col);
+
+}
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/qe/ResultSetMetaData.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/ResultSetMetaData.java
new file mode 100644
index 0000000..96ff98c
--- /dev/null
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ResultSetMetaData.java
@@ -0,0 +1,55 @@
+// 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.qe;
+
+import org.apache.doris.catalog.Column;
+
+import java.util.List;
+
+/**
+ * A ResultSetMetaData object can be used to find out about the types and
+ * properties of the columns in a ResultSet
+ */
+public interface ResultSetMetaData {
+
+    /**
+     * Whats the number of columns in the ResultSet?
+     * @return the number
+     */
+    int getColumnCount();
+
+    /**
+     * Get all columns
+     * @return all the columns as list
+     */
+    List<Column> getColumns();
+
+    /**
+     * Get a column at some index
+     * @param idx the index of column
+     * @return column data
+     */
+    Column getColumn(int idx);
+
+    /**
+     * Remove a column at some index
+     * @param idx the index of column
+     * @return column data
+     */
+    void removeColumn(int idx);
+}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowResultSet.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowResultSet.java
index 4d54acd..a2c852d 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowResultSet.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowResultSet.java
@@ -17,9 +17,7 @@
 
 package org.apache.doris.qe;
 
-import java.util.ArrayList;
-import java.util.List;
-
+import com.google.common.collect.Lists;
 import org.apache.doris.catalog.Column;
 import org.apache.doris.catalog.PrimitiveType;
 import org.apache.doris.catalog.ScalarType;
@@ -27,27 +25,18 @@ import org.apache.doris.thrift.TColumnDefinition;
 import org.apache.doris.thrift.TShowResultSet;
 import org.apache.doris.thrift.TShowResultSetMetaData;
 
-import com.google.common.collect.Lists;
-
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.LogManager;
+import java.util.ArrayList;
+import java.util.List;
 
 // Result set of show statement.
 // Redefine ResultSet now, because JDBC is too complicated.
 // TODO(zhaochun): Maybe interface is better.
-public class ShowResultSet {
-    private static final Logger LOG = 
LogManager.getLogger(ShowResultSet.class);
-    private ShowResultSetMetaData metaData;
-    private List<List<String>> resultRows;
-    int rowIdx;
+public class ShowResultSet extends AbstractResultSet {
 
-    // now only support static result.
-    public ShowResultSet(ShowResultSetMetaData metaData, List<List<String>> 
resultRows) {
-        this.metaData = metaData;
-        this.resultRows = resultRows;
-        rowIdx = -1;
+    public ShowResultSet(ResultSetMetaData metaData, List<List<String>> 
resultRows) {
+        super(metaData, resultRows);
     }
-     
+
     public ShowResultSet(TShowResultSet resultSet) {
         List<Column> columns = Lists.newArrayList();
         for (int i = 0; i < resultSet.getMetaData().getColumnsSize(); i ++) {
@@ -60,45 +49,8 @@ public class ShowResultSet {
         this.metaData = new ShowResultSetMetaData(columns);
         this.resultRows = resultSet.getResultRows();
         this.rowIdx = -1;
-        
-    }
-
-    public boolean next() {
-        if (rowIdx + 1 >= resultRows.size()) {
-            return false;
-        }
-        rowIdx++;
-        return true;
     }
 
-    public List<List<String>> getResultRows() {
-        return resultRows;
-    }
-
-    public ShowResultSetMetaData getMetaData() {
-        return metaData;
-    }
-
-    public String getString(int col) {
-        return resultRows.get(rowIdx).get(col);
-    }
-
-    public byte getByte(int col) {
-        return Byte.valueOf(getString(col));
-    }
-
-    public int getInt(int col) {
-        return Integer.valueOf(getString(col));
-    }
-
-    public long getLong(int col) {
-        return Long.valueOf(getString(col));
-    }
-
-    public short getShort(int col) {
-        return Short.valueOf(getString(col));
-    }
-    
     public TShowResultSet tothrift() {
         TShowResultSet set = new TShowResultSet();
         set.metaData = new TShowResultSetMetaData();
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowResultSetMetaData.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowResultSetMetaData.java
index cc44aa0..8eeddea 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowResultSetMetaData.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowResultSetMetaData.java
@@ -20,35 +20,15 @@ package org.apache.doris.qe;
 // Meta data to describe result set of show statement.
 // Because ResultSetMetaData is complicated, redefine it.
 
-import org.apache.doris.catalog.Column;
-
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
+import org.apache.doris.catalog.Column;
 
 import java.util.List;
 
-public class ShowResultSetMetaData {
-    private List<Column> columns;
-
-    public int getColumnCount() {
-        return columns.size();
-    }
-
-    public List<Column> getColumns() {
-        return columns;
-    }
-
-    public Column getColumn(int idx) {
-        return columns.get(idx);
-    }
-
-    public void removeColumn(int idx) {
-        Preconditions.checkArgument(idx < columns.size());
-        columns.remove(idx);
-    }
+public class ShowResultSetMetaData extends AbstractResultSetMetaData {
 
     public ShowResultSetMetaData(List<Column> columns) {
-        this.columns = columns;
+        super(columns);
     }
 
     public static Builder builder() {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
index f242f4b..ee2ca13 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
@@ -26,10 +26,12 @@ import org.apache.doris.analysis.ExportStmt;
 import org.apache.doris.analysis.Expr;
 import org.apache.doris.analysis.InsertStmt;
 import org.apache.doris.analysis.KillStmt;
+import org.apache.doris.analysis.LiteralExpr;
 import org.apache.doris.analysis.NullLiteral;
 import org.apache.doris.analysis.OutFileClause;
 import org.apache.doris.analysis.QueryStmt;
 import org.apache.doris.analysis.RedirectStatus;
+import org.apache.doris.analysis.SelectListItem;
 import org.apache.doris.analysis.SelectStmt;
 import org.apache.doris.analysis.SetStmt;
 import org.apache.doris.analysis.SetVar;
@@ -121,6 +123,8 @@ import org.glassfish.jersey.internal.guava.Sets;
 import java.io.IOException;
 import java.io.StringReader;
 import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -811,6 +815,29 @@ public class StmtExecutor implements ProfileWriter {
         return;
     }
 
+    private boolean handleSelectRequestInFe(SelectStmt parsedSelectStmt) 
throws IOException {
+        List<SelectListItem> selectItemList = 
parsedSelectStmt.getSelectList().getItems();
+        List<Column> columns = new ArrayList<>(selectItemList.size());
+        ResultSetMetaData metadata = new 
CommonResultSet.CommonResultSetMetaData(columns);
+
+        List<String> columnLabels = parsedSelectStmt.getColLabels();
+        List<String> data = new ArrayList<>();
+        for (int i = 0; i < selectItemList.size(); i++) {
+            SelectListItem item = selectItemList.get(i);
+            Expr expr = item.getExpr();
+            String columnName = columnLabels.get(i);
+            if (expr instanceof LiteralExpr) {
+                columns.add(new Column(columnName, PrimitiveType.VARCHAR));
+                data.add(((LiteralExpr) expr).getStringValue());
+            } else {
+                return false;
+            }
+        }
+        ResultSet resultSet = new CommonResultSet(metadata, 
Collections.singletonList(data));
+        sendResult(resultSet);
+        return true;
+    }
+
     // Process a select statement.
     private void handleQueryStmt() throws Exception {
         // Every time set no send flag and clean all data in buffer
@@ -826,6 +853,15 @@ public class StmtExecutor implements ProfileWriter {
         context.setQueryDetail(queryDetail);
         QueryDetailQueue.addOrUpdateQueryDetail(queryDetail);
 
+        // handle selects that fe can do without be, so we can make sql tools 
happy, especially the setup step.
+        if (parsedStmt instanceof SelectStmt && ((SelectStmt) 
parsedStmt).getTableRefs().isEmpty()
+                    && 
Catalog.getCurrentSystemInfo().getBackendIds(true).isEmpty() ) {
+            SelectStmt parsedSelectStmt = (SelectStmt) parsedStmt;
+            if (handleSelectRequestInFe(parsedSelectStmt)) {
+                return;
+            }
+        }
+
         if (queryStmt.isExplain()) {
             String explainString = 
planner.getExplainString(planner.getFragments(), queryStmt.getExplainOptions());
             handleExplainStmt(explainString);
@@ -1315,7 +1351,7 @@ public class StmtExecutor implements ProfileWriter {
         context.getState().setOk();
     }
 
-    private void sendMetaData(ShowResultSetMetaData metaData) throws 
IOException {
+    private void sendMetaData(ResultSetMetaData metaData) throws IOException {
         // sends how many columns
         serializer.reset();
         serializer.writeVInt(metaData.getColumnCount());
@@ -1351,8 +1387,7 @@ public class StmtExecutor implements ProfileWriter {
         eofPacket.writeTo(serializer);
         context.getMysqlChannel().sendOnePacket(serializer.toByteBuffer());
     }
-
-    public void sendShowResult(ShowResultSet resultSet) throws IOException {
+    public void sendResult(ResultSet resultSet) throws IOException {
         context.updateReturnRows(resultSet.getResultRows().size());
         // Send meta data.
         sendMetaData(resultSet.getMetaData());
@@ -1385,7 +1420,7 @@ public class StmtExecutor implements ProfileWriter {
             return;
         }
 
-        sendShowResult(resultSet);
+        sendResult(resultSet);
     }
 
     private void handleExplainStmt(String result) throws IOException {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java 
b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java
index 03150ba..f595d4f 100755
--- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java
@@ -33,6 +33,7 @@ import org.apache.doris.catalog.Type;
 import org.apache.doris.common.AnalysisException;
 import org.apache.doris.common.InvalidFormatException;
 import org.apache.doris.common.util.TimeUtils;
+import org.apache.doris.qe.GlobalVariable;
 
 import com.google.common.base.Preconditions;
 
@@ -51,6 +52,12 @@ import java.math.BigInteger;
  */
 public class FEFunctions {
     private static final Logger LOG = LogManager.getLogger(FEFunctions.class);
+
+    @FEFunction(name = "version", argTypes = {}, returnType = "VARCHAR")
+    public static StringLiteral version() throws AnalysisException {
+        return new StringLiteral(GlobalVariable.version);
+    }
+
     /**
      * date and time function
      */

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to