Date transformers
Module containing date transformers.
DateTransformers
¶
Bases: object
Class with set of transformers to transform dates in several forms.
Source code in mkdocs/lakehouse_engine/packages/transformers/date_transformers.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
add_current_date(output_col)
staticmethod
¶
Add column with current date.
The current date comes from the driver as a constant, not from every executor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_col |
str
|
name of the output column. |
required |
Returns:
Type | Description |
---|---|
Callable
|
A function to be executed in the .transform() spark function. |
View Example of add_current_date (See full example here)
Source code in mkdocs/lakehouse_engine/packages/transformers/date_transformers.py
convert_to_date(cols, source_format=None)
staticmethod
¶
Convert multiple string columns with a source format into dates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cols |
List[str]
|
list of names of the string columns to convert. |
required |
source_format |
Optional[str]
|
dates source format (e.g., YYYY-MM-dd). Check here. |
None
|
Returns:
Type | Description |
---|---|
Callable
|
A function to be executed in the .transform() spark function. |
View Example of convert_to_date (See full example here)
Source code in mkdocs/lakehouse_engine/packages/transformers/date_transformers.py
convert_to_timestamp(cols, source_format=None)
staticmethod
¶
Convert multiple string columns with a source format into timestamps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cols |
List[str]
|
list of names of the string columns to convert. |
required |
source_format |
Optional[str]
|
dates source format (e.g., MM-dd-yyyy HH |
None
|
Returns:
Type | Description |
---|---|
Callable
|
A function to be executed in the .transform() spark function. |
View Example of convert_to_timestamp (See full example here)
Source code in mkdocs/lakehouse_engine/packages/transformers/date_transformers.py
format_date(cols, target_format=None)
staticmethod
¶
Convert multiple date/timestamp columns into strings with the target format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cols |
List[str]
|
list of names of the string columns to convert. |
required |
target_format |
Optional[str]
|
strings target format (e.g., YYYY-MM-dd). Check here. |
None
|
Returns:
Type | Description |
---|---|
Callable
|
A function to be executed in the .transform() spark function. |
View Example of format_date (See full example here)
Source code in mkdocs/lakehouse_engine/packages/transformers/date_transformers.py
get_date_hierarchy(cols, formats=None)
staticmethod
¶
Create day/month/week/quarter/year hierarchy for the provided date columns.
Uses Spark's extract function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cols |
List[str]
|
list of names of the date columns to create the hierarchy. |
required |
formats |
Optional[dict]
|
dict with the correspondence between the hierarchy and the format to apply. Check here. Example: { "year": "year", "month": "month", "day": "day", "week": "week", "quarter": "quarter" } |
None
|
Returns:
Type | Description |
---|---|
Callable
|
A function to be executed in the .transform() spark function. |