You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/06/07 03:21:18 UTC

[GitHub] [incubator-doris] weizhengte opened a new pull request, #9983: [feature-wip](statistics) Fe queries BE by SQL

weizhengte opened a new pull request, #9983:
URL: https://github.com/apache/incubator-doris/pull/9983

   # Proposed changes
   
   Query BE from FE using MySQL protocol. This function is currently mainly used for statistics module. FE obtains statistics by SQL query BE, such as column maximum value, minimum value, etc.
   
   The main implementation of a similar SQL client, through the MySQL protocol for data interaction. The basic process is as follows:
   1. Build a similar SQL client in FE to establish a connection;
   2. Authentication and data interaction based on MySQL protocol;
   3. Execute SQL and parse the resulting packets of SQL execution.
   
   The usage process is as follows(the following code does no exception handling):
   ```
   SqlClient sqlClient = new SqlClient("db");
   sqlClient.init();
   QueryResultSet query = sqlClient.query("SELECT * FROM table1");
   List<String> columns = query.getColumns();
   while (query.next()) {
       for (String column : columns) {
           System.out.println(query.getColumnValue(column));
       }
   }
   sqlClient.close();
   ```
   
   Note: this is a tool module as statistics, it will not affect the original code, also will not affect the use of users. It can even be removed if necessary in the future.
   
   ## Problem Summary:
   
   Describe the overview of changes.
   
   ## Checklist(Required)
   
   1. Does it affect the original behavior: (Yes/No/I Don't know)
   2. Has unit tests been added: (Yes/No/No Need)
   3. Has document been added or modified: (Yes/No/No Need)
   4. Does it need to update dependencies: (Yes/No)
   5. Are there any changes that cannot be rolled back: (Yes/No)
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at [dev@doris.apache.org](mailto:dev@doris.apache.org) by explaining why you chose the solution you did and what alternatives you considered, etc...
   


-- 
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: commits-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] weizhengte commented on a diff in pull request #9983: [feature-wip](statistics) Internal-query, execute SQL query statement internally (in FE)

Posted by GitBox <gi...@apache.org>.
weizhengte commented on code in PR #9983:
URL: https://github.com/apache/doris/pull/9983#discussion_r973668119


##########
fe/fe-core/src/main/java/org/apache/doris/statistics/util/Packet.java:
##########
@@ -0,0 +1,42 @@
+// 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.statistics.util;
+
+import java.nio.ByteBuffer;
+
+public abstract class Packet {

Review Comment:
   the relevant code has been deeply refactored, and some problem have been resolved. same as following.



-- 
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: commits-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] Kikyou1997 commented on pull request #9983: [feature-wip](statistics) FE queries BE by SQL

Posted by GitBox <gi...@apache.org>.
Kikyou1997 commented on PR #9983:
URL: https://github.com/apache/doris/pull/9983#issuecomment-1248973250

   Why don't use jdbc to send query to FE itself directly?


-- 
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: commits-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] github-actions[bot] commented on pull request #9983: [feature-wip](statistics) Internal-query, execute SQL query statement internally (in FE)

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #9983:
URL: https://github.com/apache/doris/pull/9983#issuecomment-1250548525

   PR approved by anyone and no changes requested.


-- 
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: commits-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] weizhengte commented on pull request #9983: [feature-wip](statistics) Internal-query, execute SQL query statement internally (in FE)

Posted by GitBox <gi...@apache.org>.
weizhengte commented on PR #9983:
URL: https://github.com/apache/doris/pull/9983#issuecomment-1250519238

   > Why don't use jdbc to send query to FE itself directly?
   
   Indeed, the previous implementation was complicated...


-- 
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: commits-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] Kikyou1997 commented on pull request #9983: [feature-wip](statistics) Internal-query, execute SQL query statement internally (in FE)

Posted by GitBox <gi...@apache.org>.
Kikyou1997 commented on PR #9983:
URL: https://github.com/apache/doris/pull/9983#issuecomment-1250538167

   @morrySnow review plz


