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