This is an automated email from the ASF dual-hosted git repository.

kgyrtkirk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git


The following commit(s) were added to refs/heads/master by this push:
     new 6898a5a3595 Removed Microsecond from Extract function (#17247)
6898a5a3595 is described below

commit 6898a5a35956654e0fb79ce4b1ac932bb7c1606e
Author: Shivam Garg <[email protected]>
AuthorDate: Fri Oct 11 09:02:26 2024 +0530

    Removed Microsecond from Extract function (#17247)
---
 docs/querying/sql-scalar.md                        |  4 +--
 .../expression/TimestampExtractExprMacro.java      |  3 ---
 .../builtin/ExtractOperatorConversion.java         |  1 -
 .../apache/druid/sql/calcite/CalciteQueryTest.java | 29 ++++++++--------------
 4 files changed, 13 insertions(+), 24 deletions(-)

diff --git a/docs/querying/sql-scalar.md b/docs/querying/sql-scalar.md
index 8a8c47160da..f4c565cda83 100644
--- a/docs/querying/sql-scalar.md
+++ b/docs/querying/sql-scalar.md
@@ -166,13 +166,13 @@ overhead.
 |`TIME_CEIL(timestamp_expr, period[, origin[, timezone]])`|Rounds up a 
timestamp, returning it as a new timestamp. Period can be any ISO 8601 period, 
like P3M (quarters) or PT12H (half-days). Specify `origin` as a timestamp to 
set the reference time for rounding. For example, `TIME_CEIL(__time, 'PT1H', 
TIMESTAMP '2016-06-27 00:30:00')` measures an hourly period from 00:30-01:30 
instead of 00:00-01:00. See [Period granularities](granularities.md) for 
details on the default starting bounda [...]
 |`TIME_FLOOR(timestamp_expr, period[, origin[, timezone]])`|Rounds down a 
timestamp, returning it as a new timestamp. Period can be any ISO 8601 period, 
like P3M (quarters) or PT12H (half-days). Specify `origin` as a timestamp to 
set the reference time for rounding. For example, `TIME_FLOOR(__time, 'PT1H', 
TIMESTAMP '2016-06-27 00:30:00')` measures an hourly period from 00:30-01:30 
instead of 00:00-01:00. See [Period granularities](granularities.md) for 
details on the default starting bo [...]
 |`TIME_SHIFT(timestamp_expr, period, step[, timezone])`|Shifts a timestamp by 
a period (step times), returning it as a new timestamp. The `period` parameter 
can be any ISO 8601 period. The `step` parameter can be negative. The time 
zone, if provided, should be a time zone name like `America/Los_Angeles` or an 
offset like `-08:00`.|
-|`TIME_EXTRACT(timestamp_expr, unit[, timezone])`|Extracts a time part from 
`expr`, returning it as a number. Unit can be EPOCH, SECOND, MINUTE, HOUR, DAY 
(day of month), DOW (day of week), DOY (day of year), WEEK (week of [week 
year](https://en.wikipedia.org/wiki/ISO_week_date)), MONTH (1 through 12), 
QUARTER (1 through 4), or YEAR. The time zone, if provided, should be a time 
zone name like `America/Los_Angeles` or an offset like `-08:00`. The `unit` and 
`timezone` parameters must be p [...]
+|`TIME_EXTRACT(timestamp_expr, unit[, timezone])`| Extracts a time part from 
`expr`, returning it as a number. Unit can be EPOCH, MILLISECOND, SECOND, 
MINUTE, HOUR, DAY (day of month), DOW (day of week), DOY (day of year), WEEK 
(week of [week year](https://en.wikipedia.org/wiki/ISO_week_date)), MONTH (1 
through 12), QUARTER (1 through 4), or YEAR. The time zone, if provided, should 
be a time zone name like `America/Los_Angeles` or an offset like `-08:00`. The 
`unit` and `timezone` parame [...]
 |`TIME_PARSE(string_expr[, pattern[, timezone]])`|Parses a string into a 
timestamp using a given [Joda DateTimeFormat 
pattern](http://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html),
 or ISO 8601 (e.g. `2000-01-02T03:04:05Z`) if the pattern is not provided. The 
`timezone` parameter is used as the time zone for strings that do not already 
include a time zone offset. If provided, `timezone` should be a time zone name 
like `America/Los_Angeles` or an offset like `-08 [...]
 |`TIME_FORMAT(timestamp_expr[, pattern[, timezone]])`|Formats a timestamp as a 
string with a given [Joda DateTimeFormat 
pattern](http://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html),
 or ISO 8601 (e.g. `2000-01-02T03:04:05Z`) if the pattern is not provided. If 
provided, the `timezone` parameter should be a time zone name like 
`America/Los_Angeles` or an offset like `-08:00`. The `pattern` and `timezone` 
parameters must be literals.|
 |`TIME_IN_INTERVAL(timestamp_expr, interval)`|Returns whether a timestamp is 
contained within a particular interval. The interval must be a literal string 
containing any ISO 8601 interval, such as `'2001-01-01/P1D'` or 
`'2001-01-01T01:00:00/2001-01-02T01:00:00'`. The start instant of the interval 
is inclusive and the end instant is exclusive.|
 |`MILLIS_TO_TIMESTAMP(millis_expr)`|Converts a number of milliseconds since 
the epoch (1970-01-01 00:00:00 UTC) into a timestamp.|
 |`TIMESTAMP_TO_MILLIS(timestamp_expr)`|Converts a timestamp into a number of 
milliseconds since the epoch.|
-|`EXTRACT(unit FROM timestamp_expr)`|Extracts a time part from `expr`, 
returning it as a number. Unit can be EPOCH, MICROSECOND, MILLISECOND, SECOND, 
MINUTE, HOUR, DAY (day of month), DOW (day of week), ISODOW (ISO day of week), 
DOY (day of year), WEEK (week of year), MONTH, QUARTER, YEAR, ISOYEAR, DECADE, 
CENTURY or MILLENNIUM. Units must be provided unquoted, like `EXTRACT(HOUR FROM 
__time)`.|
+|`EXTRACT(unit FROM timestamp_expr)`| Extracts a time part from `expr`, 
returning it as a number. Unit can be EPOCH, MILLISECOND, SECOND, MINUTE, HOUR, 
DAY (day of month), DOW (day of week), ISODOW (ISO day of week), DOY (day of 
year), WEEK (week of year), MONTH, QUARTER, YEAR, ISOYEAR, DECADE, CENTURY or 
MILLENNIUM. Units must be provided unquoted, like `EXTRACT(HOUR FROM __time)`.  
                                                                                
                          [...]
 |`FLOOR(timestamp_expr TO unit)`|Rounds down a timestamp, returning it as a 
new timestamp. The `unit` parameter must be unquoted and can be SECOND, MINUTE, 
HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR.|
 |`CEIL(timestamp_expr TO unit)`|Rounds up a timestamp, returning it as a new 
timestamp. The `unit` parameter must be unquoted and can be SECOND, MINUTE, 
HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR.|
 |`TIMESTAMPADD(unit, count, timestamp)`|Adds a `count` number of time `unit` 
to timestamp, equivalent to `timestamp + count * unit`. The `unit` parameter 
must be unquoted and can be SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or 
YEAR.|
diff --git 
a/processing/src/main/java/org/apache/druid/query/expression/TimestampExtractExprMacro.java
 
b/processing/src/main/java/org/apache/druid/query/expression/TimestampExtractExprMacro.java
index 07d1d336449..2fac53ec8d5 100644
--- 
a/processing/src/main/java/org/apache/druid/query/expression/TimestampExtractExprMacro.java
+++ 
b/processing/src/main/java/org/apache/druid/query/expression/TimestampExtractExprMacro.java
@@ -40,7 +40,6 @@ public class TimestampExtractExprMacro implements 
ExprMacroTable.ExprMacro
   public enum Unit
   {
     EPOCH,
-    MICROSECOND,
     MILLISECOND,
     SECOND,
     MINUTE,
@@ -71,8 +70,6 @@ public class TimestampExtractExprMacro implements 
ExprMacroTable.ExprMacro
     switch (unit) {
       case EPOCH:
         return ExprEval.of(epoch);
-      case MICROSECOND:
-        return ExprEval.of(epoch / 1000);
       case MILLISECOND:
         return ExprEval.of(dateTime.millisOfSecond().get());
       case SECOND:
diff --git 
a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ExtractOperatorConversion.java
 
b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ExtractOperatorConversion.java
index cf53c941e9f..a3cc038597b 100644
--- 
a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ExtractOperatorConversion.java
+++ 
b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ExtractOperatorConversion.java
@@ -40,7 +40,6 @@ public class ExtractOperatorConversion implements 
SqlOperatorConversion
   private static final Map<TimeUnitRange, TimestampExtractExprMacro.Unit> 
EXTRACT_UNIT_MAP =
       ImmutableMap.<TimeUnitRange, TimestampExtractExprMacro.Unit>builder()
           .put(TimeUnitRange.EPOCH, TimestampExtractExprMacro.Unit.EPOCH)
-          .put(TimeUnitRange.MICROSECOND, 
TimestampExtractExprMacro.Unit.MICROSECOND)
           .put(TimeUnitRange.MILLISECOND, 
TimestampExtractExprMacro.Unit.MILLISECOND)
           .put(TimeUnitRange.SECOND, TimestampExtractExprMacro.Unit.SECOND)
           .put(TimeUnitRange.MINUTE, TimestampExtractExprMacro.Unit.MINUTE)
diff --git 
a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java 
b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java
index 928139fd014..26ee0685a13 100644
--- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java
+++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java
@@ -9361,7 +9361,6 @@ public class CalciteQueryTest extends BaseCalciteQueryTest
     testQuery(
         "SELECT COUNT(*) FROM druid.foo4\n"
         + "WHERE EXTRACT(YEAR FROM __time) = 2000\n"
-        + "AND EXTRACT(MICROSECOND FROM __time) = 946723\n"
         + "AND EXTRACT(MILLISECOND FROM __time) = 695\n"
         + "AND EXTRACT(ISODOW FROM __time) = 6\n"
         + "AND EXTRACT(ISOYEAR FROM __time) = 2000\n"
@@ -9378,31 +9377,25 @@ public class CalciteQueryTest extends 
BaseCalciteQueryTest
                       expressionVirtualColumn("v0", 
"timestamp_extract(\"__time\",'YEAR','UTC')", ColumnType.LONG),
                       expressionVirtualColumn(
                           "v1",
-                          "timestamp_extract(\"__time\",'MICROSECOND','UTC')",
-                          ColumnType.LONG
-                      ),
-                      expressionVirtualColumn(
-                          "v2",
                           "timestamp_extract(\"__time\",'MILLISECOND','UTC')",
                           ColumnType.LONG
                       ),
-                      expressionVirtualColumn("v3", 
"timestamp_extract(\"__time\",'ISODOW','UTC')", ColumnType.LONG),
-                      expressionVirtualColumn("v4", 
"timestamp_extract(\"__time\",'ISOYEAR','UTC')", ColumnType.LONG),
-                      expressionVirtualColumn("v5", 
"timestamp_extract(\"__time\",'DECADE','UTC')", ColumnType.LONG),
-                      expressionVirtualColumn("v6", 
"timestamp_extract(\"__time\",'CENTURY','UTC')", ColumnType.LONG),
-                      expressionVirtualColumn("v7", 
"timestamp_extract(\"__time\",'MILLENNIUM','UTC')", ColumnType.LONG)
+                      expressionVirtualColumn("v2", 
"timestamp_extract(\"__time\",'ISODOW','UTC')", ColumnType.LONG),
+                      expressionVirtualColumn("v3", 
"timestamp_extract(\"__time\",'ISOYEAR','UTC')", ColumnType.LONG),
+                      expressionVirtualColumn("v4", 
"timestamp_extract(\"__time\",'DECADE','UTC')", ColumnType.LONG),
+                      expressionVirtualColumn("v5", 
"timestamp_extract(\"__time\",'CENTURY','UTC')", ColumnType.LONG),
+                      expressionVirtualColumn("v6", 
"timestamp_extract(\"__time\",'MILLENNIUM','UTC')", ColumnType.LONG)
                   )
                   .aggregators(aggregators(new CountAggregatorFactory("a0")))
                   .filters(
                       and(
                           equality("v0", 2000L, ColumnType.LONG),
-                          equality("v1", 946723L, ColumnType.LONG),
-                          equality("v2", 695L, ColumnType.LONG),
-                          equality("v3", 6L, ColumnType.LONG),
-                          equality("v4", 2000L, ColumnType.LONG),
-                          equality("v5", 200L, ColumnType.LONG),
-                          equality("v6", 20L, ColumnType.LONG),
-                          equality("v7", 2L, ColumnType.LONG)
+                          equality("v1", 695L, ColumnType.LONG),
+                          equality("v2", 6L, ColumnType.LONG),
+                          equality("v3", 2000L, ColumnType.LONG),
+                          equality("v4", 200L, ColumnType.LONG),
+                          equality("v5", 20L, ColumnType.LONG),
+                          equality("v6", 2L, ColumnType.LONG)
                       )
                   )
                   .context(QUERY_CONTEXT_DEFAULT)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to