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 12:17:34 UTC

[GitHub] [incubator-doris] zhangstar333 opened a new pull request #6504: [Feature]support three functions of json

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


   ## Proposed changes
   
   support three functions of json_array、json_object、json_quote
   
   
   
   ## 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)
   - [x] New feature (non-breaking change which adds functionality)
   - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
   - [x] 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] yangzhg commented on a change in pull request #6504: [Feature]support three functions of json

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



##########
File path: be/src/exprs/json_functions.cpp
##########
@@ -107,6 +107,89 @@ DoubleVal JsonFunctions::get_json_double(FunctionContext* context, const StringV
         return DoubleVal::null();
     }
 }
+StringVal JsonFunctions::json_array(FunctionContext* context, int num_args,
+                                    const StringVal* json_str) {
+    if (json_str->is_null) {
+        return StringVal::null();
+    }
+    rapidjson::Value array_obj(rapidjson::kArrayType);
+    rapidjson::Document document;
+    rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
+    //flag: The number it contains represents the type of previous parameters
+    std::string flag((char*)json_str[num_args - 1].ptr, json_str[num_args - 1].len);
+    for (int i = 0; i < num_args - 1; ++i) {
+        std::string arg((char*)json_str[i].ptr, json_str[i].len);
+        rapidjson::Value val = parse_str_with_flag(arg, flag, i, allocator);
+        array_obj.PushBack(val, allocator);
+    }
+    rapidjson::StringBuffer buf;
+    rapidjson::Writer<rapidjson::StringBuffer> writer(buf);
+    array_obj.Accept(writer);
+    return AnyValUtil::from_string_temp(context, std::string(buf.GetString()));
+}
+
+StringVal JsonFunctions::json_object(FunctionContext* context, int num_args,
+                                     const StringVal* json_str) {
+    if (json_str->is_null) {
+        return StringVal::null();
+    }
+    rapidjson::Document document(rapidjson::kObjectType);
+    rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
+    std::string flag((char*)json_str[num_args - 1].ptr, json_str[num_args - 1].len);
+    document.SetObject();
+    for (int i = 1; i < num_args - 1; i = i + 2) {
+        std::string arg((char*)json_str[i].ptr, json_str[i].len);
+        rapidjson::Value key(rapidjson::kStringType);
+        key.SetString((char*)json_str[i - 1].ptr, json_str[i - 1].len, allocator);
+        rapidjson::Value val = parse_str_with_flag(arg, flag, i, allocator);
+        document.AddMember(key, val, allocator);
+    }
+    rapidjson::StringBuffer buf;
+    rapidjson::Writer<rapidjson::StringBuffer> writer(buf);
+    document.Accept(writer);
+    return AnyValUtil::from_string_temp(context, std::string(buf.GetString()));
+}
+
+rapidjson::Value JsonFunctions::parse_str_with_flag(const std::string& arg, const std::string& flag,
+                                                    const int& num,

Review comment:
       primitive type is no need to be reference




-- 
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] yangzhg commented on a change in pull request #6504: [Feature]support three functions of json

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



##########
File path: be/src/exprs/json_functions.cpp
##########
@@ -108,6 +109,96 @@ DoubleVal JsonFunctions::get_json_double(FunctionContext* context, const StringV
     }
 }
 
+StringVal JsonFunctions::json_array(FunctionContext* context, int num_args,
+                                    const StringVal* json_str) {
+    if (json_str->is_null) {
+        return StringVal::null();
+    }
+    rapidjson::Value array_obj(rapidjson::kArrayType);
+    rapidjson::Document document;
+    rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
+    //flag: The number it contains represents the type of previous parameters
+    StringVal flag(json_str[num_args - 1].ptr, json_str[num_args - 1].len);
+    DCHECK_EQ(num_args - 1, flag.len);
+    for (int i = 0; i < num_args - 1; ++i) {
+        StringVal arg(json_str[i].ptr, json_str[i].len);
+        rapidjson::Value val = parse_str_with_flag(arg, flag, i, allocator);

Review comment:
       ```suggestion
           rapidjson::Value val = parse_str_with_flag(arg, *flag, i, allocator);
   ```




-- 
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] yangzhg commented on a change in pull request #6504: [Feature]support three functions of json

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



##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
##########
@@ -162,6 +167,29 @@ protected FunctionCallExpr(FunctionCallExpr other) {
         fn = other.fn;
     }
 
+    public void dealJsonTypeFun() {
+        String res = "";
+        extra_mark = extra_mark + "#";

Review comment:
       Why not return this?




-- 
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] yangzhg commented on a change in pull request #6504: [Feature]support three functions of json

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



##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
##########
@@ -74,12 +75,15 @@
                     .add("stddev").add("stddev_val").add("stddev_samp")
                     .add("variance").add("variance_pop").add("variance_pop").add("var_samp").add("var_pop").build();
     private static final String ELEMENT_EXTRACT_FN_NAME = "%element_extract%";
-    
+    //extra_mark use to represents parse parameter about json_array json_object
+    private String extra_mark = "";
+    //use to record the num of json_object parameters 
+    private int originChildNum;

Review comment:
       ```suggestion
       private int originChildSize;
   ```




-- 
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] yangzhg merged pull request #6504: [Feature]support three functions of json

