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.
Other
16 stars 2 forks source link

How to SELECT a field in a DynamoDB map item? #28

Closed 6-000-000 closed 1 year ago

6-000-000 commented 1 year ago

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.

6-000-000 commented 1 year ago

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.

passren commented 1 year ago

@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.

passren commented 1 year ago

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

6-000-000 commented 1 year ago

Hey! Thank you very much for this!