Skip to content

Commit 9cac1af

Browse files
authored
feat: Enable WeekDay function (apache#2411)
1 parent b27aa03 commit 9cac1af

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

docs/source/user-guide/latest/expressions.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,26 @@ incompatible expressions.
9191

9292
## Date/Time Functions
9393

94-
| Expression | SQL | Spark-Compatible? | Compatibility Notes |
95-
| -------------- |------------------------------| ----------------- |------------------------------------------------------------------------------------------------------|
96-
| DateAdd | `date_add` | Yes | |
97-
| DateSub | `date_sub` | Yes | |
98-
| DatePart | `date_part(field, source)` | Yes | Supported values of `field`: `year`/`month`/`week`/`day`/`dayofweek`/`doy`/`quarter`/`hour`/`minute` |
99-
| Extract | `extract(field FROM source)` | Yes | Supported values of `field`: `year`/`month`/`week`/`day`/`dayofweek`/`doy`/`quarter`/`hour`/`minute` |
100-
| FromUnixTime | `from_unixtime` | No | Does not support format, supports only -8334601211038 <= sec <= 8210266876799 |
101-
| Hour | `hour` | Yes | |
102-
| Minute | `minute` | Yes | |
103-
| Second | `second` | Yes | |
104-
| TruncDate | `trunc` | Yes | |
105-
| TruncTimestamp | `trunc_date` | Yes | |
106-
| Year | `year` | Yes | |
107-
| Month | `month` | Yes | |
108-
| DayOfMonth | `day`/`dayofmonth` | Yes | |
109-
| DayOfWeek | `dayofweek` | Yes | |
110-
| DayOfYear | `dayofyear` | Yes | |
111-
| WeekOfYear | `weekofyear` | Yes | |
112-
| Quarter | `quarter` | Yes | |
94+
| Expression | SQL | Spark-Compatible? | Compatibility Notes |
95+
|----------------|------------------------------| ----------------- |----------------------------------------------------------------------------------------------------------------------|
96+
| DateAdd | `date_add` | Yes | |
97+
| DateSub | `date_sub` | Yes | |
98+
| DatePart | `date_part(field, source)` | Yes | Supported values of `field`: `year`/`month`/`week`/`day`/`dayofweek`/`dayofweek_iso`/`doy`/`quarter`/`hour`/`minute` |
99+
| Extract | `extract(field FROM source)` | Yes | Supported values of `field`: `year`/`month`/`week`/`day`/`dayofweek`/`dayofweek_iso`/`doy`/`quarter`/`hour`/`minute` |
100+
| FromUnixTime | `from_unixtime` | No | Does not support format, supports only -8334601211038 <= sec <= 8210266876799 |
101+
| Hour | `hour` | Yes | |
102+
| Minute | `minute` | Yes | |
103+
| Second | `second` | Yes | |
104+
| TruncDate | `trunc` | Yes | |
105+
| TruncTimestamp | `trunc_date` | Yes | |
106+
| Year | `year` | Yes | |
107+
| Month | `month` | Yes | |
108+
| DayOfMonth | `day`/`dayofmonth` | Yes | |
109+
| DayOfWeek | `dayofweek` | Yes | |
110+
| WeekDay | `weekday` | Yes | |
111+
| DayOfYear | `dayofyear` | Yes | |
112+
| WeekOfYear | `weekofyear` | Yes | |
113+
| Quarter | `quarter` | Yes | |
113114

114115
## Math Expressions
115116

spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,7 @@ object QueryPlanSerde extends Logging with CometExprShim {
207207
classOf[Month] -> CometMonth,
208208
classOf[DayOfMonth] -> CometDayOfMonth,
209209
classOf[DayOfWeek] -> CometDayOfWeek,
210-
// FIXME: current datafusion version does not support isodow (WeekDay)
211-
// , see: https://github.com/apache/datafusion-comet/issues/2330
212-
// classOf[WeekDay] -> CometWeekDay,
210+
classOf[WeekDay] -> CometWeekDay,
213211
classOf[DayOfYear] -> CometDayOfYear,
214212
classOf[WeekOfYear] -> CometWeekOfYear,
215213
classOf[Quarter] -> CometQuarter)

spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,9 +1729,8 @@ class CometExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelper {
17291729
withTable(table) {
17301730
sql(s"create table $table(col timestamp) using parquet")
17311731
sql(s"insert into $table values (now()), (timestamp('1900-01-01')), (null)")
1732-
// TODO: weekday(col) https://github.com/apache/datafusion-comet/issues/2330
17331732
checkSparkAnswerAndOperator(
1734-
"SELECT col, year(col), month(col), day(col)," +
1733+
"SELECT col, year(col), month(col), day(col), weekday(col), " +
17351734
s" dayofweek(col), dayofyear(col), weekofyear(col), quarter(col) FROM $table")
17361735
}
17371736
}

0 commit comments

Comments
 (0)