Skip to content

Commit

Permalink
[CALCITE-6247] BigQuery FORMAT_DATE function handles incorrectly the …
Browse files Browse the repository at this point in the history
…%e format specifier

Signed-off-by: Mihai Budiu <[email protected]>
  • Loading branch information
mihaibudiu committed Feb 9, 2024
1 parent b64dcff commit df54592
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public enum FormatElementEnum implements FormatElement {
sb.append(work.eeeFormat.format(date));
}
},
E("d", "The day of the month as a decimal number (1-31); "
+ "single digits are left-padded with space.") {
@Override public void format(StringBuilder sb, Date date) {
final Calendar calendar = Work.get().calendar;
calendar.setTime(date);
sb.append(String.format(Locale.ROOT, "%2d", calendar.get(Calendar.DAY_OF_MONTH)));
}
},
FF1("S", "Fractional seconds to 1 digit") {
@Override public void format(StringBuilder sb, Date date) {
final Work work = Work.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static org.apache.calcite.util.format.FormatElementEnum.DD;
import static org.apache.calcite.util.format.FormatElementEnum.DDD;
import static org.apache.calcite.util.format.FormatElementEnum.DY;
import static org.apache.calcite.util.format.FormatElementEnum.E;
import static org.apache.calcite.util.format.FormatElementEnum.FF1;
import static org.apache.calcite.util.format.FormatElementEnum.FF2;
import static org.apache.calcite.util.format.FormatElementEnum.FF3;
Expand Down Expand Up @@ -114,7 +115,7 @@ MI, literalElement(":"), SS, literalElement(" "),
map.put("%E4S", FF4);
map.put("%E5S", FF5);
map.put("%E*S", FF6);
map.put("%e", DD);
map.put("%e", E);
map.put("%F",
compositeElement("The date in the format %Y-%m-%d.", YYYY, literalElement("-"), MM,
literalElement("-"), DD));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12645,6 +12645,11 @@ void testTimestampDiff(boolean coercionEnabled) {
f.checkScalar("FORMAT_DATE('%b %Y', DATE '2008-12-25')",
"Dec 2008",
"VARCHAR(2000) NOT NULL");
// Test case for [CALCITE-6247] https://issues.apache.org/jira/browse/CALCITE-6247
// BigQuery FORMAT_DATE function handles incorrectly the %e format specifier
f.checkScalar("FORMAT_DATE('*%e*', DATE '2008-12-02')",
"* 2*",
"VARCHAR(2000) NOT NULL");
f.checkScalar("FORMAT_DATE('%x', DATE '2008-12-25')",
"12/25/08",
"VARCHAR(2000) NOT NULL");
Expand Down

0 comments on commit df54592

Please sign in to comment.