Posted by GitBox <gi...@apache.org>.
yangzhg merged pull request #6504:
URL: https://github.com/apache/incubator-doris/pull/6504


   


-- 
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] yangzhg commented on a change in pull request #6504: [Feature]support three functions of json

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



##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
##########
@@ -74,12 +75,15 @@
                     .add("stddev").add("stddev_val").add("stddev_samp")
                     .add("variance").add("variance_pop").add("variance_pop").add("var_samp").add("var_pop").build();
     private static final String ELEMENT_EXTRACT_FN_NAME = "%element_extract%";
-    
+    //extra_mark use to represents parse parameter about json_array json_object
+    private String extra_mark = "";
+    //use to record the num of json_object parameters 
+    private int originChildNum;
     // Save the functionCallExpr in the original statement
     private Expr originStmtFnExpr;
 
     private boolean isRewrote = false;
-
+    

Review comment:
       extra white space




-- 
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] github-actions[bot] commented on pull request #6504: [Feature]support three functions of json

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #6504:
URL: https://github.com/apache/incubator-doris/pull/6504#issuecomment-910212271






-- 
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] yangzhg commented on a change in pull request #6504: [Feature]support three functions of json

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



##########
File path: be/src/exprs/json_functions.cpp
##########
@@ -108,6 +108,96 @@ DoubleVal JsonFunctions::get_json_double(FunctionContext* context, const StringV
     }
 }
 
+StringVal JsonFunctions::json_array(FunctionContext* context, int num_args,
+                                    const StringVal* json_str) {
+    if (json_str->is_null) {
+        return StringVal::null();
+    }
+    rapidjson::Value array_obj(rapidjson::kArrayType);
+    rapidjson::Document document;
+    rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
+    //flag: The number it contains represents the type of previous parameters
+    std::string flag((char*)json_str[num_args - 1].ptr, json_str[num_args - 1].len);
+    DCHECK(num_args-1==flag.length());
+    for (int i = 0; i < num_args - 1; ++i) {
+        std::string arg((char*)json_str[i].ptr, json_str[i].len);
+        rapidjson::Value val = parse_str_with_flag(arg, flag, i, allocator);
+        array_obj.PushBack(val, allocator);
+    }
+    rapidjson::StringBuffer buf;
+    rapidjson::Writer<rapidjson::StringBuffer> writer(buf);
+    array_obj.Accept(writer);
+    return AnyValUtil::from_string_temp(context, std::string(buf.GetString()));
+}
+
+StringVal JsonFunctions::json_object(FunctionContext* context, int num_args,
+                                     const StringVal* json_str) {
+    if (json_str->is_null) {
+        return StringVal::null();
+    }
+    rapidjson::Document document(rapidjson::kObjectType);
+    rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
+    std::string flag((char*)json_str[num_args - 1].ptr, json_str[num_args - 1].len);

Review comment:
       use stringVal




-- 
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] yangzhg commented on a change in pull request #6504: [Feature]support three functions of json

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



##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
##########
@@ -322,6 +359,48 @@ private void analyzeBuiltinAggFunction(Analyzer analyzer) throws AnalysisExcepti
             }
             return;
         }
