-
Notifications
You must be signed in to change notification settings - Fork 547
feat(mysql)!: Update to SDK V3 Arrow native #11214
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
Merged
kodiakhq
merged 6 commits into
cloudquery:main
from
erezrokah:fix/update_mysql_source_sdk_v3
Jun 21, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
03e8e53
feat(mysql)!: Update to SDK V3 Arrow native
erezrokah 8315617
fix: Datetime presion
erezrokah 42d182a
Update plugins/source/mysql/client/types.go
erezrokah 27e8674
Update plugins/source/mysql/resources/plugin/plugin_test.go
erezrokah 90d69fe
refactor: Extract query
erezrokah fa85c41
Merge branch 'main' into fix/update_mysql_source_sdk_v3
kodiakhq[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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,137 +1,82 @@ | ||
| package client | ||
|
|
||
| import ( | ||
| "github.com/cloudquery/plugin-sdk/v2/schema" | ||
| "github.com/apache/arrow/go/v13/arrow" | ||
| "github.com/apache/arrow/go/v13/arrow/array" | ||
| "github.com/cloudquery/plugin-sdk/v3/types" | ||
| ) | ||
|
|
||
| // this is used for tests | ||
| type Transformer struct{} | ||
|
|
||
| func (*Transformer) TransformBool(v *schema.Bool) any { | ||
| if v.Status != schema.Present { | ||
| return nil | ||
| } | ||
| return v.Bool | ||
| } | ||
|
|
||
| func (*Transformer) TransformBytea(v *schema.Bytea) any { | ||
| if v.Status != schema.Present { | ||
| return nil | ||
| } | ||
| return v.Bytes | ||
| } | ||
|
|
||
| func (*Transformer) TransformFloat8(v *schema.Float8) any { | ||
| if v.Status != schema.Present { | ||
| return nil | ||
| } | ||
| return v.Float | ||
| } | ||
|
|
||
| func (*Transformer) TransformInt8(v *schema.Int8) any { | ||
| if v.Status != schema.Present { | ||
| return nil | ||
| } | ||
| return v.Int | ||
| } | ||
|
|
||
| func (*Transformer) TransformTimestamptz(v *schema.Timestamptz) any { | ||
| if v.Status != schema.Present { | ||
| return nil | ||
| } | ||
| return v.Time | ||
| } | ||
|
|
||
| func (*Transformer) TransformJSON(v *schema.JSON) any { | ||
| if v.Status != schema.Present { | ||
| return nil | ||
| } | ||
|
|
||
| return string(v.Bytes) | ||
| } | ||
|
|
||
| func (*Transformer) TransformUUID(v *schema.UUID) any { | ||
| if v.Status != schema.Present { | ||
| return nil | ||
| } | ||
| // We need a slice instead of a fixed sized array | ||
| bytes := make([]byte, 16) | ||
| copy(bytes, v.Bytes[:]) | ||
| return bytes | ||
| } | ||
|
|
||
| func (*Transformer) TransformUUIDArray(v *schema.UUIDArray) any { | ||
| if v.Status != schema.Present { | ||
| return nil | ||
| } | ||
|
|
||
| return v.String() | ||
| } | ||
|
|
||
| func (*Transformer) TransformInt8Array(v *schema.Int8Array) any { | ||
| if v.Status != schema.Present { | ||
| return nil | ||
| } | ||
|
|
||
| return v.String() | ||
| } | ||
|
|
||
| func (*Transformer) TransformCIDR(v *schema.CIDR) any { | ||
| if v.Status != schema.Present { | ||
| return nil | ||
| } | ||
| return v.String() | ||
| } | ||
|
|
||
| func (*Transformer) TransformInet(v *schema.Inet) any { | ||
| if v.Status != schema.Present { | ||
| return nil | ||
| } | ||
| return v.String() | ||
| } | ||
|
|
||
| func (*Transformer) TransformMacaddr(v *schema.Macaddr) any { | ||
| if v.Status != schema.Present { | ||
| return nil | ||
| } | ||
| return v.String() | ||
| } | ||
|
|
||
| func (*Transformer) TransformText(v *schema.Text) any { | ||
| if v.Status != schema.Present { | ||
| return nil | ||
| } | ||
| return v.Str | ||
| } | ||
|
|
||
| func (*Transformer) TransformCIDRArray(v *schema.CIDRArray) any { | ||
| if v.Status != schema.Present { | ||
| return nil | ||
| } | ||
|
|
||
| return v.String() | ||
| } | ||
|
|
||
| func (*Transformer) TransformInetArray(v *schema.InetArray) any { | ||
| if v.Status != schema.Present { | ||
| return nil | ||
| } | ||
|
|
||
| return v.String() | ||
| } | ||
|
|
||
| func (*Transformer) TransformMacaddrArray(v *schema.MacaddrArray) any { | ||
| if v.Status != schema.Present { | ||
| return nil | ||
| } | ||
|
|
||
| return v.String() | ||
| } | ||
|
|
||
| func (*Transformer) TransformTextArray(v *schema.TextArray) any { | ||
| if v.Status != schema.Present { | ||
| return nil | ||
| } | ||
|
|
||
| return v.String() | ||
| func GetValue(arr arrow.Array, i int) (any, error) { | ||
| if arr.IsNull(i) { | ||
| return nil, nil | ||
| } | ||
| switch a := arr.(type) { | ||
| case *array.Boolean: | ||
| return a.Value(i), nil | ||
| case *array.Int8: | ||
| return a.Value(i), nil | ||
| case *array.Int16: | ||
| return a.Value(i), nil | ||
| case *array.Int32: | ||
| return a.Value(i), nil | ||
| case *array.Int64: | ||
| return a.Value(i), nil | ||
| case *array.Uint8: | ||
| return a.Value(i), nil | ||
| case *array.Uint16: | ||
| return a.Value(i), nil | ||
| case *array.Uint32: | ||
| return a.Value(i), nil | ||
| case *array.Uint64: | ||
| return a.Value(i), nil | ||
| case *array.Float16: | ||
| return a.Value(i), nil | ||
| case *array.Float32: | ||
| return a.Value(i), nil | ||
| case *array.Float64: | ||
| return a.Value(i), nil | ||
| case *array.String: | ||
| return a.Value(i), nil | ||
| case *array.LargeString: | ||
| return a.Value(i), nil | ||
| case *array.Binary: | ||
| return a.Value(i), nil | ||
| case *array.LargeBinary: | ||
| return a.Value(i), nil | ||
| case *array.FixedSizeBinary: | ||
| return a.Value(i), nil | ||
| case *array.Timestamp: | ||
| toTime, err := a.DataType().(*arrow.TimestampType).GetToTimeFunc() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return toTime(a.Value(i)), nil | ||
| case *types.UUIDArray: | ||
| bUUID, err := a.Value(i).MarshalBinary() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return bUUID, nil | ||
| default: | ||
| return a.ValueStr(i), nil | ||
| } | ||
| } | ||
|
|
||
| // used in the tests to insert the arrow.Record | ||
| func TransformRecord(record arrow.Record) ([][]any, error) { | ||
| numRows := record.NumRows() | ||
| res := make([][]any, numRows) | ||
| var err error | ||
| for i := int64(0); i < numRows; i++ { | ||
| numCols := record.NumCols() | ||
| row := make([]any, numCols) | ||
| for j := 0; int64(j) < numCols; j++ { | ||
| row[j], err = GetValue(record.Column(j), int(i)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
| res[i] = row | ||
| } | ||
| return res, nil | ||
| } |
Oops, something went wrong.
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.
This was a workaround and no longer needed since the scalar UUID supports
**[]bytedue to cloudquery/plugin-sdk#922