passren / PyDynamoDB

PyDynamoDB is a Python DB API 2.0 (PEP 249) client for Amazon DynamoDB. A SQLAlchemy dialect is offered as well. Superset official database driver.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to SELECT a field in a DynamoDB map item?

6-000-000 opened this issue · comments

This works in the DynamoDB PartiQL editor:

SELECT payload."size"
FROM "table"
WHERE pk='foo'

But when I do:

cursor.execute('SELECT payload."size" FROM "table" WHERE pk='foo')

I get this error:

dynamodb error: An error occurred (ValidationException) when calling the ExecuteStatement operation: Statement wasn't well formed, can't be processed: Invalid path dot component

An example of what my data looks like:

[
  {
    'pk': foo',
    'payload': {'size': 2, 'bla': 'bla'},
  },
  {
    'pk': 'bar',
    'payload': {'size': 2, 'bla': 'bla'},
  }
]

How may I go about selecting size from payload?

Note that I intend to use DynamoDB in Apache Superset. Was getting the same error there in the SQL Lab section. Digging around their repo led me here. Installed the package and ran the same query to confirm it wasn't a Superset thing.

So renaming the size field solved the issue. Is this because "size" is a reserved keyword? But SELECT payload."size" should be expected to work regardless.

@6-000-000 Thanks for your feedback. You are right, the reserved keyword embraced by quote should work. Let me check if the syntax parser module removed quote.

@6-000-000 Version 0.4.8 released to fix this issue. Please try it.

Hey! Thank you very much for this!