Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Bug fix, using Local.Root when format the string #767

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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);
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down