Skip to content

Commit 5c8576f

Browse files
committed
[SQL] Ignore case when casting string to Boolean
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
1 parent 5c3c48e commit 5c8576f

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

crates/sqllib/src/casts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ cast_to_b!(u, usize);
314314
#[doc(hidden)]
315315
#[inline]
316316
pub fn cast_to_b_s(value: SqlString) -> SqlResult<bool> {
317-
Ok(value.str().trim().parse().unwrap_or(false))
317+
Ok(value.str().to_lowercase().trim().parse().unwrap_or(false))
318318
}
319319

320320
#[doc(hidden)]

docs.feldera.com/docs/sql/boolean.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ The following table defines the `IS NOT TRUE` operator:
161161
</tr>
162162
</table>
163163

164+
Casting a string to a Boolean value produces the result *true* for any
165+
string which spells 'true' when converted to lowercase. Any other
166+
non-null string produces the result *false*.
164167

165168
:::info
166169

sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/Regression1Tests.java

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,6 @@ public void limitDuplicate() {
15891589

15901590
@Test
15911591
public void issue5345() {
1592-
this.showPlan();
15931592
var ccs = this.getCCS("""
15941593
CREATE MATERIALIZED VIEW t1 AS
15951594
SELECT DISTINCT
@@ -1608,4 +1607,83 @@ public void issue5345() {
16081607
a| 1 | { by} | true | 1
16091608
b| 1 | {} | false | 1""");
16101609
}
1610+
1611+
@Test
1612+
public void issue5352() {
1613+
var ccs = this.getCCS("""
1614+
CREATE TABLE tbl(str VARCHAR);
1615+
1616+
CREATE MATERIALIZED VIEW v AS SELECT
1617+
str::BOOLEAN IS FALSE AS arr,
1618+
str::BOOLEAN IS TRUE AS arr1
1619+
FROM tbl;""");
1620+
ccs.step("INSERT INTO TBL values('TRUE')", """
1621+
arr | arr1 | weight
1622+
---------------------
1623+
false | true | 1""");
1624+
}
1625+
1626+
@Test
1627+
public void issue5352_a() {
1628+
this.qs("""
1629+
SELECT 'TRUE'::BOOLEAN;
1630+
r
1631+
---
1632+
true
1633+
(1 row)
1634+
1635+
SELECT 'true'::BOOLEAN;
1636+
r
1637+
---
1638+
true
1639+
(1 row)
1640+
1641+
SELECT 'TrUe'::BOOLEAN;
1642+
r
1643+
---
1644+
true
1645+
(1 row)
1646+
1647+
SELECT 't'::BOOLEAN;
1648+
r
1649+
---
1650+
false
1651+
(1 row)
1652+
1653+
SELECT '1'::BOOLEAN;
1654+
r
1655+
---
1656+
false
1657+
(1 row)
1658+
1659+
SELECT '0'::BOOLEAN;
1660+
r
1661+
---
1662+
false
1663+
(1 row)
1664+
1665+
SELECT 'yes'::BOOLEAN;
1666+
r
1667+
---
1668+
false
1669+
(1 row)
1670+
1671+
SELECT ''::BOOLEAN;
1672+
r
1673+
---
1674+
false
1675+
(1 row)
1676+
1677+
SELECT 'NULL'::BOOLEAN;
1678+
r
1679+
---
1680+
false
1681+
(1 row)
1682+
1683+
SELECT NULL::BOOLEAN;
1684+
r
1685+
---
1686+
NULL
1687+
(1 row)""");
1688+
}
16111689
}

0 commit comments

Comments
 (0)