You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[SPARK-45915][SQL] Treat decimal(x, 0) the same as IntegralType in PromoteStrings
### What changes were proposed in this pull request?
The common type of decimal(x, 0) and string is double. But the common type of int/bigint and string are int/bigint.
This PR updates `PromoteStrings` make the common type of decimal(x, 0) and string is decimal(x, 0).
### Why are the changes needed?
1. Make decimal(x, 0) behave the same as int/bigint in `PromoteStrings`.
2. Reduce one cast in binary comparison so we may use bucket read. For example: `cast(stringCol as double) = cast(decimalCol as double)` vs `cast(stringCol as decimal(x, 0)) = decimalCol`.
### Does this PR introduce _any_ user-facing change?
Yes. The result type of decimal(x, 0) and string is decimal(x, 0) in binary comparison.
### How was this patch tested?
Unit test.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes#43812 from wangyum/SPARK-45915.
Authored-by: Yuming Wang <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
Copy file name to clipboardExpand all lines: sql/core/src/test/resources/sql-tests/analyzer-results/typeCoercion/native/binaryComparison.sql.out
+24-24
Original file line number
Diff line number
Diff line change
@@ -1330,7 +1330,7 @@ Project [NOT (cast(cast(null as string) as bigint) = cast(1 as bigint)) AS (NOT
1330
1330
-- !query
1331
1331
SELECT cast(1 as decimal(10, 0)) = '1' FROM t
1332
1332
-- !query analysis
1333
-
Project [(cast(cast(1 as decimal(10,0)) as double) = cast(1 as double)) AS (CAST(1 AS DECIMAL(10,0)) = 1)#x]
1333
+
Project [(cast(1 as decimal(10,0)) = cast(1 as decimal(10,0))) AS (CAST(1 AS DECIMAL(10,0)) = 1)#x]
1334
1334
+- SubqueryAlias t
1335
1335
+- View (`t`, [1#x])
1336
1336
+- Project [cast(1#x as int) AS 1#x]
@@ -1341,7 +1341,7 @@ Project [(cast(cast(1 as decimal(10,0)) as double) = cast(1 as double)) AS (CAST
1341
1341
-- !query
1342
1342
SELECT cast(1 as decimal(10, 0)) > '2' FROM t
1343
1343
-- !query analysis
1344
-
Project [(cast(cast(1 as decimal(10,0)) as double) > cast(2 as double)) AS (CAST(1 AS DECIMAL(10,0)) > 2)#x]
1344
+
Project [(cast(1 as decimal(10,0)) > cast(2 as decimal(10,0))) AS (CAST(1 AS DECIMAL(10,0)) > 2)#x]
1345
1345
+- SubqueryAlias t
1346
1346
+- View (`t`, [1#x])
1347
1347
+- Project [cast(1#x as int) AS 1#x]
@@ -1352,7 +1352,7 @@ Project [(cast(cast(1 as decimal(10,0)) as double) > cast(2 as double)) AS (CAST
1352
1352
-- !query
1353
1353
SELECT cast(1 as decimal(10, 0)) >= '2' FROM t
1354
1354
-- !query analysis
1355
-
Project [(cast(cast(1 as decimal(10,0)) as double) >= cast(2 as double)) AS (CAST(1 AS DECIMAL(10,0)) >= 2)#x]
1355
+
Project [(cast(1 as decimal(10,0)) >= cast(2 as decimal(10,0))) AS (CAST(1 AS DECIMAL(10,0)) >= 2)#x]
1356
1356
+- SubqueryAlias t
1357
1357
+- View (`t`, [1#x])
1358
1358
+- Project [cast(1#x as int) AS 1#x]
@@ -1363,7 +1363,7 @@ Project [(cast(cast(1 as decimal(10,0)) as double) >= cast(2 as double)) AS (CAS
1363
1363
-- !query
1364
1364
SELECT cast(1 as decimal(10, 0)) < '2' FROM t
1365
1365
-- !query analysis
1366
-
Project [(cast(cast(1 as decimal(10,0)) as double) < cast(2 as double)) AS (CAST(1 AS DECIMAL(10,0)) < 2)#x]
1366
+
Project [(cast(1 as decimal(10,0)) < cast(2 as decimal(10,0))) AS (CAST(1 AS DECIMAL(10,0)) < 2)#x]
1367
1367
+- SubqueryAlias t
1368
1368
+- View (`t`, [1#x])
1369
1369
+- Project [cast(1#x as int) AS 1#x]
@@ -1374,7 +1374,7 @@ Project [(cast(cast(1 as decimal(10,0)) as double) < cast(2 as double)) AS (CAST
1374
1374
-- !query
1375
1375
SELECT cast(1 as decimal(10, 0)) <> '2' FROM t
1376
1376
-- !query analysis
1377
-
Project [NOT (cast(cast(1 as decimal(10,0)) as double) = cast(2 as double)) AS (NOT (CAST(1 AS DECIMAL(10,0)) = 2))#x]
1377
+
Project [NOT (cast(1 as decimal(10,0)) = cast(2 as decimal(10,0))) AS (NOT (CAST(1 AS DECIMAL(10,0)) = 2))#x]
1378
1378
+- SubqueryAlias t
1379
1379
+- View (`t`, [1#x])
1380
1380
+- Project [cast(1#x as int) AS 1#x]
@@ -1385,7 +1385,7 @@ Project [NOT (cast(cast(1 as decimal(10,0)) as double) = cast(2 as double)) AS (
1385
1385
-- !query
1386
1386
SELECT cast(1 as decimal(10, 0)) <= '2' FROM t
1387
1387
-- !query analysis
1388
-
Project [(cast(cast(1 as decimal(10,0)) as double) <= cast(2 as double)) AS (CAST(1 AS DECIMAL(10,0)) <= 2)#x]
1388
+
Project [(cast(1 as decimal(10,0)) <= cast(2 as decimal(10,0))) AS (CAST(1 AS DECIMAL(10,0)) <= 2)#x]
1389
1389
+- SubqueryAlias t
1390
1390
+- View (`t`, [1#x])
1391
1391
+- Project [cast(1#x as int) AS 1#x]
@@ -1396,7 +1396,7 @@ Project [(cast(cast(1 as decimal(10,0)) as double) <= cast(2 as double)) AS (CAS
1396
1396
-- !query
1397
1397
SELECT cast(1 as decimal(10, 0)) = cast(null as string) FROM t
1398
1398
-- !query analysis
1399
-
Project [(cast(cast(1 as decimal(10,0)) as double) = cast(cast(null as string) as double)) AS (CAST(1 AS DECIMAL(10,0)) = CAST(NULL AS STRING))#x]
1399
+
Project [(cast(1 as decimal(10,0)) = cast(cast(null as string) as decimal(10,0))) AS (CAST(1 AS DECIMAL(10,0)) = CAST(NULL AS STRING))#x]
1400
1400
+- SubqueryAlias t
1401
1401
+- View (`t`, [1#x])
1402
1402
+- Project [cast(1#x as int) AS 1#x]
@@ -1407,7 +1407,7 @@ Project [(cast(cast(1 as decimal(10,0)) as double) = cast(cast(null as string) a
1407
1407
-- !query
1408
1408
SELECT cast(1 as decimal(10, 0)) > cast(null as string) FROM t
1409
1409
-- !query analysis
1410
-
Project [(cast(cast(1 as decimal(10,0)) as double) > cast(cast(null as string) as double)) AS (CAST(1 AS DECIMAL(10,0)) > CAST(NULL AS STRING))#x]
1410
+
Project [(cast(1 as decimal(10,0)) > cast(cast(null as string) as decimal(10,0))) AS (CAST(1 AS DECIMAL(10,0)) > CAST(NULL AS STRING))#x]
1411
1411
+- SubqueryAlias t
1412
1412
+- View (`t`, [1#x])
1413
1413
+- Project [cast(1#x as int) AS 1#x]
@@ -1418,7 +1418,7 @@ Project [(cast(cast(1 as decimal(10,0)) as double) > cast(cast(null as string) a
1418
1418
-- !query
1419
1419
SELECT cast(1 as decimal(10, 0)) >= cast(null as string) FROM t
1420
1420
-- !query analysis
1421
-
Project [(cast(cast(1 as decimal(10,0)) as double) >= cast(cast(null as string) as double)) AS (CAST(1 AS DECIMAL(10,0)) >= CAST(NULL AS STRING))#x]
1421
+
Project [(cast(1 as decimal(10,0)) >= cast(cast(null as string) as decimal(10,0))) AS (CAST(1 AS DECIMAL(10,0)) >= CAST(NULL AS STRING))#x]
1422
1422
+- SubqueryAlias t
1423
1423
+- View (`t`, [1#x])
1424
1424
+- Project [cast(1#x as int) AS 1#x]
@@ -1429,7 +1429,7 @@ Project [(cast(cast(1 as decimal(10,0)) as double) >= cast(cast(null as string)
1429
1429
-- !query
1430
1430
SELECT cast(1 as decimal(10, 0)) < cast(null as string) FROM t
1431
1431
-- !query analysis
1432
-
Project [(cast(cast(1 as decimal(10,0)) as double) < cast(cast(null as string) as double)) AS (CAST(1 AS DECIMAL(10,0)) < CAST(NULL AS STRING))#x]
1432
+
Project [(cast(1 as decimal(10,0)) < cast(cast(null as string) as decimal(10,0))) AS (CAST(1 AS DECIMAL(10,0)) < CAST(NULL AS STRING))#x]
1433
1433
+- SubqueryAlias t
1434
1434
+- View (`t`, [1#x])
1435
1435
+- Project [cast(1#x as int) AS 1#x]
@@ -1440,7 +1440,7 @@ Project [(cast(cast(1 as decimal(10,0)) as double) < cast(cast(null as string) a
1440
1440
-- !query
1441
1441
SELECT cast(1 as decimal(10, 0)) <> cast(null as string) FROM t
1442
1442
-- !query analysis
1443
-
Project [NOT (cast(cast(1 as decimal(10,0)) as double) = cast(cast(null as string) as double)) AS (NOT (CAST(1 AS DECIMAL(10,0)) = CAST(NULL AS STRING)))#x]
1443
+
Project [NOT (cast(1 as decimal(10,0)) = cast(cast(null as string) as decimal(10,0))) AS (NOT (CAST(1 AS DECIMAL(10,0)) = CAST(NULL AS STRING)))#x]
1444
1444
+- SubqueryAlias t
1445
1445
+- View (`t`, [1#x])
1446
1446
+- Project [cast(1#x as int) AS 1#x]
@@ -1451,7 +1451,7 @@ Project [NOT (cast(cast(1 as decimal(10,0)) as double) = cast(cast(null as strin
1451
1451
-- !query
1452
1452
SELECT cast(1 as decimal(10, 0)) <= cast(null as string) FROM t
1453
1453
-- !query analysis
1454
-
Project [(cast(cast(1 as decimal(10,0)) as double) <= cast(cast(null as string) as double)) AS (CAST(1 AS DECIMAL(10,0)) <= CAST(NULL AS STRING))#x]
1454
+
Project [(cast(1 as decimal(10,0)) <= cast(cast(null as string) as decimal(10,0))) AS (CAST(1 AS DECIMAL(10,0)) <= CAST(NULL AS STRING))#x]
1455
1455
+- SubqueryAlias t
1456
1456
+- View (`t`, [1#x])
1457
1457
+- Project [cast(1#x as int) AS 1#x]
@@ -1462,7 +1462,7 @@ Project [(cast(cast(1 as decimal(10,0)) as double) <= cast(cast(null as string)
1462
1462
-- !query
1463
1463
SELECT '1' = cast(1 as decimal(10, 0)) FROM t
1464
1464
-- !query analysis
1465
-
Project [(cast(1 as double) = cast(cast(1 as decimal(10,0)) as double)) AS (1 = CAST(1 AS DECIMAL(10,0)))#x]
1465
+
Project [(cast(1 as decimal(10,0)) = cast(1 as decimal(10,0))) AS (1 = CAST(1 AS DECIMAL(10,0)))#x]
1466
1466
+- SubqueryAlias t
1467
1467
+- View (`t`, [1#x])
1468
1468
+- Project [cast(1#x as int) AS 1#x]
@@ -1473,7 +1473,7 @@ Project [(cast(1 as double) = cast(cast(1 as decimal(10,0)) as double)) AS (1 =
1473
1473
-- !query
1474
1474
SELECT '2' > cast(1 as decimal(10, 0)) FROM t
1475
1475
-- !query analysis
1476
-
Project [(cast(2 as double) > cast(cast(1 as decimal(10,0)) as double)) AS (2 > CAST(1 AS DECIMAL(10,0)))#x]
1476
+
Project [(cast(2 as decimal(10,0)) > cast(1 as decimal(10,0))) AS (2 > CAST(1 AS DECIMAL(10,0)))#x]
1477
1477
+- SubqueryAlias t
1478
1478
+- View (`t`, [1#x])
1479
1479
+- Project [cast(1#x as int) AS 1#x]
@@ -1484,7 +1484,7 @@ Project [(cast(2 as double) > cast(cast(1 as decimal(10,0)) as double)) AS (2 >
1484
1484
-- !query
1485
1485
SELECT '2' >= cast(1 as decimal(10, 0)) FROM t
1486
1486
-- !query analysis
1487
-
Project [(cast(2 as double) >= cast(cast(1 as decimal(10,0)) as double)) AS (2 >= CAST(1 AS DECIMAL(10,0)))#x]
1487
+
Project [(cast(2 as decimal(10,0)) >= cast(1 as decimal(10,0))) AS (2 >= CAST(1 AS DECIMAL(10,0)))#x]
1488
1488
+- SubqueryAlias t
1489
1489
+- View (`t`, [1#x])
1490
1490
+- Project [cast(1#x as int) AS 1#x]
@@ -1495,7 +1495,7 @@ Project [(cast(2 as double) >= cast(cast(1 as decimal(10,0)) as double)) AS (2 >
1495
1495
-- !query
1496
1496
SELECT '2' < cast(1 as decimal(10, 0)) FROM t
1497
1497
-- !query analysis
1498
-
Project [(cast(2 as double) < cast(cast(1 as decimal(10,0)) as double)) AS (2 < CAST(1 AS DECIMAL(10,0)))#x]
1498
+
Project [(cast(2 as decimal(10,0)) < cast(1 as decimal(10,0))) AS (2 < CAST(1 AS DECIMAL(10,0)))#x]
1499
1499
+- SubqueryAlias t
1500
1500
+- View (`t`, [1#x])
1501
1501
+- Project [cast(1#x as int) AS 1#x]
@@ -1506,7 +1506,7 @@ Project [(cast(2 as double) < cast(cast(1 as decimal(10,0)) as double)) AS (2 <
1506
1506
-- !query
1507
1507
SELECT '2' <= cast(1 as decimal(10, 0)) FROM t
1508
1508
-- !query analysis
1509
-
Project [(cast(2 as double) <= cast(cast(1 as decimal(10,0)) as double)) AS (2 <= CAST(1 AS DECIMAL(10,0)))#x]
1509
+
Project [(cast(2 as decimal(10,0)) <= cast(1 as decimal(10,0))) AS (2 <= CAST(1 AS DECIMAL(10,0)))#x]
1510
1510
+- SubqueryAlias t
1511
1511
+- View (`t`, [1#x])
1512
1512
+- Project [cast(1#x as int) AS 1#x]
@@ -1517,7 +1517,7 @@ Project [(cast(2 as double) <= cast(cast(1 as decimal(10,0)) as double)) AS (2 <
1517
1517
-- !query
1518
1518
SELECT '2' <> cast(1 as decimal(10, 0)) FROM t
1519
1519
-- !query analysis
1520
-
Project [NOT (cast(2 as double) = cast(cast(1 as decimal(10,0)) as double)) AS (NOT (2 = CAST(1 AS DECIMAL(10,0))))#x]
1520
+
Project [NOT (cast(2 as decimal(10,0)) = cast(1 as decimal(10,0))) AS (NOT (2 = CAST(1 AS DECIMAL(10,0))))#x]
1521
1521
+- SubqueryAlias t
1522
1522
+- View (`t`, [1#x])
1523
1523
+- Project [cast(1#x as int) AS 1#x]
@@ -1528,7 +1528,7 @@ Project [NOT (cast(2 as double) = cast(cast(1 as decimal(10,0)) as double)) AS (
1528
1528
-- !query
1529
1529
SELECT cast(null as string) = cast(1 as decimal(10, 0)) FROM t
1530
1530
-- !query analysis
1531
-
Project [(cast(cast(null as string) as double) = cast(cast(1 as decimal(10,0)) as double)) AS (CAST(NULL AS STRING) = CAST(1 AS DECIMAL(10,0)))#x]
1531
+
Project [(cast(cast(null as string) as decimal(10,0)) = cast(1 as decimal(10,0))) AS (CAST(NULL AS STRING) = CAST(1 AS DECIMAL(10,0)))#x]
1532
1532
+- SubqueryAlias t
1533
1533
+- View (`t`, [1#x])
1534
1534
+- Project [cast(1#x as int) AS 1#x]
@@ -1539,7 +1539,7 @@ Project [(cast(cast(null as string) as double) = cast(cast(1 as decimal(10,0)) a
1539
1539
-- !query
1540
1540
SELECT cast(null as string) > cast(1 as decimal(10, 0)) FROM t
1541
1541
-- !query analysis
1542
-
Project [(cast(cast(null as string) as double) > cast(cast(1 as decimal(10,0)) as double)) AS (CAST(NULL AS STRING) > CAST(1 AS DECIMAL(10,0)))#x]
1542
+
Project [(cast(cast(null as string) as decimal(10,0)) > cast(1 as decimal(10,0))) AS (CAST(NULL AS STRING) > CAST(1 AS DECIMAL(10,0)))#x]
1543
1543
+- SubqueryAlias t
1544
1544
+- View (`t`, [1#x])
1545
1545
+- Project [cast(1#x as int) AS 1#x]
@@ -1550,7 +1550,7 @@ Project [(cast(cast(null as string) as double) > cast(cast(1 as decimal(10,0)) a
1550
1550
-- !query
1551
1551
SELECT cast(null as string) >= cast(1 as decimal(10, 0)) FROM t
1552
1552
-- !query analysis
1553
-
Project [(cast(cast(null as string) as double) >= cast(cast(1 as decimal(10,0)) as double)) AS (CAST(NULL AS STRING) >= CAST(1 AS DECIMAL(10,0)))#x]
1553
+
Project [(cast(cast(null as string) as decimal(10,0)) >= cast(1 as decimal(10,0))) AS (CAST(NULL AS STRING) >= CAST(1 AS DECIMAL(10,0)))#x]
1554
1554
+- SubqueryAlias t
1555
1555
+- View (`t`, [1#x])
1556
1556
+- Project [cast(1#x as int) AS 1#x]
@@ -1561,7 +1561,7 @@ Project [(cast(cast(null as string) as double) >= cast(cast(1 as decimal(10,0))
1561
1561
-- !query
1562
1562
SELECT cast(null as string) < cast(1 as decimal(10, 0)) FROM t
1563
1563
-- !query analysis
1564
-
Project [(cast(cast(null as string) as double) < cast(cast(1 as decimal(10,0)) as double)) AS (CAST(NULL AS STRING) < CAST(1 AS DECIMAL(10,0)))#x]
1564
+
Project [(cast(cast(null as string) as decimal(10,0)) < cast(1 as decimal(10,0))) AS (CAST(NULL AS STRING) < CAST(1 AS DECIMAL(10,0)))#x]
1565
1565
+- SubqueryAlias t
1566
1566
+- View (`t`, [1#x])
1567
1567
+- Project [cast(1#x as int) AS 1#x]
@@ -1572,7 +1572,7 @@ Project [(cast(cast(null as string) as double) < cast(cast(1 as decimal(10,0)) a
1572
1572
-- !query
1573
1573
SELECT cast(null as string) <= cast(1 as decimal(10, 0)) FROM t
1574
1574
-- !query analysis
1575
-
Project [(cast(cast(null as string) as double) <= cast(cast(1 as decimal(10,0)) as double)) AS (CAST(NULL AS STRING) <= CAST(1 AS DECIMAL(10,0)))#x]
1575
+
Project [(cast(cast(null as string) as decimal(10,0)) <= cast(1 as decimal(10,0))) AS (CAST(NULL AS STRING) <= CAST(1 AS DECIMAL(10,0)))#x]
1576
1576
+- SubqueryAlias t
1577
1577
+- View (`t`, [1#x])
1578
1578
+- Project [cast(1#x as int) AS 1#x]
@@ -1583,7 +1583,7 @@ Project [(cast(cast(null as string) as double) <= cast(cast(1 as decimal(10,0))
1583
1583
-- !query
1584
1584
SELECT cast(null as string) <> cast(1 as decimal(10, 0)) FROM t
1585
1585
-- !query analysis
1586
-
Project [NOT (cast(cast(null as string) as double) = cast(cast(1 as decimal(10,0)) as double)) AS (NOT (CAST(NULL AS STRING) = CAST(1 AS DECIMAL(10,0))))#x]
1586
+
Project [NOT (cast(cast(null as string) as decimal(10,0)) = cast(1 as decimal(10,0))) AS (NOT (CAST(NULL AS STRING) = CAST(1 AS DECIMAL(10,0))))#x]
0 commit comments