Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -13441,16 +13441,23 @@ select * from t1 except (
},
{
// https://github.com/dolthub/dolt/issues/10070
// https://github.com/dolthub/dolt/issues/10092
Name: "NOT EXISTS with nullable filter",
SetUpScript: []string{
"CREATE TABLE t0(c0 INT , c1 INT);",
"INSERT INTO t0(c0, c1) VALUES (1, -2);",
"create table t1(c0 int, primary key(c0))",
"insert into t1 values (1)",
},
Assertions: []ScriptTestAssertion{
{
Query: `SELECT * FROM t0 WHERE NOT EXISTS (SELECT 1 FROM (SELECT 1) alias0 WHERE (CASE -1 WHEN t0.c1 THEN false END));`,
Expected: []sql.Row{{1, -2}},
},
{
Query: "select * from t1 where not exists (select 1 from (select 1) as subquery where weekday(t1.c0))",
Expected: []sql.Row{{1}},
},
},
},
}
Expand Down
24 changes: 12 additions & 12 deletions enginetest/queries/tpch_plans.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions sql/expression/function/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func (td *Extract) Description() string {
// Type implements the Expression interface.
func (td *Extract) Type() sql.Type { return types.Int64 }

// IsNullable implements the Expression interface
func (td *Extract) IsNullable() bool {
return true
}

// CollationCoercibility implements the interface sql.CollationCoercible.
func (*Extract) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
return sql.Collation_binary, 5
Expand Down
54 changes: 52 additions & 2 deletions sql/expression/function/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ func (q *Quarter) String() string { return fmt.Sprintf("%s(%s)", q.FunctionName(
// Type implements the Expression interface.
func (q *Quarter) Type() sql.Type { return types.Int32 }

// IsNullable implements the Expression interface
func (q *Quarter) IsNullable() bool {
return true
}

// CollationCoercibility implements the interface sql.CollationCoercible.
func (q *Quarter) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
return sql.Collation_binary, 5
Expand Down Expand Up @@ -192,6 +197,11 @@ func (m *Month) String() string { return fmt.Sprintf("%s(%s)", m.FunctionName(),
// Type implements the Expression interface.
func (m *Month) Type() sql.Type { return types.Int32 }

// IsNullable implements the Expression interface
func (d *Month) IsNullable() bool {
return true
}

// CollationCoercibility implements the interface sql.CollationCoercible.
func (*Month) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
return sql.Collation_binary, 5
Expand Down Expand Up @@ -238,6 +248,11 @@ func (d *Day) String() string { return fmt.Sprintf("%s(%s)", d.FunctionName(), d
// Type implements the Expression interface.
func (d *Day) Type() sql.Type { return types.Int32 }

// IsNullable implements the Expression interface
func (d *Day) IsNullable() bool {
return true
}

// CollationCoercibility implements the interface sql.CollationCoercible.
func (*Day) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
return sql.Collation_binary, 5
Expand Down Expand Up @@ -285,6 +300,11 @@ func (d *Weekday) String() string { return fmt.Sprintf("%s(%s)", d.FunctionName(
// Type implements the Expression interface.
func (d *Weekday) Type() sql.Type { return types.Int32 }

// IsNullable implements the Expression interface
func (d *Weekday) IsNullable() bool {
return true
}

// CollationCoercibility implements the interface sql.CollationCoercible.
func (*Weekday) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
return sql.Collation_binary, 5
Expand Down Expand Up @@ -470,6 +490,11 @@ func (d *DayOfWeek) String() string { return fmt.Sprintf("DAYOFWEEK(%s)", d.Chil
// Type implements the Expression interface.
func (d *DayOfWeek) Type() sql.Type { return types.Int32 }

// IsNullable implements the Expression interface
func (d *DayOfWeek) IsNullable() bool {
return true
}

// CollationCoercibility implements the interface sql.CollationCoercible.
func (*DayOfWeek) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
return sql.Collation_binary, 5
Expand Down Expand Up @@ -516,6 +541,11 @@ func (d *DayOfYear) String() string { return fmt.Sprintf("DAYOFYEAR(%s)", d.Chil
// Type implements the Expression interface.
func (d *DayOfYear) Type() sql.Type { return types.Int32 }

// IsNullable implements the Expression interface
func (d *DayOfYear) IsNullable() bool {
return true
}

// CollationCoercibility implements the interface sql.CollationCoercible.
func (*DayOfYear) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
return sql.Collation_binary, 5
Expand Down Expand Up @@ -653,7 +683,7 @@ func (d *YearWeek) Children() []sql.Expression { return []sql.Expression{d.date,

// IsNullable implements the Expression interface.
func (d *YearWeek) IsNullable() bool {
return d.date.IsNullable()
return true
}

// WithChildren implements the Expression interface.
Expand Down Expand Up @@ -781,7 +811,7 @@ func (d *Week) Children() []sql.Expression { return []sql.Expression{d.date, d.m

// IsNullable implements the Expression interface.
func (d *Week) IsNullable() bool {
return d.date.IsNullable()
return true
}

// WithChildren implements the Expression interface.
Expand Down Expand Up @@ -1288,6 +1318,11 @@ func (d *Date) String() string { return fmt.Sprintf("DATE(%s)", d.Child) }
// Type implements the Expression interface.
func (d *Date) Type() sql.Type { return types.Date }

// IsNullable implements the Expression interface
func (d *Date) IsNullable() bool {
return true
}

// CollationCoercibility implements the interface sql.CollationCoercible.
func (*Date) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
return sql.Collation_binary, 5
Expand Down Expand Up @@ -1370,6 +1405,11 @@ func (dtf *UnaryDatetimeFunc) String() string {
return fmt.Sprintf("%s(%s)", strings.ToUpper(dtf.Name), dtf.Child.String())
}

// IsNullable implements the Expression interface
func (dtf *UnaryDatetimeFunc) IsNullable() bool {
return true
}

// Type implements the Expression interface.
func (dtf *UnaryDatetimeFunc) Type() sql.Type {
return dtf.SQLType
Expand Down Expand Up @@ -1401,6 +1441,11 @@ func (*DayName) CollationCoercibility(ctx *sql.Context) (collation sql.Collation
return ctx.GetCollation(), 4
}

// IsNullable implements the Expression interface
func (d *DayName) IsNullable() bool {
return true
}

func (d *DayName) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
val, err := d.EvalChild(ctx, row)
if err != nil {
Expand Down Expand Up @@ -1487,6 +1532,11 @@ func (*MonthName) CollationCoercibility(ctx *sql.Context) (collation sql.Collati
return ctx.GetCollation(), 4
}

// IsNullable implements the Expression interface
func (d *MonthName) IsNullable() bool {
return true
}

func (d *MonthName) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
val, err := d.EvalChild(ctx, row)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion sql/expression/function/time_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func (d *DateDiff) String() string {
// Type implements the sql.Expression interface.
func (d *DateDiff) Type() sql.Type { return types.Int64 }

// IsNullable implements the Expression interface
func (d *DateDiff) IsNullable() bool {
return true
}

// CollationCoercibility implements the interface sql.CollationCoercible.
func (*DateDiff) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
return sql.Collation_binary, 5
Expand Down Expand Up @@ -600,7 +605,7 @@ func (t *TimestampDiff) Resolved() bool {

// IsNullable implements the sql.Expression interface.
func (t *TimestampDiff) IsNullable() bool {
return t.unit.IsNullable() && t.expr1.IsNullable() && t.expr2.IsNullable()
return true
}

// Type implements the sql.Expression interface.
Expand Down
4 changes: 2 additions & 2 deletions sql/types/datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ var (
// datetimeMaxTime is the maximum representable time value, MYSQL: 9999-12-31 23:59:59.999999 (microseconds)
datetimeMaxTime = time.Date(9999, 12, 31, 23, 59, 59, 999999000, time.UTC)

// datetimeMinTime is the minimum representable time value, MYSQL: 0000-01-01 00:00:00.000000 (microseconds)
datetimeMinTime = time.Date(0000, 0, 0, 0, 0, 0, 0, time.UTC)
// datetimeMinTime is the minimum representable time value, MYSQL: 0000-00-00 00:00:00.000000 (microseconds)
datetimeMinTime = ZeroTime

DateOnlyLayouts = []string{
"2006-01-02",
Expand Down