-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sink: fix avro timezone #1615
Merged
Merged
sink: fix avro timezone #1615
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e8128e5
fix avro timezone
liuzix daadeef
fix
liuzix 6df1c1c
integration test
liuzix 801931e
try to fix
liuzix 659a4ef
try to fix
liuzix 8195277
check for zero values
liuzix 5a741f2
integration tests
liuzix 8321697
Merge branch 'master' into zixiong-fix-avro-timezone
liuzix 1c56ad9
Update cdc/sink/codec/avro.go
liuzix 8db8416
Update integration/tests/case_date_time.go
liuzix 405e7ec
Merge branch 'master' into zixiong-fix-avro-timezone
liuzix 4cf67c8
Merge branch 'master' into zixiong-fix-avro-timezone
liuzix 204c6ef
Merge branch 'master' into zixiong-fix-avro-timezone
ti-chi-bot 31c9078
Merge branch 'master' into zixiong-fix-avro-timezone
ti-chi-bot f08c507
Merge branch 'master' into zixiong-fix-avro-timezone
ti-chi-bot c74e3bd
Merge branch 'master' into zixiong-fix-avro-timezone
ti-chi-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Copyright 2021 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 tests | ||
|
||
import ( | ||
"errors" | ||
"log" | ||
"time" | ||
|
||
"github.com/pingcap/ticdc/integration/framework" | ||
"github.com/pingcap/ticdc/integration/framework/avro" | ||
"github.com/pingcap/ticdc/integration/framework/canal" | ||
"github.com/pingcap/ticdc/integration/framework/mysql" | ||
) | ||
|
||
// DateTimeCase is base impl of test case for different types data | ||
type DateTimeCase struct { | ||
framework.Task | ||
} | ||
|
||
// NewDateTimeCase create a test case which has many types | ||
func NewDateTimeCase(task framework.Task) *DateTimeCase { | ||
return &DateTimeCase{ | ||
Task: task, | ||
} | ||
} | ||
|
||
// Name impl framework.Task interface | ||
func (s *DateTimeCase) Name() string { | ||
return "Date Time" | ||
} | ||
|
||
// Run impl framework.Task interface | ||
func (s *DateTimeCase) Run(ctx *framework.TaskContext) error { | ||
var createDBQuery string | ||
switch s.Task.(type) { | ||
case *avro.SingleTableTask: | ||
createDBQuery = `create table test ( | ||
id INT, | ||
t_date DATE, | ||
t_datetime DATETIME, | ||
t_timestamp TIMESTAMP NULL, | ||
PRIMARY KEY (id) | ||
)` | ||
case *canal.SingleTableTask, *mysql.SingleTableTask: | ||
log.Panic("DateTimeCase does not support downstreams other than Avro") | ||
default: | ||
return errors.New("unknown test case type") | ||
} | ||
|
||
_, err := ctx.Upstream.ExecContext(ctx.Ctx, createDBQuery) | ||
if err != nil { | ||
return err | ||
} | ||
if _, ok := s.Task.(*avro.SingleTableTask); ok { | ||
_, err = ctx.Downstream.ExecContext(ctx.Ctx, "drop table if exists test") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = ctx.Downstream.ExecContext(ctx.Ctx, createDBQuery) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
// Get a handle of an existing table | ||
table := ctx.SQLHelper().GetTable("test") | ||
|
||
// Zero value case | ||
zeroValue := time.Unix(0, 0) | ||
data := map[string]interface{}{ | ||
"id": 0, | ||
"t_date": zeroValue, | ||
"t_datetime": zeroValue, | ||
"t_timestamp": zeroValue.Add(time.Second), | ||
} | ||
err = table.Insert(data).Send().Wait().Check() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Ancient date case. We DO NOT support it. | ||
// TODO investigate why and find out a solution | ||
/* ancientTime := time.Date(960, 1, 1, 15, 33, 0, 0, time.UTC) | ||
data = map[string]interface{}{ | ||
"id": 1, | ||
"t_date": ancientTime, | ||
"t_datetime": ancientTime, | ||
"t_timestamp": zeroValue.Add(time.Second), // Timestamp does not support the Zero value of `time.Time`, so we test the Unix epoch instead | ||
} | ||
err = table.Insert(data).Send().Wait().Check() | ||
if err != nil { | ||
return err | ||
} | ||
*/ | ||
|
||
return nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nil
does not have the same type astime.Time{}
, which will cause problem in the caller of this function.