[bug](udf) fix udf return type of decimal check scale must is 9 (#16497)
This commit is contained in:
@ -21,7 +21,6 @@ import org.apache.doris.catalog.Type;
|
||||
import org.apache.doris.thrift.TJavaUdfExecutorCtorParams;
|
||||
import org.apache.doris.udf.UdfUtils.JavaUdfDataType;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.thrift.TDeserializer;
|
||||
import org.apache.thrift.TException;
|
||||
@ -327,8 +326,8 @@ public abstract class BaseExecutor {
|
||||
return true;
|
||||
}
|
||||
case DECIMALV2: {
|
||||
Preconditions.checkArgument(((BigDecimal) obj).scale() == 9, "Scale of DECIMALV2 must be 9");
|
||||
BigInteger data = ((BigDecimal) obj).unscaledValue();
|
||||
BigDecimal retValue = ((BigDecimal) obj).setScale(9, RoundingMode.HALF_EVEN);
|
||||
BigInteger data = retValue.unscaledValue();
|
||||
byte[] bytes = UdfUtils.convertByteOrder(data.toByteArray());
|
||||
//TODO: here is maybe overflow also, and may find a better way to handle
|
||||
byte[] value = new byte[16];
|
||||
@ -386,5 +385,6 @@ public abstract class BaseExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateOutputOffset(long offset) {}
|
||||
protected void updateOutputOffset(long offset) {
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,3 +21,6 @@
|
||||
112 1456778.444443300
|
||||
113 \N
|
||||
|
||||
-- !select_decimal_string --
|
||||
0E-9
|
||||
|
||||
|
||||
@ -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.
|
||||
|
||||
package org.apache.doris.udf;
|
||||
import java.math.BigDecimal;
|
||||
import org.apache.hadoop.hive.ql.exec.UDF;
|
||||
|
||||
public class DecimalStringTest extends UDF {
|
||||
public BigDecimal evaluate(BigDecimal value, String partition, String orderBy) {
|
||||
return new BigDecimal(0.0);
|
||||
}
|
||||
}
|
||||
@ -64,6 +64,16 @@ suite("test_javaudf_decimal") {
|
||||
|
||||
|
||||
sql """ DROP FUNCTION java_udf_decimal_test(decimal(27,9),decimal(27,9)); """
|
||||
|
||||
|
||||
sql """ DROP FUNCTION if exists java_udf_decimal_string_test(decimal(27,9),String,String); """
|
||||
sql """ CREATE FUNCTION java_udf_decimal_string_test(decimal(27,9),String,String) RETURNS decimal(27,9) PROPERTIES (
|
||||
"file"="file://${jarPath}",
|
||||
"symbol"="org.apache.doris.udf.DecimalStringTest",
|
||||
"type"="JAVA_UDF"
|
||||
); """
|
||||
qt_select_decimal_string """ SELECT java_udf_decimal_string_test(2.83645,'asd','a') as result; """
|
||||
sql """ DROP FUNCTION java_udf_decimal_string_test(decimal(27,9),String,String); """
|
||||
} finally {
|
||||
try_sql("DROP TABLE IF EXISTS ${tableName}")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user