Skip to content

Commit

Permalink
Merge pull request pingcap#9 from rebelice/dev_where
Browse files Browse the repository at this point in the history
suport OR and and '' for char and time\timestamp
  • Loading branch information
crazycs520 authored Jan 6, 2022
2 parents 637739d + d1e4567 commit b7ef8de
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion expression/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ func (expr *ScalarFunction) restore(t *model.TableInfo) string {
fmt.Fprint(&buffer, " != ")
buffer.WriteString(expr.GetArgs()[1].Restore(t))
fmt.Fprint(&buffer, ")")
case ast.LogicOr:
fmt.Fprint(&buffer, "(")
buffer.WriteString(expr.GetArgs()[0].Restore(t))
fmt.Fprint(&buffer, " or ")
buffer.WriteString(expr.GetArgs()[1].Restore(t))
fmt.Fprint(&buffer, ")")
}
return buffer.String()
}
Expand All @@ -117,7 +123,7 @@ func (col *Column) Restore(t *model.TableInfo) string {
}

func (expr *Constant) Restore(t *model.TableInfo) string {
return expr.ExplainInfo()
return expr.restore4S3()
}

// ExplainNormalizedInfo implements the Expression interface.
Expand All @@ -138,6 +144,25 @@ func (col *Column) ExplainNormalizedInfo() string {
return "?"
}

func (expr *Constant) restore4S3() string {
dt, err := expr.Eval(chunk.Row{})
if err != nil {
return "not recognized const vanue"
}
return expr.format4S3(dt)
}

func (expr *Constant) format4S3(dt types.Datum) string {
switch dt.Kind() {
case types.KindNull:
return "NULL"
case types.KindString, types.KindBytes, types.KindMysqlEnum, types.KindMysqlSet,
types.KindMysqlJSON, types.KindBinaryLiteral, types.KindMysqlBit, types.KindMysqlTime:
return fmt.Sprintf("'%v'", dt.GetValue())
}
return fmt.Sprintf("%v", dt.GetValue())
}

// ExplainInfo implements the Expression interface.
func (expr *Constant) ExplainInfo() string {
dt, err := expr.Eval(chunk.Row{})
Expand Down

0 comments on commit b7ef8de

Please sign in to comment.