zclllyybb commented on code in PR #31707:
URL: https://github.com/apache/doris/pull/31707#discussion_r1512099943


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Oct.java:
##########
@@ -0,0 +1,71 @@
+// 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.nereids.trees.expressions.functions.scalar;
+
+import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import 
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
+import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.BigIntType;
+import org.apache.doris.nereids.types.StringType;
+import org.apache.doris.nereids.types.VarcharType;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/**
+ * ScalarFunction 'oct'. This class is generated by GenerateFunction.
+ */
+public class Oct extends ScalarFunction
+        implements UnaryExpression, ExplicitlyCastableSignature, 
PropagateNullable {
+
+    public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
+            
FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).args(BigIntType.INSTANCE),
+            
FunctionSignature.ret(StringType.INSTANCE).args(BigIntType.INSTANCE)

Review Comment:
   no need to have two return type of same input



##########
be/src/vec/functions/function_hex.cpp:
##########
@@ -191,9 +191,85 @@ struct HexHLLImpl {
     }
 };
 
+template <typename Impl>
+class FunctionOctVariadic : public IFunction {
+public:
+    static constexpr auto name = "oct";
+
+    static FunctionPtr create() { return 
std::make_shared<FunctionOctVariadic>(); }
+
+    String get_name() const override { return name; }
+
+    size_t get_number_of_arguments() const override { return 1; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        return std::make_shared<DataTypeString>();
+    }
+
+    DataTypes get_variadic_argument_types_impl() const override {
+        return Impl::get_variadic_argument_types();
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        size_t result, size_t input_rows_count) const override 
{
+        ColumnPtr& argument_column = 
block.get_by_position(arguments[0]).column;
+
+        auto result_data_column = ColumnString::create();
+        auto& result_data = result_data_column->get_chars();
+        auto& result_offset = result_data_column->get_offsets();
+
+        RETURN_IF_ERROR(
+                Impl::vector(argument_column, input_rows_count, result_data, 
result_offset));
+        block.replace_by_position(result, std::move(result_data_column));
+        return Status::OK();
+    }
+};
+
+struct OctIntImpl {
+    static DataTypes get_variadic_argument_types() {
+        return {std::make_shared<vectorized::DataTypeInt64>()};
+    }
+
+    static std::string_view oct(uint64_t num, char* ans) {
+        static constexpr auto oct_table = "012345678";
+        if (num == 0) {
+            return {oct_table, 1};
+        }
+
+        int i = 0;
+        while (num != 0) {
+            ans[i++] = oct_table[num % 8];
+            num = num / 8;
+        }
+        ans[i] = '\0';
+
+        for (int k = 0, j = i - 1; k <= j; k++, j--) {
+            char tmp = ans[j];

Review Comment:
   just use `std::swap`



##########
be/src/vec/functions/function_hex.cpp:
##########
@@ -191,9 +191,85 @@ struct HexHLLImpl {
     }
 };
 
+template <typename Impl>
+class FunctionOctVariadic : public IFunction {
+public:
+    static constexpr auto name = "oct";
+
+    static FunctionPtr create() { return 
std::make_shared<FunctionOctVariadic>(); }
+
+    String get_name() const override { return name; }
+
+    size_t get_number_of_arguments() const override { return 1; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        return std::make_shared<DataTypeString>();
+    }
+
+    DataTypes get_variadic_argument_types_impl() const override {

Review Comment:
   Will you support the input of string type in the future? just like `hex`. If 
not, we have no need to make this function variadic and templative.



##########
be/src/vec/functions/function_hex.cpp:
##########


Review Comment:
   If you want put them in one file, please change the cpp file name. otherwise 
put oct and hex into two individual files.



##########
regression-test/suites/nereids_function_p0/scalar_function/H.groovy:
##########
@@ -101,4 +101,5 @@ suite("nereids_scalar_fn_H") {
        qt_sql_hours_sub_Date_Integer_notnull "select hours_sub(kdt, kint) from 
fn_test_not_nullable order by kdt, kint"
        qt_sql_hours_sub_DateV2_Integer "select hours_sub(kdtv2, kint) from 
fn_test order by kdtv2, kint"
        qt_sql_hours_sub_DateV2_Integer_notnull "select hours_sub(kdtv2, kint) 
from fn_test_not_nullable order by kdtv2, kint"
-}
\ No newline at end of file
+        qt_sql_oct_BigInt "select oct(kbint) from fn_test order by kbint"

Review Comment:
   please also cover the situation which input is literal.



-- 
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-unsubscr...@doris.apache.org

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


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

Reply via email to