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
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
*/
package org.elasticsearch.xpack.sql.jdbc;

import org.elasticsearch.common.logging.LoggerMessageFormat;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.sql.jdbc.EsType;
import org.elasticsearch.xpack.sql.jdbc.JdbcConfiguration;
import org.elasticsearch.xpack.sql.jdbc.JdbcPreparedStatement;

import java.net.URL;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -287,12 +285,12 @@ public void testThrownExceptionsWhenSettingFloatValues() throws SQLException {

Float floatNotInt = 5_155_000_000f;
sqle = expectThrows(SQLException.class, () -> jps.setObject(1, floatNotInt, Types.INTEGER));
assertEquals(String.format(Locale.ROOT, "Numeric %s out of range",
Long.toString(Math.round(floatNotInt.doubleValue()))), sqle.getMessage());
assertEquals(LoggerMessageFormat.format("Numeric {} out of range",
Math.round(floatNotInt.doubleValue())), sqle.getMessage());

sqle = expectThrows(SQLException.class, () -> jps.setObject(1, floatNotInt, Types.SMALLINT));
assertEquals(String.format(Locale.ROOT, "Numeric %s out of range",
Long.toString(Math.round(floatNotInt.doubleValue()))), sqle.getMessage());
assertEquals(LoggerMessageFormat.format("Numeric {} out of range",
Math.round(floatNotInt.doubleValue())), sqle.getMessage());
}