+        
+        if(fnName.getFunction().equalsIgnoreCase("json_array")) {
+            if (children.isEmpty()) {
+                throw new AnalysisException(
+                        "json_array is empty, need more parameters: " + this.toSql());
+            }
+            dealJsonTypeFun();
+            return;
+        }
+
+        if(fnName.getFunction().equalsIgnoreCase("json_object")) {
+            if (children.isEmpty()) {
+                throw new AnalysisException("json_object is empty, need more parameters: " + this.toSql());
+            }
+            if ((children.size()&1)==1 && (originChildNum == children.size())) {
+                throw new AnalysisException("json_object can't be odd parameters, need even parameters: " + this.toSql());
+            }
+            String res = "";
+            extra_mark = extra_mark + "#";
+            for (int i = 0; i < children.size(); ++i) {
+                Type type = getChild(i).getType();
+                if (type.isNull()) {
+                    if((i&1)==0){
+                        throw new AnalysisException("json_object key can't be NULL: " + this.toSql());
+                    }
+                    children.set(i, new StringLiteral("NULL"));
+                    res = res + "0";
+                } else if (type.isBoolean()) {
+                    res = res + "1";
+                } else if (type.isNumericType()) {
+                    res = res + "2";
+                } else if (type.isTime()) {
+                    res = res + "3";
+                } else {
+                    res = res + "4";
+                }
+            }
+            res = res + extra_mark;
+            children.add(new StringLiteral(res));
+            LOG.info(res + " sql: " + this.toSql());
+            return;
+        }

Review comment:
       Duplicated with dealJsonTypeFun?




-- 
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] yangzhg commented on a change in pull request #6504: [Feature]support three functions of json

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



##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
##########
@@ -162,6 +167,29 @@ protected FunctionCallExpr(FunctionCallExpr other) {
         fn = other.fn;
     }
 
+    public void dealJsonTypeFun() {
+        String res = "";
+        extra_mark = extra_mark + "#";
+        for (int i = 0; i < children.size(); ++i) {
+            Type type = getChild(i).getType();
+            if (type.isNull()) {    //Not to return NULL directly, so save string, but flag is '0'
+                children.set(i, new StringLiteral("NULL"));
+                res = res + "0";
+            } else if (type.isBoolean()) {
+                res = res + "1";
+            } else if (type.isNumericType()) {
+                res = res + "2";
+            } else if (type.isTime()) {
+                res = res + "3";
+            } else {
+                res = res + "4";
+            }
+        }
+        res = res + extra_mark;
+        children.add(new StringLiteral(res));
+        LOG.info(res + " sql: " + this.toSql());

Review comment:
       remove this 




-- 
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] yangzhg commented on a change in pull request #6504: [Feature]support three functions of json

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



##########
File path: be/src/exprs/json_functions.cpp
##########
@@ -108,6 +108,96 @@ DoubleVal JsonFunctions::get_json_double(FunctionContext* context, const StringV
     }
 }
 
+StringVal JsonFunctions::json_array(FunctionContext* context, int num_args,
+                                    const StringVal* json_str) {
+    if (json_str->is_null) {
+        return StringVal::null();
+    }
+    rapidjson::Value array_obj(rapidjson::kArrayType);
+    rapidjson::Document document;
+    rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
+    //flag: The number it contains represents the type of previous parameters
+    std::string flag((char*)json_str[num_args - 1].ptr, json_str[num_args - 1].len);
+    DCHECK(num_args-1==flag.length());

Review comment:
       ```suggestion
       DCHECK_EQ(num_args - 1, flag.length());
   ```

##########
File path: be/src/exprs/json_functions.cpp
##########
@@ -108,6 +108,96 @@ DoubleVal JsonFunctions::get_json_double(FunctionContext* context, const StringV
     }
 }
 
