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 2021/08/25 13:01:57 UTC

[GitHub] [incubator-doris] nimuyuhan opened a new pull request #6507: 【Bug】Some functions of doris push down mysql to run abnormally

nimuyuhan opened a new pull request #6507:
URL: https://github.com/apache/incubator-doris/pull/6507


   ## Proposed changes
   
   select * from (select if(get_json_string(str, "$.k1")='V1','1','0') as param from json_test) result where param=0; 
   mysql mapping table prompts that there is no get_json_string a function.
   
   1、The doris function is replaced with a MySQL compatible function.
   2、Different versions of mysql support different functions. Add the administrator command "enable_external_database_function_push_down" to start pushing down rdms.
   
   ## Types of changes
   
   What types of changes does your code introduce to Doris?
   _Put an `x` in the boxes that apply_
   
   - [ ] Bugfix (non-breaking change which fixes an issue)
   - [ ] New feature (non-breaking change which adds functionality)
   - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
   - [ ] Documentation Update (if none of the other choices apply)
   - [ ] Code refactor (Modify the code structure, format the code, etc...)
   - [ ] Optimization. Including functional usability improvements and performance improvements.
   - [ ] Dependency. Such as changes related to third-party components.
   - [ ] Other.
   
   ## Checklist
   
   _Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._
   
   - [ ] I have created an issue on (Fix #ISSUE) and described the bug/feature there in detail
   - [ ] Compiling and unit tests pass locally with my changes
   - [ ] I have added tests that prove my fix is effective or that my feature works
   - [ ] If these changes need document changes, I have updated the document
   - [ ] Any dependent changes have been merged
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at 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] [incubator-doris] nimuyuhan commented on a change in pull request #6507: 【Bug】Some functions of doris push down mysql to run abnormally

Posted by GitBox <gi...@apache.org>.
nimuyuhan commented on a change in pull request #6507:
URL: https://github.com/apache/incubator-doris/pull/6507#discussion_r698454186



##########
File path: fe/fe-core/src/main/java/org/apache/doris/planner/OdbcScanNode.java
##########
@@ -169,7 +155,8 @@ private void createOdbcFilters(Analyzer analyzer) {
         }
         ArrayList<Expr> odbcConjuncts = Expr.cloneList(conjuncts, sMap);
         for (Expr p : odbcConjuncts) {
-            if (shouldPushDownConjunct(odbcType, p)) {
+            if (Config.enable_external_database_function_push_down) {

Review comment:
       I agree. The scenario I encountered was that the functions of different versions were different. For example, there was no json_extract in the version before mysql 5.7. From the user's point of view, individual functions should not cause the statement to be modified or the code cannot be executed.




-- 
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] [incubator-doris] nimuyuhan commented on a change in pull request #6507: 【Bug】Some functions of doris push down mysql to run abnormally

Posted by GitBox <gi...@apache.org>.
nimuyuhan commented on a change in pull request #6507:
URL: https://github.com/apache/incubator-doris/pull/6507#discussion_r698454186



##########
File path: fe/fe-core/src/main/java/org/apache/doris/planner/OdbcScanNode.java
##########
@@ -169,7 +155,8 @@ private void createOdbcFilters(Analyzer analyzer) {
         }
         ArrayList<Expr> odbcConjuncts = Expr.cloneList(conjuncts, sMap);
         for (Expr p : odbcConjuncts) {
-            if (shouldPushDownConjunct(odbcType, p)) {
+            if (Config.enable_external_database_function_push_down) {

Review comment:
       I agree. The scenario I encountered was that the functions of different versions were different. For example, there was no json_extract in the version before mysql 5.7. From the user's point of view, individual functions should not cause the statement to be modified or the code cannot be executed.




-- 
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] [incubator-doris] nimuyuhan commented on a change in pull request #6507: 【Bug】Some functions of doris push down mysql to run abnormally

Posted by GitBox <gi...@apache.org>.
nimuyuhan commented on a change in pull request #6507:
URL: https://github.com/apache/incubator-doris/pull/6507#discussion_r702601931



##########
File path: fe/fe-core/src/main/java/org/apache/doris/planner/MysqlScanNode.java
##########
@@ -131,7 +131,11 @@ private void createMySQLFilters(Analyzer analyzer) {
         }
         ArrayList<Expr> mysqlConjuncts = Expr.cloneList(conjuncts, sMap);
         for (Expr p : mysqlConjuncts) {
-            filters.add(p.toMySql());
+            if (Config.enable_external_database_function_push_down) {
+                FunctionMappingHelper.mappingEngineFunction(p, "mysql");

Review comment:
       I fix these problems at d0e0b70e28897bfa67e9c7b007df6d2f03f3b7dd




-- 
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] [incubator-doris] morningman commented on a change in pull request #6507: 【Bug】Some functions of doris push down mysql to run abnormally

Posted by GitBox <gi...@apache.org>.
morningman commented on a change in pull request #6507:
URL: https://github.com/apache/incubator-doris/pull/6507#discussion_r696731255



##########
File path: fe/fe-core/src/main/java/org/apache/doris/planner/MysqlScanNode.java
##########
@@ -131,7 +131,11 @@ private void createMySQLFilters(Analyzer analyzer) {
         }
         ArrayList<Expr> mysqlConjuncts = Expr.cloneList(conjuncts, sMap);
         for (Expr p : mysqlConjuncts) {
-            filters.add(p.toMySql());
+            if (Config.enable_external_database_function_push_down) {
+                FunctionMappingHelper.mappingEngineFunction(p, "mysql");

Review comment:
       "mysql" should be defined as a const value or enum

##########
File path: fe/fe-core/src/main/java/org/apache/doris/planner/OdbcScanNode.java
##########
@@ -169,7 +155,8 @@ private void createOdbcFilters(Analyzer analyzer) {
         }
         ArrayList<Expr> odbcConjuncts = Expr.cloneList(conjuncts, sMap);
         for (Expr p : odbcConjuncts) {
-            if (shouldPushDownConjunct(odbcType, p)) {
+            if (Config.enable_external_database_function_push_down) {

Review comment:
       This better not be a `config`, because user may visit mysql and oracle in one Doris cluster.
   And what if user query both mysql and oracle in one SQL?
   This is a bit complicate, I have no idea how to solve it yet.

##########
File path: fe/fe-core/src/main/java/org/apache/doris/planner/FunctionMappingHelper.java
##########
@@ -0,0 +1,88 @@
+// 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.planner;
+
+import com.google.common.collect.Maps;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Map;
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.analysis.FunctionCallExpr;
+import org.apache.doris.analysis.FunctionName;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+public class FunctionMappingHelper {
+    private static final Logger LOG = LogManager.getLogger(FunctionMappingHelper.class);
+
+    public final static Map<String, Map<String, String>> EXTERNAL_DATABASE_FUNCTION_MAPPING = Maps.newTreeMap();
+    public final static Map<String, String> MYSQL_MAPPING_FUNCTION = Maps.newTreeMap();
+    public final static Map<String, String> ORACLE_MAPPING_FUNCTION = Maps.newTreeMap();
+    public final static Map<String, String> SQLSERVER_MAPPING_FUNCTION = Maps.newTreeMap();
+    public final static Map<String, String> POSTGRESQL_MAPPING_FUNCTION = Maps.newTreeMap();
+
+    static {
+        // Add mapping function.
+        addFunctionMapping("mysql","get_json_string", "json_extract");
+    }
+
+    public static void addFunctionMapping(String databaseType, String sourceFunction, String targetFunction) {

Review comment:
       databaseType: use enum instead of string




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