parthchandra commented on code in PR #3952: URL: https://github.com/apache/datafusion-comet/pull/3952#discussion_r3101838040
########## spark/src/test/resources/sql-tests/expressions/decimal/decimal_div_ansi.sql: ########## @@ -0,0 +1,130 @@ +-- 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. + +-- Decimal division (/) and integral division (div) in ANSI mode. +-- Divide-by-zero throws for both operators; try_divide still returns NULL. +-- Overflow throws NUMERIC_VALUE_OUT_OF_RANGE for both / and div. +-- See decimal_div.sql for legacy-mode and try_divide tests. + +-- Config: spark.sql.ansi.enabled=true + +-- ============================================================================ +-- Setup +-- ============================================================================ + +statement +CREATE TABLE test_ansi_decimal(a decimal(18,6), b decimal(18,6)) USING parquet + +statement +INSERT INTO test_ansi_decimal VALUES + (10.000000, 3.000000), + (7.500000, 2.500000), + (-10.000000, 3.000000), + (10.000000, -3.000000), + (0.000000, 5.000000), + (NULL, 3.000000), + (10.000000, NULL) + +statement +CREATE TABLE test_ansi_zero(a decimal(18,6)) USING parquet + +statement +INSERT INTO test_ansi_zero VALUES (10.000000), (-5.000000), (0.000000), (NULL) + +-- ============================================================================ +-- Normal division works in ANSI mode (no zero divisor, no overflow) +-- ============================================================================ + +query +SELECT a / b FROM test_ansi_decimal + +query +SELECT a div b FROM test_ansi_decimal + +-- ============================================================================ +-- ANSI mode: decimal / by zero throws DIVIDE_BY_ZERO +-- ============================================================================ + +-- column / zero column +query expect_error(DIVIDE_BY_ZERO) +SELECT a / cast(0.000000 as decimal(18,6)) FROM test_ansi_zero + +-- literal / zero literal +query expect_error(DIVIDE_BY_ZERO) +SELECT cast(10.0 as decimal(18,6)) / cast(0.000000 as decimal(18,6)) + +-- ============================================================================ +-- ANSI mode: decimal div by zero throws DIVIDE_BY_ZERO +-- ============================================================================ + +-- column div zero column +query expect_error(DIVIDE_BY_ZERO) +SELECT a div cast(0.000000 as decimal(18,6)) FROM test_ansi_zero + +-- literal div zero literal +query expect_error(DIVIDE_BY_ZERO) +SELECT cast(10 as decimal(18,0)) div cast(0.000000 as decimal(18,6)) + +-- ============================================================================ +-- TRY mode: try_divide returns NULL even when ANSI is enabled globally Review Comment: done -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
