Skip to content

Commit 2755460

Browse files
authored
Merge pull request #21 from aws-solutions-library-samples/fix/athena-glue-tables
Fix/athena glue tables
2 parents dd5c266 + 91bc657 commit 2755460

File tree

53 files changed

+1944
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1944
-114
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ SPDX-License-Identifier: MIT-0
55

66
## [Unreleased]
77

8+
## [0.3.6]
9+
10+
### Fixed
11+
- update Athena/Glue table configuration to use Parquet format instead of JSON
12+
13+
814
## [0.3.5]
915

1016
### Added

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.5
1+
0.3.6-wip

genaiic-idp-accelerator.code-workspace

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
"lib/idp_common_pkg"
1010
],
1111
"notebook.formatOnSave.enabled": true,
12-
<<<<<<< HEAD
13-
"[python]": {
14-
"editor.formatOnSave": true,
15-
"editor.defaultFormatter": "charliermarsh.ruff"
16-
=======
1712
"notebook.codeActionsOnSave": {
1813
"notebook.source.fixAll": "explicit",
1914
"notebook.source.organizeImports": "explicit"
@@ -25,7 +20,6 @@
2520
"source.fixAll": "explicit",
2621
"source.organizeImports": "explicit"
2722
},
28-
>>>>>>> origin/develop
2923
},
3024
"makefile.configureOnOpen": false
3125
},

