-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathmod.rs
More file actions
216 lines (210 loc) · 6.97 KB
/
mod.rs
File metadata and controls
216 lines (210 loc) · 6.97 KB
1
2
3
4
5
6
7
8
9
10
11
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
pub mod add_months;
pub mod date_add;
pub mod date_diff;
pub mod date_part;
pub mod date_sub;
pub mod date_trunc;
pub mod dayname;
pub mod extract;
pub mod from_utc_timestamp;
pub mod last_day;
pub mod make_dt_interval;
pub mod make_interval;
pub mod next_day;
pub mod time_trunc;
pub mod to_utc_timestamp;
pub mod trunc;
pub mod unix;
use datafusion_expr::ScalarUDF;
use datafusion_functions::make_udf_function;
use std::sync::Arc;
make_udf_function!(add_months::SparkAddMonths, add_months);
make_udf_function!(date_add::SparkDateAdd, date_add);
make_udf_function!(date_diff::SparkDateDiff, date_diff);
make_udf_function!(date_part::SparkDatePart, date_part);
make_udf_function!(date_sub::SparkDateSub, date_sub);
make_udf_function!(date_trunc::SparkDateTrunc, date_trunc);
make_udf_function!(
from_utc_timestamp::SparkFromUtcTimestamp,
from_utc_timestamp
);
make_udf_function!(extract::SparkHour, hour);
make_udf_function!(extract::SparkMinute, minute);
make_udf_function!(extract::SparkSecond, second);
make_udf_function!(last_day::SparkLastDay, last_day);
make_udf_function!(make_dt_interval::SparkMakeDtInterval, make_dt_interval);
make_udf_function!(make_interval::SparkMakeInterval, make_interval);
make_udf_function!(next_day::SparkNextDay, next_day);
make_udf_function!(time_trunc::SparkTimeTrunc, time_trunc);
make_udf_function!(to_utc_timestamp::SparkToUtcTimestamp, to_utc_timestamp);
make_udf_function!(trunc::SparkTrunc, trunc);
make_udf_function!(unix::SparkUnixDate, unix_date);
make_udf_function!(
unix::SparkUnixTimestamp,
unix_micros,
unix::SparkUnixTimestamp::microseconds
);
make_udf_function!(
unix::SparkUnixTimestamp,
unix_millis,
unix::SparkUnixTimestamp::milliseconds
);
make_udf_function!(
unix::SparkUnixTimestamp,
unix_seconds,
unix::SparkUnixTimestamp::seconds
);
make_udf_function!(dayname::SparkDayName, dayname);
pub mod expr_fn {
use datafusion_functions::export_functions;
export_functions!((
add_months,
"Returns the date that is months months after start. The function returns NULL if at least one of the input parameters is NULL.",
arg1 arg2
));
export_functions!((
date_add,
"Returns the date that is days days after start. The function returns NULL if at least one of the input parameters is NULL.",
arg1 arg2
));
export_functions!((
date_sub,
"Returns the date that is days days before start. The function returns NULL if at least one of the input parameters is NULL.",
arg1 arg2
));
export_functions!((hour, "Extracts the hour component of a timestamp.", arg1));
export_functions!((
minute,
"Extracts the minute component of a timestamp.",
arg1
));
export_functions!((
second,
"Extracts the second component of a timestamp.",
arg1
));
export_functions!((
last_day,
"Returns the last day of the month which the date belongs to.",
arg1
));
export_functions!((
make_dt_interval,
"Make a day time interval from given days, hours, mins and secs (return type is actually a Duration(Microsecond))",
days hours mins secs
));
export_functions!((
make_interval,
"Make interval from years, months, weeks, days, hours, mins and secs.",
years months weeks days hours mins secs
));
// TODO: add once ANSI support is added:
// "When both of the input parameters are not NULL and day_of_week is an invalid input, the function throws SparkIllegalArgumentException if spark.sql.ansi.enabled is set to true, otherwise NULL."
export_functions!((
next_day,
"Returns the first date which is later than start_date and named as indicated. The function returns NULL if at least one of the input parameters is NULL.",
arg1 arg2
));
export_functions!((
date_diff,
"Returns the number of days from start `start` to end `end`.",
end start
));
export_functions!((
date_trunc,
"Truncates a timestamp `ts` to the unit specified by the format `fmt`.",
fmt ts
));
export_functions!((
time_trunc,
"Truncates a time `t` to the unit specified by the format `fmt`.",
fmt t
));
export_functions!((
trunc,
"Truncates a date `dt` to the unit specified by the format `fmt`.",
dt fmt
));
export_functions!((
date_part,
"Extracts a part of the date or time from a date, time, or timestamp expression.",
arg1 arg2
));
export_functions!((
from_utc_timestamp,
"Interpret a given timestamp `ts` in UTC timezone and then convert it to timezone `tz`.",
ts tz
));
export_functions!((
to_utc_timestamp,
"Interpret a given timestamp `ts` in timezone `tz` and then convert it to UTC timezone.",
ts tz
));
export_functions!((
unix_date,
"Returns the number of days since epoch (1970-01-01) for the given date `dt`.",
dt
));
export_functions!((
unix_micros,
"Returns the number of microseconds since epoch (1970-01-01 00:00:00 UTC) for the given timestamp `ts`.",
ts
));
export_functions!((
unix_millis,
"Returns the number of milliseconds since epoch (1970-01-01 00:00:00 UTC) for the given timestamp `ts`.",
ts
));
export_functions!((
unix_seconds,
"Returns the number of seconds since epoch (1970-01-01 00:00:00 UTC) for the given timestamp `ts`.",
ts
));
export_functions!((
dayname,
"Returns the three-letter abbreviated day name from the given date.",
arg1
));
}
pub fn functions() -> Vec<Arc<ScalarUDF>> {
vec![
add_months(),
date_add(),
date_diff(),
date_part(),
date_sub(),
date_trunc(),
from_utc_timestamp(),
hour(),
last_day(),
make_dt_interval(),
make_interval(),
minute(),
next_day(),
second(),
time_trunc(),
to_utc_timestamp(),
trunc(),
unix_date(),
unix_micros(),
unix_millis(),
unix_seconds(),
dayname(),
]
}