Skip to content

Commit 3c71e5c

Browse files
author
ffffwh
committed
use basic types for Column.Default #1032
Fixing error: gob: type types.MyDecimal...
1 parent fc01122 commit 3c71e5c

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

driver/common/common.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"io/ioutil"
99
"time"
1010

11-
"github.com/pingcap/tidb/types"
12-
1311
"github.com/actiontech/dtle/g"
1412
"github.com/go-mysql-org/go-mysql/mysql"
1513
uuid "github.com/satori/go.uuid"
@@ -63,8 +61,7 @@ type GencodeType interface {
6361

6462
func init() {
6563
// "Only types that will be transferred as implementations of interface values need to be registered."
66-
gob.Register(types.BinaryLiteral{})
67-
gob.Register(types.MyDecimal{})
64+
//gob.Register(types.BinaryLiteral{})
6865
if g.EnvIsTrue(g.ENV_BIG_MSG_100K) {
6966
g.NatsMaxMsg = 100 * 1024 // TODO this does not works
7067
}

driver/kafka/kafka2.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ import (
1414
"math/big"
1515
"strings"
1616

17-
"github.com/actiontech/dtle/g"
18-
"github.com/pingcap/tidb/types"
19-
2017
"github.com/actiontech/dtle/driver/common"
18+
"github.com/actiontech/dtle/g"
2119

2220
"strconv"
2321

@@ -503,8 +501,7 @@ func NewJsonField(optional bool, field string) *Schema {
503501

504502
func NewBitsField(optional bool, field string, length string, defaultValue interface{}) *Schema {
505503
if defaultValue != nil {
506-
defaultV := defaultValue.(types.BinaryLiteral)
507-
defaultValue = base64.StdEncoding.EncodeToString(defaultV)
504+
defaultValue = base64.StdEncoding.EncodeToString(defaultValue.([]byte))
508505
}
509506
return &Schema{
510507
Field: field,

driver/kafka/kafka3.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/actiontech/dtle/g"
2727
gomysql "github.com/go-mysql-org/go-mysql/mysql"
2828
"github.com/hashicorp/nomad/plugins/drivers"
29-
"github.com/pingcap/tidb/types"
3029
"github.com/pkg/errors"
3130

3231
gonats "github.com/nats-io/go-nats"
@@ -1234,7 +1233,7 @@ func kafkaColumnListToColDefs(colList *common.ColumnList, loc *time.Location) (v
12341233
case mysqlconfig.BitColumnType:
12351234
if cols[i].ColumnType == "bit(1)" {
12361235
if defaultValue != nil {
1237-
if string(defaultValue.(types.BinaryLiteral)) == "\x01" {
1236+
if string(defaultValue.([]byte)) == "\x01" {
12381237
defaultValue = true
12391238
} else {
12401239
defaultValue = false

driver/mysql/base/utils.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"bytes"
1111
gosql "database/sql"
1212
"fmt"
13+
"github.com/hashicorp/go-hclog"
14+
"github.com/pingcap/tidb/types"
1315
"regexp"
1416
"strings"
1517
"time"
@@ -545,7 +547,18 @@ func GetTableColumnsSqle(sqleContext *sqle.Context, schema string,
545547
if !ok {
546548
newColumn.Default = nil
547549
} else {
548-
newColumn.Default = value.GetValue()
550+
switch v := value.GetValue().(type) {
551+
case int64, uint64, float32, float64, string, []byte:
552+
newColumn.Default = v
553+
case types.BinaryLiteral:
554+
newColumn.Default = []byte(v)
555+
case fmt.Stringer:
556+
newColumn.Default = v.String()
557+
default:
558+
newColumn.Default = nil
559+
g.Logger.Warn("GetTableColumnsSqle: unknown type for a default value",
560+
"schema", schema, "table", table, "type", hclog.Fmt("%T", v))
561+
}
549562
}
550563
case ast.ColumnOptionUniqKey:
551564
newColumn.Key = "UNI"

driver/mysql/mysqlconfig/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type Column struct {
6969
IsUnsigned bool
7070
Charset string
7171
Type ColumnType
72+
// Default is currently only used for kafka and limited to basic types.
7273
Default interface{}
7374
ColumnType string
7475
Key string

0 commit comments

Comments
 (0)