File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -112,3 +112,32 @@ class Max(NonGroupableFunc):
112112
113113 def __init__ (self , expression ):
114114 super ().__init__ (expression , function = 'Max' )
115+
116+
117+ class DateTimeEpochColumn (expressions .Col ):
118+ """Gets the date/time column as a UNIX epoch timestamp."""
119+
120+ contains_column_references = True
121+
122+ def as_sql (self , compiler , connection ):
123+ """Compiles this expression into SQL."""
124+
125+ sql , params = super ().as_sql (compiler , connection )
126+ return 'EXTRACT(epoch FROM {})' .format (sql ), params
127+
128+ def get_group_by_cols (self ):
129+ return []
130+
131+
132+ class DateTimeEpoch (expressions .F ):
133+ """Gets the date/time column as a UNIX epoch timestamp."""
134+
135+ contains_aggregate = False
136+
137+ def resolve_expression (self , * args , ** kwargs ):
138+ original_expression = super ().resolve_expression (* args , ** kwargs )
139+ expression = DateTimeEpochColumn (
140+ original_expression .alias ,
141+ original_expression .target ,
142+ )
143+ return expression
You can’t perform that action at this time.
0 commit comments