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

Invalid Query or Scan syntax with "single-table design" indexes #274

Open
mnapoli opened this issue Aug 10, 2023 · 1 comment
Open

Invalid Query or Scan syntax with "single-table design" indexes #274

mnapoli opened this issue Aug 10, 2023 · 1 comment
Assignees
Labels
bug enhancement needs more info More information is needed or was requested

Comments

@mnapoli
Copy link

mnapoli commented Aug 10, 2023

Describe the bug

When querying a table designed with "single-table design" practices, the package fails to escape index names.

Schema

The standard names for secondary indexes would be:

                'GSI-1-PK': '...',
                'GSI-1-SK': '...',
                etc.

Here's an example of a query I do in JavaScript on that table:

        TableName: ...,
        IndexName: 'GSI-1',
        KeyConditionExpression: '#indexName = :PK',
        ExpressionAttributeValues: {
            ':PK': `...`,
        },
        ExpressionAttributeNames: {
            // The `-` character is a reserved character in DynamoDB, so we need to escape it
            '#indexName': 'GSI-1-PK',
        },

That's what ExpressionAttributeNames is here for (to alias attribute names).

I think this package needs to do the same thing and escape attribute names. Can you confirm that this isn't the case currently?

I get the following error:

Error executing "Query" on "https://dynamodb.us-east-1.amazonaws.com"; AWS HTTP error: Client error: POST https://dynamodb.us-east-1.amazonaws.com resulted in a 400 Bad Request response: {"__type":"com.amazon.coral.validate#ValidationException","message":"ExpressionAttributeNames contains invalid key: Synt (truncated...) ValidationException (client): ExpressionAttributeNames contains invalid key: Syntax error; key: "#GSI-1-PK" - {"__type":"com.amazon.coral.validate#ValidationException","message":"ExpressionAttributeNames contains invalid key: Syntax error; key: "#GSI-1-PK""}

Most important part:

Syntax error; key: "#GSI-1-PK"

DynamoDB doesn't like the - in the names.

Debug info

Show the query that you're having trouble with by copy-pasting the result of:

Route::get('/', function () {
    return view('home', [
        'measures' => Measure::query()
            ->where('GSI-1-PK', '...')
            ->where('GSI-1-SK', '*')
            ->get(),
    ]);
});

Version info

  • Laravel: latest
  • laravel-dynamodb: latest
@nelson6e65
Copy link
Collaborator

Hi. Try to enable debug in config and then run the query only.

There will be some debug logs of your query in your .log file under storage/logs/xxx.log (you can use daily type and debug as min level in the laravel logs config).

I'll look into it this weekend. 🧐

@nelson6e65 nelson6e65 added bug enhancement needs more info More information is needed or was requested labels Sep 26, 2023
@nelson6e65 nelson6e65 self-assigned this Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug enhancement needs more info More information is needed or was requested
Projects
None yet
Development

No branches or pull requests

2 participants