Skip to content

Commit

Permalink
feat: add pagination support when retrieving partition values
Browse files Browse the repository at this point in the history
  • Loading branch information
mgjules committed Oct 6, 2021
1 parent c59357d commit 9cd1568
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions cmd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,33 @@ var Backup = &cli.Command{

sugar.Debugw("retrieving partition values...", "sql", sql)

partitionOutput, err := querySvc.QueryWithContext(c.Context, &timestreamquery.QueryInput{
QueryString: aws.String(sql),
MaxRows: aws.Int64(100),
})
if err != nil {
sugar.Errorw("retrieve partition values", "error", err, "sql", sql)
return fmt.Errorf("retrieve partition values: %v", err)
}
var (
nextToken *string = nil
partitionValues []string
)

for {
partitionOutput, err := querySvc.QueryWithContext(c.Context, &timestreamquery.QueryInput{
QueryString: aws.String(sql),
NextToken: nextToken,
MaxRows: aws.Int64(100),
})
if err != nil {
sugar.Errorw("retrieve partition values", "error", err, "sql", sql)
return fmt.Errorf("retrieve partition values: %v", err)
}

for _, row := range partitionOutput.Rows {
if row.Data[0].ScalarValue == nil {
continue
}
partitionValues = append(partitionValues, *row.Data[0].ScalarValue)
}

var partitionValues []string
for _, row := range partitionOutput.Rows {
if row.Data[0].ScalarValue == nil {
continue
nextToken = partitionOutput.NextToken
if nextToken == nil {
break
}
partitionValues = append(partitionValues, *row.Data[0].ScalarValue)
}

sugar.Debugw("partition", "column", partitionColumn, "values", partitionValues)
Expand Down

0 comments on commit 9cd1568

Please sign in to comment.