-- 
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: commits-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] morrySnow merged pull request #9983: [feature-wip](statistics) Internal-query, execute SQL query statement internally (in FE)

Posted by GitBox <gi...@apache.org>.
morrySnow merged PR #9983:
URL: https://github.com/apache/doris/pull/9983


-- 
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: commits-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] morrySnow commented on a diff in pull request #9983: [feature-wip](statistics) FE queries BE by SQL

Posted by GitBox <gi...@apache.org>.
morrySnow commented on code in PR #9983:
URL: https://github.com/apache/doris/pull/9983#discussion_r941285015


##########
fe/fe-core/src/main/java/org/apache/doris/statistics/util/Packet.java:
##########
@@ -0,0 +1,42 @@
+// 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.statistics.util;
+
+import java.nio.ByteBuffer;
+
+public abstract class Packet {

Review Comment:
   please add some comments to explain what is Packet and where to use it



##########
fe/fe-core/src/main/java/org/apache/doris/statistics/util/Connection.java:
##########
@@ -0,0 +1,424 @@
+// 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.statistics.util;
+
+import org.apache.doris.common.Config;
+import org.apache.doris.mysql.MysqlCapability;
+import org.apache.doris.mysql.MysqlCommand;
+import org.apache.doris.mysql.privilege.PaloAuth;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.nio.ByteBuffer;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+public class Connection implements AutoCloseable {

Review Comment:
   please add usage in commit msg into this class's comment directly



##########
fe/fe-core/src/main/java/org/apache/doris/statistics/util/Connection.java:
##########
@@ -0,0 +1,424 @@
+// 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.statistics.util;
+
+import org.apache.doris.common.Config;
+import org.apache.doris.mysql.MysqlCapability;
+import org.apache.doris.mysql.MysqlCommand;
+import org.apache.doris.mysql.privilege.PaloAuth;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.nio.ByteBuffer;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+public class Connection implements AutoCloseable {
+    private static final Logger LOG = LogManager.getLogger(Connection.class);
+
+    private static final int BUFFER_SIZE = 1024;
+    private static final int ERROR_STATUS = 0xff;
+    private static final int OK_STATUS = 0x00;
+
+    private final StringBuilder sb = new StringBuilder();
+
+    private String host;
+    private int port;
+    private String username;
+    private String password;
+    private String database;
+
+    private Socket socket;
+
+    private InputStream in;
+    private OutputStream out;
+
+    private ByteBuffer hpBuffer;
+    private ByteBuffer buffer;
+
+    private HandshakePacket handshakePacket;
+
+    private Boolean initialized = false;
+
+    public Connection() {
+    }
+
+    /**
+     * Fe query be does not require a password,
+     * root and admin user is allowed to login from 127.0.0.1, in case user forget password.
+     *
+     * @param database database name
+     * @see PaloAuth
+     */
+    public Connection(String database) {
+        host = "127.0.0.1";
+        port = Config.query_port;
+        username = PaloAuth.ROOT_USER;
+        password = "";

Review Comment:
   be's password is same with fe's password? should we get correct password automatically rather than set by user?



-- 
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: commits-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] weizhengte commented on a diff in pull request #9983: [feature-wip](statistics) FE queries BE by SQL

Posted by GitBox <gi...@apache.org>.
weizhengte commented on code in PR #9983:
URL: https://github.com/apache/doris/pull/9983#discussion_r973668119


##########
fe/fe-core/src/main/java/org/apache/doris/statistics/util/Packet.java:
##########
@@ -0,0 +1,42 @@
+// 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.statistics.util;
+
+import java.nio.ByteBuffer;
+
+public abstract class Packet {

Review Comment:
   the relevant code has been deeply refactored, and your comments have been resolved. same as following.



-- 
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: commits-unsubscribe@doris.apache.org

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


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