public void testSettingDoubleValues() throws SQLException {
Expand Down Expand Up @@ -328,8 +326,8 @@ public void testThrownExceptionsWhenSettingDoubleValues() throws SQLException {

Double doubleNotInt = 5_155_000_000d;
sqle = expectThrows(SQLException.class, () -> jps.setObject(1, doubleNotInt, Types.INTEGER));
assertEquals(String.format(Locale.ROOT, "Numeric %s out of range",
Long.toString(((Number) doubleNotInt).longValue())), sqle.getMessage());
assertEquals(LoggerMessageFormat.format("Numeric {} out of range",
((Number) doubleNotInt).longValue()), sqle.getMessage());
}

public void testUnsupportedClasses() throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.Node;

import java.util.Locale;
import static org.elasticsearch.common.logging.LoggerMessageFormat.format;

public class AnalysisException extends ClientSqlException {

Expand Down Expand Up @@ -54,6 +54,6 @@ public RestStatus status() {

@Override
public String getMessage() {
return String.format(Locale.ROOT, "line %s:%s: %s", getLineNumber(), getColumnNumber(), super.getMessage());
return format("line {}:{}: {}", getLineNumber(), getColumnNumber(), super.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import org.elasticsearch.xpack.sql.expression.Nullability;
import org.elasticsearch.xpack.sql.expression.gen.processor.Processor;
import org.elasticsearch.xpack.sql.expression.gen.script.ScriptTemplate;
import org.elasticsearch.xpack.sql.tree.Source;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.tree.Source;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.DataTypeConversion;
import org.elasticsearch.xpack.sql.type.DataTypes;

import java.util.Locale;
import java.util.Objects;

import static org.elasticsearch.common.logging.LoggerMessageFormat.format;
import static org.elasticsearch.xpack.sql.expression.gen.script.ParamsBuilder.paramsBuilder;

public class Cast extends UnaryScalarFunction {
Expand Down Expand Up @@ -86,7 +86,7 @@ protected Processor makeProcessor() {
public ScriptTemplate asScript() {
ScriptTemplate fieldAsScript = asScript(field());
return new ScriptTemplate(
formatTemplate(String.format(Locale.ROOT, "{sql}.cast(%s,{})", fieldAsScript.template())),
formatTemplate(format("{sql}.", "cast({},{})", fieldAsScript.template())),
paramsBuilder()
.script(fieldAsScript.params())
.variable(dataType.name())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.sql.expression.gen.script;

import java.util.Locale;
import static org.elasticsearch.common.logging.LoggerMessageFormat.format;

abstract class Param<T> {
private final T value;
Expand All @@ -22,6 +22,6 @@ T value() {

@Override
public String toString() {
return String.format(Locale.ROOT, "{%s=%s}", prefix(), value);
return format(null, "{{}={}}", prefix(), value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
import org.elasticsearch.xpack.sql.expression.function.scalar.ScalarFunction;
import org.elasticsearch.xpack.sql.expression.gen.pipeline.Pipe;
import org.elasticsearch.xpack.sql.expression.gen.script.ScriptTemplate;
import org.elasticsearch.xpack.sql.tree.Source;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.tree.Source;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.util.CollectionUtils;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.StringJoiner;
import java.util.stream.Collectors;

import static org.elasticsearch.common.logging.LoggerMessageFormat.format;
import static org.elasticsearch.xpack.sql.expression.gen.script.ParamsBuilder.paramsBuilder;

public class In extends ScalarFunction {
Expand Down Expand Up @@ -100,7 +100,7 @@ public ScriptTemplate asScript() {
List<Object> values = new ArrayList<>(new LinkedHashSet<>(Foldables.valuesOf(list, value.dataType())));

return new ScriptTemplate(
formatTemplate(String.format(Locale.ROOT, "{sql}.in(%s, {})", leftScript.template())),
formatTemplate(format("{sql}.","in({}, {})", leftScript.template())),
paramsBuilder()
.script(leftScript.params())
.variable(values)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.elasticsearch.xpack.sql.ClientSqlException;
import org.elasticsearch.xpack.sql.tree.Source;

import java.util.Locale;
import static org.elasticsearch.common.logging.LoggerMessageFormat.format;

public class ParsingException extends ClientSqlException {
private final int line;
Expand Down Expand Up @@ -56,6 +56,6 @@ public RestStatus status() {

@Override
public String getMessage() {
return String.format(Locale.ROOT, "line %s:%s: %s", getLineNumber(), getColumnNumber(), getErrorMessage());
return format("line {}:{}: {}", getLineNumber(), getColumnNumber(), getErrorMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.Node;

import java.util.Locale;
import static org.elasticsearch.common.logging.LoggerMessageFormat.format;

public class FoldingException extends ClientSqlException {

Expand Down Expand Up @@ -54,6 +54,6 @@ public RestStatus status() {

@Override
public String getMessage() {
return String.format(Locale.ROOT, "line %s:%s: %s", getLineNumber(), getColumnNumber(), super.getMessage());
return format("line {}:{}: {}", getLineNumber(), getColumnNumber(), super.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;

import static org.elasticsearch.common.logging.LoggerMessageFormat.format;

public class IndexResolverTests extends ESTestCase {

public void testMergeSameMapping() throws Exception {
Expand Down Expand Up @@ -218,14 +219,14 @@ public String[] nonAggregatableIndices() {

@Override
public String toString() {
return String.format(Locale.ROOT, "%s,%s->%s", getName(), getType(), indices);
return format("{},{}->{}", getName(), getType(), indices);
}
}

private static <K, V> void assertEqualsMaps(Map<K, V> left, Map<K, V> right) {
for (Entry<K, V> entry : left.entrySet()) {
V rv = right.get(entry.getKey());
assertEquals(String.format(Locale.ROOT, "Key [%s] has different values", entry.getKey()), entry.getValue(), rv);
assertEquals(format("Key [{}] has different values", entry.getKey()), entry.getValue(), rv);
}
}

Expand All @@ -235,4 +236,4 @@ private void addFieldCaps(Map<String, Map<String, FieldCapabilities>> fieldCaps,
cap.put(name, new FieldCapabilities(name, type, isSearchable, isAggregatable));
fieldCaps.put(name, cap);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;

import static org.elasticsearch.common.logging.LoggerMessageFormat.format;

public class QuotingTests extends ESTestCase {

Expand All @@ -48,7 +48,7 @@ public void testSingleQuoteLiteral() {
public void testMultiSingleQuotedLiteral() {
String first = "bucket";
String second = "head";
Expression exp = new SqlParser().createExpression(String.format(Locale.ROOT, "'%s' '%s'", first, second));
Expression exp = new SqlParser().createExpression(format(null, "'{}' '{}'", first, second));
assertThat(exp, instanceOf(Literal.class));
Literal l = (Literal) exp;
assertThat(l.value(), equalTo(first + second));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
import org.elasticsearch.xpack.sql.proto.SqlTypedParamValue;
import org.elasticsearch.xpack.sql.type.DataType;

import java.util.Locale;

import static java.util.Collections.singletonList;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;

import static org.elasticsearch.common.logging.LoggerMessageFormat.format;

public class LikeEscapingParsingTests extends ESTestCase {

private final SqlParser parser = new SqlParser();

private String error(String pattern) {
ParsingException ex = expectThrows(ParsingException.class,
() -> parser.createExpression(String.format(Locale.ROOT, "exp LIKE %s", pattern)));
() -> parser.createExpression(format(null, "exp LIKE {}", pattern)));

return ex.getMessage();
}
Expand All @@ -35,7 +35,7 @@ private LikePattern like(String pattern) {
if (parameterized) {
exp = parser.createExpression("exp LIKE ?", singletonList(new SqlTypedParamValue(DataType.KEYWORD.esType, pattern)));
} else {
exp = parser.createExpression(String.format(Locale.ROOT, "exp LIKE '%s'", pattern));
exp = parser.createExpression(format(null, "exp LIKE '{}'", pattern));
}
assertThat(exp, instanceOf(Like.class));
Like l = (Like) exp;
Expand Down