SQL: Minor fixes
Original commit: elastic/x-pack-elasticsearch@14ea747e20
This commit is contained in:
parent
817c4759c6
commit
b5dd4c649a
|
@ -136,6 +136,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.elasticsearch.test.SecurityTestsUtils.assertAuthenticationException;
|
||||
import static org.elasticsearch.test.SecurityTestsUtils.assertThrowsAuthorizationException;
|
||||
import static org.elasticsearch.test.SecurityTestsUtils.assertThrowsAuthorizationExceptionRunAs;
|
||||
|
@ -341,11 +342,10 @@ public class AuthorizationServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testUnknownRoleCausesDenial() {
|
||||
@SuppressWarnings("unchecked")
|
||||
Tuple<String, TransportRequest> tuple = randomFrom(
|
||||
Tuple<String, TransportRequest> tuple = randomFrom(asList(
|
||||
new Tuple<>(SearchAction.NAME, new SearchRequest()),
|
||||
new Tuple<>(IndicesExistsAction.NAME, new IndicesExistsRequest()),
|
||||
new Tuple<>(SqlQueryAction.NAME, new SqlQueryRequest()));
|
||||
new Tuple<>(SqlQueryAction.NAME, new SqlQueryRequest())));
|
||||
String action = tuple.v1();
|
||||
TransportRequest request = tuple.v2();
|
||||
User user = new User("test user", "non-existent-role");
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.sql.jdbc.debug;
|
||||
|
||||
// Debug marker interface for compatible proxy.
|
||||
/**
|
||||
* Debug marker interface for compatible proxy.
|
||||
*/
|
||||
interface DebugProxy {
|
||||
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@ package org.elasticsearch.xpack.sql.jdbc.jdbc;
|
|||
|
||||
import org.elasticsearch.xpack.sql.client.shared.ConnectionConfiguration;
|
||||
import org.elasticsearch.xpack.sql.client.shared.StringUtils;
|
||||
import org.elasticsearch.xpack.sql.jdbc.JdbcSQLException;
|
||||
import org.elasticsearch.xpack.sql.client.shared.Version;
|
||||
import org.elasticsearch.xpack.sql.jdbc.JdbcSQLException;
|
||||
|
||||
import java.net.URI;
|
||||
import java.sql.DriverPropertyInfo;
|
||||
|
@ -25,16 +25,15 @@ import java.util.concurrent.TimeUnit;
|
|||
import static org.elasticsearch.xpack.sql.client.shared.UriUtils.parseURI;
|
||||
import static org.elasticsearch.xpack.sql.client.shared.UriUtils.removeQuery;
|
||||
|
||||
//
|
||||
// Supports the following syntax
|
||||
//
|
||||
// jdbc:es://[host|ip]
|
||||
// jdbc:es://[host|ip]:port/(prefix)
|
||||
// jdbc:es://[host|ip]:port/(prefix)(?options=value&)
|
||||
//
|
||||
// Additional properties can be specified either through the Properties object or in the URL. In case of duplicates, the URL wins.
|
||||
//
|
||||
|
||||
/**
|
||||
/ Supports the following syntax
|
||||
/
|
||||
/ jdbc:es://[host|ip]
|
||||
/ jdbc:es://[host|ip]:port/(prefix)
|
||||
/ jdbc:es://[host|ip]:port/(prefix)(?options=value&)
|
||||
/
|
||||
/ Additional properties can be specified either through the Properties object or in the URL. In case of duplicates, the URL wins.
|
||||
*/
|
||||
//TODO: beef this up for Security/SSL
|
||||
public class JdbcConfiguration extends ConnectionConfiguration {
|
||||
static final String URL_PREFIX = "jdbc:es://";
|
||||
|
|
|
@ -332,14 +332,12 @@ public class JdbcConnection implements Connection, JdbcWrapper {
|
|||
@Override
|
||||
public void setClientInfo(String name, String value) throws SQLClientInfoException {
|
||||
checkOpenClientInfo();
|
||||
// no-op
|
||||
throw new SQLClientInfoException("Unsupported operation", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientInfo(Properties properties) throws SQLClientInfoException {
|
||||
checkOpenClientInfo();
|
||||
// no-op
|
||||
throw new SQLClientInfoException("Unsupported operation", null);
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,8 @@ class JdbcDatabaseMetaData implements DatabaseMetaData, JdbcWrapper {
|
|||
|
||||
@Override
|
||||
public boolean nullsAreSortedAtEnd() throws SQLException {
|
||||
return false;
|
||||
// missing/null values are sorted (by default) last
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,9 +11,10 @@ import org.elasticsearch.xpack.sql.expression.FieldAttribute;
|
|||
import org.elasticsearch.xpack.sql.tree.Location;
|
||||
import org.elasticsearch.xpack.sql.tree.NodeInfo;
|
||||
import org.elasticsearch.xpack.sql.type.EsField;
|
||||
import org.elasticsearch.xpack.sql.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -91,8 +92,36 @@ public class EsRelation extends LeafPlan {
|
|||
return Objects.equals(index, other.index);
|
||||
}
|
||||
|
||||
private static final int TO_STRING_LIMIT = 52;
|
||||
|
||||
private static <E> String limitedToString(Collection<E> c) {
|
||||
Iterator<E> it = c.iterator();
|
||||
if (!it.hasNext()) {
|
||||
return "[]";
|
||||
}
|
||||
|
||||
// ..]
|
||||
StringBuilder sb = new StringBuilder(TO_STRING_LIMIT + 4);
|
||||
sb.append('[');
|
||||
for (;;) {
|
||||
E e = it.next();
|
||||
String next = e == c ? "(this Collection)" : String.valueOf(e);
|
||||
if (next.length() + sb.length() > TO_STRING_LIMIT) {
|
||||
sb.append(next.substring(0, Math.max(0, TO_STRING_LIMIT - sb.length())));
|
||||
sb.append('.').append('.').append(']');
|
||||
return sb.toString();
|
||||
} else {
|
||||
sb.append(next);
|
||||
}
|
||||
if (!it.hasNext()) {
|
||||
return sb.append(']').toString();
|
||||
}
|
||||
sb.append(',').append(' ');
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nodeString() {
|
||||
return nodeName() + "[" + index + "]" + StringUtils.limitedToString(attrs);
|
||||
return nodeName() + "[" + index + "]" + limitedToString(attrs);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,8 +17,6 @@ import org.elasticsearch.xpack.sql.SqlIllegalArgumentException;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -29,40 +27,6 @@ public abstract class StringUtils {
|
|||
public static final String EMPTY = "";
|
||||
public static final String NEW_LINE = "\n";
|
||||
|
||||
private static final int TO_STRING_LIMIT = 52;
|
||||
|
||||
public static String limitedToString(Object o) {
|
||||
String s = String.valueOf(o);
|
||||
return s.length() > TO_STRING_LIMIT ? s.substring(0, TO_STRING_LIMIT).concat("...") : s;
|
||||
}
|
||||
|
||||
public static <E> String limitedToString(Collection<E> c) {
|
||||
Iterator<E> it = c.iterator();
|
||||
if (!it.hasNext()) {
|
||||
return "[]";
|
||||
}
|
||||
|
||||
// ..]
|
||||
StringBuilder sb = new StringBuilder(TO_STRING_LIMIT + 4);
|
||||
sb.append('[');
|
||||
for (;;) {
|
||||
E e = it.next();
|
||||
String next = e == c ? "(this Collection)" : String.valueOf(e);
|
||||
if (next.length() + sb.length() > TO_STRING_LIMIT) {
|
||||
sb.append(next.substring(0, Math.max(0, TO_STRING_LIMIT - sb.length())));
|
||||
sb.append('.').append('.').append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
else {
|
||||
sb.append(next);
|
||||
}
|
||||
if (!it.hasNext()) {
|
||||
return sb.append(']').toString();
|
||||
}
|
||||
sb.append(',').append(' ');
|
||||
}
|
||||
}
|
||||
|
||||
//CamelCase to camel_case
|
||||
public static String camelCaseToUnderscore(String string) {
|
||||
if (!Strings.hasText(string)) {
|
||||
|
|
Loading…
Reference in New Issue