mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-09 14:34:43 +00:00
Move more tests to integration tests
Original commit: elastic/x-pack-elasticsearch@0a75293d97
This commit is contained in:
parent
fd77cb24a1
commit
317cf0253e
@ -86,6 +86,7 @@ public class EsCatalog implements Catalog {
|
||||
return EsType.NOT_FOUND;
|
||||
}
|
||||
|
||||
// NOCOMMIT verify that this works if the index isn't on the node
|
||||
MappingMetaData mapping = metadata().index(index).mapping(type);
|
||||
if (mapping == null) {
|
||||
return EsType.NOT_FOUND;
|
||||
|
@ -5,14 +5,6 @@
|
||||
*/
|
||||
package org.elasticsearch.xpack.sql.plugin.jdbc.server;
|
||||
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.sql.Types;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.elasticsearch.ResourceNotFoundException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
@ -29,7 +21,15 @@ import org.elasticsearch.xpack.sql.jdbc.net.protocol.Response;
|
||||
import org.elasticsearch.xpack.sql.parser.ParsingException;
|
||||
import org.elasticsearch.xpack.sql.session.RowSet;
|
||||
import org.elasticsearch.xpack.sql.session.RowSetCursor;
|
||||
import org.joda.time.ReadableDateTime;
|
||||
import org.joda.time.ReadableInstant;
|
||||
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.sql.Types;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static org.elasticsearch.xpack.sql.util.StringUtils.EMPTY;
|
||||
|
||||
@ -64,8 +64,9 @@ public abstract class JdbcServerProtoUtils {
|
||||
for (int i = 0; i < rowSet.rowSize(); i++) {
|
||||
Object value = rowSet.column(i);
|
||||
// unpack Joda classes on the server-side to not 'pollute' the common project and thus the client
|
||||
if (jdbcTypes[i] == Types.TIMESTAMP_WITH_TIMEZONE && value instanceof ReadableDateTime) {
|
||||
value = ((ReadableDateTime) value).getMillis();
|
||||
if (jdbcTypes[i] == Types.TIMESTAMP && value instanceof ReadableInstant) {
|
||||
// NOCOMMIT feels like a hack that'd be better cleaned up another way.
|
||||
value = ((ReadableInstant) value).getMillis();
|
||||
}
|
||||
ProtoUtils.writeValue(out, value, jdbcTypes[i]);
|
||||
}
|
||||
|
@ -19,7 +19,19 @@ public class DateType extends AbstractDataType {
|
||||
private final List<String> formats;
|
||||
|
||||
DateType(boolean docValues, String... formats) {
|
||||
super(JDBCType.TIMESTAMP_WITH_TIMEZONE, docValues);
|
||||
/* Since we normalize timestamps to UTC for storage and do not keep
|
||||
* the origination zone information information we are technically
|
||||
* `TIMESTAMP WITHOUT TIME ZONE` or just `TIMESTAMP`, or, in Oracle
|
||||
* parlance, `TIMESTAMP WITH LOCAL TIME ZONE`.
|
||||
* `TIMESTAMP WITH TIME ZONE` implies that we store the original
|
||||
* time zone of the even. Confusingly, PostgreSQL's
|
||||
* `TIMESTAMP WITH TIME ZONE` type does not store original time zone,
|
||||
* unlike H2 and Oracle, *but* it is aware of the session's time zone
|
||||
* so it is preferred. But it is *weird*. As bad as it feels not to
|
||||
* be like PostgreSQL, we are going to not be like PostgreSQL here
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ abstract class JdbcUtils {
|
||||
case DOUBLE: return 25;
|
||||
case VARCHAR:
|
||||
case VARBINARY: return -1;
|
||||
case TIME_WITH_TIMEZONE: return 20;
|
||||
case TIMESTAMP: return 20;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
@ -106,7 +106,7 @@ abstract class JdbcUtils {
|
||||
case TINYINT: return Byte.BYTES;
|
||||
case SMALLINT: return Short.BYTES;
|
||||
case INTEGER: return Integer.BYTES;
|
||||
case TIME_WITH_TIMEZONE:
|
||||
case TIMESTAMP:
|
||||
case BIGINT: return Long.BYTES;
|
||||
case REAL: return Float.BYTES;
|
||||
case FLOAT:
|
||||
|
@ -12,6 +12,7 @@ import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.sql.JDBCType;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Locale;
|
||||
|
||||
import static java.lang.String.format;
|
||||
@ -28,6 +29,7 @@ import static java.sql.Types.LONGVARCHAR;
|
||||
import static java.sql.Types.NULL;
|
||||
import static java.sql.Types.REAL;
|
||||
import static java.sql.Types.SMALLINT;
|
||||
import static java.sql.Types.TIMESTAMP;
|
||||
import static java.sql.Types.TIMESTAMP_WITH_TIMEZONE;
|
||||
import static java.sql.Types.TINYINT;
|
||||
import static java.sql.Types.VARBINARY;
|
||||
@ -114,11 +116,13 @@ public abstract class ProtoUtils {
|
||||
// See Jdbc spec, appendix B
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T readValue(DataInput in, int type) throws IOException {
|
||||
// NOCOMMIT <T> feels slippery here
|
||||
Object result;
|
||||
byte hasNext = in.readByte();
|
||||
if (hasNext == 0) { // NOCOMMIT feels like a bitmask at the start of the row would be better.
|
||||
return null;
|
||||
}
|
||||
// NOCOMMIT we ought to make sure we use all of these
|
||||
switch (type) {
|
||||
case NULL:
|
||||
// used to move the stream forward
|
||||
@ -165,8 +169,8 @@ public abstract class ProtoUtils {
|
||||
case LONGVARCHAR:
|
||||
result = in.readUTF();
|
||||
break;
|
||||
case TIMESTAMP_WITH_TIMEZONE:
|
||||
result = in.readLong();
|
||||
case TIMESTAMP:
|
||||
result = new Timestamp(in.readLong());
|
||||
break;
|
||||
default:
|
||||
throw new IOException("Don't know how to read type [" + type + " / " + JDBCType.valueOf(type) + "]");
|
||||
@ -182,6 +186,7 @@ public abstract class ProtoUtils {
|
||||
out.writeByte(1);
|
||||
|
||||
switch (type) {
|
||||
// NOCOMMIT we ought to make sure we use all of these
|
||||
case NULL:
|
||||
// used to move the stream forward
|
||||
out.writeBoolean(false);
|
||||
@ -225,7 +230,7 @@ public abstract class ProtoUtils {
|
||||
case LONGVARCHAR:
|
||||
out.writeUTF(o.toString());
|
||||
return;
|
||||
case TIMESTAMP_WITH_TIMEZONE:
|
||||
case TIMESTAMP:
|
||||
out.writeLong(((Number) o).longValue());
|
||||
return;
|
||||
default:
|
||||
|
@ -67,6 +67,7 @@ jar {
|
||||
}
|
||||
|
||||
apply plugin: 'elasticsearch.rest-test'
|
||||
integTest.mustRunAfter test
|
||||
|
||||
integTestCluster {
|
||||
distribution = 'zip' // NOCOMMIT make double sure we want all the modules
|
||||
|
@ -300,7 +300,6 @@ class JdbcResultSet implements ResultSet, JdbcWrapper {
|
||||
return getObject(columnIndex, type);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T convert(int columnIndex, Class<T> type) throws SQLException {
|
||||
checkOpen();
|
||||
if (columnIndex < 1 || columnIndex > cursor.columnSize()) {
|
||||
|
@ -118,8 +118,6 @@ public abstract class JdbcUtils {
|
||||
return Blob.class;
|
||||
case CLOB:
|
||||
return Clob.class;
|
||||
case TIMESTAMP_WITH_TIMEZONE:
|
||||
return Long.class;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported JDBC type [" + jdbcType + "/" + nameOf(jdbcType) + "]");
|
||||
}
|
||||
|
@ -179,6 +179,7 @@ abstract class TypeConverter {
|
||||
case CHAR:
|
||||
case VARCHAR:
|
||||
case LONGVARCHAR:
|
||||
case TIMESTAMP:
|
||||
result = v;
|
||||
break;
|
||||
// since the date is already in UTC just do calendar math
|
||||
@ -188,10 +189,6 @@ abstract class TypeConverter {
|
||||
case TIME:
|
||||
result = new Time(utcMillisRemoveDate(((Long) v).longValue()));
|
||||
break;
|
||||
case TIMESTAMP:
|
||||
case TIMESTAMP_WITH_TIMEZONE:
|
||||
result = new Timestamp(((Long) v).longValue());
|
||||
break;
|
||||
default:
|
||||
}
|
||||
return result;
|
||||
|
@ -21,7 +21,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.lang.String.format;
|
||||
import static org.elasticsearch.xpack.sql.jdbc.integration.util.JdbcAssert.assertResultSets;
|
||||
import static org.elasticsearch.xpack.sql.jdbc.query.JdbcAssert.assertResultSets;
|
||||
|
||||
public abstract class CompareToH2BaseTestCase extends ESTestCase {
|
||||
// NOCOMMIT subclasses should probably all be integration tests running against a running Elasticsearch
|
||||
|
@ -10,7 +10,6 @@ import java.sql.SQLException;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.elasticsearch.common.CheckedSupplier;
|
||||
import org.elasticsearch.xpack.sql.jdbc.integration.query.filter.FilterSpecTests;
|
||||
import org.elasticsearch.xpack.sql.jdbc.integration.query.function.aggregate.AggSpecTests;
|
||||
import org.elasticsearch.xpack.sql.jdbc.integration.query.function.scalar.datetime.DateTimeSpecTests;
|
||||
import org.elasticsearch.xpack.sql.jdbc.integration.query.function.scalar.math.MathSpecTests;
|
||||
@ -18,6 +17,8 @@ import org.elasticsearch.xpack.sql.jdbc.integration.util.EsDataLoader;
|
||||
import org.elasticsearch.xpack.sql.jdbc.integration.util.EsJdbcServer;
|
||||
import org.elasticsearch.xpack.sql.jdbc.integration.util.H2;
|
||||
import org.elasticsearch.xpack.sql.jdbc.integration.util.JdbcTemplate;
|
||||
import org.elasticsearch.xpack.sql.jdbc.query.FilterIT;
|
||||
import org.elasticsearch.xpack.sql.jdbc.query.SelectIT;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -27,7 +28,7 @@ import org.junit.runners.Suite.SuiteClasses;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({ SelectSpecTests.class, FilterSpecTests.class, AggSpecTests.class, MathSpecTests.class, DateTimeSpecTests.class })
|
||||
@SuiteClasses({ SelectIT.class, FilterIT.class, AggSpecTests.class, MathSpecTests.class, DateTimeSpecTests.class })
|
||||
//@SuiteClasses({ DebugSpecTest.class })
|
||||
//@SuiteClasses({ AggSpecTest.class })
|
||||
//@SuiteClasses({ DateTimeSpecTest.class })
|
||||
|
@ -1,20 +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.jdbc.integration.query.select;
|
||||
|
||||
import org.elasticsearch.xpack.sql.jdbc.integration.query.CompareToH2BaseTestCase;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class SelectSpecTests extends CompareToH2BaseTestCase {
|
||||
public SelectSpecTests(String queryName, String query, Integer lineNumber, Path source) {
|
||||
super(queryName, query, lineNumber, source);
|
||||
}
|
||||
|
||||
public static Iterable<Object[]> queries() throws Exception {
|
||||
return readScriptSpec("/org/elasticsearch/sql/jdbc/integration/query/select/select.spec");
|
||||
}
|
||||
}
|
@ -91,22 +91,22 @@ public abstract class EsDataLoader {
|
||||
|
||||
// add mapping
|
||||
indices().preparePutMapping(index)
|
||||
.setType(type)
|
||||
.setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.startObject(type)
|
||||
.startObject("properties")
|
||||
.startObject("emp_no").field("type", "integer").endObject()
|
||||
.startObject("birth_date").field("type", "date").endObject()
|
||||
// .startObject("first_name").field("type", "text").endObject()
|
||||
// .startObject("last_name").field("type", "text").endObject()
|
||||
// .startObject("gender").field("type", "keyword").endObject()
|
||||
.startObject("hire_date").field("type", "date").endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
)
|
||||
.get();
|
||||
.setType(type)
|
||||
.setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.startObject(type)
|
||||
.startObject("properties")
|
||||
.startObject("emp_no").field("type", "integer").endObject()
|
||||
.startObject("birth_date").field("type", "date").endObject()
|
||||
// .startObject("first_name").field("type", "text").endObject()
|
||||
// .startObject("last_name").field("type", "text").endObject()
|
||||
// .startObject("gender").field("type", "keyword").endObject()
|
||||
.startObject("hire_date").field("type", "date").endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
)
|
||||
.get();
|
||||
|
||||
loadFromFile("/employees.csv", index, type, "emp_no", "birth_date", "first_name", "last_name", "gender", "hire_date");
|
||||
}
|
||||
|
@ -94,13 +94,13 @@ public class JdbcTemplate {
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T map(CheckedFunction<Connection, T, SQLException> c) throws Exception {
|
||||
public <T> T map(CheckedFunction<Connection, T, SQLException> c) throws SQLException {
|
||||
try (Connection con = conn.get()) {
|
||||
return c.apply(con);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T query(String q, CheckedFunction<ResultSet, T, SQLException> f) throws Exception {
|
||||
public <T> T query(String q, CheckedFunction<ResultSet, T, SQLException> f) throws SQLException {
|
||||
return map(c -> {
|
||||
try (Statement st = c.createStatement();
|
||||
ResultSet rset = st.executeQuery(q)) {
|
||||
@ -109,11 +109,11 @@ public class JdbcTemplate {
|
||||
});
|
||||
}
|
||||
|
||||
public void queryToConsole(String q) throws Exception {
|
||||
public void queryToConsole(String q) throws SQLException {
|
||||
query(q, resultSetToConsole());
|
||||
}
|
||||
|
||||
public <T> T queryObject(String q, Class<T> type) throws Exception {
|
||||
public <T> T queryObject(String q, Class<T> type) throws SQLException {
|
||||
return query(q, singleResult(type));
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ public class JdbcTemplate {
|
||||
});
|
||||
}
|
||||
|
||||
public <T> T execute(String query, CheckedFunction<PreparedStatement, T, SQLException> callback) throws Exception {
|
||||
public <T> T execute(String query, CheckedFunction<PreparedStatement, T, SQLException> callback) throws SQLException {
|
||||
return map(c -> {
|
||||
try (PreparedStatement ps = c.prepareStatement(query)) {
|
||||
return callback.apply(ps);
|
||||
@ -135,7 +135,7 @@ public class JdbcTemplate {
|
||||
}
|
||||
|
||||
public <T> T execute(String query, CheckedConsumer<PreparedStatement, SQLException> prepare,
|
||||
CheckedFunction<ResultSet, T, SQLException> mapper) throws Exception {
|
||||
CheckedFunction<ResultSet, T, SQLException> mapper) throws SQLException {
|
||||
return execute(query, ps -> {
|
||||
prepare.accept(ps);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
@ -144,7 +144,7 @@ public class JdbcTemplate {
|
||||
});
|
||||
}
|
||||
|
||||
public <T> T query(String q, CheckedFunction<ResultSet, T, SQLException> mapper, Object... args) throws Exception {
|
||||
public <T> T query(String q, CheckedFunction<ResultSet, T, SQLException> mapper, Object... args) throws SQLException {
|
||||
CheckedConsumer<PreparedStatement, SQLException> p = ps -> {
|
||||
if (args != null) {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
|
@ -0,0 +1,168 @@
|
||||
/*
|
||||
* 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.jdbc.query;
|
||||
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.elasticsearch.common.io.PathUtils;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.xpack.sql.jdbc.JdbcIntegrationTestCase;
|
||||
import org.elasticsearch.xpack.sql.jdbc.integration.util.EsDataLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static org.elasticsearch.xpack.sql.jdbc.query.JdbcAssert.assertResultSets;
|
||||
|
||||
/**
|
||||
* Compares Elasticsearch's JDBC driver to H2.
|
||||
*/
|
||||
public abstract class CompareToH2BaseTestCase extends JdbcIntegrationTestCase {
|
||||
public final String queryName;
|
||||
public final String query;
|
||||
public final Integer lineNumber;
|
||||
public final Path source;
|
||||
|
||||
public CompareToH2BaseTestCase(String queryName, String query, Integer lineNumber, Path source) {
|
||||
this.queryName = queryName;
|
||||
this.query = query;
|
||||
this.lineNumber = lineNumber;
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
protected static List<Object[]> readScriptSpec(String spec) throws Exception {
|
||||
String url = "/" + spec + ".spec";
|
||||
URL resource = CompareToH2BaseTestCase.class.getResource(url);
|
||||
if (resource == null) {
|
||||
throw new IllegalArgumentException("Couldn't find [" + url + "]");
|
||||
}
|
||||
Path source = PathUtils.get(resource.toURI());
|
||||
List<String> lines = Files.readAllLines(source);
|
||||
|
||||
Map<String, Integer> testNames = new LinkedHashMap<>();
|
||||
List<Object[]> ctorArgs = new ArrayList<>();
|
||||
|
||||
String name = null;
|
||||
StringBuilder query = new StringBuilder();
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
String line = lines.get(i).trim();
|
||||
// ignore comments
|
||||
if (!line.isEmpty() && !line.startsWith("//")) {
|
||||
if (name == null) {
|
||||
if (testNames.keySet().contains(line)) {
|
||||
throw new IllegalStateException("Duplicate test name [" + line
|
||||
+ "] at line [" + i + "] (previously seen at line [" + testNames.get(line) + "])");
|
||||
} else {
|
||||
name = line;
|
||||
testNames.put(name, Integer.valueOf(i));
|
||||
}
|
||||
} else {
|
||||
if (line.endsWith(";")) {
|
||||
query.append(line.substring(0, line.length() - 1));
|
||||
}
|
||||
ctorArgs.add(new Object[] { name, query.toString(), Integer.valueOf(i), source });
|
||||
name = null;
|
||||
query.setLength(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
assertNull("Cannot find query for test " + name, name);
|
||||
|
||||
return ctorArgs;
|
||||
}
|
||||
|
||||
public void testQuery() throws Throwable {
|
||||
/*
|
||||
* The syntax on the connection string is fairly particular:
|
||||
* mem:; creates an anonymous database in memory. The `;` is
|
||||
* technically the separator that comes after the name.
|
||||
* DATABASE_TO_UPPER=false turns *off* H2's Oracle-like habit
|
||||
* of upper-casing everything that isn't quoted.
|
||||
* ALIAS_COLUMN_NAME=true turn *on* returning alias names in
|
||||
* result set metadata which is what most DBs do except
|
||||
* for MySQL and, by default, H2. Our jdbc driver does it.
|
||||
* RUNSCRIPT FROM 'classpath:/h2-setup.sql' initializes the
|
||||
* database with test data.
|
||||
*/
|
||||
try (Connection h2 = DriverManager.getConnection(
|
||||
"jdbc:h2:mem:;DATABASE_TO_UPPER=false;ALIAS_COLUMN_NAME=true;INIT=RUNSCRIPT FROM 'classpath:/h2-setup.sql'")) {
|
||||
try (PreparedStatement h2Query = h2.prepareStatement(query);
|
||||
ResultSet expected = h2Query.executeQuery()) {
|
||||
setupElasticsearchIndex();
|
||||
j.query(query, actual -> {
|
||||
assertResultSets(expected, actual);
|
||||
return null;
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private void setupElasticsearchIndex() throws IOException, URISyntaxException {
|
||||
XContentBuilder createIndex = JsonXContent.contentBuilder().startObject();
|
||||
createIndex.startObject("settings"); {
|
||||
createIndex.field("number_of_shards", 1);
|
||||
}
|
||||
createIndex.endObject();
|
||||
createIndex.startObject("mappings"); {
|
||||
createIndex.startObject("emp"); {
|
||||
createIndex.startObject("properties"); {
|
||||
createIndex.startObject("emp_no").field("type", "integer").endObject();
|
||||
createIndex.startObject("birth_date").field("type", "date").endObject();
|
||||
createIndex.startObject("first_name").field("type", "text").endObject();
|
||||
createIndex.startObject("last_name").field("type", "text").endObject();
|
||||
createIndex.startObject("gender").field("type", "keyword").endObject();
|
||||
createIndex.startObject("hire_date").field("type", "date").endObject();
|
||||
}
|
||||
createIndex.endObject();
|
||||
}
|
||||
createIndex.endObject();
|
||||
}
|
||||
createIndex.endObject().endObject();
|
||||
client().performRequest("PUT", "/emp", emptyMap(), new StringEntity(createIndex.string(), ContentType.APPLICATION_JSON));
|
||||
|
||||
URL dataSet = EsDataLoader.class.getResource("/employees.csv");
|
||||
if (dataSet == null) {
|
||||
throw new IllegalArgumentException("Can't find employees.csv");
|
||||
}
|
||||
StringBuilder bulk = new StringBuilder();
|
||||
List<String> lines = Files.readAllLines(PathUtils.get(dataSet.toURI()));
|
||||
if (lines.isEmpty()) {
|
||||
throw new IllegalArgumentException("employees.csv must contain at least a title row");
|
||||
}
|
||||
String[] titles = lines.get(0).split(",");
|
||||
for (int t = 0; t < titles.length; t++) {
|
||||
titles[t] = titles[t].replaceAll("\"", "");
|
||||
}
|
||||
for (int l = 1; l < lines.size(); l++) {
|
||||
bulk.append("{\"index\":{}}\n");
|
||||
bulk.append('{');
|
||||
String[] columns = lines.get(l).split(",");
|
||||
for (int c = 0; c < columns.length; c++) {
|
||||
if (c != 0) {
|
||||
bulk.append(',');
|
||||
}
|
||||
bulk.append('"').append(titles[c]).append("\":\"").append(columns[c]).append('"');
|
||||
}
|
||||
bulk.append("}\n");
|
||||
}
|
||||
client().performRequest("POST", "/emp/emp/_bulk", singletonMap("refresh", "true"),
|
||||
new StringEntity(bulk.toString(), ContentType.APPLICATION_JSON));
|
||||
}
|
||||
}
|
@ -3,16 +3,19 @@
|
||||
* 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.jdbc.integration.query;
|
||||
package org.elasticsearch.xpack.sql.jdbc.query;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class SelectSpecTests extends CompareToH2BaseTestCase {
|
||||
public SelectSpecTests(String queryName, String query, Integer lineNumber, Path source) {
|
||||
public class FilterIT extends CompareToH2BaseTestCase {
|
||||
public FilterIT(String queryName, String query, Integer lineNumber, Path source) {
|
||||
super(queryName, query, lineNumber, source);
|
||||
}
|
||||
|
||||
@ParametersFactory
|
||||
public static Iterable<Object[]> queries() throws Exception {
|
||||
return readScriptSpec("/org/elasticsearch/sql/jdbc/integration/query/select/select.spec");
|
||||
return readScriptSpec("filter");
|
||||
}
|
||||
}
|
@ -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.jdbc.integration.util;
|
||||
package org.elasticsearch.xpack.sql.jdbc.query;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
@ -19,7 +19,6 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcUtils.nameOf;
|
||||
|
||||
public class JdbcAssert {
|
||||
|
||||
public static void assertResultSets(ResultSet expected, ResultSet actual) throws SQLException {
|
||||
assertResultSetMetadata(expected, actual);
|
||||
assertResultSetData(expected, actual);
|
||||
@ -67,27 +66,26 @@ public class JdbcAssert {
|
||||
Object actualObject = actual.getObject(column);
|
||||
int type = metaData.getColumnType(column);
|
||||
|
||||
// handle timestamp differently
|
||||
// handle timestamps with care because h2 returns "funny" objects
|
||||
if (type == Types.TIMESTAMP_WITH_TIMEZONE) {
|
||||
expectedObject = getDate(expected, column);
|
||||
actualObject = getDate(actual, column);
|
||||
}
|
||||
if (type == Types.TIME) {
|
||||
expectedObject = getTime(expected, column);
|
||||
actualObject = getTime(actual, column);
|
||||
expectedObject = expected.getTimestamp(column);
|
||||
actualObject = actual.getTimestamp(column);
|
||||
} else if (type == Types.TIME) {
|
||||
expectedObject = expected.getTime(column);
|
||||
actualObject = actual.getTime(column);
|
||||
} else if (type == Types.DATE) {
|
||||
expectedObject = expected.getDate(column);
|
||||
actualObject = actual.getDate(column);
|
||||
}
|
||||
|
||||
String msg = f("Different result for column %s, entry %d", metaData.getColumnName(column), count);
|
||||
|
||||
if (type == Types.DOUBLE) {
|
||||
// NOCOMMIT 1d/1f seems like a huge difference.
|
||||
assertEquals(msg, (double) expectedObject, (double) actualObject, 1d);
|
||||
|
||||
}
|
||||
else if (type == Types.FLOAT) {
|
||||
} else if (type == Types.FLOAT) {
|
||||
assertEquals(msg, (float) expectedObject, (float) actualObject, 1f);
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
assertEquals(msg, expectedObject, actualObject);
|
||||
}
|
||||
}
|
||||
@ -95,16 +93,6 @@ public class JdbcAssert {
|
||||
assertEquals(f("%s still has data after %d entries", actual, count), expected.next(), actual.next());
|
||||
}
|
||||
|
||||
private static Object getDate(ResultSet resultSet, int column) throws SQLException {
|
||||
// return just the date as a string
|
||||
return resultSet.getDate(column).toString();
|
||||
}
|
||||
|
||||
private static Object getTime(ResultSet resultSet, int column) throws SQLException {
|
||||
// return just the time as a string
|
||||
return resultSet.getTime(column).toString();
|
||||
}
|
||||
|
||||
private static String f(String message, Object... args) {
|
||||
return format(Locale.ROOT, message, args);
|
||||
}
|
@ -3,18 +3,19 @@
|
||||
* 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.jdbc.integration.query.filter;
|
||||
package org.elasticsearch.xpack.sql.jdbc.query;
|
||||
|
||||
import org.elasticsearch.xpack.sql.jdbc.integration.query.CompareToH2BaseTestCase;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class FilterSpecTests extends CompareToH2BaseTestCase {
|
||||
public FilterSpecTests(String queryName, String query, Integer lineNumber, Path source) {
|
||||
public class SelectIT extends CompareToH2BaseTestCase {
|
||||
public SelectIT(String queryName, String query, Integer lineNumber, Path source) {
|
||||
super(queryName, query, lineNumber, source);
|
||||
}
|
||||
|
||||
@ParametersFactory
|
||||
public static Iterable<Object[]> queries() throws Exception {
|
||||
return readScriptSpec("/org/elasticsearch/sql/jdbc/integration/query/filter/filter.spec");
|
||||
return readScriptSpec("select");
|
||||
}
|
||||
}
|
101
sql-clients/jdbc/src/test/resources/employees.csv
Normal file
101
sql-clients/jdbc/src/test/resources/employees.csv
Normal file
@ -0,0 +1,101 @@
|
||||
"birth_date","emp_no","first_name","gender","hire_date","last_name"
|
||||
1953-09-02T00:00:00Z,10001,Georgi,M,1986-06-26T00:00:00Z,Facello
|
||||
1964-06-02T00:00:00Z,10002,Bezalel,F,1985-11-21T00:00:00Z,Simmel
|
||||
1959-12-03T00:00:00Z,10003,Parto,M,1986-08-28T00:00:00Z,Bamford
|
||||
1954-05-01T00:00:00Z,10004,Chirstian,M,1986-12-01T00:00:00Z,Koblick
|
||||
1955-01-21T00:00:00Z,10005,Kyoichi,M,1989-09-12T00:00:00Z,Maliniak
|
||||
1953-04-20T00:00:00Z,10006,Anneke,F,1989-06-02T00:00:00Z,Preusig
|
||||
1957-05-23T00:00:00Z,10007,Tzvetan,F,1989-02-10T00:00:00Z,Zielinski
|
||||
1958-02-19T00:00:00Z,10008,Saniya,M,1994-09-15T00:00:00Z,Kalloufi
|
||||
1952-04-19T00:00:00Z,10009,Sumant,F,1985-02-18T00:00:00Z,Peac
|
||||
1963-06-01T00:00:00Z,10010,Duangkaew,F,1989-08-24T00:00:00Z,Piveteau
|
||||
1953-11-07T00:00:00Z,10011,Mary,F,1990-01-22T00:00:00Z,Sluis
|
||||
1960-10-04T00:00:00Z,10012,Patricio,M,1992-12-18T00:00:00Z,Bridgland
|
||||
1963-06-07T00:00:00Z,10013,Eberhardt,M,1985-10-20T00:00:00Z,Terkki
|
||||
1956-02-12T00:00:00Z,10014,Berni,M,1987-03-11T00:00:00Z,Genin
|
||||
1959-08-19T00:00:00Z,10015,Guoxiang,M,1987-07-02T00:00:00Z,Nooteboom
|
||||
1961-05-02T00:00:00Z,10016,Kazuhito,M,1995-01-27T00:00:00Z,Cappelletti
|
||||
1958-07-06T00:00:00Z,10017,Cristinel,F,1993-08-03T00:00:00Z,Bouloucos
|
||||
1954-06-19T00:00:00Z,10018,Kazuhide,F,1987-04-03T00:00:00Z,Peha
|
||||
1953-01-23T00:00:00Z,10019,Lillian,M,1999-04-30T00:00:00Z,Haddadi
|
||||
1952-12-24T00:00:00Z,10020,Mayuko,M,1991-01-26T00:00:00Z,Warwick
|
||||
1960-02-20T00:00:00Z,10021,Ramzi,M,1988-02-10T00:00:00Z,Erde
|
||||
1952-07-08T00:00:00Z,10022,Shahaf,M,1995-08-22T00:00:00Z,Famili
|
||||
1953-09-29T00:00:00Z,10023,Bojan,F,1989-12-17T00:00:00Z,Montemayor
|
||||
1958-09-05T00:00:00Z,10024,Suzette,F,1997-05-19T00:00:00Z,Pettey
|
||||
1958-10-31T00:00:00Z,10025,Prasadram,M,1987-08-17T00:00:00Z,Heyers
|
||||
1953-04-03T00:00:00Z,10026,Yongqiao,M,1995-03-20T00:00:00Z,Berztiss
|
||||
1962-07-10T00:00:00Z,10027,Divier,F,1989-07-07T00:00:00Z,Reistad
|
||||
1963-11-26T00:00:00Z,10028,Domenick,M,1991-10-22T00:00:00Z,Tempesti
|
||||
1956-12-13T00:00:00Z,10029,Otmar,M,1985-11-20T00:00:00Z,Herbst
|
||||
1958-07-14T00:00:00Z,10030,Elvis,M,1994-02-17T00:00:00Z,Demeyer
|
||||
1959-01-27T00:00:00Z,10031,Karsten,M,1991-09-01T00:00:00Z,Joslin
|
||||
1960-08-09T00:00:00Z,10032,Jeong,F,1990-06-20T00:00:00Z,Reistad
|
||||
1956-11-14T00:00:00Z,10033,Arif,M,1987-03-18T00:00:00Z,Merlo
|
||||
1962-12-29T00:00:00Z,10034,Bader,M,1988-09-21T00:00:00Z,Swan
|
||||
1953-02-08T00:00:00Z,10035,Alain,M,1988-09-05T00:00:00Z,Chappelet
|
||||
1959-08-10T00:00:00Z,10036,Adamantios,M,1992-01-03T00:00:00Z,Portugali
|
||||
1963-07-22T00:00:00Z,10037,Pradeep,M,1990-12-05T00:00:00Z,Makrucki
|
||||
1960-07-20T00:00:00Z,10038,Huan,M,1989-09-20T00:00:00Z,Lortz
|
||||
1959-10-01T00:00:00Z,10039,Alejandro,M,1988-01-19T00:00:00Z,Brender
|
||||
1959-09-13T00:00:00Z,10040,Weiyi,F,1993-02-14T00:00:00Z,Meriste
|
||||
1959-08-27T00:00:00Z,10041,Uri,F,1989-11-12T00:00:00Z,Lenart
|
||||
1956-02-26T00:00:00Z,10042,Magy,F,1993-03-21T00:00:00Z,Stamatiou
|
||||
1960-09-19T00:00:00Z,10043,Yishay,M,1990-10-20T00:00:00Z,Tzvieli
|
||||
1961-09-21T00:00:00Z,10044,Mingsen,F,1994-05-21T00:00:00Z,Casley
|
||||
1957-08-14T00:00:00Z,10045,Moss,M,1989-09-02T00:00:00Z,Shanbhogue
|
||||
1960-07-23T00:00:00Z,10046,Lucien,M,1992-06-20T00:00:00Z,Rosenbaum
|
||||
1952-06-29T00:00:00Z,10047,Zvonko,M,1989-03-31T00:00:00Z,Nyanchama
|
||||
1963-07-11T00:00:00Z,10048,Florian,M,1985-02-24T00:00:00Z,Syrotiuk
|
||||
1961-04-24T00:00:00Z,10049,Basil,F,1992-05-04T00:00:00Z,Tramer
|
||||
1958-05-21T00:00:00Z,10050,Yinghua,M,1990-12-25T00:00:00Z,Dredge
|
||||
1953-07-28T00:00:00Z,10051,Hidefumi,M,1992-10-15T00:00:00Z,Caine
|
||||
1961-02-26T00:00:00Z,10052,Heping,M,1988-05-21T00:00:00Z,Nitsch
|
||||
1954-09-13T00:00:00Z,10053,Sanjiv,F,1986-02-04T00:00:00Z,Zschoche
|
||||
1957-04-04T00:00:00Z,10054,Mayumi,M,1995-03-13T00:00:00Z,Schueller
|
||||
1956-06-06T00:00:00Z,10055,Georgy,M,1992-04-27T00:00:00Z,Dredge
|
||||
1961-09-01T00:00:00Z,10056,Brendon,F,1990-02-01T00:00:00Z,Bernini
|
||||
1954-05-30T00:00:00Z,10057,Ebbe,F,1992-01-15T00:00:00Z,Callaway
|
||||
1954-10-01T00:00:00Z,10058,Berhard,M,1987-04-13T00:00:00Z,McFarlin
|
||||
1953-09-19T00:00:00Z,10059,Alejandro,F,1991-06-26T00:00:00Z,McAlpine
|
||||
1961-10-15T00:00:00Z,10060,Breannda,M,1987-11-02T00:00:00Z,Billingsley
|
||||
1962-10-19T00:00:00Z,10061,Tse,M,1985-09-17T00:00:00Z,Herber
|
||||
1961-11-02T00:00:00Z,10062,Anoosh,M,1991-08-30T00:00:00Z,Peyn
|
||||
1952-08-06T00:00:00Z,10063,Gino,F,1989-04-08T00:00:00Z,Leonhardt
|
||||
1959-04-07T00:00:00Z,10064,Udi,M,1985-11-20T00:00:00Z,Jansch
|
||||
1963-04-14T00:00:00Z,10065,Satosi,M,1988-05-18T00:00:00Z,Awdeh
|
||||
1952-11-13T00:00:00Z,10066,Kwee,M,1986-02-26T00:00:00Z,Schusler
|
||||
1953-01-07T00:00:00Z,10067,Claudi,M,1987-03-04T00:00:00Z,Stavenow
|
||||
1962-11-26T00:00:00Z,10068,Charlene,M,1987-08-07T00:00:00Z,Brattka
|
||||
1960-09-06T00:00:00Z,10069,Margareta,F,1989-11-05T00:00:00Z,Bierman
|
||||
1955-08-20T00:00:00Z,10070,Reuven,M,1985-10-14T00:00:00Z,Garigliano
|
||||
1958-01-21T00:00:00Z,10071,Hisao,M,1987-10-01T00:00:00Z,Lipner
|
||||
1952-05-15T00:00:00Z,10072,Hironoby,F,1988-07-21T00:00:00Z,Sidou
|
||||
1954-02-23T00:00:00Z,10073,Shir,M,1991-12-01T00:00:00Z,McClurg
|
||||
1955-08-28T00:00:00Z,10074,Mokhtar,F,1990-08-13T00:00:00Z,Bernatsky
|
||||
1960-03-09T00:00:00Z,10075,Gao,F,1987-03-19T00:00:00Z,Dolinsky
|
||||
1952-06-13T00:00:00Z,10076,Erez,F,1985-07-09T00:00:00Z,Ritzmann
|
||||
1964-04-18T00:00:00Z,10077,Mona,M,1990-03-02T00:00:00Z,Azuma
|
||||
1959-12-25T00:00:00Z,10078,Danel,F,1987-05-26T00:00:00Z,Mondadori
|
||||
1961-10-05T00:00:00Z,10079,Kshitij,F,1986-03-27T00:00:00Z,Gils
|
||||
1957-12-03T00:00:00Z,10080,Premal,M,1985-11-19T00:00:00Z,Baek
|
||||
1960-12-17T00:00:00Z,10081,Zhongwei,M,1986-10-30T00:00:00Z,Rosen
|
||||
1963-09-09T00:00:00Z,10082,Parviz,M,1990-01-03T00:00:00Z,Lortz
|
||||
1959-07-23T00:00:00Z,10083,Vishv,M,1987-03-31T00:00:00Z,Zockler
|
||||
1960-05-25T00:00:00Z,10084,Tuval,M,1995-12-15T00:00:00Z,Kalloufi
|
||||
1962-11-07T00:00:00Z,10085,Kenroku,M,1994-04-09T00:00:00Z,Malabarba
|
||||
1962-11-19T00:00:00Z,10086,Somnath,M,1990-02-16T00:00:00Z,Foote
|
||||
1959-07-23T00:00:00Z,10087,Xinglin,F,1986-09-08T00:00:00Z,Eugenio
|
||||
1954-02-25T00:00:00Z,10088,Jungsoon,F,1988-09-02T00:00:00Z,Syrzycki
|
||||
1963-03-21T00:00:00Z,10089,Sudharsan,F,1986-08-12T00:00:00Z,Flasterstein
|
||||
1961-05-30T00:00:00Z,10090,Kendra,M,1986-03-14T00:00:00Z,Hofting
|
||||
1955-10-04T00:00:00Z,10091,Amabile,M,1992-11-18T00:00:00Z,Gomatam
|
||||
1964-10-18T00:00:00Z,10092,Valdiodio,F,1989-09-22T00:00:00Z,Niizuma
|
||||
1964-06-11T00:00:00Z,10093,Sailaja,M,1996-11-05T00:00:00Z,Desikan
|
||||
1957-05-25T00:00:00Z,10094,Arumugam,F,1987-04-18T00:00:00Z,Ossenbruggen
|
||||
1965-01-03T00:00:00Z,10095,Hilari,M,1986-07-15T00:00:00Z,Morton
|
||||
1954-09-16T00:00:00Z,10096,Jayson,M,1990-01-14T00:00:00Z,Mandell
|
||||
1952-02-27T00:00:00Z,10097,Remzi,M,1990-09-15T00:00:00Z,Waschkowski
|
||||
1961-09-23T00:00:00Z,10098,Sreekrishna,F,1985-05-13T00:00:00Z,Servieres
|
||||
1956-05-25T00:00:00Z,10099,Valter,F,1988-10-18T00:00:00Z,Sullins
|
||||
1953-04-21T00:00:00Z,10100,Hironobu,F,1987-09-21T00:00:00Z,Haraldson
|
|
20
sql-clients/jdbc/src/test/resources/filter.spec
Normal file
20
sql-clients/jdbc/src/test/resources/filter.spec
Normal file
@ -0,0 +1,20 @@
|
||||
//
|
||||
// Filter
|
||||
//
|
||||
|
||||
whereFieldQuality
|
||||
SELECT last_name l FROM "emp.emp" WHERE emp_no = 10000 LIMIT 5;
|
||||
whereFieldLessThan
|
||||
SELECT last_name l FROM "emp.emp" WHERE emp_no < 10003 ORDER BY emp_no LIMIT 5;
|
||||
whereFieldAndComparison
|
||||
SELECT last_name l FROM "emp.emp" WHERE emp_no > 10000 AND emp_no < 10005 ORDER BY emp_no LIMIT 5;
|
||||
whereFieldOrComparison
|
||||
SELECT last_name l FROM "emp.emp" WHERE emp_no < 10003 OR emp_no = 10005 ORDER BY emp_no LIMIT 5;
|
||||
whereFieldWithOrder
|
||||
SELECT last_name l FROM "emp.emp" WHERE emp_no < 10003 ORDER BY emp_no;
|
||||
whereFieldWithExactMatchOnString
|
||||
SELECT last_name l FROM "emp.emp" WHERE emp_no < 10003 AND gender = 'M';
|
||||
whereFieldWithLikeMatch
|
||||
SELECT last_name l FROM "emp.emp" WHERE emp_no < 10003 AND last_name LIKE 'K%';
|
||||
whereFieldOnMatchWithAndAndOr
|
||||
SELECT last_name l FROM "emp.emp" WHERE emp_no < 10003 AND (gender = 'M' AND NOT FALSE OR last_name LIKE 'K%') ORDER BY emp_no;
|
8
sql-clients/jdbc/src/test/resources/h2-setup.sql
Normal file
8
sql-clients/jdbc/src/test/resources/h2-setup.sql
Normal file
@ -0,0 +1,8 @@
|
||||
CREATE TABLE "emp.emp" ("birth_date" TIMESTAMP,
|
||||
"emp_no" INT,
|
||||
"first_name" VARCHAR(50),
|
||||
"gender" VARCHAR(1),
|
||||
"hire_date" TIMESTAMP,
|
||||
"last_name" VARCHAR(50)
|
||||
)
|
||||
AS SELECT * FROM CSVREAD('classpath:/employees.csv');
|
@ -1,101 +0,0 @@
|
||||
"birth_date","emp_no","first_name","gender","hire_date","last_name"
|
||||
1953-09-02,10001,Georgi,M,1986-06-26,Facello
|
||||
1964-06-02,10002,Bezalel,F,1985-11-21,Simmel
|
||||
1959-12-03,10003,Parto,M,1986-08-28,Bamford
|
||||
1954-05-01,10004,Chirstian,M,1986-12-01,Koblick
|
||||
1955-01-21,10005,Kyoichi,M,1989-09-12,Maliniak
|
||||
1953-04-20,10006,Anneke,F,1989-06-02,Preusig
|
||||
1957-05-23,10007,Tzvetan,F,1989-02-10,Zielinski
|
||||
1958-02-19,10008,Saniya,M,1994-09-15,Kalloufi
|
||||
1952-04-19,10009,Sumant,F,1985-02-18,Peac
|
||||
1963-06-01,10010,Duangkaew,F,1989-08-24,Piveteau
|
||||
1953-11-07,10011,Mary,F,1990-01-22,Sluis
|
||||
1960-10-04,10012,Patricio,M,1992-12-18,Bridgland
|
||||
1963-06-07,10013,Eberhardt,M,1985-10-20,Terkki
|
||||
1956-02-12,10014,Berni,M,1987-03-11,Genin
|
||||
1959-08-19,10015,Guoxiang,M,1987-07-02,Nooteboom
|
||||
1961-05-02,10016,Kazuhito,M,1995-01-27,Cappelletti
|
||||
1958-07-06,10017,Cristinel,F,1993-08-03,Bouloucos
|
||||
1954-06-19,10018,Kazuhide,F,1987-04-03,Peha
|
||||
1953-01-23,10019,Lillian,M,1999-04-30,Haddadi
|
||||
1952-12-24,10020,Mayuko,M,1991-01-26,Warwick
|
||||
1960-02-20,10021,Ramzi,M,1988-02-10,Erde
|
||||
1952-07-08,10022,Shahaf,M,1995-08-22,Famili
|
||||
1953-09-29,10023,Bojan,F,1989-12-17,Montemayor
|
||||
1958-09-05,10024,Suzette,F,1997-05-19,Pettey
|
||||
1958-10-31,10025,Prasadram,M,1987-08-17,Heyers
|
||||
1953-04-03,10026,Yongqiao,M,1995-03-20,Berztiss
|
||||
1962-07-10,10027,Divier,F,1989-07-07,Reistad
|
||||
1963-11-26,10028,Domenick,M,1991-10-22,Tempesti
|
||||
1956-12-13,10029,Otmar,M,1985-11-20,Herbst
|
||||
1958-07-14,10030,Elvis,M,1994-02-17,Demeyer
|
||||
1959-01-27,10031,Karsten,M,1991-09-01,Joslin
|
||||
1960-08-09,10032,Jeong,F,1990-06-20,Reistad
|
||||
1956-11-14,10033,Arif,M,1987-03-18,Merlo
|
||||
1962-12-29,10034,Bader,M,1988-09-21,Swan
|
||||
1953-02-08,10035,Alain,M,1988-09-05,Chappelet
|
||||
1959-08-10,10036,Adamantios,M,1992-01-03,Portugali
|
||||
1963-07-22,10037,Pradeep,M,1990-12-05,Makrucki
|
||||
1960-07-20,10038,Huan,M,1989-09-20,Lortz
|
||||
1959-10-01,10039,Alejandro,M,1988-01-19,Brender
|
||||
1959-09-13,10040,Weiyi,F,1993-02-14,Meriste
|
||||
1959-08-27,10041,Uri,F,1989-11-12,Lenart
|
||||
1956-02-26,10042,Magy,F,1993-03-21,Stamatiou
|
||||
1960-09-19,10043,Yishay,M,1990-10-20,Tzvieli
|
||||
1961-09-21,10044,Mingsen,F,1994-05-21,Casley
|
||||
1957-08-14,10045,Moss,M,1989-09-02,Shanbhogue
|
||||
1960-07-23,10046,Lucien,M,1992-06-20,Rosenbaum
|
||||
1952-06-29,10047,Zvonko,M,1989-03-31,Nyanchama
|
||||
1963-07-11,10048,Florian,M,1985-02-24,Syrotiuk
|
||||
1961-04-24,10049,Basil,F,1992-05-04,Tramer
|
||||
1958-05-21,10050,Yinghua,M,1990-12-25,Dredge
|
||||
1953-07-28,10051,Hidefumi,M,1992-10-15,Caine
|
||||
1961-02-26,10052,Heping,M,1988-05-21,Nitsch
|
||||
1954-09-13,10053,Sanjiv,F,1986-02-04,Zschoche
|
||||
1957-04-04,10054,Mayumi,M,1995-03-13,Schueller
|
||||
1956-06-06,10055,Georgy,M,1992-04-27,Dredge
|
||||
1961-09-01,10056,Brendon,F,1990-02-01,Bernini
|
||||
1954-05-30,10057,Ebbe,F,1992-01-15,Callaway
|
||||
1954-10-01,10058,Berhard,M,1987-04-13,McFarlin
|
||||
1953-09-19,10059,Alejandro,F,1991-06-26,McAlpine
|
||||
1961-10-15,10060,Breannda,M,1987-11-02,Billingsley
|
||||
1962-10-19,10061,Tse,M,1985-09-17,Herber
|
||||
1961-11-02,10062,Anoosh,M,1991-08-30,Peyn
|
||||
1952-08-06,10063,Gino,F,1989-04-08,Leonhardt
|
||||
1959-04-07,10064,Udi,M,1985-11-20,Jansch
|
||||
1963-04-14,10065,Satosi,M,1988-05-18,Awdeh
|
||||
1952-11-13,10066,Kwee,M,1986-02-26,Schusler
|
||||
1953-01-07,10067,Claudi,M,1987-03-04,Stavenow
|
||||
1962-11-26,10068,Charlene,M,1987-08-07,Brattka
|
||||
1960-09-06,10069,Margareta,F,1989-11-05,Bierman
|
||||
1955-08-20,10070,Reuven,M,1985-10-14,Garigliano
|
||||
1958-01-21,10071,Hisao,M,1987-10-01,Lipner
|
||||
1952-05-15,10072,Hironoby,F,1988-07-21,Sidou
|
||||
1954-02-23,10073,Shir,M,1991-12-01,McClurg
|
||||
1955-08-28,10074,Mokhtar,F,1990-08-13,Bernatsky
|
||||
1960-03-09,10075,Gao,F,1987-03-19,Dolinsky
|
||||
1952-06-13,10076,Erez,F,1985-07-09,Ritzmann
|
||||
1964-04-18,10077,Mona,M,1990-03-02,Azuma
|
||||
1959-12-25,10078,Danel,F,1987-05-26,Mondadori
|
||||
1961-10-05,10079,Kshitij,F,1986-03-27,Gils
|
||||
1957-12-03,10080,Premal,M,1985-11-19,Baek
|
||||
1960-12-17,10081,Zhongwei,M,1986-10-30,Rosen
|
||||
1963-09-09,10082,Parviz,M,1990-01-03,Lortz
|
||||
1959-07-23,10083,Vishv,M,1987-03-31,Zockler
|
||||
1960-05-25,10084,Tuval,M,1995-12-15,Kalloufi
|
||||
1962-11-07,10085,Kenroku,M,1994-04-09,Malabarba
|
||||
1962-11-19,10086,Somnath,M,1990-02-16,Foote
|
||||
1959-07-23,10087,Xinglin,F,1986-09-08,Eugenio
|
||||
1954-02-25,10088,Jungsoon,F,1988-09-02,Syrzycki
|
||||
1963-03-21,10089,Sudharsan,F,1986-08-12,Flasterstein
|
||||
1961-05-30,10090,Kendra,M,1986-03-14,Hofting
|
||||
1955-10-04,10091,Amabile,M,1992-11-18,Gomatam
|
||||
1964-10-18,10092,Valdiodio,F,1989-09-22,Niizuma
|
||||
1964-06-11,10093,Sailaja,M,1996-11-05,Desikan
|
||||
1957-05-25,10094,Arumugam,F,1987-04-18,Ossenbruggen
|
||||
1965-01-03,10095,Hilari,M,1986-07-15,Morton
|
||||
1954-09-16,10096,Jayson,M,1990-01-14,Mandell
|
||||
1952-02-27,10097,Remzi,M,1990-09-15,Waschkowski
|
||||
1961-09-23,10098,Sreekrishna,F,1985-05-13,Servieres
|
||||
1956-05-25,10099,Valter,F,1988-10-18,Sullins
|
||||
1953-04-21,10100,Hironobu,F,1987-09-21,Haraldson
|
|
@ -1,9 +0,0 @@
|
||||
DROP TABLE IF EXISTS "emp.emp";
|
||||
CREATE TABLE "emp.emp" ("birth_date" TIMESTAMP WITH TIME ZONE,
|
||||
"emp_no" INT,
|
||||
"first_name" VARCHAR(50),
|
||||
"gender" VARCHAR(1),
|
||||
"hire_date" TIMESTAMP WITH TIME ZONE,
|
||||
"last_name" VARCHAR(50)
|
||||
)
|
||||
AS SELECT * FROM CSVREAD('classpath:/org/elasticsearch/sql/jdbc/integration/employees.csv');
|
@ -1,91 +0,0 @@
|
||||
//
|
||||
// Basic SELECT
|
||||
//
|
||||
|
||||
wildcardWithOrder
|
||||
SELECT * FROM "emp.emp" ORDER BY emp_no;
|
||||
column
|
||||
SELECT last_name FROM "emp.emp" ORDER BY emp_no;
|
||||
columnWithAlias
|
||||
SELECT last_name AS l FROM "emp.emp" ORDER BY emp_no;
|
||||
columnWithAliasNoAs
|
||||
SELECT last_name l FROM "emp.emp" ORDER BY emp_no;
|
||||
multipleColumnsNoAlias
|
||||
SELECT first_name, last_name FROM "emp.emp" ORDER BY emp_no;
|
||||
multipleColumnWithAliasWithAndWithoutAs
|
||||
SELECT first_name f, last_name AS l FROM "emp.emp" ORDER BY emp_no;
|
||||
|
||||
//
|
||||
// SELECT with LIMIT
|
||||
//
|
||||
|
||||
wildcardWithLimit
|
||||
SELECT * FROM "emp.emp" ORDER BY emp_no LIMIT 5;
|
||||
wildcardWithOrderWithLimit
|
||||
SELECT * FROM "emp.emp" ORDER BY emp_no LIMIT 5;
|
||||
columnWithLimit
|
||||
SELECT last_name FROM "emp.emp" ORDER BY emp_no LIMIT 5;
|
||||
columnWithAliasWithLimit
|
||||
SELECT last_name AS l FROM "emp.emp" ORDER BY emp_no LIMIT 5;
|
||||
columnWithAliasNoAsWithLimit
|
||||
SELECT last_name l FROM "emp.emp" ORDER BY emp_no LIMIT 5;
|
||||
multipleColumnsNoAliasWithLimit
|
||||
SELECT first_name, last_name FROM "emp.emp" ORDER BY emp_no LIMIT 5;
|
||||
multipleColumnWithAliasWithAndWithoutAsWithLimit
|
||||
SELECT first_name f, last_name AS l FROM "emp.emp" ORDER BY emp_no LIMIT 5;
|
||||
|
||||
|
||||
//
|
||||
// SELECT with CAST
|
||||
//
|
||||
//castWithLiteralToInt
|
||||
//SELECT CAST(1 AS INT);
|
||||
castOnColumnNumberToVarchar
|
||||
SELECT CAST(emp_no AS VARCHAR) AS emp_no_cast FROM "emp.emp" ORDER BY emp_no LIMIT 5;
|
||||
castOnColumnNumberToLong
|
||||
SELECT CAST(emp_no AS BIGINT) AS emp_no_cast FROM "emp.emp" ORDER BY emp_no LIMIT 5;
|
||||
castOnColumnNumberToSmallint
|
||||
SELECT CAST(emp_no AS SMALLINT) AS emp_no_cast FROM "emp.emp" ORDER BY emp_no LIMIT 5;
|
||||
castOnColumnNumberWithAliasToInt
|
||||
SELECT CAST(emp_no AS INT) AS emp_no_cast FROM "emp.emp" ORDER BY emp_no LIMIT 5;
|
||||
castOnColumnNumberToReal
|
||||
SELECT CAST(emp_no AS REAL) AS emp_no_cast FROM "emp.emp" ORDER BY emp_no LIMIT 5;
|
||||
castOnColumnNumberToDouble
|
||||
SELECT CAST(emp_no AS DOUBLE) AS emp_no_cast FROM "emp.emp" ORDER BY emp_no LIMIT 5;
|
||||
castOnColumnNumberToBoolean
|
||||
SELECT CAST(emp_no AS BOOL) AS emp_no_cast FROM "emp.emp" ORDER BY emp_no LIMIT 5;
|
||||
|
||||
|
||||
//
|
||||
// Filter
|
||||
//
|
||||
|
||||
whereFieldQuality
|
||||
SELECT last_name l FROM "emp.emp" WHERE emp_no = 10000 LIMIT 5;
|
||||
whereFieldLessThan
|
||||
SELECT last_name l FROM "emp.emp" WHERE emp_no < 10003 ORDER BY emp_no LIMIT 5;
|
||||
whereFieldAndComparison
|
||||
SELECT last_name l FROM "emp.emp" WHERE emp_no > 10000 AND emp_no < 10005 ORDER BY emp_no LIMIT 5;
|
||||
whereFieldOrComparison
|
||||
SELECT last_name l FROM "emp.emp" WHERE emp_no < 10003 OR emp_no = 10005 ORDER BY emp_no LIMIT 5;
|
||||
whereFieldWithOrder
|
||||
SELECT last_name l FROM "emp.emp" WHERE emp_no < 10003 ORDER BY emp_no;
|
||||
whereFieldWithExactMatchOnString
|
||||
SELECT last_name l FROM "emp.emp" WHERE emp_no < 10003 AND gender = 'M';
|
||||
whereFieldWithLikeMatch
|
||||
SELECT last_name l FROM "emp.emp" WHERE emp_no < 10003 AND last_name LIKE 'K%';
|
||||
whereFieldOnMatchWithAndAndOr
|
||||
SELECT last_name l FROM "emp.emp" WHERE emp_no < 10003 AND (gender = 'M' AND NOT FALSE OR last_name LIKE 'K%') ORDER BY emp_no;
|
||||
|
||||
|
||||
//
|
||||
// Group-By
|
||||
//
|
||||
|
||||
groupByGender
|
||||
SELECT gender g FROM "emp.emp" GROUP BY gender;
|
||||
groupByWithWhereClause
|
||||
SELECT gender g FROM "emp.emp" WHERE emp_no < 10020 GROUP BY gender;
|
||||
// investigate
|
||||
//groupByWithLimit
|
||||
//SELECT gender g FROM "emp.emp" WHERE emp_no < 10010 GROUP BY g LIMIT 1;
|
Loading…
x
Reference in New Issue
Block a user