Skip to content

Undesired behaviour with AthenaArray/AthenaStruct #627

@jmspereira

Description

@jmspereira

Hi @laughingman7743,

I have the following model defined:

from sqlalchemy import Column, Float, Integer
from sqlalchemy.orm import declarative_base
from pyathena.sqlalchemy.types import AthenaArray, AthenaStruct, AthenaTimestamp

Base = declarative_base()


class DummyTable(Base):
    __tablename__ = "dummy_table_athena"

    id = Column(Integer, primary_key=True)

    positions = Column(
        "positions",
        AthenaArray(
            AthenaStruct(
                ("header", AthenaStruct(("stamp", AthenaTimestamp))), ("x", Float), ("y", Float)
            )
        ),
    )

And if I access the database directly, I can see that the data has indeed the defined format (i.e., header={stamp=xyz, seq=ghi}, x=abc, y=def}). However, after executing a simple select:

query = (
    athena_session.query(DummyTable.positions)
    .where(DummyTable.id == <requested_id>)
)

The value of the positions is something like:

[{'seq': 0, 'x': 4.736, 'y': 0.583}, {'seq': 0, 'x': 4.501, 'y': 1.023}, ...]

I.e., does not even reference the header{stamp} and has the seq at the same level as the other attributes.
Do you have any ideas of what may be causing this?

Best regards,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions