Skip to content

Commit

Permalink
Merge pull request #21 from luisvicenteatprima/bugfix-error-with-pref…
Browse files Browse the repository at this point in the history
…fix-grain

target-s3: Seconds will not be included if the grain is hour or lower
  • Loading branch information
crowemi authored Jun 29, 2023
2 parents 709734e + 4cd2616 commit a8f9cd9
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions target_s3/formats/format_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,24 @@ def create_key(self) -> str:

def create_folder_structure(self, batch_start: datetime, grain: int, partition_name_enabled: bool) -> str:
ret = ""
ret += f"{'year=' if partition_name_enabled else ''}{batch_start.year}/" if grain <= 7 else ""
ret += f"{'month=' if partition_name_enabled else ''}{batch_start.month:02}/" if grain <= 6 else ""
ret += f"{'day=' if partition_name_enabled else ''}{batch_start.day:02}/" if grain <= 5 else ""
ret += f"{'hour=' if partition_name_enabled else ''}{batch_start.hour:02}/" if grain <= 4 else ""
ret += f"{'minute=' if partition_name_enabled else ''}{batch_start.minute:02}/" if grain <= 3 else ""
ret += f"{'second=' if partition_name_enabled else ''}{batch_start.second:02}/" if grain <= 4 else ""
ret += f"{'microsecond=' if partition_name_enabled else ''}{batch_start.microsecond}/" if grain <= 1 else ""
ret += f"{'year=' if partition_name_enabled else ''}{batch_start.year}/" if grain <= DATE_GRAIN["year"] else ""
ret += f"{'month=' if partition_name_enabled else ''}{batch_start.month:02}/" if grain <= DATE_GRAIN["month"] else ""
ret += f"{'day=' if partition_name_enabled else ''}{batch_start.day:02}/" if grain <= DATE_GRAIN["day"] else ""
ret += f"{'hour=' if partition_name_enabled else ''}{batch_start.hour:02}/" if grain <= DATE_GRAIN["hour"] else ""
ret += f"{'minute=' if partition_name_enabled else ''}{batch_start.minute:02}/" if grain <= DATE_GRAIN["minute"] else ""
ret += f"{'second=' if partition_name_enabled else ''}{batch_start.second:02}/" if grain <= DATE_GRAIN["second"] else ""
ret += f"{'microsecond=' if partition_name_enabled else ''}{batch_start.microsecond}/" if grain <= DATE_GRAIN["microsecond"] else ""
return ret

def create_file_structure(self, batch_start: datetime, grain: int) -> str:
ret = ""
ret += f"{batch_start.year}" if grain <= 7 else ""
ret += f"{batch_start.month:02}" if grain <= 6 else ""
ret += f"{batch_start.day:02}" if grain <= 5 else ""
ret += f"-{batch_start.hour:02}" if grain <= 4 else ""
ret += f"{batch_start.minute:02}" if grain <= 3 else ""
ret += f"{batch_start.second:02}" if grain <= 4 else ""
ret += f"{batch_start.microsecond}" if grain <= 1 else ""
ret += f"{batch_start.year}" if grain <= DATE_GRAIN["year"] else ""
ret += f"{batch_start.month:02}" if grain <= DATE_GRAIN["month"] else ""
ret += f"{batch_start.day:02}" if grain <= DATE_GRAIN["day"] else ""
ret += f"-{batch_start.hour:02}" if grain <= DATE_GRAIN["hour"] else ""
ret += f"{batch_start.minute:02}" if grain <= DATE_GRAIN["minute"] else ""
ret += f"{batch_start.second:02}" if grain <= DATE_GRAIN["second"] else ""
ret += f"{batch_start.microsecond}" if grain <= DATE_GRAIN["microsecond"] else ""
return ret

def flatten_key(self, k, parent_key, sep) -> str:
Expand Down

0 comments on commit a8f9cd9

Please sign in to comment.