Skip to content

Commit 24a3fad

Browse files
authored
Merge pull request #3325 from dolthub/angela/nullable
Make `IsNullable` return `true` for log and math functions where applicable
2 parents 8031558 + 94bb136 commit 24a3fad

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

enginetest/queries/script_queries.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13472,24 +13472,40 @@ select * from t1 except (
1347213472
},
1347313473
},
1347413474
{
13475-
// https://github.com/dolthub/dolt/issues/10070
13476-
// https://github.com/dolthub/dolt/issues/10092
1347713475
Name: "NOT EXISTS with nullable filter",
1347813476
SetUpScript: []string{
1347913477
"CREATE TABLE t0(c0 INT , c1 INT);",
1348013478
"INSERT INTO t0(c0, c1) VALUES (1, -2);",
1348113479
"create table t1(c0 int, primary key(c0))",
1348213480
"insert into t1 values (1)",
13481+
"create table t2(c0 varchar(500), primary key(c0))",
13482+
"insert into t2 values ('9')",
13483+
"create table t3(c0 boolean, primary key(c0))",
13484+
"insert into t3 values(false)",
1348313485
},
1348413486
Assertions: []ScriptTestAssertion{
1348513487
{
13488+
// https://github.com/dolthub/dolt/issues/10070
1348613489
Query: `SELECT * FROM t0 WHERE NOT EXISTS (SELECT 1 FROM (SELECT 1) alias0 WHERE (CASE -1 WHEN t0.c1 THEN false END));`,
1348713490
Expected: []sql.Row{{1, -2}},
1348813491
},
1348913492
{
13493+
// https://github.com/dolthub/dolt/issues/10092
1349013494
Query: "select * from t1 where not exists (select 1 from (select 1) as subquery where weekday(t1.c0))",
1349113495
Expected: []sql.Row{{1}},
1349213496
},
13497+
{
13498+
// https://github.com/dolthub/dolt/issues/10102
13499+
Query: "SELECT * FROM t2 WHERE NOT EXISTS (SELECT 1 FROM (SELECT 1) AS sub0 WHERE ASIN(t2.c0));",
13500+
Expected: []sql.Row{{"9"}},
13501+
// Postgres does not allow varchar types as inputs for ASIN
13502+
Dialect: "mysql",
13503+
},
13504+
{
13505+
// https://github.com/dolthub/dolt/issues/10157
13506+
Query: "SELECT * FROM t3 WHERE NOT EXISTS (SELECT 1 FROM (SELECT 1) AS sub0 WHERE LOG2(t3.c0));",
13507+
Expected: []sql.Row{{0}},
13508+
},
1349313509
},
1349413510
},
1349513511
}

sql/expression/function/logarithm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (*LogBase) CollationCoercibility(ctx *sql.Context) (collation sql.Collation
112112

113113
// IsNullable implements the sql.Expression interface.
114114
func (l *LogBase) IsNullable() bool {
115-
return l.base == float64(1) || l.base <= float64(0) || l.Child.IsNullable()
115+
return true
116116
}
117117

118118
// Eval implements the Expression interface.
@@ -196,7 +196,7 @@ func (*Log) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID,
196196

197197
// IsNullable implements the Expression interface.
198198
func (l *Log) IsNullable() bool {
199-
return l.LeftChild.IsNullable() || l.RightChild.IsNullable()
199+
return true
200200
}
201201

202202
// Eval implements the Expression interface.

sql/expression/function/math.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ func (*Tan) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID,
268268
return sql.Collation_binary, 5
269269
}
270270

271+
// IsNullable implements sql.Expression
272+
func (t *Tan) IsNullable() bool {
273+
return true
274+
}
275+
271276
// Eval implements sql.Expression
272277
func (t *Tan) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
273278
val, err := t.EvalChild(ctx, row)
@@ -325,6 +330,11 @@ func (*Asin) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID,
325330
return sql.Collation_binary, 5
326331
}
327332

333+
// IsNullable implements sql.Expression
334+
func (a *Asin) IsNullable() bool {
335+
return true
336+
}
337+
328338
// Eval implements sql.Expression
329339
func (a *Asin) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
330340
val, err := a.EvalChild(ctx, row)
@@ -382,6 +392,11 @@ func (*Acos) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID,
382392
return sql.Collation_binary, 5
383393
}
384394

395+
// IsNullable implements sql.Expression
396+
func (a *Acos) IsNullable() bool {
397+
return true
398+
}
399+
385400
// Eval implements sql.Expression
386401
func (a *Acos) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
387402
val, err := a.EvalChild(ctx, row)
@@ -559,6 +574,11 @@ func (*Cot) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID,
559574
return sql.Collation_binary, 5
560575
}
561576

577+
// IsNullable implements sql.Expression
578+
func (c *Cot) IsNullable() bool {
579+
return true
580+
}
581+
562582
// Eval implements sql.Expression
563583
func (c *Cot) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
564584
val, err := c.EvalChild(ctx, row)
@@ -991,6 +1011,11 @@ func (e *Exp) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID
9911011
return sql.Collation_binary, 5
9921012
}
9931013

1014+
// IsNullable implements sql.Expression
1015+
func (e *Exp) IsNullable() bool {
1016+
return true
1017+
}
1018+
9941019
// Eval implements the Expression interface.
9951020
func (e *Exp) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
9961021
if e.Child == nil {

0 commit comments

Comments
 (0)