1313
1414
1515class AthenaTimestamp (TypeEngine [datetime ]):
16+ """SQLAlchemy type for Athena TIMESTAMP values.
17+
18+ This type handles the conversion of Python datetime objects to Athena's
19+ TIMESTAMP literal syntax. When used in queries, datetime values are
20+ rendered as ``TIMESTAMP 'YYYY-MM-DD HH:MM:SS.mmm'``.
21+
22+ The type supports millisecond precision (3 decimal places) which matches
23+ Athena's TIMESTAMP type precision.
24+
25+ Example:
26+ >>> from sqlalchemy import Column, Table, MetaData
27+ >>> from pyathena.sqlalchemy.types import AthenaTimestamp
28+ >>> metadata = MetaData()
29+ >>> events = Table('events', metadata,
30+ ... Column('event_time', AthenaTimestamp)
31+ ... )
32+ """
33+
1634 render_literal_cast = True
1735 render_bind_cast = True
1836
@@ -27,6 +45,21 @@ def literal_processor(self, dialect: "Dialect") -> Optional["_LiteralProcessorTy
2745
2846
2947class AthenaDate (TypeEngine [date ]):
48+ """SQLAlchemy type for Athena DATE values.
49+
50+ This type handles the conversion of Python date objects to Athena's
51+ DATE literal syntax. When used in queries, date values are rendered
52+ as ``DATE 'YYYY-MM-DD'``.
53+
54+ Example:
55+ >>> from sqlalchemy import Column, Table, MetaData
56+ >>> from pyathena.sqlalchemy.types import AthenaDate
57+ >>> metadata = MetaData()
58+ >>> orders = Table('orders', metadata,
59+ ... Column('order_date', AthenaDate)
60+ ... )
61+ """
62+
3063 render_literal_cast = True
3164 render_bind_cast = True
3265
@@ -41,14 +74,53 @@ def literal_processor(self, dialect: "Dialect") -> Optional["_LiteralProcessorTy
4174
4275
4376class Tinyint (sqltypes .Integer ):
77+ """SQLAlchemy type for Athena TINYINT (8-bit signed integer).
78+
79+ TINYINT stores values from -128 to 127. This type is useful for
80+ columns that contain small integer values to optimize storage.
81+ """
82+
4483 __visit_name__ = "tinyint"
4584
4685
4786class TINYINT (Tinyint ):
87+ """Uppercase alias for Tinyint type.
88+
89+ This provides SQLAlchemy-style uppercase naming convention.
90+ """
91+
4892 __visit_name__ = "TINYINT"
4993
5094
5195class AthenaStruct (TypeEngine [Dict [str , Any ]]):
96+ """SQLAlchemy type for Athena STRUCT/ROW complex type.
97+
98+ STRUCT represents a record with named fields, similar to a database row
99+ or a Python dictionary with typed values. Each field has a name and a
100+ data type.
101+
102+ Args:
103+ *fields: Field specifications. Each can be either:
104+ - A string (field name, defaults to STRING type)
105+ - A tuple of (field_name, field_type)
106+
107+ Example:
108+ >>> from sqlalchemy import Column, Table, MetaData, types
109+ >>> from pyathena.sqlalchemy.types import AthenaStruct
110+ >>> metadata = MetaData()
111+ >>> users = Table('users', metadata,
112+ ... Column('address', AthenaStruct(
113+ ... ('street', types.String),
114+ ... ('city', types.String),
115+ ... ('zip_code', types.Integer)
116+ ... ))
117+ ... )
118+
119+ See Also:
120+ AWS Athena STRUCT Type:
121+ https://docs.aws.amazon.com/athena/latest/ug/rows-and-structs.html
122+ """
123+
52124 __visit_name__ = "struct"
53125
54126 def __init__ (self , * fields : Union [str , Tuple [str , Any ]]) -> None :
@@ -76,10 +148,34 @@ def python_type(self) -> type:
76148
77149
78150class STRUCT (AthenaStruct ):
151+ """Uppercase alias for AthenaStruct type."""
152+
79153 __visit_name__ = "STRUCT"
80154
81155
82156class AthenaMap (TypeEngine [Dict [str , Any ]]):
157+ """SQLAlchemy type for Athena MAP complex type.
158+
159+ MAP represents a collection of key-value pairs where all keys have the
160+ same type and all values have the same type.
161+
162+ Args:
163+ key_type: SQLAlchemy type for map keys. Defaults to String.
164+ value_type: SQLAlchemy type for map values. Defaults to String.
165+
166+ Example:
167+ >>> from sqlalchemy import Column, Table, MetaData, types
168+ >>> from pyathena.sqlalchemy.types import AthenaMap
169+ >>> metadata = MetaData()
170+ >>> settings = Table('settings', metadata,
171+ ... Column('config', AthenaMap(types.String, types.Integer))
172+ ... )
173+
174+ See Also:
175+ AWS Athena MAP Type:
176+ https://docs.aws.amazon.com/athena/latest/ug/maps.html
177+ """
178+
83179 __visit_name__ = "map"
84180
85181 def __init__ (self , key_type : Any = None , value_type : Any = None ) -> None :
@@ -105,10 +201,32 @@ def python_type(self) -> type:
105201
106202
107203class MAP (AthenaMap ):
204+ """Uppercase alias for AthenaMap type."""
205+
108206 __visit_name__ = "MAP"
109207
110208
111209class AthenaArray (TypeEngine [List [Any ]]):
210+ """SQLAlchemy type for Athena ARRAY complex type.
211+
212+ ARRAY represents an ordered collection of elements of the same type.
213+
214+ Args:
215+ item_type: SQLAlchemy type for array elements. Defaults to String.
216+
217+ Example:
218+ >>> from sqlalchemy import Column, Table, MetaData, types
219+ >>> from pyathena.sqlalchemy.types import AthenaArray
220+ >>> metadata = MetaData()
221+ >>> posts = Table('posts', metadata,
222+ ... Column('tags', AthenaArray(types.String))
223+ ... )
224+
225+ See Also:
226+ AWS Athena ARRAY Type:
227+ https://docs.aws.amazon.com/athena/latest/ug/arrays.html
228+ """
229+
112230 __visit_name__ = "array"
113231
114232 def __init__ (self , item_type : Any = None ) -> None :
@@ -126,4 +244,6 @@ def python_type(self) -> type:
126244
127245
128246class ARRAY (AthenaArray ):
247+ """Uppercase alias for AthenaArray type."""
248+
129249 __visit_name__ = "ARRAY"
0 commit comments