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

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


The following commit(s) were added to refs/heads/master by this push:
     new 883f575cfe [fix](string function) fix wrong usage of iconv_open 
(#17048)
883f575cfe is described below

commit 883f575cfef9e0c4fc988338a3db4bdfd9c887c1
Author: TengJianPing <18241664+jackte...@users.noreply.github.com>
AuthorDate: Fri Feb 24 09:13:10 2023 +0800

    [fix](string function) fix wrong usage of iconv_open (#17048)
    
    * [fix](string function) fix wrong usage of iconv_open
    
    Also add test case for function convert
    
    * fix test case
---
 be/src/vec/functions/function_string.h             | 12 +++++-----
 .../string_functions/test_convert.out              |  4 ++++
 .../string_functions/test_convert.groovy           | 26 ++++++++++++++++++++++
 3 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/be/src/vec/functions/function_string.h 
b/be/src/vec/functions/function_string.h
index d230c9a60c..2f12658817 100644
--- a/be/src/vec/functions/function_string.h
+++ b/be/src/vec/functions/function_string.h
@@ -2508,17 +2508,16 @@ public:
         const auto& character_data = 
context->get_constant_col(1)->column_ptr->get_data_at(0);
         if (doris::iequal(character_data.to_string(), "gbk")) {
             iconv_t cd = iconv_open("gb2312", "utf-8");
-            if (cd == nullptr) {
-                return Status::RuntimeError("function {} is convert to gbk 
failed in iconv_open",
+            if (cd == (iconv_t)-1) {
+                LOG(WARNING) << "iconv_open error: " << strerror(errno);
+                return Status::RuntimeError("function {} converting to gbk 
failed in iconv_open",
                                             get_name());
             }
             // IconvWrapper will call iconv_close during deconstructor
             std::shared_ptr<IconvWrapper> cd_wrapper = 
std::make_shared<IconvWrapper>(cd);
             context->set_function_state(scope, cd_wrapper);
         } else {
-            return Status::RuntimeError(
-                    "Illegal second argument column of function convert. now 
only support "
-                    "convert to character set of gbk");
+            return Status::NotSupported("convert to character set " + 
character_data.to_string());
         }
 
         return Status::OK();
@@ -2549,7 +2548,8 @@ public:
             char* in = const_cast<char*>(value_data);
             out_len = in_len;
             if (iconv(cd, &in, &in_len, &out, &out_len) == -1) {
-                return Status::RuntimeError("function {} is convert to gbk 
failed in iconv",
+                LOG(WARNING) << "iconv failed, error: " << strerror(errno);
+                return Status::RuntimeError("function {} converting to gbk 
failed in iconv",
                                             get_name());
             } else {
                 res_offset[i] = res_chars.size();
diff --git 
a/regression-test/data/query_p0/sql_functions/string_functions/test_convert.out 
b/regression-test/data/query_p0/sql_functions/string_functions/test_convert.out
new file mode 100644
index 0000000000..2de201d668
--- /dev/null
+++ 
b/regression-test/data/query_p0/sql_functions/string_functions/test_convert.out
@@ -0,0 +1,4 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !convert_const_to_gbk --
+a      ˿�
+
diff --git 
a/regression-test/suites/query_p0/sql_functions/string_functions/test_convert.groovy
 
b/regression-test/suites/query_p0/sql_functions/string_functions/test_convert.groovy
new file mode 100644
index 0000000000..0edbaad5d0
--- /dev/null
+++ 
b/regression-test/suites/query_p0/sql_functions/string_functions/test_convert.groovy
@@ -0,0 +1,26 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_convert") {
+    test {
+        sql "select convert('a' using utf8);"
+        exception "errCode = 2, detailMessage = [NOT_IMPLEMENTED_ERROR]"
+    }
+
+    qt_convert_const_to_gbk """select convert("a" using gbk), convert("丝" 
using gbk);"""
+}
+


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

Reply via email to