Skip to content
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

DynamoDB PartiQL 'ORDER BY' not working with 'Limit' #2917

Closed
2 of 3 tasks
leo-the-nardo opened this issue Nov 30, 2024 · 2 comments
Closed
2 of 3 tasks

DynamoDB PartiQL 'ORDER BY' not working with 'Limit' #2917

leo-the-nardo opened this issue Nov 30, 2024 · 2 comments
Assignees
Labels
bug This issue is a bug. closed-for-staleness p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. service-api This issue is due to a problem in a service API, not the SDK implementation.

Comments

@leo-the-nardo
Copy link

Acknowledgements

Describe the bug

running a statement with both 'Limit' key and 'ORDER BY' on a LSI SK causes order by to be ignored

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

order by sort key of LSI to works when limit is defined

Current Behavior

'order by' doesn't works when limit is set on dynamodb.ExecuteStatementInput . There is no error, just seems to be ignored.

Reproduction Steps

// main.go
package main

import (
	"context"
	"os"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/dynamodb"
	"github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue"
	"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"

)
func main() {
	ctx := context.Background()
	db := dynamodb.NewFromConfig(awsConfig)
	awsConfig, _ := config.LoadDefaultConfig(ctx)
	input := &dynamodb.ExecuteStatementInput{
		Statement: aws.String("SELECT * FROM BlogTable.LSI1 WHERE PK = ? ORDER BY SK_LSI1 DESC"),
		Parameters: []types.AttributeValue{
			&types.AttributeValueMemberS{Value: pk},
		},
		Limit: aws.Int32(int32(5)), //if i comment this line, the ORDER BY works as expected.
	}
	result, err := db.ExecuteStatement(ctx, input)
}

docker compose for local:

version: '3.8'
services:
  dynamodb:
    image: amazon/dynamodb-local
    container_name: dynamodb-local
    ports:
      - "8000:8000"  # aws --endpoint-url http://localhost:8000 dynamodb list-tables
    volumes:
      - ./.data/dynamo:/home/dynamodblocal/data
    command: -jar DynamoDBLocal.jar -sharedDb -dbPath /home/dynamodblocal/data
  backend:
    image: cosmtrek/air  # live reload
    working_dir: /live-reload
    ports:
      - "8080:8080"
    environment:
      AWS_DYNAMO_TABLE_NAME: 'BlogTable'
      AWS_REGION: 'us-east-1'
      AWS_ACCESS_KEY_ID: 'fakeAccessKeyId'
      AWS_SECRET_ACCESS_KEY: 'fakeSecretAccessKey'
      AWS_ENDPOINT_URL_DYNAMODB: 'http://dynamodb:8000'
    volumes:
      - ./:/live-reload/
  dynamodb-init:
    image: amazon/aws-cli:2.13.32
    depends_on:
      - dynamodb
    environment:
      AWS_ACCESS_KEY_ID: "fakeAccessKeyId"  # Provide dummy keys for local DynamoDB
      AWS_SECRET_ACCESS_KEY: "fakeSecretAccessKey"
      AWS_DEFAULT_REGION: "us-east-1"
    entrypoint: >
      bash -c '
        aws dynamodb create-table \
        --endpoint-url http://dynamodb:8000 \
        --table-name BlogTable \
        --attribute-definitions \
        AttributeName=PK,AttributeType=S \
        AttributeName=SK,AttributeType=S \
        AttributeName=SK_LSI1,AttributeType=S \
        AttributeName=GSI1PK,AttributeType=S \
        AttributeName=GSI1SK,AttributeType=S \
        --key-schema \
        AttributeName=PK,KeyType=HASH \
        AttributeName=SK,KeyType=RANGE \
        --provisioned-throughput \
        ReadCapacityUnits=5,WriteCapacityUnits=5 \
        --local-secondary-indexes \
        "[
            {
              \"IndexName\": \"LSI1\",
              \"KeySchema\": [
                {\"AttributeName\": \"PK\", \"KeyType\": \"HASH\"},
                {\"AttributeName\": \"SK_LSI1\", \"KeyType\": \"RANGE\"}
              ],
              \"Projection\": {\"ProjectionType\": \"ALL\"}
            }
          ]" \
        --global-secondary-indexes \
        "[
            {
              \"IndexName\": \"GSI1\",
              \"KeySchema\": [
                {\"AttributeName\": \"GSI1PK\", \"KeyType\": \"HASH\"},
                {\"AttributeName\": \"GSI1SK\", \"KeyType\": \"RANGE\"}
              ],
              \"Projection\": {\"ProjectionType\": \"ALL\"},
              \"ProvisionedThroughput\": {\"ReadCapacityUnits\": 5, \"WriteCapacityUnits\": 5}
            }
          ]"
        '

Possible Solution

No response

Additional Information/Context

No response

AWS Go SDK V2 Module Versions Used

module cloudificando

go 1.22.3

require (
	github.com/aws/aws-sdk-go-v2 v1.32.5
	github.com/aws/aws-sdk-go-v2/config v1.28.5
	github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.15.17
	github.com/aws/aws-sdk-go-v2/service/dynamodb v1.37.1
)

Compiler and Version used

go1.22.4 linux/amd64

Operating System and version

linux

@leo-the-nardo leo-the-nardo added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 30, 2024
@leo-the-nardo leo-the-nardo changed the title PartiQL 'ORDER BY' not working with 'Limit' DynamoDB PartiQL 'ORDER BY' not working with 'Limit' Nov 30, 2024
@RanVaknin RanVaknin self-assigned this Dec 3, 2024
@RanVaknin
Copy link
Contributor

Hi @leo-the-nardo ,

What happens if you run this code against the actual ddb server? In my reproduction I provisioned a table on DDB (not ddb local) and its working perfectly. My guess is this is a problem only with DDB local?

Thanks,
Ran~

@RanVaknin RanVaknin added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. service-api This issue is due to a problem in a service API, not the SDK implementation. p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Dec 3, 2024
Copy link

This issue has not received a response in 1 week. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. closed-for-staleness p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. service-api This issue is due to a problem in a service API, not the SDK implementation.
Projects
None yet
Development

No branches or pull requests

2 participants