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

Commit

Permalink
Bug fix, using Local.Root when format the string (#767)
Browse files Browse the repository at this point in the history
* Bug fix, using Local.Root when format the string

* fix format
  • Loading branch information
penghuo authored Oct 8, 2020
1 parent e6e5ad0 commit 50715ad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 50715ad

Please sign in to comment.