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
Copy file name to clipboardExpand all lines: CLAUDE.md
+58Lines changed: 58 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,6 +32,43 @@ The project supports different cursor implementations for various use cases:
32
32
33
33
### Code Style and Quality
34
34
35
+
#### Import Guidelines
36
+
**CRITICAL: Runtime Imports are Prohibited**
37
+
-**NEVER** use `import` or `from ... import` statements inside functions, methods, or conditional blocks
38
+
-**ALWAYS** place all imports at the top of the file, after the license header and module docstring
39
+
- This applies to all files: source code, tests, scripts, documentation examples
40
+
- Runtime imports cause issues with static analysis, code completion, dependency tracking, and can mask import errors
41
+
42
+
**Bad Examples:**
43
+
```python
44
+
defmy_function():
45
+
from some_module import something # NEVER do this
46
+
import os # NEVER do this
47
+
if condition:
48
+
from optional import feature # NEVER do this
49
+
```
50
+
51
+
**Good Examples:**
52
+
```python
53
+
# At the top of the file, after license header
54
+
from__future__import annotations
55
+
56
+
import os
57
+
from some_module import something
58
+
from typing import Optional
59
+
60
+
# Optional dependencies can be handled with TYPE_CHECKING
61
+
from typing importTYPE_CHECKING
62
+
ifTYPE_CHECKING:
63
+
from optional import feature
64
+
65
+
defmy_function():
66
+
# Use imported modules here
67
+
return something.process()
68
+
```
69
+
70
+
**Exception for Optional Dependencies**: The PyAthena codebase does use runtime imports for optional dependencies like `pyarrow` and `pandas` in the main source code. However, when contributing new code or modifying tests, avoid runtime imports unless absolutely necessary for optional dependency handling.
Copy file name to clipboardExpand all lines: docs/sqlalchemy.rst
+165Lines changed: 165 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -302,3 +302,168 @@ or :code:`table_name$history` metadata. Again the hint goes after the select sta
302
302
.. code:: sql
303
303
304
304
SELECT * FROM table_name FOR VERSION AS OF 949530903748831860
305
+
306
+
Complex Data Types
307
+
------------------
308
+
309
+
STRUCT Type Support
310
+
~~~~~~~~~~~~~~~~~~~
311
+
312
+
PyAthena provides comprehensive support for Amazon Athena's STRUCT (also known as ROW) data types, enabling you to work with complex nested data structures in your Python applications.
313
+
314
+
Basic Usage
315
+
^^^^^^^^^^^
316
+
317
+
.. code:: python
318
+
319
+
from sqlalchemy import Column, String, Integer, Table, MetaData
320
+
from pyathena.sqlalchemy.types import AthenaStruct
321
+
322
+
# Define a table with STRUCT columns
323
+
users = Table('users', metadata,
324
+
Column('id', Integer),
325
+
Column('profile', AthenaStruct(
326
+
('name', String),
327
+
('age', Integer),
328
+
('email', String)
329
+
)),
330
+
Column('settings', AthenaStruct(
331
+
('theme', String),
332
+
('notifications', AthenaStruct(
333
+
('email', String),
334
+
('push', String)
335
+
))
336
+
))
337
+
)
338
+
339
+
This generates the following SQL structure:
340
+
341
+
.. code:: sql
342
+
343
+
CREATE TABLE users (
344
+
id INTEGER,
345
+
profile ROW(name STRING, age INTEGER, email STRING),
0 commit comments