Closer to compiling
Original commit: elastic/x-pack-elasticsearch@630bd7967d
This commit is contained in:
parent
b00105f608
commit
593e6572c1
|
@ -86,6 +86,7 @@ dependencies {
|
|||
// sql deps
|
||||
compile project(':x-pack-elasticsearch:sql-clients:jdbc-proto')
|
||||
compile project(':x-pack-elasticsearch:sql-clients:cli-proto')
|
||||
compile 'org.antlr:antlr4-runtime:4.5.1-1'
|
||||
|
||||
// common test deps
|
||||
testCompile 'org.elasticsearch:securemock:1.2'
|
||||
|
|
|
@ -84,4 +84,9 @@ public class HttpCliAction extends BaseRestHandler {
|
|||
}
|
||||
channel.sendResponse(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "sql_cli_action";
|
||||
}
|
||||
}
|
|
@ -85,4 +85,9 @@ public class HttpJdbcAction extends BaseRestHandler {
|
|||
}
|
||||
channel.sendResponse(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "sql_jdbc_action";
|
||||
}
|
||||
}
|
|
@ -58,26 +58,32 @@ public class RestSqlAction extends BaseRestHandler {
|
|||
}
|
||||
channel.sendResponse(response);
|
||||
}
|
||||
}
|
||||
|
||||
class Payload {
|
||||
static final ObjectParser<Payload, Void> PARSER = new ObjectParser<>("sql/query");
|
||||
|
||||
static {
|
||||
PARSER.declareString(Payload::setQuery, new ParseField("query"));
|
||||
@Override
|
||||
public String getName() {
|
||||
return "sql_action";
|
||||
}
|
||||
|
||||
String query;
|
||||
static class Payload {
|
||||
static final ObjectParser<Payload, Void> PARSER = new ObjectParser<>("sql/query");
|
||||
|
||||
static Payload from(RestRequest request) throws IOException {
|
||||
Payload payload = new Payload();
|
||||
try (XContentParser parser = request.contentParser()) {
|
||||
Payload.PARSER.parse(parser, payload, null);
|
||||
static {
|
||||
PARSER.declareString(Payload::setQuery, new ParseField("query"));
|
||||
}
|
||||
|
||||
return payload;
|
||||
String query;
|
||||
|
||||
static Payload from(RestRequest request) throws IOException {
|
||||
Payload payload = new Payload();
|
||||
try (XContentParser parser = request.contentParser()) {
|
||||
Payload.PARSER.parse(parser, payload, null);
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
public void setQuery(String query) {
|
||||
this.query = query;
|
||||
}
|
||||
}
|
||||
public void setQuery(String query) {
|
||||
this.query = query;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
apply plugin: 'elasticsearch.build'
|
||||
|
||||
apply plugin: 'application'
|
||||
|
||||
project.compactProfile = 'full'
|
||||
|
||||
dependencies {
|
||||
compile "org.jline:jline:3.3.0"
|
||||
|
||||
|
@ -9,6 +10,7 @@ dependencies {
|
|||
compile project(':x-pack-elasticsearch:sql-clients:cli-proto')
|
||||
|
||||
testCompile project(":x-pack-elasticsearch:transport-client")
|
||||
testCompile project(':x-pack-elasticsearch:sql-clients:test-utils')
|
||||
}
|
||||
|
||||
// TODO seems like we should use the jars....
|
||||
|
|
|
@ -5,15 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.sql.cli;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.elasticsearch.xpack.sql.cli.net.client.HttpCliClient;
|
||||
import org.elasticsearch.xpack.sql.cli.net.protocol.CommandResponse;
|
||||
import org.elasticsearch.xpack.sql.cli.net.protocol.InfoResponse;
|
||||
|
@ -27,6 +18,15 @@ import org.jline.terminal.Terminal;
|
|||
import org.jline.terminal.TerminalBuilder;
|
||||
import org.jline.utils.InfoCmp.Capability;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
public class Cli {
|
||||
|
|
|
@ -23,7 +23,7 @@ class Keys {
|
|||
|
||||
final KeyMap<Key> keys = new KeyMap<>();
|
||||
|
||||
public Keys(Terminal terminal) {
|
||||
Keys(Terminal terminal) {
|
||||
keys.setNomatch(Key.NONE);
|
||||
keys.setAmbiguousTimeout(400);
|
||||
keys.bind(Key.UP, key(terminal, Capability.key_up));
|
||||
|
|
|
@ -24,6 +24,10 @@ import org.elasticsearch.xpack.sql.cli.net.protocol.Proto.Action;
|
|||
import org.elasticsearch.xpack.sql.net.client.util.Bytes;
|
||||
|
||||
public class HttpCliClient implements AutoCloseable {
|
||||
@FunctionalInterface
|
||||
interface DataInputFunction<R> {
|
||||
R apply(DataInput in) throws IOException;
|
||||
}
|
||||
|
||||
private final HttpClient http;
|
||||
private final CliConfiguration cfg;
|
||||
|
@ -88,9 +92,4 @@ public class HttpCliClient implements AutoCloseable {
|
|||
}
|
||||
|
||||
public void close() {}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface DataInputFunction<R> {
|
||||
R apply(DataInput in) throws IOException;
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
package org.elasticsearch.xpack.sql.cli.integration.server;
|
||||
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.xpack.sql.net.client.integration.server.ProtoHttpServer;
|
||||
import org.elasticsearch.xpack.sql.test.server.ProtoHttpServer;
|
||||
|
||||
public class CliHttpServer extends ProtoHttpServer {
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ import org.elasticsearch.xpack.sql.TestUtils;
|
|||
import org.elasticsearch.xpack.sql.cli.net.protocol.ProtoUtils;
|
||||
import org.elasticsearch.xpack.sql.cli.net.protocol.Request;
|
||||
import org.elasticsearch.xpack.sql.cli.net.protocol.Response;
|
||||
import org.elasticsearch.xpack.sql.net.client.integration.server.ProtoHandler;
|
||||
import org.elasticsearch.xpack.sql.plugin.cli.http.CliServerProtoUtils;
|
||||
import org.elasticsearch.xpack.sql.plugin.cli.server.CliServer;
|
||||
import org.elasticsearch.xpack.sql.test.server.ProtoHandler;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -37,6 +37,7 @@ dependencies {
|
|||
compile project(':x-pack-elasticsearch:sql-clients:jdbc-proto')
|
||||
|
||||
testCompile project(":x-pack-elasticsearch:transport-client")
|
||||
testCompile project(':x-pack-elasticsearch:sql-clients:test-utils')
|
||||
|
||||
testRuntime "com.h2database:h2:1.4.194"
|
||||
testRuntime "net.sourceforge.csvjdbc:csvjdbc:1.0.31"
|
||||
|
|
|
@ -38,6 +38,10 @@ import org.elasticsearch.xpack.sql.jdbc.util.BytesArray;
|
|||
import org.elasticsearch.xpack.sql.jdbc.util.FastByteArrayInputStream;
|
||||
|
||||
public class HttpJdbcClient implements Closeable {
|
||||
@FunctionalInterface
|
||||
interface DataInputFunction<R> {
|
||||
R apply(DataInput in) throws IOException, SQLException;
|
||||
}
|
||||
|
||||
private final HttpClient http;
|
||||
private final JdbcConfiguration conCfg;
|
||||
|
@ -203,8 +207,3 @@ public class HttpJdbcClient implements Closeable {
|
|||
throw new JdbcException("Invalid response status %08X", header);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface DataInputFunction<R> {
|
||||
R apply(DataInput in) throws IOException, SQLException;
|
||||
}
|
|
@ -35,7 +35,7 @@ public class FastByteArrayInputStream extends InputStream {
|
|||
* position within the buffer by the <code>mark()</code> method.
|
||||
* The current buffer position is set to this point by the
|
||||
* <code>reset()</code> method.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If no mark has been set, then the value of mark is the offset
|
||||
* passed to the constructor (or 0 if the offset was not supplied).
|
||||
*
|
||||
|
@ -82,7 +82,7 @@ public class FastByteArrayInputStream extends InputStream {
|
|||
* <code>0</code> to <code>255</code>. If no byte is available
|
||||
* because the end of the stream has been reached, the value
|
||||
* <code>-1</code> is returned.
|
||||
* <p/>
|
||||
* <p>
|
||||
* This <code>read</code> method
|
||||
* cannot block.
|
||||
*
|
||||
|
@ -108,7 +108,7 @@ public class FastByteArrayInputStream extends InputStream {
|
|||
* by <code>System.arraycopy</code>. The
|
||||
* value <code>k</code> is added into <code>pos</code>
|
||||
* and <code>k</code> is returned.
|
||||
* <p/>
|
||||
* <p>
|
||||
* This <code>read</code> method cannot block.
|
||||
*
|
||||
* @param b the buffer into which the data is read.
|
||||
|
@ -169,7 +169,7 @@ public class FastByteArrayInputStream extends InputStream {
|
|||
/**
|
||||
* Returns the number of remaining bytes that can be read (or skipped over)
|
||||
* from this input stream.
|
||||
* <p/>
|
||||
* <p>
|
||||
* The value returned is <code>count - pos</code>,
|
||||
* which is the number of bytes remaining to be read from the input buffer.
|
||||
*
|
||||
|
@ -200,11 +200,10 @@ public class FastByteArrayInputStream extends InputStream {
|
|||
* ByteArrayInputStream objects are marked at position zero by
|
||||
* default when constructed. They may be marked at another
|
||||
* position within the buffer by this method.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If no mark has been set, then the value of the mark is the
|
||||
* offset passed to the constructor (or 0 if the offset was not
|
||||
* supplied).
|
||||
* <p/>
|
||||
* <p> Note: The <code>readAheadLimit</code> for this class
|
||||
* has no meaning.
|
||||
*
|
||||
|
@ -227,7 +226,6 @@ public class FastByteArrayInputStream extends InputStream {
|
|||
* Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
|
||||
* this class can be called after the stream has been closed without
|
||||
* generating an <tt>IOException</tt>.
|
||||
* <p/>
|
||||
*/
|
||||
public void close() {}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ public class FastByteArrayOutputStream extends OutputStream {
|
|||
/**
|
||||
* Creates a new byte array output stream. The buffer capacity is
|
||||
* initially 1024 bytes, though its size increases if necessary.
|
||||
* <p/>
|
||||
* <p>
|
||||
* ES: We use 1024 bytes since we mainly use this to build json/smile
|
||||
* content in memory, and rarely does the 32 byte default in ByteArrayOutputStream fits...
|
||||
*/
|
||||
|
@ -33,7 +33,6 @@ public class FastByteArrayOutputStream extends OutputStream {
|
|||
* the specified size, in bytes.
|
||||
*
|
||||
* @param size the initial size.
|
||||
* @throws EsHadoopIllegalArgumentException if size is negative.
|
||||
*/
|
||||
public FastByteArrayOutputStream(int size) {
|
||||
Assert.isTrue(size >= 0, "Negative initial size: " + size);
|
||||
|
@ -56,7 +55,7 @@ public class FastByteArrayOutputStream extends OutputStream {
|
|||
/**
|
||||
* Writes <code>len</code> bytes from the specified byte array
|
||||
* starting at offset <code>off</code> to this byte array output stream.
|
||||
* <p/>
|
||||
* <p>
|
||||
* <b>NO checks for bounds, parameters must be ok!</b>
|
||||
*
|
||||
* @param b the data.
|
||||
|
@ -118,7 +117,6 @@ public class FastByteArrayOutputStream extends OutputStream {
|
|||
* Closing a <tt>ByteArrayOutputStream</tt> has no effect. The methods in
|
||||
* this class can be called after the stream has been closed without
|
||||
* generating an <tt>IOException</tt>.
|
||||
* <p/>
|
||||
*/
|
||||
public void close() throws IOException {}
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
package org.elasticsearch.xpack.sql.jdbc.integration.server;
|
||||
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.xpack.sql.net.client.integration.server.ProtoHttpServer;
|
||||
import org.elasticsearch.xpack.sql.test.server.ProtoHttpServer;
|
||||
|
||||
public class JdbcHttpServer extends ProtoHttpServer {
|
||||
|
||||
|
|
|
@ -5,19 +5,19 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.sql.jdbc.integration.server;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.xpack.sql.TestUtils;
|
||||
import org.elasticsearch.xpack.sql.jdbc.net.protocol.ProtoUtils;
|
||||
import org.elasticsearch.xpack.sql.jdbc.net.protocol.Request;
|
||||
import org.elasticsearch.xpack.sql.jdbc.net.protocol.Response;
|
||||
import org.elasticsearch.xpack.sql.net.client.integration.server.ProtoHandler;
|
||||
import org.elasticsearch.xpack.sql.plugin.jdbc.server.JdbcServer;
|
||||
import org.elasticsearch.xpack.sql.plugin.jdbc.server.JdbcServerProtoUtils;
|
||||
import org.elasticsearch.xpack.sql.test.server.ProtoHandler;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.action.ActionListener.wrap;
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
package org.elasticsearch.xpack.sql.jdbc.integration.util;
|
||||
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.xpack.sql.integration.es.LocalEs;
|
||||
import org.elasticsearch.xpack.sql.jdbc.integration.server.JdbcHttpServer;
|
||||
import org.elasticsearch.xpack.sql.jdbc.integration.util.JdbcTemplate.JdbcSupplier;
|
||||
import org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcDriver;
|
||||
|
@ -19,15 +18,12 @@ import java.util.Properties;
|
|||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class EsJdbcServer extends ExternalResource implements JdbcSupplier<Connection> {
|
||||
|
||||
private final LocalEs es;
|
||||
private JdbcHttpServer server;
|
||||
private String jdbcUrl;
|
||||
private JdbcDriver driver;
|
||||
private final Properties properties;
|
||||
|
||||
public EsJdbcServer(boolean remote, boolean debug) {
|
||||
es = (remote ? null : new LocalEs());
|
||||
properties = new Properties();
|
||||
if (debug) {
|
||||
properties.setProperty("debug", "true");
|
||||
|
@ -44,11 +40,7 @@ public class EsJdbcServer extends ExternalResource implements JdbcSupplier<Conne
|
|||
|
||||
@Override
|
||||
protected void before() throws Throwable {
|
||||
if (es != null) {
|
||||
es.start();
|
||||
}
|
||||
|
||||
server = new JdbcHttpServer(es != null ? es.client() : null);
|
||||
server = new JdbcHttpServer(null);
|
||||
driver = new JdbcDriver();
|
||||
|
||||
server.start(0);
|
||||
|
@ -59,9 +51,6 @@ public class EsJdbcServer extends ExternalResource implements JdbcSupplier<Conne
|
|||
protected void after() {
|
||||
server.stop();
|
||||
server = null;
|
||||
if (es != null) {
|
||||
es.stop();
|
||||
}
|
||||
}
|
||||
|
||||
public Connection jdbc() throws SQLException {
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
apply plugin: 'elasticsearch.build'
|
||||
|
||||
description = 'Common base for protos'
|
||||
// Tests have some testing utilities
|
||||
|
||||
dependencies {
|
||||
testCompile "org.elasticsearch.client:transport:${version}"
|
||||
}
|
||||
description = 'Common base things for protos'
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
apply plugin: 'elasticsearch.build'
|
||||
|
||||
description = 'Shared test utilities for jdbc and cli'
|
||||
|
||||
dependencies {
|
||||
compile "org.elasticsearch.client:transport:${version}"
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
* 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.net.client.integration.server;
|
||||
package org.elasticsearch.xpack.sql.test.server;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
* 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.net.client.integration.server;
|
||||
package org.elasticsearch.xpack.sql.test.server;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
|
@ -3,7 +3,7 @@
|
|||
* 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.net.client.integration.server;
|
||||
package org.elasticsearch.xpack.sql.test.server;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
|
@ -3,7 +3,7 @@
|
|||
* 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.net.client.integration.server;
|
||||
package org.elasticsearch.xpack.sql.test.server;
|
||||
|
||||
import java.io.IOException;
|
||||
|
Loading…
Reference in New Issue