-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into moving-mongo-around
- Loading branch information
Showing
11 changed files
with
97 additions
and
84 deletions.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,47 @@ | ||
package dynamodb | ||
|
||
import ( | ||
"fmt" | ||
"github.com/artie-labs/reader/lib" | ||
"github.com/artie-labs/reader/lib/dynamo" | ||
"github.com/aws/aws-sdk-go-v2/service/dynamodbstreams/types" | ||
) | ||
|
||
type SnapshotIterator struct { | ||
ch chan map[string]types.AttributeValue | ||
keys []string | ||
tableName string | ||
batchSize int32 | ||
done bool | ||
} | ||
|
||
func NewSnapshotIterator(ch chan map[string]types.AttributeValue, keys []string, tblName string, batchSize int32) *SnapshotIterator { | ||
return &SnapshotIterator{ | ||
ch: ch, | ||
keys: keys, | ||
tableName: tblName, | ||
batchSize: batchSize, | ||
} | ||
} | ||
|
||
func (s *SnapshotIterator) HasNext() bool { | ||
return !s.done | ||
} | ||
|
||
func (s *SnapshotIterator) Next() ([]lib.RawMessage, error) { | ||
var msgs []lib.RawMessage | ||
for msg := range s.ch { | ||
dynamoMsg, err := dynamo.NewMessageFromExport(msg, s.keys, s.tableName) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to cast message from DynamoDB, msg: %v, err: %w", msg, err) | ||
} | ||
|
||
msgs = append(msgs, dynamoMsg.RawMessage()) | ||
if int32(len(msgs)) >= s.batchSize { | ||
return msgs, nil | ||
} | ||
} | ||
|
||
s.done = true | ||
return msgs, nil | ||
} |
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