Skip to content

Commit 20f8e41

Browse files
Zhou Fancrazycs520
andcommitted
[xc]feat:support field INTERVAL YEAR TO MONTH (pingcap#58)
Co-authored-by: crazycs520 <[email protected]> Reviewed-on: https://git.pingcap.net/pingkai/tidb/pulls/58 Co-authored-by: Zhou Fan <[email protected]> Co-committed-by: Zhou Fan <[email protected]>
1 parent 6882811 commit 20f8e41

File tree

17 files changed

+7465
-7219
lines changed

17 files changed

+7465
-7219
lines changed

pkg/ddl/add_column.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ func getDefaultValue(ctx exprctx.BuildContext, col *table.Column, option *ast.Co
863863
case mysql.TypeEnum:
864864
val, err := getEnumDefaultValue(v, col)
865865
return val, false, err
866-
case mysql.TypeDuration, mysql.TypeDate:
866+
case mysql.TypeDuration, mysql.TypeDate, mysql.TypeIntervalYearToMonth:
867867
if v, err = v.ConvertTo(ctx.GetEvalCtx().TypeCtx(), &col.FieldType); err != nil {
868868
return "", false, errors.Trace(err)
869869
}

pkg/expression/builtin_cast.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,11 +1562,17 @@ func (b *builtinCastStringAsIntSig) evalInt(ctx EvalContext, row chunk.Row) (res
15621562
}
15631563

15641564
val = strings.TrimSpace(val)
1565+
if b.tp.GetType() == mysql.TypeIntervalYearToMonth {
1566+
res, _, err = types.ParseIntervalYearMonth(val, 9)
1567+
if err != nil {
1568+
return res, false, err
1569+
}
1570+
return res, false, err
1571+
}
15651572
isNegative := false
15661573
if len(val) > 1 && val[0] == '-' { // negative number
15671574
isNegative = true
15681575
}
1569-
15701576
var ures uint64
15711577
tc := typeCtx(ctx)
15721578
if !isNegative {

pkg/parser/mysql/const.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ var DefaultLengthOfMysqlTypes = map[byte]int{
338338
TypeEnum: 2,
339339
TypeString: 1,
340340
TypeSet: 8,
341+
342+
// a temp value
343+
TypeIntervalYearToMonth: 3,
341344
}
342345

343346
// DefaultLengthOfTimeFraction is the map for default physical length of time fractions.

pkg/parser/mysql/type.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ const (
4646
TypeString byte = 0xfe /* TypeString is char type */
4747
TypeGeometry byte = 0xff
4848

49-
TypeTiDBVectorFloat32 byte = 0xe1
49+
TypeTiDBVectorFloat32 byte = 0xe1
50+
TypeIntervalYearToMonth byte = 0xa1
51+
TypeIntervalDayToSecond byte = 0xa2
5052
)
5153

5254
// Flag information.

0 commit comments

Comments
 (0)