More polishing
Original commit: elastic/x-pack-elasticsearch@043edf250b
This commit is contained in:
parent
405b4a4166
commit
83d73c9b3a
|
@ -8,11 +8,8 @@ package org.elasticsearch.xpack.sql.jdbc.framework;
|
|||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.time.Instant;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcUtils.nameOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -73,23 +70,13 @@ public class JdbcAssert {
|
|||
String msg = "Different result for column [" + metaData.getColumnName(column) + "], entry [" + count + "]";
|
||||
|
||||
if (type == Types.TIMESTAMP) {
|
||||
/*
|
||||
* Life is just too confusing with timestamps and default
|
||||
* time zones and default locales. Instead we compare the
|
||||
* string representations of the dates converted into UTC
|
||||
* in the ROOT locale. This gives us error messages in UTC
|
||||
* on failure which is *way* easier to reason about.
|
||||
*
|
||||
* Life is confusing because H2 always uses the default
|
||||
* locale and time zone for date functions.
|
||||
*/
|
||||
msg += " locale is [" + Locale.getDefault() + "] and time zone is [" + TimeZone.getDefault() + "]";
|
||||
expectedObject = TestUtils.UTC_FORMATTER.format(Instant.ofEpochMilli(((Timestamp) expectedObject).getTime()));
|
||||
actualObject = TestUtils.UTC_FORMATTER.format(Instant.ofEpochMilli(((Timestamp) actualObject).getTime()));
|
||||
expectedObject = getTime(expected, column);
|
||||
actualObject = getTime(actual, column);
|
||||
assertEquals(expectedObject, actualObject);
|
||||
// NOCOMMIT look at ResultSet.getTimestamp(int, Calendar)
|
||||
}
|
||||
|
||||
if (type == Types.DOUBLE) {
|
||||
else if (type == Types.DOUBLE) {
|
||||
// NOCOMMIT 1d/1f seems like a huge difference.
|
||||
assertEquals(msg, (double) expectedObject, (double) actualObject, 1d);
|
||||
} else if (type == Types.FLOAT) {
|
||||
|
@ -101,4 +88,8 @@ public class JdbcAssert {
|
|||
}
|
||||
assertEquals("[" + actual + "] still has data after [" + count + "] entries", expected.next(), actual.next());
|
||||
}
|
||||
|
||||
private static Object getTime(ResultSet rs, int column) throws SQLException {
|
||||
return TestUtils.UTC_FORMATTER.format(Instant.ofEpochMilli(rs.getTime(column).getTime()));
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ import org.elasticsearch.xpack.sql.test.server.ProtoHttpServer;
|
|||
public class JdbcHttpServer extends ProtoHttpServer<Response> {
|
||||
|
||||
public JdbcHttpServer(Client client) {
|
||||
super(client, new SqlProtoHandler(client), "/jdbc/", "sql/");
|
||||
super(client, new SqlProtoHandler(client), "/_jdbc");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -40,6 +40,7 @@ public abstract class SpecBaseIntegrationTestCase extends ESTestCase {
|
|||
// @BeforeClass
|
||||
// public static void start() throws Exception {
|
||||
// TestUtils.loadDatasetInEs(TestUtils.restClient("localhost", 9200));
|
||||
// System.out.println("Loaded dataset in ES");
|
||||
// }
|
||||
|
||||
public SpecBaseIntegrationTestCase(String groupName, String testName, Integer lineNumber, Path source) {
|
||||
|
|
|
@ -76,7 +76,8 @@ public abstract class TestUtils {
|
|||
}
|
||||
createIndex.endObject();
|
||||
createIndex.startObject("mappings"); {
|
||||
createIndex.startObject("emp"); {
|
||||
createIndex.startObject("emp");
|
||||
{
|
||||
createIndex.startObject("properties"); {
|
||||
createIndex.startObject("emp_no").field("type", "integer").endObject();
|
||||
createIndex.startObject("birth_date").field("type", "date").endObject();
|
||||
|
@ -116,7 +117,7 @@ public abstract class TestUtils {
|
|||
*/
|
||||
public static void loadDatesetInH2(Connection h2) throws Exception {
|
||||
csvToLines("employees", (titles, fields) -> {
|
||||
StringBuilder insert = new StringBuilder("INSERT INTO \"emp.emp\" (");
|
||||
StringBuilder insert = new StringBuilder("INSERT INTO \"test_emp.emp\" (");
|
||||
for (int t = 0; t < titles.size(); t++) {
|
||||
if (t != 0) {
|
||||
insert.append(',');
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.sql.jdbc.h2;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.annotations.Name;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
|
||||
|
||||
import org.elasticsearch.xpack.sql.jdbc.framework.LocalH2;
|
||||
|
@ -53,7 +52,7 @@ public class SqlSpecIntegrationTest extends SpecBaseIntegrationTestCase {
|
|||
return H2.get();
|
||||
}
|
||||
|
||||
public SqlSpecIntegrationTest(String groupName, @Name("testName") String testName, Integer lineNumber, Path source, String query) {
|
||||
public SqlSpecIntegrationTest(String groupName, String testName, Integer lineNumber, Path source, String query) {
|
||||
super(groupName, testName, lineNumber, source);
|
||||
this.query = query;
|
||||
}
|
||||
|
@ -73,7 +72,8 @@ public class SqlSpecIntegrationTest extends SpecBaseIntegrationTestCase {
|
|||
throw reworkException(new AssertionError(errorMessage(ae), ae.getCause()));
|
||||
}
|
||||
} catch (Throwable th) {
|
||||
throw reworkException(new RuntimeException(errorMessage(th)));
|
||||
//throw reworkException(new RuntimeException(errorMessage(th)));
|
||||
throw th;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -257,7 +257,7 @@ abstract class QueryTranslator {
|
|||
// dates are handled differently because of date histograms
|
||||
if (exp instanceof DateTimeFunction) {
|
||||
DateTimeFunction dtf = (DateTimeFunction) exp;
|
||||
agg = new GroupByDateAgg(aggId, AggPath.bucketValue(propertyPath), nameOf(exp), dtf.interval());
|
||||
agg = new GroupByDateAgg(aggId, AggPath.bucketValue(propertyPath), nameOf(exp), dtf.interval(), dtf.timeZone());
|
||||
}
|
||||
else {
|
||||
agg = new GroupByColumnAgg(aggId, AggPath.bucketValue(propertyPath), ne.name());
|
||||
|
|
|
@ -43,6 +43,12 @@ public abstract class ProtoHandler<R> implements HttpHandler, AutoCloseable {
|
|||
public void handle(HttpExchange http) throws IOException {
|
||||
log.debug("Received query call...");
|
||||
|
||||
if ("HEAD".equals(http.getRequestMethod())) {
|
||||
http.sendResponseHeaders(RestStatus.OK.getStatus(), 0);
|
||||
http.close();
|
||||
return;
|
||||
}
|
||||
|
||||
try (DataInputStream in = new DataInputStream(http.getRequestBody())) {
|
||||
String msg = headerReader.apply(in);
|
||||
if (msg != null) {
|
||||
|
|
|
@ -17,21 +17,19 @@ import java.util.concurrent.Executors;
|
|||
public abstract class ProtoHttpServer<R> {
|
||||
|
||||
private final ProtoHandler<R> handler;
|
||||
private final String defaultPrefix, protoPrefix;
|
||||
private final String protoSuffix;
|
||||
private final Client client;
|
||||
private HttpServer server;
|
||||
|
||||
public ProtoHttpServer(Client client, ProtoHandler<R> handler, String defaultPrefix, String protoPrefix) {
|
||||
public ProtoHttpServer(Client client, ProtoHandler<R> handler, String protoSuffix) {
|
||||
this.client = client;
|
||||
this.handler = handler;
|
||||
this.defaultPrefix = defaultPrefix;
|
||||
this.protoPrefix = protoPrefix;
|
||||
this.protoSuffix = protoSuffix;
|
||||
}
|
||||
|
||||
public void start(int port) throws IOException {
|
||||
server = HttpServer.create(new InetSocketAddress(InetAddress.getLoopbackAddress(), port), 0);
|
||||
server.createContext(defaultPrefix, new RootHttpHandler());
|
||||
server.createContext(defaultPrefix + protoPrefix, handler);
|
||||
server.createContext(protoSuffix, handler);
|
||||
server.setExecutor(Executors.newCachedThreadPool());
|
||||
server.start();
|
||||
}
|
||||
|
@ -46,7 +44,7 @@ public abstract class ProtoHttpServer<R> {
|
|||
}
|
||||
|
||||
public String url() {
|
||||
return server != null ? "localhost:" + address().getPort() + defaultPrefix + protoPrefix : "<not started>";
|
||||
return server != null ? "localhost:" + address().getPort() + protoSuffix : "<not started>";
|
||||
}
|
||||
|
||||
public Client client() {
|
||||
|
|
|
@ -1,25 +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.test.server;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.common.logging.ESLoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
class RootHttpHandler implements HttpHandler {
|
||||
private static final Logger logger = ESLoggerFactory.getLogger(RootHttpHandler.class);
|
||||
|
||||
@Override
|
||||
public void handle(HttpExchange t) throws IOException {
|
||||
logger.debug("Received ping call...");
|
||||
t.sendResponseHeaders(200, -1);
|
||||
t.close();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue