*: Remove conversion function

It is useless in MySQL and will cause conflict with
year/time/datetime/date function.
This commit is contained in:
shenli
2015-09-06 18:07:17 +08:00
parent 22d537cbbe
commit ced00cc547
5 changed files with 0 additions and 117 deletions

View File

@ -1,64 +0,0 @@
// Copyright 2015 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package expressions
import (
"fmt"
"github.com/pingcap/tidb/context"
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/util/types"
)
var (
_ expression.Expression = (*Conversion)(nil)
)
// Conversion is the conversion expression like "type ()".
type Conversion struct {
// Tp is the conversion type.
Tp byte
// Val is the expression to be converted.
Val expression.Expression
}
// Clone implements the Expression Clone interface.
func (c *Conversion) Clone() (expression.Expression, error) {
Val, err := c.Val.Clone()
if err != nil {
return nil, err
}
return &Conversion{Tp: c.Tp, Val: Val}, nil
}
// IsStatic implements the Expression IsStatic interface.
func (c *Conversion) IsStatic() bool {
return c.Val.IsStatic()
}
// String implements the Expression String interface.
func (c *Conversion) String() string {
return fmt.Sprintf("%s(%s)", types.TypeStr(c.Tp), c.Val)
}
// Eval implements the Expression Eval interface.
func (c *Conversion) Eval(ctx context.Context, args map[interface{}]interface{}) (v interface{}, err error) {
Val, err := c.Val.Eval(ctx, args)
if err != nil {
return
}
ft := types.NewFieldType(c.Tp)
return types.Convert(Val, ft)
}

View File

@ -1,37 +0,0 @@
package expressions
import (
"errors"
. "github.com/pingcap/check"
mysql "github.com/pingcap/tidb/mysqldef"
)
var _ = Suite(&testConversionSuite{})
type testConversionSuite struct {
}
func (s *testConversionSuite) TestConversion(c *C) {
expr := Conversion{
Tp: mysql.TypeLonglong,
Val: Value{int64(1)},
}
v, err := expr.Eval(nil, nil)
c.Assert(err, IsNil)
c.Assert(v, Equals, int64(1))
c.Assert(expr.IsStatic(), IsTrue)
c.Assert(len(expr.String()), Greater, 0)
_, err = expr.Clone()
c.Assert(err, IsNil)
// test error
expr.Val = mockExpr{err: errors.New("must error")}
_, err = expr.Clone()
c.Assert(err, NotNil)
_, err = expr.Eval(nil, nil)
c.Assert(err, NotNil)
}

View File

@ -163,8 +163,6 @@ func mentionedAggregateFuncs(e expression.Expression, m *[]expression.Expression
for _, e := range x.Args {
mentionedAggregateFuncs(e, m)
}
case *Conversion:
mentionedAggregateFuncs(x.Val, m)
case *IsNull:
mentionedAggregateFuncs(x.Expr, m)
case *PExpr:
@ -243,8 +241,6 @@ func mentionedColumns(e expression.Expression, m map[string]bool, names *[]strin
for _, e := range x.Args {
mentionedColumns(e, m, names)
}
case *Conversion:
mentionedColumns(x.Val, m, names)
case *Ident:
name := x.L
if !m[name] {

View File

@ -27,7 +27,6 @@ func (s *testHelperSuite) TestContainAggFunc(c *C) {
{&BinaryOperation{L: v, R: v}, false},
{&Call{F: "count", Args: []expression.Expression{v}}, true},
{&Call{F: "abs", Args: []expression.Expression{v}}, false},
{&Conversion{Val: v}, false},
{&IsNull{Expr: v}, false},
{&PExpr{Expr: v}, false},
{&PatternIn{Expr: v, List: []expression.Expression{v}}, false},
@ -59,7 +58,6 @@ func (s *testHelperSuite) TestMentionedColumns(c *C) {
{&BinaryOperation{L: v, R: v}, 0},
{&Ident{model.NewCIStr("id")}, 1},
{&Call{F: "count", Args: []expression.Expression{v}}, 0},
{&Conversion{Val: v}, 0},
{&IsNull{Expr: v}, 0},
{&PExpr{Expr: v}, 0},
{&PatternIn{Expr: v, List: []expression.Expression{v}}, 0},

View File

@ -270,7 +270,6 @@ import (
ConstraintKeywordOpt "Constraint Keyword or empty"
ConstraintOpt "optional column value constraint"
ConstraintOpts "optional column value constraints"
Conversion "conversion"
CreateDatabase "Create {DATABASE | SCHEMA}"
CreateDatabaseStmt "Create Database Statement"
CreateIndexStmt "CREATE INDEX statement"
@ -855,14 +854,6 @@ ConstraintOpts:
}
}
Conversion:
Type '(' Expression ')'
{
t := $1.(*types.FieldType)
$$ = &expressions.Conversion{Tp: t.Tp, Val: expressions.Expr($3)}
}
CreateIndexStmt:
"CREATE" CreateIndexStmtUnique "INDEX" Identifier "ON" TableIdent '(' IndexColNameList ')'
{
@ -1738,7 +1729,6 @@ OrderByOptional:
PrimaryExpression:
Operand
| Conversion
| Function
| SubSelect
| '!' PrimaryExpression %prec neg