Skip to content

Commit 46c4722

Browse files
Fix Redshift data creator (#2242)
* Raise error for Redshift table names with >127 characters Signed-off-by: Felix Wang <wangfelix98@gmail.com> * Fix lint error Signed-off-by: Felix Wang <wangfelix98@gmail.com>
1 parent 88fac8b commit 46c4722

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

sdk/python/feast/errors.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,13 @@ def __init__(self, details):
243243
super().__init__(f"Redshift SQL Query failed to finish. Details: {details}")
244244

245245

246+
class RedshiftTableNameTooLong(Exception):
247+
def __init__(self, table_name: str):
248+
super().__init__(
249+
f"Redshift table names have a maximum length of 127 characters, but the table name {table_name} has length {len(table_name)} characters."
250+
)
251+
252+
246253
class EntityTimestampInferenceException(Exception):
247254
def __init__(self, expected_column_name: str):
248255
super().__init__(

sdk/python/feast/infra/utils/aws_utils.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
wait_exponential,
1616
)
1717

18-
from feast.errors import RedshiftCredentialsError, RedshiftQueryError
18+
from feast.errors import (
19+
RedshiftCredentialsError,
20+
RedshiftQueryError,
21+
RedshiftTableNameTooLong,
22+
)
1923
from feast.type_map import pa_to_redshift_value_type
2024

2125
try:
@@ -28,6 +32,9 @@
2832
raise FeastExtrasDependencyImportError("aws", str(e))
2933

3034

35+
REDSHIFT_TABLE_NAME_MAX_LENGTH = 127
36+
37+
3138
def get_redshift_data_client(aws_region: str):
3239
"""
3340
Get the Redshift Data API Service client for the given AWS region.
@@ -184,7 +191,7 @@ def upload_df_to_redshift(
184191
iam_role: str,
185192
table_name: str,
186193
df: pd.DataFrame,
187-
) -> None:
194+
):
188195
"""Uploads a Pandas DataFrame to Redshift as a new table.
189196
190197
The caller is responsible for deleting the table when no longer necessary.
@@ -208,9 +215,12 @@ def upload_df_to_redshift(
208215
table_name: The name of the new Redshift table where we copy the dataframe
209216
df: The Pandas DataFrame to upload
210217
211-
Returns: None
212-
218+
Raises:
219+
RedshiftTableNameTooLong: The specified table name is too long.
213220
"""
221+
if len(table_name) > REDSHIFT_TABLE_NAME_MAX_LENGTH:
222+
raise RedshiftTableNameTooLong(table_name)
223+
214224
bucket, key = get_bucket_and_key(s3_path)
215225

216226
# Drop the index so that we dont have unnecessary columns

sdk/python/tests/integration/feature_repos/repo_configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def construct_test_environment(
258258
worker_id: str = "worker_id",
259259
) -> Environment:
260260

261-
_uuid = str(uuid.uuid4()).replace("-", "")[:8]
261+
_uuid = str(uuid.uuid4()).replace("-", "")[:6]
262262

263263
run_id = os.getenv("GITHUB_RUN_ID", default=None)
264264
run_id = f"gh_run_{run_id}_{_uuid}" if run_id else _uuid

sdk/python/tests/integration/registration/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ def test_nullable_online_store(test_nullable_online_store) -> None:
174174

175175
with tempfile.TemporaryDirectory() as repo_dir_name:
176176
try:
177+
repo_path = Path(repo_dir_name)
177178
feature_store_yaml = make_feature_store_yaml(
178-
project, test_nullable_online_store, repo_dir_name
179+
project, test_nullable_online_store, repo_path
179180
)
180-
repo_path = Path(repo_dir_name)
181181

182182
repo_config = repo_path / "feature_store.yaml"
183183

0 commit comments

Comments
 (0)