branch-2.1: [fix](Nereids) could not work well when check precision for null literal #50815 (#50899)

Cherry-picked from #50815

Co-authored-by: morrySnow <zhangwenxin@selectdb.com>
This commit is contained in:
github-actions[bot]
2025-05-22 14:38:39 +08:00
committed by GitHub
parent fbad523a13
commit 5bc1618c2d
2 changed files with 51 additions and 1 deletions

View File

@ -152,7 +152,9 @@ public class SearchSignature {
finalType = DecimalV3Type.forType(arguments.get(i).getDataType());
} else {
Expression arg = arguments.get(i);
if (arg.isLiteral() && arg.getDataType().isIntegralType()) {
if (arg.isNullLiteral()) {
// do nothing
} else if (arg.isLiteral() && arg.getDataType().isIntegralType()) {
// create decimalV3 with minimum scale enough to hold the integral literal
finalType = DecimalV3Type.createDecimalV3Type(new BigDecimal(((Literal) arg).getStringValue()));
} else {

View File

@ -0,0 +1,48 @@
// 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("decimal_precision") {
sql """
CREATE TABLE IF NOT EXISTS test_null_literal_compute (
id INT,
name VARCHAR(50),
age INT,
score DECIMAL(5,2),
create_time DATETIME,
is_active BOOLEAN
) ENGINE=OLAP
DUPLICATE KEY(id)
DISTRIBUTED BY HASH(id) BUCKETS 10
PROPERTIES (
"replication_num" = "1"
);
"""
sql """
INSERT INTO test_null_literal_compute VALUES
(1, 'Alice', 25, 89.5, '2023-01-01 10:00:00', true),
(2, 'Bob', 30, 76.2, '2023-01-02 11:00:00', true),
(3, 'Charlie', 22, 92.0, '2023-01-03 12:00:00', false),
(4, 'David', 28, 85.7, '2023-01-04 13:00:00', true),
(5, 'Eve', 35, 67.8, '2023-01-05 14:00:00', false);
"""
sql """
SELECT name, age, LAG(age, 1) OVER (ORDER BY id) AS prev_age FROM test_null_literal_compute;
"""
}