Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions sqlglot/dialects/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,12 @@ def _build_levenshtein(args: t.List) -> exp.Levenshtein:

def _build_format_time(expr_type: t.Type[exp.Expression]) -> t.Callable[[t.List], exp.TimeToStr]:
def _builder(args: t.List) -> exp.TimeToStr:
return exp.TimeToStr(
this=expr_type(this=seq_get(args, 1)),
format=seq_get(args, 0),
zone=seq_get(args, 2),
# "bigquery")(expr_type(... -> "bigquery")([expr_type(...])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this comment

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this comment

done

formatted_time = build_formatted_time(exp.TimeToStr, "bigquery")(
[expr_type(this=seq_get(args, 1)), seq_get(args, 0)]
)
formatted_time.set("zone", seq_get(args, 2))
return formatted_time

return _builder

Expand Down Expand Up @@ -369,6 +370,7 @@ class BigQuery(Dialect):

# https://cloud.google.com/bigquery/docs/reference/standard-sql/format-elements#format_elements_date_time
TIME_MAPPING = {
"%x": "%m/%d/%y",
"%D": "%m/%d/%y",
"%E6S": "%S.%f",
"%e": "%-d",
Expand Down
1 change: 1 addition & 0 deletions sqlglot/dialects/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ class DuckDB(Dialect):
**Dialect.DATE_PART_MAPPING,
"DAYOFWEEKISO": "ISODOW",
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this new line

DATE_PART_MAPPING.pop("WEEKDAY")

def to_json_path(self, path: t.Optional[exp.Expression]) -> t.Optional[exp.Expression]:
Expand Down
4 changes: 2 additions & 2 deletions tests/dialects/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2897,8 +2897,8 @@ def test_format_temporal(self):
self.validate_all(
"SELECT FORMAT_DATETIME('%x', '2023-12-25 15:30:00')",
write={
"bigquery": "SELECT FORMAT_DATETIME('%x', '2023-12-25 15:30:00')",
"duckdb": "SELECT STRFTIME(CAST('2023-12-25 15:30:00' AS TIMESTAMP), '%x')",
"bigquery": "SELECT FORMAT_DATETIME('%D', '2023-12-25 15:30:00')",
"duckdb": "SELECT STRFTIME(CAST('2023-12-25 15:30:00' AS TIMESTAMP), '%m/%d/%y')",
},
)
self.validate_all(
Expand Down