Skip to content

Top-level map columns reflect as String #857

Closed

Description

@aminghadersohi

Problem

AthenaDialect._get_column_type now reflects array<...> and nested map/struct types, but a top-level map<string,int> column still reflects as String, so the key and value types are lost for inspectors and autoload_with tables.

Reproduction

from pyathena.sqlalchemy.base import AthenaDialect
AthenaDialect()._get_column_type('map<string,int>')   # String()
AthenaDialect()._get_column_type('array<map<string,int>>').item_type  # AthenaMap(...)

Environment

PyAthena 3.35.4 and master (c01c56f), Python 3.11, SQLAlchemy 2.0.52, Athena engine version 3.

Proposed fix (optional)

Apply the nested map branch at the top level too, returning AthenaMap(key_type, value_type).

Activity

  1. laughingman7743 commented on Sep 26, 2026

    @laughingman7743
    Member

    Confirmed. _get_column_type only takes the map and row/struct branches when _nested is set; #755 / PR #774 deliberately limited typed reflection to ARRAY columns, so top-level map<...> still reflects as String. The same applies to top-level struct<...> / row(...) columns, which this issue does not mention. Please widen the scope to cover both so reflection is consistent, returning AthenaMap(...) and AthenaStruct(...) respectively.

    This changes the reflected type of existing columns from String, so it will be release-noted as a behavior change.

    Per CONTRIBUTING.md, please validate against a real table (Glue metadata and the information_schema fallback both feed this code) in your own AWS environment and record before/after results in the PR's TEST section. External-fork PRs are not run in the project's AWS CI.

  2. added this to the 4.0.0 milestone on Sep 26, 2026
  3. laughingman7743 commented on Sep 26, 2026

    @laughingman7743
    Member

    Target master for the fix; the maintainers will port it to the 3.x maintenance branch afterwards, so please do not open a PR against 3.x.

  4. laughingman7743 commented on Sep 26, 2026

    @laughingman7743
    Member

    If you plan to send a PR for this, please say so here. If the issue stays open for a long time without a PR, the maintainers may pick it up and implement the fix themselves.

  5. removed this from the 4.0.0 milestone on Sep 26, 2026
  6. laughingman7743 commented on Oct 3, 2026

    @laughingman7743
    Member

    Fixed on master by #995 (6be7de3): top-level map<...> columns now reflect as AthenaMap(key_type, value_type), and top-level struct<...> / row(...) columns as AthenaStruct(...), as nested ones already did. For example, AthenaDialect()._get_column_type("map<string,int>") returns AthenaMap(key_type=String(), value_type=INTEGER()). The change will be release-noted as a behavior change, since these columns previously reflected as String. Thank you for the report.

  7. added a commit that references this issue on Oct 6, 2026
  8. laughingman7743 commented on Oct 6, 2026

    @laughingman7743
    Member

    The fix is released in v3.38.0, backported to the 3.x line in #1104.

    Reflected top-level map<...> columns are AthenaMap(key_type, value_type), and top-level struct<...> / row(...) columns are AthenaStruct with their field types, instead of String.

    On 3.x, an unrecognized field, key, or value type is reflected as NullType with a warning and still renders as NULL in CREATE TABLE. In 4.0.0, NullType raises CompileError in DDL instead (#995, #961). Thank you again for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions