Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public abstract class Type {
public static final ScalarType DECIMAL64 = DEFAULT_DECIMAL64;
public static final ScalarType DECIMAL128 = DEFAULT_DECIMAL128;
public static final ScalarType DECIMAL256 = DEFAULT_DECIMAL256;
public static final ScalarType WILDCARD_DECIMAL = ScalarType.createDecimalType(-1, -1);
public static final ScalarType JSONB = new ScalarType(PrimitiveType.JSONB);
// (ScalarType) ScalarType.createDecimalTypeInternal(-1, -1);
public static final ScalarType DEFAULT_VARCHAR = ScalarType.createVarcharType(-1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1618,8 +1618,25 @@ && collectChildReturnTypes()[0].isDecimalV3()) {
// now first find table function in table function sets
if (isTableFnCall) {
Type[] childTypes = collectChildReturnTypes();
fn = getTableFunction(fnName.getFunction(), childTypes,
Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF);
// when we call explode<Array<Decimal>> with nested decimal has specific precision and scale,
// collectChildReturnTypes will return specific precision and scale decimal type witch may not match
// builtln func we defined in fe code, because we make array_support_type is actual origin type.here we
// temp write this if to get matched explode function and then set actually decimal type from sql to
// func return type. if we switch nereid would hasn't this problems.
if (fnName.getFunction().equalsIgnoreCase("explode") && childTypes[0].isArrayType()) {
// get origin type to match builtln func
Type[] matchFuncChildTypes = getActualArgTypes(childTypes);
fn = getTableFunction(fnName.getFunction(), matchFuncChildTypes,
Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF);
if (fn == null) {
throw new AnalysisException(getFunctionNotFoundError(argTypes));
}
// set param child types
fn.setReturnType(((ArrayType) childTypes[0]).getItemType());
} else {
fn = getTableFunction(fnName.getFunction(), childTypes,
Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF);
}
if (fn == null) {
throw new AnalysisException(getFunctionNotFoundError(argTypes));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,9 @@ private void initTableFunction() {
Lists.newArrayList(new ArrayType(subType)), false,
"_ZN5doris19DummyTableFunctions7explodeEPN9doris_udf15FunctionContextERKNS1_13CollectionValE");
}
addTableFunctionWithCombinator(EXPLODE, Type.WILDCARD_DECIMAL, Function.NullableMode.ALWAYS_NULLABLE,
Lists.newArrayList(new ArrayType(Type.WILDCARD_DECIMAL)), false,
"_ZN5doris19DummyTableFunctions7explodeEPN9doris_udf15FunctionContextERKNS1_13CollectionValE");
}

public boolean isAggFunctionName(String name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql_old_planner --
0.800 [0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,1,9,5,5,5,5,5,5,5,5,5,0.8,0.8,0.8,0.8,0.8]

-- !sql_nereid --
0.800 [0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,1,9,5,5,5,5,5,5,5,5,5,0.8,0.8,0.8,0.8,0.8]

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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("explode_array_decimal") {
sql "DROP TABLE IF EXISTS ods_device_data_1d_inc;"

sql """
CREATE TABLE `ods_device_data_1d_inc` (
`id` INT NULL,
`electricityPrice` VARCHAR(5000) NULL
) ENGINE=OLAP
DUPLICATE KEY(`id`, `electricityPrice`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`id`) BUCKETS 10
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"min_load_replica_num" = "-1",
"is_being_synced" = "false",
"storage_format" = "V2",
"light_schema_change" = "true",
"disable_auto_compaction" = "false",
"enable_single_replica_compaction" = "false",
"group_commit_interval_ms" = "10000"
);"""

sql """insert into ods_device_data_1d_inc values(1, "[0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,1,9,5,5,5,5,5,5,5,5,5,0.8,0.8,0.8,0.8,0.8]")"""

sql "SET enable_nereids_planner=false;"

qt_sql_old_planner """
SELECT * from
(
select
e1,t.electricityPrice
from
ods_device_data_1d_inc as t
lateral view explode(cast (electricityPrice as ARRAY<DECIMAL(10,3)>)) tmp1 as e1
) kk limit 1
"""

sql 'set enable_fallback_to_original_planner=false'
sql 'set enable_nereids_planner=true'

qt_sql_nereid """
SELECT * from
(
select
e1,t.electricityPrice
from
ods_device_data_1d_inc as t
lateral view explode(cast (electricityPrice as ARRAY<DECIMAL(10,3)>)) tmp1 as e1
) kk limit 1
"""
}