diff --git a/common/src/main/java/com/amazon/opendistroforelasticsearch/sql/common/utils/StringUtils.java b/common/src/main/java/com/amazon/opendistroforelasticsearch/sql/common/utils/StringUtils.java index 51a757506e..8b16e819ed 100644 --- a/common/src/main/java/com/amazon/opendistroforelasticsearch/sql/common/utils/StringUtils.java +++ b/common/src/main/java/com/amazon/opendistroforelasticsearch/sql/common/utils/StringUtils.java @@ -16,6 +16,8 @@ package com.amazon.opendistroforelasticsearch.sql.common.utils; import com.google.common.base.Strings; +import java.util.IllegalFormatException; +import java.util.Locale; public class StringUtils { /** @@ -60,6 +62,23 @@ public static String unquoteIdentifier(String identifier) { } } + /** + * Returns a formatted string using the specified format string and + * arguments, as well as the {@link Locale#ROOT} locale. + * + * @param format format string + * @param args arguments referenced by the format specifiers in the format string + * @return A formatted string + * @throws IllegalFormatException If a format string contains an illegal syntax, a format + * specifier that is incompatible with the given arguments, + * insufficient arguments given the format string, or other + * illegal conditions. + * @see java.lang.String#format(Locale, String, Object...) + */ + public static String format(final String format, Object... args) { + return String.format(Locale.ROOT, format, args); + } + private static boolean isQuoted(String text, String mark) { return !Strings.isNullOrEmpty(text) && text.startsWith(mark) && text.endsWith(mark); } diff --git a/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/ppl/DateTimeFunctionIT.java b/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/ppl/DateTimeFunctionIT.java index 626f033bea..a68780300d 100644 --- a/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/ppl/DateTimeFunctionIT.java +++ b/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/ppl/DateTimeFunctionIT.java @@ -21,6 +21,7 @@ import static com.amazon.opendistroforelasticsearch.sql.util.MatcherUtils.verifySchema; import static com.amazon.opendistroforelasticsearch.sql.util.MatcherUtils.verifySome; +import com.amazon.opendistroforelasticsearch.sql.common.utils.StringUtils; import java.io.IOException; import org.json.JSONObject; import org.junit.jupiter.api.Test; @@ -371,7 +372,7 @@ public void testToDays() throws IOException { } private void week(String date, int mode, int expectedResult) throws IOException { - JSONObject result = executeQuery(String.format( + JSONObject result = executeQuery(StringUtils.format( "source=%s | eval f = week(date('%s'), %d) | fields f", TEST_INDEX_DATE, date, mode)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(expectedResult));