You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add comprehensive MAP type support for SQLAlchemy ORM
This implements complete MAP type support addressing GitHub issue #553:
## Core Implementation
- Add _to_map converter function supporting JSON and Athena native formats
- Create AthenaMap and MAP type classes for SQLAlchemy integration
- Add visit_map methods to type compiler for SQL generation
- Smart format detection for optimal performance
## Features
- Full SQLAlchemy ORM support with MAP<key_type, value_type> syntax
- Automatic conversion between string and dictionary representations
- Support for both JSON and Athena native {key=value} formats
- Type-safe key and value type specifications
- Performance optimized with format detection
## Testing & Documentation
- Comprehensive unit tests for types, compiler, and converter
- Integration tests with actual Athena MAP queries
- Complete documentation with usage examples and best practices
- Migration guide for existing raw string handling
Closes#553
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
PyAthena provides comprehensive support for Amazon Athena's MAP data types, enabling you to work with key-value data structures in your Python applications.
475
+
476
+
Basic Usage
477
+
^^^^^^^^^^^
478
+
479
+
.. code:: python
480
+
481
+
from sqlalchemy import Column, String, Integer, Table, MetaData
482
+
from pyathena.sqlalchemy.types import AthenaMap
483
+
484
+
# Define a table with MAP columns
485
+
products = Table('products', metadata,
486
+
Column('id', Integer),
487
+
Column('attributes', AthenaMap(String, String)),
488
+
Column('metrics', AthenaMap(String, Integer)),
489
+
Column('categories', AthenaMap(Integer, String))
490
+
)
491
+
492
+
This generates the following SQL structure:
493
+
494
+
.. code:: sql
495
+
496
+
CREATE TABLE products (
497
+
id INTEGER,
498
+
attributes MAP<STRING, STRING>,
499
+
metrics MAP<STRING, INTEGER>,
500
+
categories MAP<INTEGER, STRING>
501
+
)
502
+
503
+
Querying MAP Data
504
+
^^^^^^^^^^^^^^^^^
505
+
506
+
PyAthena automatically converts MAP data between different formats:
507
+
508
+
.. code:: python
509
+
510
+
from sqlalchemy import create_engine, select
511
+
512
+
# Query MAP data using MAP constructor
513
+
result = connection.execute(
514
+
select().from_statement(
515
+
text("SELECT MAP(ARRAY['name', 'category'], ARRAY['Laptop', 'Electronics']) as product_info")
0 commit comments