+StringVal JsonFunctions::json_array(FunctionContext* context, int num_args,
+                                    const StringVal* json_str) {
+    if (json_str->is_null) {
+        return StringVal::null();
+    }
+    rapidjson::Value array_obj(rapidjson::kArrayType);
+    rapidjson::Document document;
+    rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
+    //flag: The number it contains represents the type of previous parameters
+    std::string flag((char*)json_str[num_args - 1].ptr, json_str[num_args - 1].len);
+    DCHECK(num_args-1==flag.length());
+    for (int i = 0; i < num_args - 1; ++i) {
+        std::string arg((char*)json_str[i].ptr, json_str[i].len);
+        rapidjson::Value val = parse_str_with_flag(arg, flag, i, allocator);
+        array_obj.PushBack(val, allocator);
+    }
+    rapidjson::StringBuffer buf;
+    rapidjson::Writer<rapidjson::StringBuffer> writer(buf);
+    array_obj.Accept(writer);
+    return AnyValUtil::from_string_temp(context, std::string(buf.GetString()));
+}
+
+StringVal JsonFunctions::json_object(FunctionContext* context, int num_args,
+                                     const StringVal* json_str) {
+    if (json_str->is_null) {
+        return StringVal::null();
+    }
+    rapidjson::Document document(rapidjson::kObjectType);
+    rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
+    std::string flag((char*)json_str[num_args - 1].ptr, json_str[num_args - 1].len);

Review comment:
       use stringVal

##########
File path: be/src/exprs/json_functions.cpp
##########
@@ -108,6 +109,96 @@ DoubleVal JsonFunctions::get_json_double(FunctionContext* context, const StringV
     }
 }
 
+StringVal JsonFunctions::json_array(FunctionContext* context, int num_args,
+                                    const StringVal* json_str) {
+    if (json_str->is_null) {
+        return StringVal::null();
+    }
+    rapidjson::Value array_obj(rapidjson::kArrayType);
+    rapidjson::Document document;
+    rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
+    //flag: The number it contains represents the type of previous parameters
+    StringVal flag(json_str[num_args - 1].ptr, json_str[num_args - 1].len);

Review comment:
       
   ```suggestion
       StringVal* flag = json_str[num_args - 1];
   ```

##########
File path: be/src/exprs/json_functions.cpp
##########
@@ -108,6 +109,96 @@ DoubleVal JsonFunctions::get_json_double(FunctionContext* context, const StringV
     }
 }
 
+StringVal JsonFunctions::json_array(FunctionContext* context, int num_args,
+                                    const StringVal* json_str) {
+    if (json_str->is_null) {
+        return StringVal::null();
+    }
+    rapidjson::Value array_obj(rapidjson::kArrayType);
+    rapidjson::Document document;
+    rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
+    //flag: The number it contains represents the type of previous parameters
+    StringVal flag(json_str[num_args - 1].ptr, json_str[num_args - 1].len);
+    DCHECK_EQ(num_args - 1, flag.len);
+    for (int i = 0; i < num_args - 1; ++i) {
+        StringVal arg(json_str[i].ptr, json_str[i].len);
+        rapidjson::Value val = parse_str_with_flag(arg, flag, i, allocator);

Review comment:
       ```suggestion
           rapidjson::Value val = parse_str_with_flag(arg, *flag, i, allocator);
   ```




-- 
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] yangzhg commented on a change in pull request #6504: [Feature]support three functions of json

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



##########
File path: be/src/exprs/json_functions.cpp
##########
@@ -107,6 +107,89 @@ DoubleVal JsonFunctions::get_json_double(FunctionContext* context, const StringV
         return DoubleVal::null();
     }
 }
+StringVal JsonFunctions::json_array(FunctionContext* context, int num_args,
+                                    const StringVal* json_str) {
+    if (json_str->is_null) {
+        return StringVal::null();
+    }
+    rapidjson::Value array_obj(rapidjson::kArrayType);
+    rapidjson::Document document;
+    rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
+    //flag: The number it contains represents the type of previous parameters
+    std::string flag((char*)json_str[num_args - 1].ptr, json_str[num_args - 1].len);
+    for (int i = 0; i < num_args - 1; ++i) {
+        std::string arg((char*)json_str[i].ptr, json_str[i].len);
+        rapidjson::Value val = parse_str_with_flag(arg, flag, i, allocator);
+        array_obj.PushBack(val, allocator);
+    }
+    rapidjson::StringBuffer buf;
+    rapidjson::Writer<rapidjson::StringBuffer> writer(buf);
+    array_obj.Accept(writer);
+    return AnyValUtil::from_string_temp(context, std::string(buf.GetString()));
+}
+
+StringVal JsonFunctions::json_object(FunctionContext* context, int num_args,
+                                     const StringVal* json_str) {
+    if (json_str->is_null) {
+        return StringVal::null();
+    }
+    rapidjson::Document document(rapidjson::kObjectType);
+    rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
+    std::string flag((char*)json_str[num_args - 1].ptr, json_str[num_args - 1].len);
+    document.SetObject();
+    for (int i = 1; i < num_args - 1; i = i + 2) {
+        std::string arg((char*)json_str[i].ptr, json_str[i].len);
+        rapidjson::Value key(rapidjson::kStringType);
+        key.SetString((char*)json_str[i - 1].ptr, json_str[i - 1].len, allocator);
+        rapidjson::Value val = parse_str_with_flag(arg, flag, i, allocator);
+        document.AddMember(key, val, allocator);
+    }
+    rapidjson::StringBuffer buf;
+    rapidjson::Writer<rapidjson::StringBuffer> writer(buf);
+    document.Accept(writer);
+    return AnyValUtil::from_string_temp(context, std::string(buf.GetString()));
+}
+
+rapidjson::Value JsonFunctions::parse_str_with_flag(const std::string& arg, const std::string& flag,
+                                                    const int& num,

Review comment:
       primitive type is no need to be reference




-- 
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] yangzhg commented on a change in pull request #6504: [Feature]support three functions of json

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



##########
File path: be/src/exprs/json_functions.h
##########
@@ -122,6 +129,8 @@ class JsonFunctions {
                                          bool is_insert_null = false);
     static void get_parsed_paths(const std::vector<std::string>& path_exprs,
                                  std::vector<JsonPath>* parsed_paths);
+    static void parse_str_with_flag(std::string& result, const std::string& arg,

Review comment:
       If you want to change the value of string, use pointer instead of reference




-- 
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] yangzhg commented on a change in pull request #6504: [Feature]support three functions of json

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



##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
##########
@@ -74,12 +75,15 @@
                     .add("stddev").add("stddev_val").add("stddev_samp")
                     .add("variance").add("variance_pop").add("variance_pop").add("var_samp").add("var_pop").build();
     private static final String ELEMENT_EXTRACT_FN_NAME = "%element_extract%";
-    
+    //extra_mark use to represents parse parameter about json_array json_object
+    private String extra_mark = "";

Review comment:
       1. camel Case
   2.  paramTypes maybe better




-- 
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] yangzhg commented on a change in pull request #6504: [Feature]support three functions of json

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



##########
File path: be/src/exprs/json_functions.cpp
##########
@@ -108,6 +108,96 @@ DoubleVal JsonFunctions::get_json_double(FunctionContext* context, const StringV
     }
 }
 
+StringVal JsonFunctions::json_array(FunctionContext* context, int num_args,
+                                    const StringVal* json_str) {
+    if (json_str->is_null) {
+        return StringVal::null();
+    }
+    rapidjson::Value array_obj(rapidjson::kArrayType);
+    rapidjson::Document document;
+    rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
+    //flag: The number it contains represents the type of previous parameters
+    std::string flag((char*)json_str[num_args - 1].ptr, json_str[num_args - 1].len);
+    DCHECK(num_args-1==flag.length());

Review comment:
       ```suggestion
       DCHECK_EQ(num_args - 1, flag.length());
   ```




-- 
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] yangzhg commented on a change in pull request #6504: [Feature]support three functions of json

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



##########
File path: be/src/exprs/json_functions.cpp
##########
@@ -108,6 +109,96 @@ DoubleVal JsonFunctions::get_json_double(FunctionContext* context, const StringV
     }
 }
 
+StringVal JsonFunctions::json_array(FunctionContext* context, int num_args,
+                                    const StringVal* json_str) {
+    if (json_str->is_null) {
+        return StringVal::null();
+    }
+    rapidjson::Value array_obj(rapidjson::kArrayType);
+    rapidjson::Document document;
+    rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
+    //flag: The number it contains represents the type of previous parameters
+    StringVal flag(json_str[num_args - 1].ptr, json_str[num_args - 1].len);

Review comment:
       
   ```suggestion
       StringVal* flag = json_str[num_args - 1];
   ```




-- 
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] yangzhg commented on a change in pull request #6504: [Feature]support three functions of json

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



##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
##########
@@ -162,6 +167,29 @@ protected FunctionCallExpr(FunctionCallExpr other) {
         fn = other.fn;
     }
 
+    public void dealJsonTypeFun() {

Review comment:
       ```suggestion
       public void parseJsonDataType() {
   ```




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