From f57b6469e1bfb2f0d71404d4da6d02c3789ead20 Mon Sep 17 00:00:00 2001 From: Yvonne Pan <103622026+yvonnep165@users.noreply.github.com> Date: Thu, 19 Mar 2026 23:41:59 -0400 Subject: [PATCH 1/2] Add timestamp expressions --- .../pipeline/expressions/Expression.java | 571 +++++++++++++++++- .../cloud/firestore/it/ITPipelineTest.java | 150 ++++- 2 files changed, 702 insertions(+), 19 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java index 695051c20..fb5434fd2 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java @@ -3239,7 +3239,7 @@ public static Expression timestampTruncate(String fieldName, Expression granular * @return A new {@link Expression} representing the truncated timestamp. */ @BetaApi - public static Expression timestampTruncate( + public static Expression timestampTruncateWithTimezone( Expression timestamp, String granularity, String timezone) { return new FunctionExpression( "timestamp_trunc", ImmutableList.of(timestamp, constant(granularity), constant(timezone))); @@ -3259,7 +3259,7 @@ public static Expression timestampTruncate( * @return A new {@link Expression} representing the truncated timestamp. */ @BetaApi - public static Expression timestampTruncate( + public static Expression timestampTruncateWithTimezone( Expression timestamp, Expression granularity, String timezone) { return new FunctionExpression( "timestamp_trunc", ImmutableList.of(timestamp, granularity, constant(timezone))); @@ -3279,9 +3279,9 @@ public static Expression timestampTruncate( * @return A new {@link Expression} representing the truncated timestamp. */ @BetaApi - public static Expression timestampTruncate( + public static Expression timestampTruncateWithTimezone( String fieldName, String granularity, String timezone) { - return timestampTruncate(field(fieldName), constant(granularity), timezone); + return timestampTruncateWithTimezone(field(fieldName), constant(granularity), timezone); } /** @@ -3298,9 +3298,360 @@ public static Expression timestampTruncate( * @return A new {@link Expression} representing the truncated timestamp. */ @BetaApi - public static Expression timestampTruncate( + public static Expression timestampTruncateWithTimezone( String fieldName, Expression granularity, String timezone) { - return timestampTruncate(field(fieldName), granularity, timezone); + return timestampTruncateWithTimezone(field(fieldName), granularity, timezone); + } + + /** + * Creates an expression that truncates a timestamp to a specified granularity in a given + * timezone. + * + * @param timestamp The timestamp expression. + * @param granularity The granularity expression to truncate to. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "day", "week", "week(monday)", "week(tuesday)", + * "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", + * "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone expression to use for truncation. Valid values are from the TZ + * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". + * @return A new {@link Expression} representing the truncated timestamp. + */ + @BetaApi + public static Expression timestampTruncateWithTimezone( + Expression timestamp, Expression granularity, Expression timezone) { + return new FunctionExpression( + "timestamp_trunc", ImmutableList.of(timestamp, granularity, timezone)); + } + + /** + * Creates an expression that truncates a timestamp to a specified granularity in a given + * timezone. + * + * @param timestamp The timestamp expression. + * @param granularity The granularity to truncate to. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "day", "week", "week(monday)", "week(tuesday)", + * "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", + * "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone expression to use for truncation. Valid values are from the TZ + * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". + * @return A new {@link Expression} representing the truncated timestamp. + */ + @BetaApi + public static Expression timestampTruncateWithTimezone( + Expression timestamp, String granularity, Expression timezone) { + return timestampTruncateWithTimezone(timestamp, constant(granularity), timezone); + } + + /** + * Creates an expression that truncates a timestamp to a specified granularity in a given + * timezone. + * + * @param fieldName The name of the field containing the timestamp. + * @param granularity The granularity to truncate to. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "day", "week", "week(monday)", "week(tuesday)", + * "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", + * "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone expression to use for truncation. Valid values are from the TZ + * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". + * @return A new {@link Expression} representing the truncated timestamp. + */ + @BetaApi + public static Expression timestampTruncateWithTimezone( + String fieldName, String granularity, Expression timezone) { + return timestampTruncateWithTimezone(field(fieldName), constant(granularity), timezone); + } + + /** + * Creates an expression that truncates a timestamp to a specified granularity in a given + * timezone. + * + * @param fieldName The name of the field containing the timestamp. + * @param granularity The granularity expression to truncate to. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "day", "week", "week(monday)", "week(tuesday)", + * "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", + * "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone expression to use for truncation. Valid values are from the TZ + * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". + * @return A new {@link Expression} representing the truncated timestamp. + */ + @BetaApi + public static Expression timestampTruncateWithTimezone( + String fieldName, Expression granularity, Expression timezone) { + return timestampTruncateWithTimezone(field(fieldName), granularity, timezone); + } + + /** + * Creates an expression that calculates the difference between two timestamps. + * + * @param end The ending timestamp expression. + * @param start The starting timestamp expression. + * @param unit The unit of time for the difference. Valid values include "microsecond", + * "millisecond", "second", "minute", "hour" and "day". + * @return A new {@link Expression} representing the difference. + */ + @BetaApi + public static Expression timestampDiff(Expression end, Expression start, Expression unit) { + return new FunctionExpression("timestamp_diff", ImmutableList.of(end, start, unit)); + } + + /** + * Creates an expression that calculates the difference between two timestamps. + * + * @param end The ending timestamp expression. + * @param start The starting timestamp expression. + * @param unit The unit of time for the difference. Valid values include "microsecond", + * "millisecond", "second", "minute", "hour" and "day". + * @return A new {@link Expression} representing the difference. + */ + @BetaApi + public static Expression timestampDiff(Expression end, Expression start, String unit) { + return timestampDiff(end, start, constant(unit)); + } + + /** + * Creates an expression that calculates the difference between two timestamps. + * + * @param endFieldName The ending timestamp field name. + * @param startFieldName The starting timestamp field name. + * @param unit The unit of time for the difference. Valid values include "microsecond", + * "millisecond", "second", "minute", "hour" and "day". + * @return A new {@link Expression} representing the difference. + */ + @BetaApi + public static Expression timestampDiff(String endFieldName, String startFieldName, String unit) { + return timestampDiff(field(endFieldName), field(startFieldName), constant(unit)); + } + + /** + * Creates an expression that calculates the difference between two timestamps. + * + * @param endFieldName The ending timestamp field name. + * @param start The starting timestamp expression. + * @param unit The unit of time for the difference. Valid values include "microsecond", + * "millisecond", "second", "minute", "hour" and "day". + * @return A new {@link Expression} representing the difference. + */ + @BetaApi + public static Expression timestampDiff(String endFieldName, Expression start, String unit) { + return timestampDiff(field(endFieldName), start, constant(unit)); + } + + /** + * Creates an expression that calculates the difference between two timestamps. + * + * @param end The ending timestamp expression. + * @param startFieldName The starting timestamp field name. + * @param unit The unit of time for the difference. Valid values include "microsecond", + * "millisecond", "second", "minute", "hour" and "day". + * @return A new {@link Expression} representing the difference. + */ + @BetaApi + public static Expression timestampDiff(Expression end, String startFieldName, String unit) { + return timestampDiff(end, field(startFieldName), constant(unit)); + } + + /** + * Creates an expression that extracts a specified part from a timestamp. + * + * @param timestamp The timestamp expression. + * @param part The part to extract from the timestamp. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", + * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", + * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @return A new {@link Expression} representing the extracted part. + */ + @BetaApi + public static Expression timestampExtract(Expression timestamp, Expression part) { + return new FunctionExpression("timestamp_extract", ImmutableList.of(timestamp, part)); + } + + /** + * Creates an expression that extracts a specified part from a timestamp. + * + * @param timestamp The timestamp expression. + * @param part The part to extract from the timestamp. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", + * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", + * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @return A new {@link Expression} representing the extracted part. + */ + @BetaApi + public static Expression timestampExtract(Expression timestamp, String part) { + return timestampExtract(timestamp, constant(part)); + } + + /** + * Creates an expression that extracts a specified part from a timestamp. + * + * @param fieldName The name of the field containing the timestamp. + * @param part The part to extract from the timestamp. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", + * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", + * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @return A new {@link Expression} representing the extracted part. + */ + @BetaApi + public static Expression timestampExtract(String fieldName, Expression part) { + return timestampExtract(field(fieldName), part); + } + + /** + * Creates an expression that extracts a specified part from a timestamp. + * + * @param fieldName The name of the field containing the timestamp. + * @param part The part to extract from the timestamp. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", + * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", + * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @return A new {@link Expression} representing the extracted part. + */ + @BetaApi + public static Expression timestampExtract(String fieldName, String part) { + return timestampExtract(field(fieldName), constant(part)); + } + + /** + * Creates an expression that extracts a specified part from a timestamp in a given timezone. + * + * @param timestamp The timestamp expression. + * @param part The part to extract from the timestamp. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", + * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", + * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone expression to use for extraction.Valid values are from the TZ + * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" + * if not specified. + * @return A new {@link Expression} representing the extracted part. + */ + @BetaApi + public static Expression timestampExtractWithTimezone(Expression timestamp, Expression part, Expression timezone) { + return new FunctionExpression("timestamp_extract", ImmutableList.of(timestamp, part, timezone)); + } + + /** + * Creates an expression that extracts a specified part from a timestamp in a given timezone. + * + * @param timestamp The timestamp expression. + * @param part The part to extract from the timestamp. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", + * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", + * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone to use for extraction.Valid values are from the TZ database + * (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if not + * specified. + * @return A new {@link Expression} representing the extracted part. + */ + @BetaApi + public static Expression timestampExtractWithTimezone(Expression timestamp, Expression part, String timezone) { + return timestampExtractWithTimezone(timestamp, part, constant(timezone)); + } + + /** + * Creates an expression that extracts a specified part from a timestamp in a given timezone. + * + * @param timestamp The timestamp expression. + * @param part The part to extract from the timestamp. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", + * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", + * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone to use for extraction.Valid values are from the TZ database + * (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if not + * specified. + * @return A new {@link Expression} representing the extracted part. + */ + @BetaApi + public static Expression timestampExtractWithTimezone(Expression timestamp, String part, String timezone) { + return timestampExtractWithTimezone(timestamp, constant(part), constant(timezone)); + } + + /** + * Creates an expression that extracts a specified part from a timestamp in a given timezone. + * + * @param fieldName The name of the field containing the timestamp. + * @param part The part to extract from the timestamp. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", + * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", + * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone to use for extraction.Valid values are from the TZ database + * (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if not + * specified. + * @return A new {@link Expression} representing the extracted part. + */ + @BetaApi + public static Expression timestampExtractWithTimezone(String fieldName, Expression part, String timezone) { + return timestampExtractWithTimezone(field(fieldName), part, constant(timezone)); + } + + /** + * Creates an expression that extracts a specified part from a timestamp in a given timezone. + * + * @param fieldName The name of the field containing the timestamp. + * @param part The part to extract from the timestamp. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", + * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", + * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone to use for extraction.Valid values are from the TZ database + * (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if not + * specified. + * @return A new {@link Expression} representing the extracted part. + */ + @BetaApi + public static Expression timestampExtractWithTimezone(String fieldName, String part, String timezone) { + return timestampExtractWithTimezone(field(fieldName), constant(part), constant(timezone)); + } + + /** + * Creates an expression that extracts a specified part from a timestamp in a given timezone. + * + * @param timestamp The timestamp expression. + * @param part The part to extract from the timestamp. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", + * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", + * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone expression to use for extraction.Valid values are from the TZ + * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" + * if not specified. + * @return A new {@link Expression} representing the extracted part. + */ + @BetaApi + public static Expression timestampExtractWithTimezone(Expression timestamp, String part, Expression timezone) { + return timestampExtractWithTimezone(timestamp, constant(part), timezone); + } + + /** + * Creates an expression that extracts a specified part from a timestamp in a given timezone. + * + * @param fieldName The name of the field containing the timestamp. + * @param part The part to extract from the timestamp. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", + * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", + * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone expression to use for extraction.Valid values are from the TZ + * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" + * if not specified. + * @return A new {@link Expression} representing the extracted part. + */ + @BetaApi + public static Expression timestampExtractWithTimezone(String fieldName, Expression part, Expression timezone) { + return timestampExtractWithTimezone(field(fieldName), part, timezone); + } + + /** + * Creates an expression that extracts a specified part from a timestamp in a given timezone. + * + * @param fieldName The name of the field containing the timestamp. + * @param part The part to extract from the timestamp. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", + * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", + * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone expression to use for extraction.Valid values are from the TZ + * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" + * if not specified. + * @return A new {@link Expression} representing the extracted part. + */ + @BetaApi + public static Expression timestampExtractWithTimezone(String fieldName, String part, Expression timezone) { + return timestampExtractWithTimezone(field(fieldName), constant(part), timezone); } // Conditional Functions @@ -5553,6 +5904,214 @@ public final Expression timestampTruncate(Expression granularity) { return timestampTruncate(this, granularity); } + /** + * Creates an expression that truncates this timestamp expression to a specified granularity in a + * given timezone. + * + * @param granularity The granularity to truncate to. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "day", "week", "week(monday)", "week(tuesday)", + * "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", + * "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone to use for truncation. Valid values are from the TZ database + * (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if not + * specified. + * @return A new {@link Expression} representing the truncated timestamp. + */ + @BetaApi + public final Expression timestampTruncateWithTimezone(String granularity, String timezone) { + return timestampTruncateWithTimezone(this, granularity, timezone); + } + + /** + * Creates an expression that truncates this timestamp expression to a specified granularity in a + * given timezone. + * + * @param granularity The granularity expression to truncate to. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "day", "week", "week(monday)", "week(tuesday)", + * "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", + * "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone to use for truncation. Valid values are from the TZ database + * (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". + * @return A new {@link Expression} representing the truncated timestamp. + */ + @BetaApi + public final Expression timestampTruncateWithTimezone(Expression granularity, String timezone) { + return timestampTruncateWithTimezone(this, granularity, timezone); + } + + /** + * Creates an expression that truncates this timestamp expression to a specified granularity in a + * given timezone. + * + * @param granularity The granularity to truncate to. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "day", "week", "week(monday)", "week(tuesday)", + * "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", + * "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone expression to use for truncation. Valid values are from the TZ + * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". + * @return A new {@link Expression} representing the truncated timestamp. + */ + @BetaApi + public final Expression timestampTruncateWithTimezone(String granularity, Expression timezone) { + return timestampTruncateWithTimezone(this, granularity, timezone); + } + + /** + * Creates an expression that truncates this timestamp expression to a specified granularity in a + * given timezone. + * + * @param granularity The granularity expression to truncate to. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "day", "week", "week(monday)", "week(tuesday)", + * "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", + * "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone expression to use for truncation. Valid values are from the TZ + * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". + * @return A new {@link Expression} representing the truncated timestamp. + */ + @BetaApi + public final Expression timestampTruncateWithTimezone(Expression granularity, Expression timezone) { + return timestampTruncateWithTimezone(this, granularity, timezone); + } + + /** + * Calculates the difference between this timestamp and another timestamp. + * + * @param start The starting timestamp expression. + * @param unit The unit of time for the difference. Valid values include "microsecond", + * "millisecond", "second", "minute", "hour" and "day". + * @return A new {@link Expression} representing the difference. + */ + @BetaApi + public final Expression timestampDiff(Expression start, Expression unit) { + return timestampDiff(this, start, unit); + } + + /** + * Calculates the difference between this timestamp and another timestamp. + * + * @param start The starting timestamp expression. + * @param unit The unit of time for the difference. Valid values include "microsecond", + * "millisecond", "second", "minute", "hour" and "day". + * @return A new {@link Expression} representing the difference. + */ + @BetaApi + public final Expression timestampDiff(Expression start, String unit) { + return timestampDiff(this, start, unit); + } + + /** + * Calculates the difference between this timestamp and another timestamp. + * + * @param startFieldName The name of the field containing the starting timestamp. + * @param unit The unit of time for the difference. Valid values include "microsecond", + * "millisecond", "second", "minute", "hour" and "day". + * @return A new {@link Expression} representing the difference. + */ + @BetaApi + public final Expression timestampDiff(String startFieldName, String unit) { + return timestampDiff(this, startFieldName, unit); + } + + /** + * Creates an expression that extracts a specified part from this timestamp expression. + * + * @param part The part to extract. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", + * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", + * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @return A new {@link Expression} representing the extracted part. + */ + @BetaApi + public final Expression timestampExtract(Expression part) { + return timestampExtract(this, part); + } + + /** + * Creates an expression that extracts a specified part from this timestamp expression. + * + * @param part The part to extract. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", + * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", + * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @return A new {@link Expression} representing the extracted part. + */ + @BetaApi + public final Expression timestampExtract(String part) { + return timestampExtract(this, part); + } + + /** + * Creates an expression that extracts a specified part from this timestamp expression in + * a given timezone. + * + * @param part The part to extract. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", + * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", + * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone to use for extraction. Valid values are from the TZ database + * (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if not + * specified. + * @return A new {@link Expression} representing the extracted part. + */ + @BetaApi + public final Expression timestampExtractWithTimezone(Expression part, String timezone) { + return timestampExtractWithTimezone(this, part, timezone); + } + + /** + * Creates an expression that extracts a specified part from this timestamp expression in + * a given timezone. + * + * @param part The part to extract. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", + * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", + * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone to use for extraction. Valid values are from the TZ database + * (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if not + * specified. + * @return A new {@link Expression} representing the extracted part. + */ + @BetaApi + public final Expression timestampExtractWithTimezone(String part, String timezone) { + return timestampExtractWithTimezone(this, part, timezone); + } + + /** + * Creates an expression that extracts a specified part from this timestamp expression in + * a given timezone. + * + * @param part The part to extract. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", + * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", + * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone expression to use for extraction. Valid values are from the TZ + * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if + * not specified. + * @return A new {@link Expression} representing the extracted part. + */ + @BetaApi + public final Expression timestampExtractWithTimezone(Expression part, Expression timezone) { + return timestampExtractWithTimezone(this, part, timezone); + } + + /** + * Creates an expression that extracts a specified part from this timestamp expression in + * a given timezone. + * + * @param part The part to extract. Valid values are "microsecond", + * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", + * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", + * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @param timezone The timezone expression to use for extraction. Valid values are from the TZ + * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if + * not specified. + * @return A new {@link Expression} representing the extracted part. + */ + @BetaApi + public final Expression timestampExtractWithTimezone(String part, Expression timezone) { + return timestampExtractWithTimezone(this, part, timezone); + } + /** * Creates an expression that checks if this expression evaluates to a name of the field that * exists. diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index e14fa8a94..ba3ca9268 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -80,6 +80,11 @@ import static com.google.cloud.firestore.pipeline.expressions.Expression.substring; import static com.google.cloud.firestore.pipeline.expressions.Expression.subtract; import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampAdd; +import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampTruncate; +import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampTruncateWithTimezone; +import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampDiff; +import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampExtract; +import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampExtractWithTimezone; import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampToUnixMicros; import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampToUnixMillis; import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampToUnixSeconds; @@ -2192,28 +2197,27 @@ public void testTimestampTrunc() throws Exception { .collection(collection.getPath()) .where(equal("title", "Timestamp Book")) .select( - Expression.timestampTruncate(field("timestamp"), "year").as("trunc_year"), - Expression.timestampTruncate(field("timestamp"), "month").as("trunc_month"), - Expression.timestampTruncate(field("timestamp"), "day").as("trunc_day"), - Expression.timestampTruncate(field("timestamp"), "hour").as("trunc_hour"), - Expression.timestampTruncate(field("timestamp"), "minute").as("trunc_minute"), - Expression.timestampTruncate(field("timestamp"), "second").as("trunc_second")) + timestampTruncate(field("timestamp"), "year").as("standalone_str"), + field("timestamp").timestampTruncate("month").as("fluid_str"), + timestampTruncate(field("timestamp"), constant("day")).as("standalone_expr"), + field("timestamp").timestampTruncate(constant("hour")).as("fluid_expr")) .execute() .get() .getResults(); + assertThat(results).hasSize(1); Map data = results.get(0).getData(); Date originalDate = (Date) bookDocs.get("book11").get("timestamp"); java.util.Calendar cal = java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone("UTC")); - cal.setTime(originalDate); + cal.setTime(originalDate); cal.set(java.util.Calendar.MONTH, java.util.Calendar.JANUARY); cal.set(java.util.Calendar.DAY_OF_MONTH, 1); cal.set(java.util.Calendar.HOUR_OF_DAY, 0); cal.set(java.util.Calendar.MINUTE, 0); cal.set(java.util.Calendar.SECOND, 0); cal.set(java.util.Calendar.MILLISECOND, 0); - assertThat(data.get("trunc_year")).isEqualTo(Timestamp.of(cal.getTime())); + assertThat(data.get("standalone_str")).isEqualTo(Timestamp.of(cal.getTime())); cal.setTime(originalDate); cal.set(java.util.Calendar.DAY_OF_MONTH, 1); @@ -2221,29 +2225,149 @@ public void testTimestampTrunc() throws Exception { cal.set(java.util.Calendar.MINUTE, 0); cal.set(java.util.Calendar.SECOND, 0); cal.set(java.util.Calendar.MILLISECOND, 0); - assertThat(data.get("trunc_month")).isEqualTo(Timestamp.of(cal.getTime())); + assertThat(data.get("fluid_str")).isEqualTo(Timestamp.of(cal.getTime())); cal.setTime(originalDate); cal.set(java.util.Calendar.HOUR_OF_DAY, 0); cal.set(java.util.Calendar.MINUTE, 0); cal.set(java.util.Calendar.SECOND, 0); cal.set(java.util.Calendar.MILLISECOND, 0); - assertThat(data.get("trunc_day")).isEqualTo(Timestamp.of(cal.getTime())); + assertThat(data.get("standalone_expr")).isEqualTo(Timestamp.of(cal.getTime())); cal.setTime(originalDate); cal.set(java.util.Calendar.MINUTE, 0); cal.set(java.util.Calendar.SECOND, 0); cal.set(java.util.Calendar.MILLISECOND, 0); - assertThat(data.get("trunc_hour")).isEqualTo(Timestamp.of(cal.getTime())); + assertThat(data.get("fluid_expr")).isEqualTo(Timestamp.of(cal.getTime())); + } + + @Test + public void testTimestampTruncWithTimezone() throws Exception { + List results = + firestore + .pipeline() + .collection(collection.getPath()) + .where(equal("title", "Timestamp Book")) + .select( + timestampTruncateWithTimezone(field("timestamp"), "year", "America/Los_Angeles").as("st_str_str"), + field("timestamp").timestampTruncateWithTimezone("month", "America/Los_Angeles").as("fl_str_str"), + timestampTruncateWithTimezone(field("timestamp"), constant("day"), constant("America/Los_Angeles")).as("st_expr_expr"), + field("timestamp").timestampTruncateWithTimezone(constant("hour"), constant("America/Los_Angeles")).as("fl_expr_expr")) + .execute() + .get() + .getResults(); + + assertThat(results).hasSize(1); + Map data = results.get(0).getData(); + Date originalDate = (Date) bookDocs.get("book11").get("timestamp"); + java.util.Calendar cal = java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone("America/Los_Angeles")); cal.setTime(originalDate); + cal.set(java.util.Calendar.MONTH, java.util.Calendar.JANUARY); + cal.set(java.util.Calendar.DAY_OF_MONTH, 1); + cal.set(java.util.Calendar.HOUR_OF_DAY, 0); + cal.set(java.util.Calendar.MINUTE, 0); cal.set(java.util.Calendar.SECOND, 0); cal.set(java.util.Calendar.MILLISECOND, 0); - assertThat(data.get("trunc_minute")).isEqualTo(Timestamp.of(cal.getTime())); + assertThat(data.get("st_str_str")).isEqualTo(Timestamp.of(cal.getTime())); cal.setTime(originalDate); + cal.set(java.util.Calendar.DAY_OF_MONTH, 1); + cal.set(java.util.Calendar.HOUR_OF_DAY, 0); + cal.set(java.util.Calendar.MINUTE, 0); + cal.set(java.util.Calendar.SECOND, 0); cal.set(java.util.Calendar.MILLISECOND, 0); - assertThat(data.get("trunc_second")).isEqualTo(Timestamp.of(cal.getTime())); + assertThat(data.get("fl_str_str")).isEqualTo(Timestamp.of(cal.getTime())); + } + + @Test + public void testTimestampDiff() throws Exception { + List results = + firestore + .pipeline() + .createFrom(collection) + .limit(1) + .replaceWith( + Expression.map( + ImmutableMap.of( + "end", Timestamp.ofTimeSecondsAndNanos(1741437296, 123456789), + "start", Timestamp.ofTimeSecondsAndNanos(1741428000, 0)))) + .select( + timestampDiff("end", "start", "hour").as("diff_hour"), + field("end").timestampDiff(field("start"), "minute").as("diff_minute"), + timestampDiff(field("end"), "start", "second").as("diff_second"), + field("start").timestampDiff("end", "hour").as("diff_hour_neg")) + .execute() + .get() + .getResults(); + + Map data = data(results).get(0); + assertThat(data.get("diff_hour")).isEqualTo(2L); + assertThat(data.get("diff_minute")).isEqualTo(154L); + assertThat(data.get("diff_second")).isEqualTo(9296L); + assertThat(data.get("diff_hour_neg")).isEqualTo(-2L); + } + + @Test + public void testTimestampExtract() throws Exception { + List results = + firestore + .pipeline() + .createFrom(collection) + .limit(1) + .replaceWith( + Expression.map( + ImmutableMap.of("ts", Timestamp.ofTimeSecondsAndNanos(1741437296, 123456789)))) + .select( + timestampExtract("ts", "year").as("year"), + field("ts").timestampExtract("month").as("month"), + timestampExtract(field("ts"), constant("day")).as("day"), + field("ts").timestampExtract(constant("hour")).as("hour"), + timestampExtract("ts", constant("minute")).as("minute"), + field("ts").timestampExtract("second").as("second"), + timestampExtract(field("ts"), "millisecond").as("millis"), + field("ts").timestampExtract("microsecond").as("micros"), + timestampExtract(field("ts"), "dayofyear").as("day_of_year")) + .execute() + .get() + .getResults(); + + Map data = data(results).get(0); + assertThat(data.get("year")).isEqualTo(2025L); + assertThat(data.get("month")).isEqualTo(3L); + assertThat(data.get("day")).isEqualTo(8L); + assertThat(data.get("hour")).isEqualTo(12L); + assertThat(data.get("minute")).isEqualTo(34L); + assertThat(data.get("second")).isEqualTo(56L); + assertThat(data.get("millis")).isEqualTo(123L); + assertThat(data.get("micros")).isEqualTo(123456L); + assertThat(data.get("day_of_year")).isEqualTo(67L); + } + + @Test + public void testTimestampExtractWithTimezone() throws Exception { + List results = + firestore + .pipeline() + .createFrom(collection) + .limit(1) + .replaceWith( + Expression.map( + ImmutableMap.of("ts", Timestamp.ofTimeSecondsAndNanos(1741437296, 123456789)))) + .select( + timestampExtractWithTimezone("ts", "hour", "America/Los_Angeles").as("st_str_str"), + field("ts").timestampExtractWithTimezone("hour", "America/Los_Angeles").as("fl_str_str"), + timestampExtractWithTimezone(field("ts"), constant("hour"), constant("America/Los_Angeles")).as("st_expr_expr"), + field("ts").timestampExtractWithTimezone(constant("hour"), constant("America/Los_Angeles")).as("fl_expr_expr")) + .execute() + .get() + .getResults(); + + Map data = data(results).get(0); + assertThat(data.get("st_str_str")).isEqualTo(4L); + assertThat(data.get("fl_str_str")).isEqualTo(4L); + assertThat(data.get("st_expr_expr")).isEqualTo(4L); + assertThat(data.get("fl_expr_expr")).isEqualTo(4L); } @Test From 398f432275b3c9a1216545353053193f1a32c150 Mon Sep 17 00:00:00 2001 From: cloud-java-bot Date: Fri, 20 Mar 2026 14:37:05 +0000 Subject: [PATCH 2/2] chore: generate libraries at Fri Mar 20 14:34:46 UTC 2026 --- .../pipeline/expressions/Expression.java | 127 +++++++++--------- .../cloud/firestore/it/ITPipelineTest.java | 35 +++-- 2 files changed, 91 insertions(+), 71 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java index fb5434fd2..ef7dff6a1 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java @@ -3519,12 +3519,13 @@ public static Expression timestampExtract(String fieldName, String part) { * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". * @param timezone The timezone expression to use for extraction.Valid values are from the TZ - * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" - * if not specified. + * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if + * not specified. * @return A new {@link Expression} representing the extracted part. */ @BetaApi - public static Expression timestampExtractWithTimezone(Expression timestamp, Expression part, Expression timezone) { + public static Expression timestampExtractWithTimezone( + Expression timestamp, Expression part, Expression timezone) { return new FunctionExpression("timestamp_extract", ImmutableList.of(timestamp, part, timezone)); } @@ -3536,13 +3537,13 @@ public static Expression timestampExtractWithTimezone(Expression timestamp, Expr * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". - * @param timezone The timezone to use for extraction.Valid values are from the TZ database - * (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if not - * specified. + * @param timezone The timezone to use for extraction.Valid values are from the TZ database (e.g., + * "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if not specified. * @return A new {@link Expression} representing the extracted part. */ @BetaApi - public static Expression timestampExtractWithTimezone(Expression timestamp, Expression part, String timezone) { + public static Expression timestampExtractWithTimezone( + Expression timestamp, Expression part, String timezone) { return timestampExtractWithTimezone(timestamp, part, constant(timezone)); } @@ -3554,13 +3555,13 @@ public static Expression timestampExtractWithTimezone(Expression timestamp, Expr * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". - * @param timezone The timezone to use for extraction.Valid values are from the TZ database - * (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if not - * specified. + * @param timezone The timezone to use for extraction.Valid values are from the TZ database (e.g., + * "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if not specified. * @return A new {@link Expression} representing the extracted part. */ @BetaApi - public static Expression timestampExtractWithTimezone(Expression timestamp, String part, String timezone) { + public static Expression timestampExtractWithTimezone( + Expression timestamp, String part, String timezone) { return timestampExtractWithTimezone(timestamp, constant(part), constant(timezone)); } @@ -3572,13 +3573,13 @@ public static Expression timestampExtractWithTimezone(Expression timestamp, Stri * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". - * @param timezone The timezone to use for extraction.Valid values are from the TZ database - * (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if not - * specified. + * @param timezone The timezone to use for extraction.Valid values are from the TZ database (e.g., + * "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if not specified. * @return A new {@link Expression} representing the extracted part. */ @BetaApi - public static Expression timestampExtractWithTimezone(String fieldName, Expression part, String timezone) { + public static Expression timestampExtractWithTimezone( + String fieldName, Expression part, String timezone) { return timestampExtractWithTimezone(field(fieldName), part, constant(timezone)); } @@ -3590,13 +3591,13 @@ public static Expression timestampExtractWithTimezone(String fieldName, Expressi * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". - * @param timezone The timezone to use for extraction.Valid values are from the TZ database - * (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if not - * specified. + * @param timezone The timezone to use for extraction.Valid values are from the TZ database (e.g., + * "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if not specified. * @return A new {@link Expression} representing the extracted part. */ @BetaApi - public static Expression timestampExtractWithTimezone(String fieldName, String part, String timezone) { + public static Expression timestampExtractWithTimezone( + String fieldName, String part, String timezone) { return timestampExtractWithTimezone(field(fieldName), constant(part), constant(timezone)); } @@ -3609,12 +3610,13 @@ public static Expression timestampExtractWithTimezone(String fieldName, String p * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". * @param timezone The timezone expression to use for extraction.Valid values are from the TZ - * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" - * if not specified. + * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if + * not specified. * @return A new {@link Expression} representing the extracted part. */ @BetaApi - public static Expression timestampExtractWithTimezone(Expression timestamp, String part, Expression timezone) { + public static Expression timestampExtractWithTimezone( + Expression timestamp, String part, Expression timezone) { return timestampExtractWithTimezone(timestamp, constant(part), timezone); } @@ -3627,12 +3629,13 @@ public static Expression timestampExtractWithTimezone(Expression timestamp, Stri * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". * @param timezone The timezone expression to use for extraction.Valid values are from the TZ - * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" - * if not specified. + * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if + * not specified. * @return A new {@link Expression} representing the extracted part. */ @BetaApi - public static Expression timestampExtractWithTimezone(String fieldName, Expression part, Expression timezone) { + public static Expression timestampExtractWithTimezone( + String fieldName, Expression part, Expression timezone) { return timestampExtractWithTimezone(field(fieldName), part, timezone); } @@ -3645,12 +3648,13 @@ public static Expression timestampExtractWithTimezone(String fieldName, Expressi * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". * @param timezone The timezone expression to use for extraction.Valid values are from the TZ - * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" - * if not specified. + * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if + * not specified. * @return A new {@link Expression} representing the extracted part. */ @BetaApi - public static Expression timestampExtractWithTimezone(String fieldName, String part, Expression timezone) { + public static Expression timestampExtractWithTimezone( + String fieldName, String part, Expression timezone) { return timestampExtractWithTimezone(field(fieldName), constant(part), timezone); } @@ -5969,7 +5973,8 @@ public final Expression timestampTruncateWithTimezone(String granularity, Expres * @return A new {@link Expression} representing the truncated timestamp. */ @BetaApi - public final Expression timestampTruncateWithTimezone(Expression granularity, Expression timezone) { + public final Expression timestampTruncateWithTimezone( + Expression granularity, Expression timezone) { return timestampTruncateWithTimezone(this, granularity, timezone); } @@ -6015,10 +6020,10 @@ public final Expression timestampDiff(String startFieldName, String unit) { /** * Creates an expression that extracts a specified part from this timestamp expression. * - * @param part The part to extract. Valid values are "microsecond", - * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", - * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", - * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @param part The part to extract. Valid values are "microsecond", "millisecond", "second", + * "minute", "hour", "dayofweek", "day", "dayofyear", "week", "week(monday)", "week(tuesday)", + * "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", + * "isoweek", "month", "quarter", "year", and "isoyear". * @return A new {@link Expression} representing the extracted part. */ @BetaApi @@ -6029,10 +6034,10 @@ public final Expression timestampExtract(Expression part) { /** * Creates an expression that extracts a specified part from this timestamp expression. * - * @param part The part to extract. Valid values are "microsecond", - * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", - * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", - * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @param part The part to extract. Valid values are "microsecond", "millisecond", "second", + * "minute", "hour", "dayofweek", "day", "dayofyear", "week", "week(monday)", "week(tuesday)", + * "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", + * "isoweek", "month", "quarter", "year", and "isoyear". * @return A new {@link Expression} representing the extracted part. */ @BetaApi @@ -6041,13 +6046,13 @@ public final Expression timestampExtract(String part) { } /** - * Creates an expression that extracts a specified part from this timestamp expression in - * a given timezone. + * Creates an expression that extracts a specified part from this timestamp expression in a given + * timezone. * - * @param part The part to extract. Valid values are "microsecond", - * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", - * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", - * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @param part The part to extract. Valid values are "microsecond", "millisecond", "second", + * "minute", "hour", "dayofweek", "day", "dayofyear", "week", "week(monday)", "week(tuesday)", + * "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", + * "isoweek", "month", "quarter", "year", and "isoyear". * @param timezone The timezone to use for extraction. Valid values are from the TZ database * (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if not * specified. @@ -6059,13 +6064,13 @@ public final Expression timestampExtractWithTimezone(Expression part, String tim } /** - * Creates an expression that extracts a specified part from this timestamp expression in - * a given timezone. + * Creates an expression that extracts a specified part from this timestamp expression in a given + * timezone. * - * @param part The part to extract. Valid values are "microsecond", - * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", - * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", - * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @param part The part to extract. Valid values are "microsecond", "millisecond", "second", + * "minute", "hour", "dayofweek", "day", "dayofyear", "week", "week(monday)", "week(tuesday)", + * "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", + * "isoweek", "month", "quarter", "year", and "isoyear". * @param timezone The timezone to use for extraction. Valid values are from the TZ database * (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if not * specified. @@ -6077,13 +6082,13 @@ public final Expression timestampExtractWithTimezone(String part, String timezon } /** - * Creates an expression that extracts a specified part from this timestamp expression in - * a given timezone. + * Creates an expression that extracts a specified part from this timestamp expression in a given + * timezone. * - * @param part The part to extract. Valid values are "microsecond", - * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", - * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", - * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @param part The part to extract. Valid values are "microsecond", "millisecond", "second", + * "minute", "hour", "dayofweek", "day", "dayofyear", "week", "week(monday)", "week(tuesday)", + * "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", + * "isoweek", "month", "quarter", "year", and "isoyear". * @param timezone The timezone expression to use for extraction. Valid values are from the TZ * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if * not specified. @@ -6095,13 +6100,13 @@ public final Expression timestampExtractWithTimezone(Expression part, Expression } /** - * Creates an expression that extracts a specified part from this timestamp expression in - * a given timezone. + * Creates an expression that extracts a specified part from this timestamp expression in a given + * timezone. * - * @param part The part to extract. Valid values are "microsecond", - * "millisecond", "second", "minute", "hour", "dayofweek", "day", "dayofyear", "week", - * "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", - * "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear". + * @param part The part to extract. Valid values are "microsecond", "millisecond", "second", + * "minute", "hour", "dayofweek", "day", "dayofyear", "week", "week(monday)", "week(tuesday)", + * "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", + * "isoweek", "month", "quarter", "year", and "isoyear". * @param timezone The timezone expression to use for extraction. Valid values are from the TZ * database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1". Defaults to "UTC" if * not specified. diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index ba3ca9268..6a552e460 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -80,14 +80,14 @@ import static com.google.cloud.firestore.pipeline.expressions.Expression.substring; import static com.google.cloud.firestore.pipeline.expressions.Expression.subtract; import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampAdd; -import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampTruncate; -import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampTruncateWithTimezone; import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampDiff; import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampExtract; import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampExtractWithTimezone; import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampToUnixMicros; import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampToUnixMillis; import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampToUnixSeconds; +import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampTruncate; +import static com.google.cloud.firestore.pipeline.expressions.Expression.timestampTruncateWithTimezone; import static com.google.cloud.firestore.pipeline.expressions.Expression.trunc; import static com.google.cloud.firestore.pipeline.expressions.Expression.truncToPrecision; import static com.google.cloud.firestore.pipeline.expressions.Expression.unixMicrosToTimestamp; @@ -2249,10 +2249,18 @@ public void testTimestampTruncWithTimezone() throws Exception { .collection(collection.getPath()) .where(equal("title", "Timestamp Book")) .select( - timestampTruncateWithTimezone(field("timestamp"), "year", "America/Los_Angeles").as("st_str_str"), - field("timestamp").timestampTruncateWithTimezone("month", "America/Los_Angeles").as("fl_str_str"), - timestampTruncateWithTimezone(field("timestamp"), constant("day"), constant("America/Los_Angeles")).as("st_expr_expr"), - field("timestamp").timestampTruncateWithTimezone(constant("hour"), constant("America/Los_Angeles")).as("fl_expr_expr")) + timestampTruncateWithTimezone(field("timestamp"), "year", "America/Los_Angeles") + .as("st_str_str"), + field("timestamp") + .timestampTruncateWithTimezone("month", "America/Los_Angeles") + .as("fl_str_str"), + timestampTruncateWithTimezone( + field("timestamp"), constant("day"), constant("America/Los_Angeles")) + .as("st_expr_expr"), + field("timestamp") + .timestampTruncateWithTimezone( + constant("hour"), constant("America/Los_Angeles")) + .as("fl_expr_expr")) .execute() .get() .getResults(); @@ -2260,7 +2268,8 @@ public void testTimestampTruncWithTimezone() throws Exception { assertThat(results).hasSize(1); Map data = results.get(0).getData(); Date originalDate = (Date) bookDocs.get("book11").get("timestamp"); - java.util.Calendar cal = java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone("America/Los_Angeles")); + java.util.Calendar cal = + java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone("America/Los_Angeles")); cal.setTime(originalDate); cal.set(java.util.Calendar.MONTH, java.util.Calendar.JANUARY); @@ -2356,9 +2365,15 @@ public void testTimestampExtractWithTimezone() throws Exception { ImmutableMap.of("ts", Timestamp.ofTimeSecondsAndNanos(1741437296, 123456789)))) .select( timestampExtractWithTimezone("ts", "hour", "America/Los_Angeles").as("st_str_str"), - field("ts").timestampExtractWithTimezone("hour", "America/Los_Angeles").as("fl_str_str"), - timestampExtractWithTimezone(field("ts"), constant("hour"), constant("America/Los_Angeles")).as("st_expr_expr"), - field("ts").timestampExtractWithTimezone(constant("hour"), constant("America/Los_Angeles")).as("fl_expr_expr")) + field("ts") + .timestampExtractWithTimezone("hour", "America/Los_Angeles") + .as("fl_str_str"), + timestampExtractWithTimezone( + field("ts"), constant("hour"), constant("America/Los_Angeles")) + .as("st_expr_expr"), + field("ts") + .timestampExtractWithTimezone(constant("hour"), constant("America/Los_Angeles")) + .as("fl_expr_expr")) .execute() .get() .getResults();