morrySnow commented on code in PR #49048:
URL: https://github.com/apache/doris/pull/49048#discussion_r2022203768


##########
regression-test/suites/query_p0/sql_functions/string_functions/test_printf.groovy:
##########
@@ -0,0 +1,171 @@
+// 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_printf") {
+    sql "drop table if exists printf_args;"
+    sql """
+        create table printf_args (
+            k0 int,
+            format_str_not_null string not null,

Review Comment:
   should test hll, bitmap, quantile_state, variant, json, ipv4, ipv6, 
datetimev1, datetimev2, datev1, datev2, agg_state, array, map, struct, timev1, 
timev2, decimalv2



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Printf.java:
##########
@@ -0,0 +1,82 @@
+// 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.ExpressionTrait;
+import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.types.DoubleType;
+import org.apache.doris.nereids.types.StringType;
+import org.apache.doris.nereids.util.ExpressionUtils;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+/**
+ * Printf function
+ * printf(strfmt[, obj1, ...])
+ * - strfmt: A STRING expression.
+ * - objN: A STRING or numeric expression.
+ * Returns a formatted string from printf-style format strings.
+ */
+public class Printf extends ScalarFunction
+        implements ExplicitlyCastableSignature, PropagateNullable {
+
+    /**
+     * constructor with 1 or more arguments.
+     */
+    public Printf(Expression arg0, Expression... varArgs) {
+        super("Printf", ExpressionUtils.mergeArguments(arg0, varArgs));
+    }
+
+    /**
+     * withChildren.
+     */
+    @Override
+    public Printf withChildren(List<Expression> children) {
+        Preconditions.checkArgument(children.size() >= 1);
+        return new Printf(children.get(0), children.subList(1, 
children.size()).toArray(new Expression[0]));
+    }
+
+    @Override
+    public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
+        return visitor.visitPrintf(this, context);
+    }
+
+    @Override
+    public List<FunctionSignature> getSignatures() {
+        // replace decimal with double
+        Function<DataType, DataType> replaceDecimalWithDouble = dataType -> {
+            return dataType.isDecimalLikeType() ? DoubleType.INSTANCE : 
dataType;
+        };

Review Comment:
   why replace decimal with double? add a comment to explain. what about the 
decimal type in array, map and struct? 
   you can use 
`org.apache.doris.nereids.util.TypeCoercionUtils#replaceSpecifiedType` to do 
replace



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