mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-24 17:09:48 +00:00
SQL: clean unused Exceptions and replace Util functions with core versions (elastic/x-pack-elasticsearch#2654)
This commit removes ThrowableConsumer, WrappingException, ActionUtils and ObjectUtils by replacing them with core equivalents when needed. Original commit: elastic/x-pack-elasticsearch@5a68418a3d
This commit is contained in:
parent
fa410095ce
commit
ed712d0e3f
@ -13,6 +13,7 @@ import org.elasticsearch.action.search.ShardSearchFailure;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.util.CollectionUtils;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.aggregations.Aggregations;
|
||||
import org.elasticsearch.search.aggregations.InternalAggregation;
|
||||
@ -47,7 +48,6 @@ import org.elasticsearch.xpack.sql.session.RowSet;
|
||||
import org.elasticsearch.xpack.sql.session.Rows;
|
||||
import org.elasticsearch.xpack.sql.session.SqlSettings;
|
||||
import org.elasticsearch.xpack.sql.type.Schema;
|
||||
import org.elasticsearch.xpack.sql.util.ObjectUtils;
|
||||
import org.elasticsearch.xpack.sql.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -320,7 +320,7 @@ public class Scroller {
|
||||
public void onResponse(final SearchResponse response) {
|
||||
try {
|
||||
ShardSearchFailure[] failure = response.getShardFailures();
|
||||
if (!ObjectUtils.isEmpty(failure)) {
|
||||
if (!CollectionUtils.isEmpty(failure)) {
|
||||
onFailure(new ExecutionException(failure[0].reason(), failure[0].getCause()));
|
||||
}
|
||||
listener.onResponse(handleResponse(response));
|
||||
|
@ -5,9 +5,9 @@
|
||||
*/
|
||||
package org.elasticsearch.xpack.sql.tree;
|
||||
|
||||
import org.elasticsearch.common.util.CollectionUtils;
|
||||
import org.elasticsearch.xpack.sql.SqlIllegalArgumentException;
|
||||
import org.elasticsearch.xpack.sql.util.Assert;
|
||||
import org.elasticsearch.xpack.sql.util.ObjectUtils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -126,7 +126,7 @@ public abstract class NodeUtils {
|
||||
// perform discovery (and cache it)
|
||||
if (treeNodeInfo == null) {
|
||||
Constructor<?>[] constructors = clazz.getConstructors();
|
||||
Assert.isTrue(!ObjectUtils.isEmpty(constructors), "No public constructors found for class %s", clazz);
|
||||
Assert.isTrue(!CollectionUtils.isEmpty(constructors), "No public constructors found for class %s", clazz);
|
||||
|
||||
// find the longest constructor
|
||||
Constructor<?> ctr = null;
|
||||
|
@ -5,12 +5,12 @@
|
||||
*/
|
||||
package org.elasticsearch.xpack.sql.type;
|
||||
|
||||
import org.elasticsearch.common.util.CollectionUtils;
|
||||
|
||||
import java.sql.JDBCType;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.elasticsearch.xpack.sql.util.ObjectUtils;
|
||||
|
||||
public class DateType extends AbstractDataType {
|
||||
|
||||
public static final List<String> DEFAULT_FORMAT = Arrays.asList("strict_date_optional_time", "epoch_millis");
|
||||
@ -32,7 +32,7 @@ public class DateType extends AbstractDataType {
|
||||
* and return TIMESTAMP so we more closely conform with H2 and
|
||||
* (shudder) Oracle. */
|
||||
super(JDBCType.TIMESTAMP, docValues);
|
||||
this.formats = ObjectUtils.isEmpty(formats) ? DEFAULT_FORMAT : Arrays.asList(formats);
|
||||
this.formats = CollectionUtils.isEmpty(formats) ? DEFAULT_FORMAT : Arrays.asList(formats);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,11 +6,11 @@
|
||||
package org.elasticsearch.xpack.sql.type;
|
||||
|
||||
import java.sql.JDBCType;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
|
||||
import static org.elasticsearch.xpack.sql.util.ObjectUtils.mapCollector;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
public abstract class StringType implements DataType {
|
||||
|
||||
@ -24,11 +24,16 @@ public abstract class StringType implements DataType {
|
||||
|
||||
if (docValue || fields.isEmpty()) {
|
||||
docValueFields = emptyMap();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
docValueFields = fields.entrySet().stream()
|
||||
.filter(e -> e.getValue().hasDocValues())
|
||||
.collect(mapCollector());
|
||||
.collect(toMap(
|
||||
Map.Entry::getKey,
|
||||
Map.Entry::getValue,
|
||||
(k1, k2) -> {
|
||||
throw new IllegalStateException("Duplicate key " + k1);
|
||||
},
|
||||
LinkedHashMap::new));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.xpack.sql.util;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
|
||||
public abstract class ActionUtils {
|
||||
|
||||
public static <Input, Output> ActionListener<Input> chain(ActionListener<Output> outputListener, Function<Input, Output> action) {
|
||||
return ActionListener.wrap(i -> outputListener.onResponse(action.apply(i)), outputListener::onFailure);
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@ public abstract class CollectionUtils {
|
||||
@SafeVarargs
|
||||
@SuppressWarnings("varargs")
|
||||
public static <T> List<T> combine(Collection<? extends T>... collections) {
|
||||
if (ObjectUtils.isEmpty(collections)) {
|
||||
if (org.elasticsearch.common.util.CollectionUtils.isEmpty(collections)) {
|
||||
return emptyList();
|
||||
}
|
||||
|
||||
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.xpack.sql.util;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collector;
|
||||
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
public abstract class ObjectUtils {
|
||||
|
||||
private static final Consumer<Object> NO_OP_CONSUMER = whatever -> {};
|
||||
private static final Runnable NO_OP_RUNNER = () -> {};
|
||||
|
||||
public static <T> boolean isEmpty(Object[] array) {
|
||||
return (array == null || array.length == 0);
|
||||
}
|
||||
|
||||
public static <T> Predicate<T> not(Predicate<T> predicate) {
|
||||
return predicate.negate();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Consumer<T> noOpConsumer() {
|
||||
return (Consumer<T>) NO_OP_CONSUMER;
|
||||
}
|
||||
|
||||
public static Runnable noOpRunnable() {
|
||||
return NO_OP_RUNNER;
|
||||
}
|
||||
|
||||
public static <K, V> Collector<Entry<K, V>, ?, LinkedHashMap<K, V>> mapCollector() {
|
||||
return toMap(
|
||||
Entry::getKey,
|
||||
Entry::getValue,
|
||||
(k1,k2) -> { throw new IllegalStateException("Duplicate key"); },
|
||||
LinkedHashMap::new);
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.xpack.sql.util;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface ThrowableConsumer<T> extends Consumer<T> { // NOCOMMIT replace with CheckedConsumer
|
||||
|
||||
@Override
|
||||
default void accept(T t) {
|
||||
try {
|
||||
acceptThrows(t);
|
||||
} catch (Exception ex) {
|
||||
throw new WrappingException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
void acceptThrows(T t) throws Exception;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.xpack.sql.util;
|
||||
|
||||
public class WrappingException extends RuntimeException {
|
||||
// NOCOMMIT probably not needed after replacing "ThrowableXXXX"
|
||||
|
||||
public WrappingException(String message, Exception cause) {
|
||||
super(message, cause, false, false);
|
||||
}
|
||||
|
||||
public WrappingException(Exception cause) {
|
||||
super(cause.getMessage(), cause, false, false);
|
||||
}
|
||||
|
||||
public Exception wrapped() {
|
||||
return (Exception) getCause();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user