|
18 | 18 | BaseRelation, |
19 | 19 | Policy, |
20 | 20 | ComponentName, |
| 21 | + EventTimeFilter, |
21 | 22 | ) |
22 | 23 | from typing import Optional, Tuple, Iterator |
23 | 24 |
|
@@ -45,6 +46,7 @@ class DremioRelation(BaseRelation): |
45 | 46 | no_schema = "no_schema" |
46 | 47 | format: Optional[str] = None |
47 | 48 | format_clause: Optional[str] = None |
| 49 | + event_time_filter: Optional[EventTimeFilter] = None |
48 | 50 |
|
49 | 51 | def quoted_by_component(self, identifier, componentName): |
50 | 52 | dot_char = "." |
@@ -85,3 +87,42 @@ def _render_iterator( |
85 | 87 | ): # or key == ComponentName.Schema): |
86 | 88 | path_part = self.quoted_by_component(path_part, key) |
87 | 89 | yield key, path_part |
| 90 | + |
| 91 | + def _format_timestamp(self, timestamp_str: str) -> str: |
| 92 | + """ |
| 93 | + Convert timestamp with timezone info to Dremio-compatible format. |
| 94 | + Removes timezone information and limits microseconds precision since Dremio |
| 95 | + doesn't support timezone info in timestamp literals and has limited microsecond precision. |
| 96 | +
|
| 97 | + Example: '2025-10-02 11:45:01.142708+00:00' -> '2025-10-02 11:45:01.142' |
| 98 | + """ |
| 99 | + if timestamp_str is None: |
| 100 | + return timestamp_str |
| 101 | + |
| 102 | + # Remove timezone information (e.g., +00:00, -05:00, Z) |
| 103 | + # This regex matches timezone patterns at the end of the string |
| 104 | + timestamp_str = str(timestamp_str) |
| 105 | + timestamp_str = re.sub(r'[+-]\d{2}:\d{2}$|Z$', '', timestamp_str) |
| 106 | + |
| 107 | + # Limit microseconds to 3 digits (milliseconds) as Dremio does not support full 6-digit microseconds |
| 108 | + # Pattern: YYYY-MM-DD HH:MM:SS.ssssss -> YYYY-MM-DD HH:MM:SS.sss |
| 109 | + timestamp_str = re.sub(r'(\.\d{3})\d{3}$', r'\1', timestamp_str) |
| 110 | + |
| 111 | + return timestamp_str |
| 112 | + |
| 113 | + # Override in order to apply _format_timestamp |
| 114 | + def _render_event_time_filtered(self, event_time_filter: EventTimeFilter) -> str: |
| 115 | + """ |
| 116 | + Returns "" if start and end are both None |
| 117 | + """ |
| 118 | + filter = "" |
| 119 | + start_ts = self._format_timestamp(event_time_filter.start) |
| 120 | + end_ts = self._format_timestamp(event_time_filter.end) |
| 121 | + if event_time_filter.start and event_time_filter.end: |
| 122 | + filter = f"{event_time_filter.field_name} >= '{start_ts}' and {event_time_filter.field_name} < '{end_ts}'" |
| 123 | + elif event_time_filter.start: |
| 124 | + filter = f"{event_time_filter.field_name} >= '{start_ts}'" |
| 125 | + elif event_time_filter.end: |
| 126 | + filter = f"{event_time_filter.field_name} < '{end_ts}'" |
| 127 | + |
| 128 | + return filter |
0 commit comments