lib/idp_common_pkg/idp_common/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ def __getattr__(name):
1313
if name in [
1414
"bedrock",
1515
"s3",
16+
"dynamodb",
17+
"appsync",
18+
"docs_service",
1619
"metrics",
1720
"image",
1821
"utils",
@@ -45,6 +48,9 @@ def __getattr__(name):
4548
__all__ = [
4649
"bedrock",
4750
"s3",
51+
"dynamodb",
52+
"appsync",
53+
"docs_service",
4854
"metrics",
4955
"image",
5056
"utils",
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: MIT-0
3+
4+
"""
5+
Document service factory module for IDP Common package.
6+
7+
This module provides a factory function to create document services based on
8+
the DOCUMENT_TRACKING_MODE environment variable. It allows switching between
9+
AppSync and DynamoDB implementations while maintaining the same interface.
10+
"""
11+
12+
import logging
13+
import os
14+
from typing import Optional, Union
15+
16+
from idp_common.appsync import DocumentAppSyncService
17+
from idp_common.dynamodb import DocumentDynamoDBService
18+
19+
logger = logging.getLogger(__name__)
20+
21+
# Supported document tracking modes
22+
APPSYNC_MODE = "appsync"
23+
DYNAMODB_MODE = "dynamodb"
24+
SUPPORTED_MODES = [APPSYNC_MODE, DYNAMODB_MODE]
25+
26+
# Default mode
27+
DEFAULT_MODE = APPSYNC_MODE
28+
29+
30+
class DocumentServiceFactory:
31+
"""
32+
Factory class for creating document services based on configuration.
33+
34+
This factory allows switching between AppSync and DynamoDB implementations
35+
while maintaining the same interface for document operations.
36+
"""
37+
38+
@staticmethod
39+
def create_service(
40+
mode: Optional[str] = None, **kwargs
41+
) -> Union[DocumentAppSyncService, DocumentDynamoDBService]:
42+
"""
43+
Create a document service based on the specified mode.
44+
45+
Args:
46+
mode: Optional mode override. If not provided, uses DOCUMENT_TRACKING_MODE
47+
environment variable, defaulting to 'appsync'
48+
**kwargs: Additional arguments passed to the service constructor
49+
50+
Returns:
51+
DocumentAppSyncService or DocumentDynamoDBService instance
52+
53+
Raises:
54+
ValueError: If an unsupported mode is specified
55+
56+
Examples:
57+
# Use environment variable (default behavior)
58+
service = DocumentServiceFactory.create_service()
59+
60+
# Override mode explicitly
61+
service = DocumentServiceFactory.create_service(mode='dynamodb')
62+
63+
# Pass additional arguments
64+
service = DocumentServiceFactory.create_service(
65+
mode='appsync',
66+
api_url='https://example.appsync-api.us-east-1.amazonaws.com/graphql'
67+
)
68+
"""
69+
# Determine the mode
70+
if mode is None:
71+
mode = os.environ.get("DOCUMENT_TRACKING_MODE", DEFAULT_MODE).lower()
72+
else:
73+
mode = mode.lower()
74+
75+
# Validate mode
76+
if mode not in SUPPORTED_MODES:
77+
raise ValueError(
78+
f"Unsupported document tracking mode: '{mode}'. "
79+
f"Supported modes are: {', '.join(SUPPORTED_MODES)}"
80+
)
81+
82+
logger.info(f"Creating document service with mode: {mode}")
83+
84+
# Create the appropriate service
85+
if mode == APPSYNC_MODE:
86+
return DocumentAppSyncService(**kwargs)
87+
elif mode == DYNAMODB_MODE:
88+
return DocumentDynamoDBService(**kwargs)
89+
else:
90+
# This should never happen due to validation above, but included for completeness
91+
raise ValueError(f"Unsupported mode: {mode}")
92+
93+
@staticmethod
94+
def get_current_mode() -> str:
95+
"""
96+
Get the current document tracking mode from environment variable.
97+
98+
Returns:
99+
Current mode string ('appsync' or 'dynamodb')
100+
"""
101+
return os.environ.get("DOCUMENT_TRACKING_MODE", DEFAULT_MODE).lower()
102+
103+
@staticmethod
104+
def is_appsync_mode() -> bool:
105+
"""
106+
Check if current mode is AppSync.
107+
108+
Returns:
109+
True if current mode is AppSync, False otherwise
110+
"""
111+
return DocumentServiceFactory.get_current_mode() == APPSYNC_MODE
112+
113+
@staticmethod
114+
def is_dynamodb_mode() -> bool:
115+
"""
116+
Check if current mode is DynamoDB.
117+
118+
Returns:
119+
True if current mode is DynamoDB, False otherwise
120+
"""
121+
return DocumentServiceFactory.get_current_mode() == DYNAMODB_MODE
122+
123+
124+
# Convenience function for creating services
125+
def create_document_service(
126+
mode: Optional[str] = None, **kwargs
127+
) -> Union[DocumentAppSyncService, DocumentDynamoDBService]:
128+
"""
129+
Convenience function to create a document service.
130+
131+
This is a shorthand for DocumentServiceFactory.create_service().
132+
133+
Args:
134+
mode: Optional mode override. If not provided, uses DOCUMENT_TRACKING_MODE
135+
environment variable, defaulting to 'appsync'
136+
**kwargs: Additional arguments passed to the service constructor
137+
138+
Returns:
139+
DocumentAppSyncService or DocumentDynamoDBService instance
140+
141+
Examples:
142+
# Simple usage
143+
service = create_document_service()
144+
145+
# With mode override
146+
service = create_document_service(mode='dynamodb')
147+
148+
# With additional parameters
149+
service = create_document_service(
150+
mode='appsync',
151+
api_url='https://example.appsync-api.us-east-1.amazonaws.com/graphql'
152+
)
153+
"""
154+
return DocumentServiceFactory.create_service(mode=mode, **kwargs)
155+
156+
157+
# Convenience functions for mode checking
158+
def get_document_tracking_mode() -> str:
159+
"""Get the current document tracking mode."""
160+
return DocumentServiceFactory.get_current_mode()
161+
162+
163+
def is_appsync_mode() -> bool:
164+
"""Check if current mode is AppSync."""
165+
return DocumentServiceFactory.is_appsync_mode()
166+
167+
168+
def is_dynamodb_mode() -> bool:
169+
"""Check if current mode is DynamoDB."""
170+
return DocumentServiceFactory.is_dynamodb_mode()
171+
172+
173+
__all__ = [
174+
"DocumentServiceFactory",
175+
"create_document_service",
176+
"get_document_tracking_mode",
177+
"is_appsync_mode",
178+
"is_dynamodb_mode",
179+
"APPSYNC_MODE",
180+
"DYNAMODB_MODE",
181+
"DEFAULT_MODE",
182+
]

0 commit comments

Comments
 (0)