Skip to content

Commit fcd0593

Browse files
committed
Converted uses of *expression.Literal with sql.Literal
1 parent ef5a371 commit fcd0593

28 files changed

+62
-109
lines changed

sql/analyzer/apply_hash_in.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func applyHashIn(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, s
5858
func hasSingleOutput(e sql.Expression) bool {
5959
return !transform.InspectExpr(e, func(expr sql.Expression) bool {
6060
switch expr.(type) {
61-
case expression.Tuple, *expression.Literal, *expression.GetField,
61+
case expression.Tuple, sql.LiteralExpression, *expression.GetField,
6262
expression.Comparer, *expression.Convert, sql.FunctionExpression,
6363
*expression.IsTrue, *expression.IsNull, expression.ArithmeticOp:
6464
return false
@@ -73,7 +73,7 @@ func hasSingleOutput(e sql.Expression) bool {
7373
func isStatic(e sql.Expression) bool {
7474
return !transform.InspectExpr(e, func(expr sql.Expression) bool {
7575
switch expr.(type) {
76-
case expression.Tuple, *expression.Literal:
76+
case expression.Tuple, sql.LiteralExpression:
7777
return false
7878
default:
7979
return true

sql/analyzer/costed_index_scan_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ func (i *indexSearchableTable) IndexWithPrefix(ctx *sql.Context, expressions []s
912912
func (i *indexSearchableTable) LookupForExpressions(ctx *sql.Context, exprs ...sql.Expression) (sql.IndexLookup, *sql.FuncDepSet, sql.Expression, bool, error) {
913913
if eq, ok := exprs[0].(*expression.Equals); ok {
914914
if gf, ok := eq.Left().(*expression.GetField); ok && strings.EqualFold(gf.Name(), "x") {
915-
if lit, ok := eq.Right().(*expression.Literal); ok {
915+
if lit, ok := eq.Right().(sql.LiteralExpression); ok {
916916
ranges := sql.MySQLRangeCollection{{sql.ClosedRangeColumnExpr(lit.LiteralValue(), lit.LiteralValue(), lit.Type())}}
917917
return sql.IndexLookup{Index: xIdx, Ranges: ranges}, nil, nil, true, nil
918918
}

sql/analyzer/indexed_joins.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ func convertSemiToInnerJoin(m *memo.Memo) error {
436436
if rightOutTables.Contains(int(e.TableId())) {
437437
projectExpressions = append(projectExpressions, e)
438438
}
439-
case *expression.Literal, *expression.And, *expression.Or, *expression.Equals, *expression.Arithmetic, *expression.BindVar, expression.Tuple:
439+
case sql.LiteralExpression, *expression.And, *expression.Or, *expression.Equals, *expression.Arithmetic, *expression.BindVar, expression.Tuple:
440440
default:
441441
if _, ok := e.(expression.Equality); !ok {
442442
return true
@@ -528,7 +528,7 @@ func convertAntiToLeftJoin(m *memo.Memo) error {
528528
projectExpressions = append(projectExpressions, e)
529529
nullify = append(nullify, e)
530530
}
531-
case *expression.Literal, *expression.And, *expression.Or, *expression.Equals, *expression.Arithmetic, *expression.BindVar, expression.Tuple:
531+
case sql.LiteralExpression, *expression.And, *expression.Or, *expression.Equals, *expression.Arithmetic, *expression.BindVar, expression.Tuple:
532532
default:
533533
if _, ok := e.(expression.Equality); !ok {
534534
return true
@@ -642,7 +642,7 @@ func addRightSemiJoins(ctx *sql.Context, m *memo.Memo) error {
642642
if rightOutTables.Contains(int(e.TableId())) {
643643
projectExpressions = append(projectExpressions, e)
644644
}
645-
case *expression.Literal, *expression.And, *expression.Or, *expression.Equals, *expression.Arithmetic, *expression.BindVar:
645+
case sql.LiteralExpression, *expression.And, *expression.Or, *expression.Equals, *expression.Arithmetic, *expression.BindVar:
646646
default:
647647
if _, ok := e.(expression.Equality); !ok {
648648
return true
@@ -1294,14 +1294,14 @@ func makeIndexScan(ctx *sql.Context, statsProv sql.StatsProvider, tab plan.Table
12941294
var j int
12951295
for {
12961296
found := idx.Cols()[j] == matchedIdx
1297-
var lit *expression.Literal
1297+
var lit sql.LiteralExpression
12981298
for _, f := range filters {
12991299
if eq, ok := f.(expression.Equality); ok {
13001300
if l, ok := eq.Left().(*expression.GetField); ok && l.Id() == idx.Cols()[j] {
1301-
lit, _ = eq.Right().(*expression.Literal)
1301+
lit, _ = eq.Right().(sql.LiteralExpression)
13021302
}
13031303
if r, ok := eq.Right().(*expression.GetField); ok && r.Id() == idx.Cols()[j] {
1304-
lit, _ = eq.Left().(*expression.Literal)
1304+
lit, _ = eq.Left().(sql.LiteralExpression)
13051305
}
13061306
if lit != nil {
13071307
break
@@ -1398,7 +1398,7 @@ func isWeaklyMonotonic(e sql.Expression) bool {
13981398
return true
13991399
}
14001400
return false
1401-
case *expression.Equals, *expression.NullSafeEquals, *expression.Literal, *expression.GetField,
1401+
case *expression.Equals, *expression.NullSafeEquals, sql.LiteralExpression, *expression.GetField,
14021402
*expression.Tuple, *expression.IsNull, *expression.BindVar:
14031403
return false
14041404
default:

sql/analyzer/inserts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func wrapRowSource(ctx *sql.Context, insertSource sql.Node, destTbl sql.Table, s
195195
firstGeneratedAutoIncRowIdx = ii
196196
break
197197
}
198-
if lit, isLit := expr.(*expression.Literal); isLit {
198+
if lit, isLit := expr.(sql.LiteralExpression); isLit {
199199
// If a literal NULL or if 0 is specified and the NO_AUTO_VALUE_ON_ZERO SQL mode is
200200
// not active, then MySQL will fill in an auto_increment value.
201201
if types.Null.Equals(lit.Type()) ||
@@ -238,7 +238,7 @@ func wrapRowSource(ctx *sql.Context, insertSource sql.Node, destTbl sql.Table, s
238238
}
239239

240240
// isZero returns true if the specified literal value |lit| has a value equal to 0.
241-
func isZero(ctx *sql.Context, lit *expression.Literal) bool {
241+
func isZero(ctx *sql.Context, lit sql.LiteralExpression) bool {
242242
if !types.IsNumber(lit.Type()) {
243243
return false
244244
}

sql/analyzer/optimization_rules.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ func expressionSources(expr sql.Expression) (sql.FastIntSet, bool) {
178178
case *expression.NullSafeEquals:
179179
nullRejecting = false
180180
case *expression.Equals:
181-
if lit, ok := e.Left().(*expression.Literal); ok && lit.LiteralValue() == nil {
181+
if lit, ok := e.Left().(sql.LiteralExpression); ok && lit.LiteralValue() == nil {
182182
nullRejecting = false
183183
}
184-
if lit, ok := e.Right().(*expression.Literal); ok && lit.LiteralValue() == nil {
184+
if lit, ok := e.Right().(sql.LiteralExpression); ok && lit.LiteralValue() == nil {
185185
nullRejecting = false
186186
}
187187
case *plan.Subquery:
@@ -194,10 +194,10 @@ func expressionSources(expr sql.Expression) (sql.FastIntSet, bool) {
194194
case *expression.NullSafeEquals:
195195
nullRejecting = false
196196
case *expression.Equals:
197-
if lit, ok := e.Left().(*expression.Literal); ok && lit.LiteralValue() == nil {
197+
if lit, ok := e.Left().(sql.LiteralExpression); ok && lit.LiteralValue() == nil {
198198
nullRejecting = false
199199
}
200-
if lit, ok := e.Right().(*expression.Literal); ok && lit.LiteralValue() == nil {
200+
if lit, ok := e.Right().(sql.LiteralExpression); ok && lit.LiteralValue() == nil {
201201
nullRejecting = false
202202
}
203203
}
@@ -281,7 +281,7 @@ func simplifyFilters(ctx *sql.Context, a *Analyzer, node sql.Node, scope *plan.S
281281
return e, transform.SameTree, nil
282282
}
283283
// TODO: maybe more cases to simplify
284-
r, ok := e.RightChild.(*expression.Literal)
284+
r, ok := e.RightChild.(sql.LiteralExpression)
285285
if !ok {
286286
return e, transform.SameTree, nil
287287
}
@@ -327,7 +327,7 @@ func simplifyFilters(ctx *sql.Context, a *Analyzer, node sql.Node, scope *plan.S
327327
newRightUpper := expression.NewLiteral(valStr, e.RightChild.Type())
328328
newExpr := expression.NewAnd(expression.NewGreaterThanOrEqual(e.LeftChild, newRightLower), expression.NewLessThanOrEqual(e.LeftChild, newRightUpper))
329329
return newExpr, transform.NewTree, nil
330-
case *expression.Literal, expression.Tuple, *expression.Interval, *expression.CollatedExpression, *expression.MatchAgainst:
330+
case sql.LiteralExpression, expression.Tuple, *expression.Interval, *expression.CollatedExpression, *expression.MatchAgainst:
331331
return e, transform.SameTree, nil
332332
default:
333333
if !isEvaluable(e) {
@@ -368,7 +368,7 @@ func simplifyFilters(ctx *sql.Context, a *Analyzer, node sql.Node, scope *plan.S
368368
}
369369

370370
func isFalse(e sql.Expression) bool {
371-
lit, ok := e.(*expression.Literal)
371+
lit, ok := e.(sql.LiteralExpression)
372372
if ok && lit != nil && lit.Type() == types.Boolean && lit.LiteralValue() != nil {
373373
switch v := lit.LiteralValue().(type) {
374374
case bool:
@@ -381,7 +381,7 @@ func isFalse(e sql.Expression) bool {
381381
}
382382

383383
func isTrue(e sql.Expression) bool {
384-
lit, ok := e.(*expression.Literal)
384+
lit, ok := e.(sql.LiteralExpression)
385385
if ok && lit != nil && lit.Type() == types.Boolean && lit.LiteralValue() != nil {
386386
switch v := lit.LiteralValue().(type) {
387387
case bool:

sql/analyzer/replace_count_star.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func replaceCountStar(ctx *sql.Context, a *Analyzer, n sql.Node, _ *plan.Scope,
7171

7272
var doReplace bool
7373
switch e := cnt.Child.(type) {
74-
case *expression.Star, *expression.Literal:
74+
case *expression.Star, sql.LiteralExpression:
7575
doReplace = true
7676

7777
case *expression.GetField:

sql/analyzer/replace_order_by_distance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func replaceIdxOrderByDistanceHelper(ctx *sql.Context, scope *plan.Scope, node s
6969
// depend on the row. Right now that can be a Literal or a UserVar.
7070
isLiteral := func(expr sql.Expression) bool {
7171
switch expr.(type) {
72-
case *expression.Literal, *expression.UserVar:
72+
case sql.LiteralExpression, *expression.UserVar:
7373
return true
7474
}
7575
return false

sql/analyzer/validation_rules.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func validateOffsetAndLimit(ctx *sql.Context, a *Analyzer, n sql.Node, scope *pl
3737
switch n := n.(type) {
3838
case *plan.Limit:
3939
switch e := n.Limit.(type) {
40-
case *expression.Literal:
40+
case sql.LiteralExpression:
4141
if !types.IsInteger(e.Type()) {
4242
err = sql.ErrInvalidType.New(e.Type().String())
4343
return false
@@ -63,7 +63,7 @@ func validateOffsetAndLimit(ctx *sql.Context, a *Analyzer, n sql.Node, scope *pl
6363
}
6464
case *plan.Offset:
6565
switch e := n.Offset.(type) {
66-
case *expression.Literal:
66+
case sql.LiteralExpression:
6767
if !types.IsInteger(e.Type()) {
6868
err = sql.ErrInvalidType.New(e.Type().String())
6969
return false
@@ -296,7 +296,7 @@ func expressionReferencesOnlyGroupBys(groupBys []string, expr sql.Expression) bo
296296
valid := true
297297
sql.Inspect(expr, func(expr sql.Expression) bool {
298298
switch expr := expr.(type) {
299-
case nil, sql.Aggregation, *expression.Literal:
299+
case nil, sql.Aggregation, sql.LiteralExpression:
300300
return false
301301
case *expression.Alias, sql.FunctionExpression:
302302
if stringContains(groupBys, expr.String()) {

sql/expression/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func Dispose(e sql.Expression) {
137137

138138
// LiteralToInt extracts a non-negative integer from an expression.Literal, or errors
139139
func LiteralToInt(e sql.Expression) (int, error) {
140-
lit, ok := e.(*Literal)
140+
lit, ok := e.(sql.LiteralExpression)
141141
if !ok {
142142
return 0, ErrInvalidOffset.New(e)
143143
}

sql/expression/div.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ func getFloatOrMaxDecimalType(e sql.Expression, treatIntsAsFloats bool) sql.Type
354354
maxFrac = s
355355
}
356356
}
357-
case *Literal:
357+
case sql.LiteralExpression:
358358
if types.IsNumber(c.Type()) {
359359
l, err := c.Eval(nil, nil)
360360
if err == nil {
@@ -576,8 +576,8 @@ func getFinalScale(ctx *sql.Context, row sql.Row, expr sql.Expression, divOpCnt
576576
// TODO: likely need a case for IntDiv
577577

578578
var fScale uint8
579-
if lit, isLit := expr.(*Literal); isLit {
580-
_, fScale = GetPrecisionAndScale(lit.value)
579+
if lit, isLit := expr.(sql.LiteralExpression); isLit {
580+
_, fScale = GetPrecisionAndScale(lit.LiteralValue())
581581
}
582582
typ := expr.Type()
583583
if dt, dok := typ.(sql.DecimalType); dok {

0 commit comments

Comments
 (0)