Skip to content

Commit

Permalink
fix projection issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nthienan committed May 13, 2023
1 parent 5bcc94c commit 723f4e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.1
0.3.2
21 changes: 13 additions & 8 deletions internal/plugins/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ func InitDynamodb(configs []DynamoDbConfiguration, initializeCache bool) {
}
}

func buildProjectionExpression(fieldExpr string) *string {
func buildProjectionExpression(fieldExpr string) (*string, map[string]*string) {
if len(fieldExpr) != 0 {
fields := strings.Split(fieldExpr, ",")
println(PrintPrefix, "Projection fields: ", fields)

proj := expression.NamesList(expression.Name(fields[0]))
for i := 1; i < len(fields); i++ {
proj = expression.AddNames(proj, expression.Name(fields[i]))
Expand All @@ -63,19 +64,21 @@ func buildProjectionExpression(fieldExpr string) *string {
if err != nil {
println(PrintPrefix, "Caught an unexpected error: %s", err)
}
return expr.Projection()
return expr.Projection(), expr.Names()
}
return nil
return nil, nil
}

// Load data from Dynamodb
func LoadData(config DynamoDbConfiguration) bool {
if config.HashKey != "" {

// Set up the input parameters for the Scan operation
projection, attributeNames := buildProjectionExpression(config.Fields)
params := &dynamodb.ScanInput{
TableName: aws.String(config.Table),
ProjectionExpression: buildProjectionExpression(config.Fields),
TableName: aws.String(config.Table),
ProjectionExpression: projection,
ExpressionAttributeNames: attributeNames,
}

// Execute the Scan operation to read every item in the table.
Expand Down Expand Up @@ -185,11 +188,13 @@ func GetData(config DynamoDbConfiguration) string {
// Create attributeValue map based on hash and sort key
var attributeMap = map[string]*dynamodb.AttributeValue{}
UpdateAttributeMap(attributeMap, config)
projection, attributeNames := buildProjectionExpression(config.Fields)

result, err := dynamoDbClient.GetItem(&dynamodb.GetItemInput{
TableName: aws.String(config.Table),
Key: attributeMap,
ProjectionExpression: buildProjectionExpression(config.Fields),
TableName: aws.String(config.Table),
Key: attributeMap,
ProjectionExpression: projection,
ExpressionAttributeNames: attributeNames,
})

if err != nil {
Expand Down

0 comments on commit 723f4e3

Please sign in to comment.