Skip to content

Commit 192b3e2

Browse files
author
ffffwh
committed
rename kafka TimeZone to DateTimeZone #1043
1 parent 49d9a1b commit 192b3e2

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

driver/common/taskconfig.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ type DtleTaskConfig struct {
7575
SrcConnectionConfig *mysqlconfig.ConnectionConfig `codec:"SrcConnectionConfig"`
7676
DestConnectionConfig *mysqlconfig.ConnectionConfig `codec:"DestConnectionConfig"`
7777
KafkaConfig *KafkaConfig `codec:"KafkaConfig"`
78-
DestType string `codec:"DestType"`
78+
DestType string `codec:"DestType"`
7979
// support oracle extractor/applier
8080
SrcOracleConfig *config.OracleConfig `codec:"SrcOracleConfig"`
8181
}
@@ -146,7 +146,7 @@ type KafkaConfig struct {
146146
Brokers []string
147147
Topic string
148148
Converter string
149-
TimeZone string
149+
DateTimeZone string
150150
User string
151151
Password string
152152
MessageGroupMaxSize uint64

driver/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ var (
170170
"Brokers": hclspec.NewAttr("Brokers", "list(string)", true),
171171
"Converter": hclspec.NewDefault(hclspec.NewAttr("Converter", "string", false),
172172
hclspec.NewLiteral(`"json"`)),
173-
"TimeZone": hclspec.NewDefault(hclspec.NewAttr("TimeZone", "string", false),
173+
"DateTimeZone": hclspec.NewDefault(hclspec.NewAttr("DateTimeZone", "string", false),
174174
hclspec.NewLiteral(`"UTC"`)),
175175
"MessageGroupMaxSize": hclspec.NewAttr("MessageGroupMaxSize", "number", false),
176176
"MessageGroupTimeout": hclspec.NewAttr("MessageGroupTimeout", "number", false),

driver/kafka/kafka3.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ type KafkaRunner struct {
6363
BinlogFile string
6464
BinlogPos int64
6565

66-
location *time.Location
66+
// Only for Datetime column type. Not for
67+
dateTimeLocation *time.Location
6768

6869
chBinlogEntries chan *common.DataEntries
6970
chDumpEntry chan *common.DumpEntry
@@ -108,7 +109,7 @@ func NewKafkaRunner(execCtx *common.ExecContext, logger g.LoggerType, storeManag
108109
chDumpEntry: make(chan *common.DumpEntry, 2),
109110
chBinlogEntries: make(chan *common.DataEntries, 2),
110111

111-
location: time.UTC, // default value
112+
dateTimeLocation: time.UTC, // default value
112113

113114
memory1: new(int64),
114115
memory2: new(int64),
@@ -280,8 +281,8 @@ func (kr *KafkaRunner) Run() {
280281
return
281282
}
282283

283-
if kr.kafkaConfig.TimeZone != "" {
284-
kr.location, err = time.LoadLocation(kr.kafkaConfig.TimeZone)
284+
if kr.kafkaConfig.DateTimeZone != "" {
285+
kr.dateTimeLocation, err = time.LoadLocation(kr.kafkaConfig.DateTimeZone)
285286
if err != nil {
286287
kr.onError(common.TaskStateDead, errors.Wrap(err, "LoadLocation"))
287288
return
@@ -318,7 +319,7 @@ func (kr *KafkaRunner) getOrSetTable(schemaName string, tableName string,
318319
} else {
319320
kr.logger.Debug("new table info", "schemaName", schemaName, "tableName", tableName)
320321
tableIdent := fmt.Sprintf("%v.%v.%v", kr.kafkaMgr.Cfg.Topic, table.TableSchema, table.TableName)
321-
colDefs, keyColDefs := kafkaColumnListToColDefs(table.OriginalTableColumns, kr.location)
322+
colDefs, keyColDefs := kafkaColumnListToColDefs(table.OriginalTableColumns, kr.dateTimeLocation)
322323
keySchema := &SchemaJson{
323324
schema: NewKeySchema(tableIdent, keyColDefs),
324325
}
@@ -793,7 +794,7 @@ func (kr *KafkaRunner) kafkaTransformSnapshotData(
793794
value = base64.StdEncoding.EncodeToString([]byte(valueStr))
794795
case mysqlconfig.DateTimeColumnType:
795796
if valueStr != "" {
796-
value = DateTimeValue(valueStr, kr.location)
797+
value = DateTimeValue(valueStr, kr.dateTimeLocation)
797798
}
798799
case mysqlconfig.DateColumnType:
799800
if valueStr != "" {
@@ -1088,7 +1089,7 @@ func (kr *KafkaRunner) kafkaConvertArg(column *mysqlconfig.Column, theValue inte
10881089
}
10891090
case mysqlconfig.DateTimeColumnType:
10901091
if theValue != nil {
1091-
theValue = DateTimeValue(theValue.(string), kr.location)
1092+
theValue = DateTimeValue(theValue.(string), kr.dateTimeLocation)
10921093
}
10931094
case mysqlconfig.VarbinaryColumnType:
10941095
if theValue != nil {
@@ -1224,7 +1225,7 @@ func reverseBytes(bytes []byte) string {
12241225
return value
12251226
}
12261227

1227-
func kafkaColumnListToColDefs(colList *common.ColumnList, loc *time.Location) (valColDefs ColDefs, keyColDefs ColDefs) {
1228+
func kafkaColumnListToColDefs(colList *common.ColumnList, dateTimeLoc *time.Location) (valColDefs ColDefs, keyColDefs ColDefs) {
12281229
cols := colList.ColumnList()
12291230
for i, _ := range cols {
12301231
var field *Schema
@@ -1304,7 +1305,7 @@ func kafkaColumnListToColDefs(colList *common.ColumnList, loc *time.Location) (v
13041305
case mysqlconfig.YearColumnType:
13051306
field = NewYearField(SCHEMA_TYPE_INT32, optional, fieldName, defaultValue)
13061307
case mysqlconfig.DateTimeColumnType:
1307-
field = NewDateTimeField(optional, fieldName, defaultValue, loc)
1308+
field = NewDateTimeField(optional, fieldName, defaultValue, dateTimeLoc)
13081309
case mysqlconfig.TimeColumnType:
13091310
field = NewTimeField(optional, fieldName, defaultValue)
13101311
case mysqlconfig.TimestampColumnType:

0 commit comments

Comments
 (0)