Merge branch 'feature/sql' of github.com:elastic/x-pack-elasticsearch into feature/sql

Original commit: elastic/x-pack-elasticsearch@34d536c5e1
This commit is contained in:
Nik Everett 2017-07-05 08:15:11 -04:00
commit 9d83eccf27
25 changed files with 253 additions and 303 deletions

View File

@ -64,7 +64,7 @@ dependencies {
// watcher deps
compile 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:r239'
compile 'com.google.guava:guava:16.0.1' // needed by watcher for the html sanitizer and security tests for jimfs
compile 'com.google.guava:guava:18.0' // needed by watcher for the html sanitizer and security tests for jimfs
compile 'com.sun.mail:javax.mail:1.5.6'
// HACK: java 9 removed javax.activation from the default modules, so instead of trying to add modules, which would have
// to be conditionalized for java 8/9, we pull in the classes directly

View File

@ -12,7 +12,6 @@ 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;
@ -30,7 +29,6 @@ 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;
import static java.sql.Types.VARCHAR;
@ -169,8 +167,9 @@ public abstract class ProtoUtils {
case LONGVARCHAR:
result = in.readUTF();
break;
// NB: date/time is kept in its raw form since the JdbcDriver has to do calendar/timezone conversion anyway and thus the long value is relevant
case TIMESTAMP:
result = new Timestamp(in.readLong());
result = in.readLong();
break;
default:
throw new IOException("Don't know how to read type [" + type + " / " + JDBCType.valueOf(type) + "]");

View File

@ -45,7 +45,7 @@ public class JdbcConfiguration extends ConnectionConfiguration {
static final String DEBUG_OUTPUT_DEFAULT = "err";
static final String TIME_ZONE = "time_zone";
static final String TIME_ZONE_DEFAULT = "UTC";
static final String TIME_ZONE_DEFAULT = "UTC_CALENDAR";
private static final List<String> KNOWN_OPTIONS = Arrays.asList(DEBUG, DEBUG_OUTPUT, TIME_ZONE);

View File

@ -39,7 +39,7 @@ import static java.lang.String.format;
class JdbcResultSet implements ResultSet, JdbcWrapper {
// temporary calendar instance (per connection) used for normalizing the date and time
// even though the info is already in UTC format, JDBC 3.0 requires java.sql.Time to have its date
// even though the info is already in UTC_CALENDAR format, JDBC 3.0 requires java.sql.Time to have its date
// removed (set to Jan 01 1970) and java.sql.Date to have its HH:mm:ss component removed
// instead of dealing with longs, a Calendar object is used instead
private final Calendar DEFAULT_CALENDAR = TypeConverter.defaultCalendar();

View File

@ -51,7 +51,7 @@ import static java.util.Calendar.YEAR;
abstract class TypeConverter {
static final Calendar UTC_CALENDAR = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT);
static final Calendar UTC_CALENDAR = Calendar.getInstance(TimeZone.getTimeZone("UTC_CALENDAR"), Locale.ROOT);
private static final long DAY_IN_MILLIS = 60 * 60 * 24;
@ -182,7 +182,7 @@ abstract class TypeConverter {
case TIMESTAMP:
result = v;
break;
// since the date is already in UTC just do calendar math
// since the date is already in UTC_CALENDAR just do calendar math
case DATE:
result = new Date(utcMillisRemoveTime(((Long) v).longValue()));
break;

View File

@ -5,13 +5,16 @@
*/
package org.elasticsearch.xpack.sql.jdbc.net.client;
import java.lang.reflect.Array;
import java.util.List;
import org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcException;
import org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcUtils;
import org.elasticsearch.xpack.sql.jdbc.net.protocol.ColumnInfo;
import java.lang.reflect.Array;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.List;
// Stores a page of data in a columnar-format since:
// * the structure does not change
// * array allocation can be quite efficient
@ -72,6 +75,9 @@ public class Page {
for (int i = 0; i < columnInfo.size(); i++) {
Class<?> types = JdbcUtils.classOf(columnInfo.get(i).type);
if (types == Timestamp.class || types == Date.class || types == Time.class) {
types = Long.class;
}
data[i] = (Object[]) Array.newInstance(types, dataSize);
}

View File

@ -10,7 +10,6 @@ import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.common.CheckedSupplier;
import org.elasticsearch.xpack.sql.jdbc.framework.CsvSpecTableReader;
import org.elasticsearch.xpack.sql.jdbc.framework.SpecBaseIntegrationTestCase;
import org.elasticsearch.xpack.sql.jdbc.framework.SpecBaseIntegrationTestCase.Parser;
import org.elasticsearch.xpack.sql.util.CollectionUtils;
import org.junit.AfterClass;
import org.junit.Test;
@ -54,7 +53,7 @@ public class CsvSpecIntegrationTest extends SpecBaseIntegrationTestCase {
};
}
@ParametersFactory(shuffle = false, argumentFormatting = "name=%1s")
@ParametersFactory(shuffle = false, argumentFormatting = PARAM_FORMATTNG)
public static List<Object[]> readScriptSpec() throws Exception {
CsvSpecParser parser = new CsvSpecParser();
return CollectionUtils.combine(
@ -85,7 +84,7 @@ public class CsvSpecIntegrationTest extends SpecBaseIntegrationTestCase {
throw reworkException(new AssertionError(errorMessage(ae), ae.getCause()));
}
} catch (Throwable th) {
throw new RuntimeException(errorMessage(th), th);
throw reworkException(th);
}
}

View File

@ -18,6 +18,7 @@ import static org.junit.Assert.assertNotNull;
public class EsJdbcServer extends ExternalResource implements CheckedSupplier<Connection, SQLException> {
private Client client;
private JdbcHttpServer server;
private String jdbcUrl;
private JdbcDriver driver;
@ -36,7 +37,8 @@ public class EsJdbcServer extends ExternalResource implements CheckedSupplier<Co
@Override
protected void before() throws Throwable {
server = new JdbcHttpServer(TestUtils.client());
client = TestUtils.client();
server = new JdbcHttpServer(client);
driver = new JdbcDriver();
server.start(0);
@ -47,6 +49,8 @@ public class EsJdbcServer extends ExternalResource implements CheckedSupplier<Co
@Override
protected void after() {
client.close();
client = null;
server.stop();
server = null;

View File

@ -8,11 +8,7 @@ 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 +69,10 @@ 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()));
// NOCOMMIT look at ResultSet.getTimestamp(int, Calendar)
assertEquals(getTime(expected, column), getTime(actual, column));
}
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 +84,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 rs.getTime(column, TestUtils.UTC_CALENDAR).getTime();
}
}

View File

@ -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

View File

@ -12,6 +12,7 @@ import org.junit.rules.ExternalResource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import java.util.TimeZone;
public class LocalH2 extends ExternalResource implements CheckedSupplier<Connection, SQLException> {
@ -32,15 +33,21 @@ public class LocalH2 extends ExternalResource implements CheckedSupplier<Connect
* result set metadata which is what most DBs do except
* for MySQL and, by default, H2. Our jdbc driver does it.
*/
// http://www.h2database.com/html/features.html#in_memory_databases
public LocalH2() {
this.url = "jdbc:H2:mem:essql;DATABASE_TO_UPPER=false;ALIAS_COLUMN_NAME=true";
this.url = "jdbc:h2:mem:essql;DATABASE_TO_UPPER=false;ALIAS_COLUMN_NAME=true";
}
@Override
protected void before() throws Throwable {
keepAlive = get();
//NOCOMMIT: check timezone issue
keepAlive.createStatement().executeQuery("RUNSCRIPT FROM 'classpath:h2-setup.sql'");
TimeZone tz = TimeZone.getDefault();
try {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
keepAlive.createStatement().execute("RUNSCRIPT FROM 'classpath:/h2-setup.sql'");
} finally {
TimeZone.setDefault(tz);
}
}
@Override

View File

@ -7,7 +7,6 @@ package org.elasticsearch.xpack.sql.jdbc.framework;
import org.elasticsearch.common.Strings;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcDriver;
import org.junit.Assert;
import org.junit.ClassRule;
@ -24,10 +23,8 @@ import java.util.Map;
import static java.lang.String.format;
public abstract class SpecBaseIntegrationTestCase extends ESTestCase {
static {
// Initialize the jdbc driver
JdbcDriver.jdbcMajorVersion();
}
protected static final String PARAM_FORMATTNG = "%0$s.test%2$s";
protected final String groupName;
protected final String testName;
@ -37,6 +34,15 @@ public abstract class SpecBaseIntegrationTestCase extends ESTestCase {
@ClassRule
public static EsJdbcServer ES = new EsJdbcServer();
//
// This typically is uncommented when starting up a new instance of ES
//
// @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) {
this.groupName = groupName;
this.testName = testName;
@ -52,7 +58,7 @@ public abstract class SpecBaseIntegrationTestCase extends ESTestCase {
StackTraceElement[] stackTrace = th.getStackTrace();
StackTraceElement[] redone = new StackTraceElement[stackTrace.length + 1];
System.arraycopy(stackTrace, 0, redone, 1, stackTrace.length);
redone[0] = new StackTraceElement(getClass().getName(), groupName + "." + testName, source.getFileName().toString(), lineNumber);
redone[0] = new StackTraceElement(getClass().getName(), groupName + ".test" + testName, source.getFileName().toString(), lineNumber);
th.setStackTrace(redone);
return th;
@ -62,10 +68,12 @@ public abstract class SpecBaseIntegrationTestCase extends ESTestCase {
// spec reader
//
// returns testName, its line location, its source and the custom object (based on each test parser)
// returns groupName, testName, its line location, its source and the custom object (based on each test parser)
protected static List<Object[]> readScriptSpec(String url, Parser parser) throws Exception {
Path source = Paths.get(TestUtils.class.getResource(url).toURI());
String groupName = source.getFileName().toString();
String fileName = source.getFileName().toString();
int dot = fileName.indexOf(".");
String groupName = dot > 0 ? fileName.substring(0, dot) : fileName;
List<String> lines = Files.readAllLines(source);

View File

@ -26,26 +26,18 @@ import java.net.InetAddress;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static org.junit.Assert.assertEquals;
public abstract class TestUtils {
static final DateTimeFormatter UTC_FORMATTER = DateTimeFormatter.ISO_DATE_TIME
.withLocale(Locale.ROOT)
.withZone(ZoneId.of("UTC"));
static final Calendar UTC_CALENDAR = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
public static RestClient restClient(String host, int port) {
return RestClient.builder(new HttpHost(host, port)).build();
@ -76,7 +68,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();
@ -90,7 +83,7 @@ public abstract class TestUtils {
createIndex.endObject();
}
createIndex.endObject().endObject();
client.performRequest("PUT", "/emp", emptyMap(), new StringEntity(createIndex.string(), ContentType.APPLICATION_JSON));
client.performRequest("PUT", "/test_emp", emptyMap(), new StringEntity(createIndex.string(), ContentType.APPLICATION_JSON));
StringBuilder bulk = new StringBuilder();
csvToLines("employees", (titles, fields) -> {
@ -104,53 +97,9 @@ public abstract class TestUtils {
}
bulk.append("}\n");
});
client.performRequest("POST", "/emp/emp/_bulk", singletonMap("refresh", "true"), new StringEntity(bulk.toString(), ContentType.APPLICATION_JSON));
client.performRequest("POST", "/test_emp/emp/_bulk", singletonMap("refresh", "true"), new StringEntity(bulk.toString(), ContentType.APPLICATION_JSON));
}
/**
* Fill the H2 database. Note that we have to parse the CSV ourselves
* because H2 interprets the CSV using the default locale which is
* randomized by the testing framework. Because some locales (th-TH,
* for example) parse dates in very different ways we parse using the
* root locale.
*/
public static void loadDatesetInH2(Connection h2) throws Exception {
csvToLines("employees", (titles, fields) -> {
StringBuilder insert = new StringBuilder("INSERT INTO \"emp.emp\" (");
for (int t = 0; t < titles.size(); t++) {
if (t != 0) {
insert.append(',');
}
insert.append('"').append(titles.get(t)).append('"');
}
insert.append(") VALUES (");
for (int t = 0; t < titles.size(); t++) {
if (t != 0) {
insert.append(',');
}
insert.append('?');
}
insert.append(')');
PreparedStatement s = h2.prepareStatement(insert.toString());
for (int t = 0; t < titles.size(); t++) {
String field = fields.get(t);
if (titles.get(t).endsWith("date")) {
/* Dates need special handling because H2 uses the default local for
* parsing which doesn't work because Elasticsearch always uses
* the "root" locale. This mismatch would cause the test to fail
* all the time in places like Thailand. Luckily Elasticsearch's
* randomized testing sometimes randomly pretends you are in
* Thailand and caught this.... */
s.setTimestamp(t + 1, new Timestamp(Instant.from(UTC_FORMATTER.parse(field)).toEpochMilli()));
} else {
s.setString(t + 1, field);
}
}
assertEquals(1, s.executeUpdate());
});
}
private static void csvToLines(String name, CheckedBiConsumer<List<String>, List<String>, Exception> consumeLine) throws Exception {
String location = "/" + name + ".csv";
URL dataSet = SqlSpecIntegrationTest.class.getResource(location);

View File

@ -5,12 +5,10 @@
*/
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;
import org.elasticsearch.xpack.sql.jdbc.framework.SpecBaseIntegrationTestCase;
import org.elasticsearch.xpack.sql.jdbc.framework.SpecBaseIntegrationTestCase.Parser;
import org.elasticsearch.xpack.sql.util.CollectionUtils;
import org.junit.ClassRule;
import org.junit.Test;
@ -32,7 +30,7 @@ public class SqlSpecIntegrationTest extends SpecBaseIntegrationTestCase {
@ClassRule
public static LocalH2 H2 = new LocalH2();
@ParametersFactory(shuffle = false, argumentFormatting = "name=%1s")
@ParametersFactory(shuffle = false, argumentFormatting = PARAM_FORMATTNG)
public static List<Object[]> readScriptSpec() throws Exception {
SqlSpecParser parser = new SqlSpecParser();
return CollectionUtils.combine(
@ -54,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 +71,7 @@ public class SqlSpecIntegrationTest extends SpecBaseIntegrationTestCase {
throw reworkException(new AssertionError(errorMessage(ae), ae.getCause()));
}
} catch (Throwable th) {
throw reworkException(new RuntimeException(errorMessage(th)));
throw reworkException(th);
}
}

View File

@ -3,33 +3,33 @@
//
groupByOnText
SELECT gender g FROM "emp.emp" GROUP BY gender;
SELECT gender g FROM "test_emp.emp" GROUP BY gender;
groupByOnTextWithWhereClause
SELECT gender g FROM "emp.emp" WHERE emp_no < 10020 GROUP BY gender;
SELECT gender g FROM "test_emp.emp" WHERE emp_no < 10020 GROUP BY gender;
groupByOnTextWithWhereAndLimit
SELECT gender g FROM "emp.emp" WHERE emp_no < 10020 GROUP BY gender LIMIT 1;
SELECT gender g FROM "test_emp.emp" WHERE emp_no < 10020 GROUP BY gender LIMIT 1;
groupByOnTextOnAlias
SELECT gender g FROM "emp.emp" WHERE emp_no < 10020 GROUP BY g;
SELECT gender g FROM "test_emp.emp" WHERE emp_no < 10020 GROUP BY g;
groupByOnTextOnAliasOrderDesc
SELECT gender g FROM "emp.emp" WHERE emp_no < 10020 GROUP BY g ORDER BY g DESC;
SELECT gender g FROM "test_emp.emp" WHERE emp_no < 10020 GROUP BY g ORDER BY g DESC;
groupByOnDate
SELECT birth_date b FROM "emp.emp" GROUP BY birth_date ORDER BY birth_date DESC;
SELECT birth_date b FROM "test_emp.emp" GROUP BY birth_date ORDER BY birth_date DESC;
groupByOnDateWithWhereClause
SELECT birth_date b FROM "emp.emp" WHERE emp_no < 10020 GROUP BY birth_date ORDER BY birth_date DESC;
SELECT birth_date b FROM "test_emp.emp" WHERE emp_no < 10020 GROUP BY birth_date ORDER BY birth_date DESC;
groupByOnDateWithWhereAndLimit
SELECT birth_date b FROM "emp.emp" WHERE emp_no < 10020 GROUP BY birth_date ORDER BY birth_date DESC LIMIT 1;
SELECT birth_date b FROM "test_emp.emp" WHERE emp_no < 10020 GROUP BY birth_date ORDER BY birth_date DESC LIMIT 1;
groupByOnDateOnAlias
SELECT birth_date b FROM "emp.emp" WHERE emp_no < 10020 GROUP BY b ORDER BY birth_date DESC;
SELECT birth_date b FROM "test_emp.emp" WHERE emp_no < 10020 GROUP BY b ORDER BY birth_date DESC;
groupByOnNumber
SELECT emp_no e FROM "emp.emp" GROUP BY emp_no ORDER BY emp_no DESC;
SELECT emp_no e FROM "test_emp.emp" GROUP BY emp_no ORDER BY emp_no DESC;
groupByOnNumberWithWhereClause
SELECT emp_no e FROM "emp.emp" WHERE emp_no < 10020 GROUP BY emp_no ORDER BY emp_no DESC;
SELECT emp_no e FROM "test_emp.emp" WHERE emp_no < 10020 GROUP BY emp_no ORDER BY emp_no DESC;
groupByOnNumberWithWhereAndLimit
SELECT emp_no e FROM "emp.emp" WHERE emp_no < 10020 GROUP BY emp_no ORDER BY emp_no DESC LIMIT 1;
SELECT emp_no e FROM "test_emp.emp" WHERE emp_no < 10020 GROUP BY emp_no ORDER BY emp_no DESC LIMIT 1;
groupByOnNumberOnAlias
SELECT emp_no e FROM "emp.emp" WHERE emp_no < 10020 GROUP BY e ORDER BY emp_no DESC;
SELECT emp_no e FROM "test_emp.emp" WHERE emp_no < 10020 GROUP BY e ORDER BY emp_no DESC;
//
// Aggregate Functions
@ -37,160 +37,160 @@ SELECT emp_no e FROM "emp.emp" WHERE emp_no < 10020 GROUP BY e ORDER BY emp_no D
// COUNT
aggCountImplicit
SELECT COUNT(*) c FROM "emp.emp";
SELECT COUNT(*) c FROM "test_emp.emp";
aggCountImplicitWithCast
SELECT CAST(COUNT(*) AS INT) c FROM "emp.emp";
SELECT CAST(COUNT(*) AS INT) c FROM "test_emp.emp";
aggCountImplicitWithConstant
SELECT COUNT(1) FROM "emp.emp";
SELECT COUNT(1) FROM "test_emp.emp";
aggCountImplicitWithConstantAndFilter
SELECT COUNT(1) FROM "emp.emp" WHERE emp_no < 10010;
SELECT COUNT(1) FROM "test_emp.emp" WHERE emp_no < 10010;
aggCountAliasAndWhereClause
SELECT gender g, COUNT(*) c FROM "emp.emp" WHERE emp_no < 10020 GROUP BY gender;
SELECT gender g, COUNT(*) c FROM "test_emp.emp" WHERE emp_no < 10020 GROUP BY gender;
aggCountAliasAndWhereClauseAndLimit
SELECT gender g, COUNT(*) c FROM "emp.emp" WHERE emp_no < 10020 GROUP BY gender LIMIT 1;
SELECT gender g, COUNT(*) c FROM "test_emp.emp" WHERE emp_no < 10020 GROUP BY gender LIMIT 1;
aggCountAliasWithCastAndFilter
SELECT gender g, CAST(COUNT(*) AS INT) c FROM "emp.emp" WHERE emp_no < 10020 GROUP BY gender;
SELECT gender g, CAST(COUNT(*) AS INT) c FROM "test_emp.emp" WHERE emp_no < 10020 GROUP BY gender;
aggCountWithAlias
SELECT gender g, COUNT(*) c FROM "emp.emp" GROUP BY g;
SELECT gender g, COUNT(*) c FROM "test_emp.emp" GROUP BY g;
// Conditional COUNT
aggCountAndHaving
SELECT gender g, COUNT(*) c FROM "emp.emp" GROUP BY g HAVING COUNT(*) > 10;
SELECT gender g, COUNT(*) c FROM "test_emp.emp" GROUP BY g HAVING COUNT(*) > 10;
aggCountOnColumnAndHaving
SELECT gender g, COUNT(gender) c FROM "emp.emp" GROUP BY g HAVING COUNT(gender) > 10;
SELECT gender g, COUNT(gender) c FROM "test_emp.emp" GROUP BY g HAVING COUNT(gender) > 10;
// NOT supported yet since Having introduces a new agg
//aggCountOnColumnAndWildcardAndHaving
//SELECT gender g, COUNT(*) c FROM "emp.emp" GROUP BY g HAVING COUNT(gender) > 10;
//SELECT gender g, COUNT(*) c FROM "test_emp.emp" GROUP BY g HAVING COUNT(gender) > 10;
aggCountAndHavingOnAlias
SELECT gender g, COUNT(*) c FROM "emp.emp" GROUP BY g HAVING c > 10;
SELECT gender g, COUNT(*) c FROM "test_emp.emp" GROUP BY g HAVING c > 10;
aggCountOnColumnAndHavingOnAlias
SELECT gender g, COUNT(gender) c FROM "emp.emp" GROUP BY g HAVING c > 10;
SELECT gender g, COUNT(gender) c FROM "test_emp.emp" GROUP BY g HAVING c > 10;
aggCountOnColumnAndMultipleHaving
SELECT gender g, COUNT(gender) c FROM "emp.emp" GROUP BY g HAVING c > 10 AND c < 70;
SELECT gender g, COUNT(gender) c FROM "test_emp.emp" GROUP BY g HAVING c > 10 AND c < 70;
aggCountOnColumnAndMultipleHavingWithLimit
SELECT gender g, COUNT(gender) c FROM "emp.emp" GROUP BY g HAVING c > 10 AND c < 70 LIMIT 1;
SELECT gender g, COUNT(gender) c FROM "test_emp.emp" GROUP BY g HAVING c > 10 AND c < 70 LIMIT 1;
aggCountOnColumnAndHavingOnAliasAndFunction
SELECT gender g, COUNT(gender) c FROM "emp.emp" GROUP BY g HAVING c > 10 AND COUNT(gender) < 70;
SELECT gender g, COUNT(gender) c FROM "test_emp.emp" GROUP BY g HAVING c > 10 AND COUNT(gender) < 70;
// NOT supported yet since Having introduces a new agg
//aggCountOnColumnAndHavingOnAliasAndFunctionWildcard -> COUNT(*/1) vs COUNT(gender)
//SELECT gender g, COUNT(gender) c FROM "emp.emp" GROUP BY g HAVING c > 10 AND COUNT(*) < 70;
//SELECT gender g, COUNT(gender) c FROM "test_emp.emp" GROUP BY g HAVING c > 10 AND COUNT(*) < 70;
//aggCountOnColumnAndHavingOnAliasAndFunctionConstant
//SELECT gender g, COUNT(gender) c FROM "emp.emp" GROUP BY g HAVING c > 10 AND COUNT(1) < 70;
//SELECT gender g, COUNT(gender) c FROM "test_emp.emp" GROUP BY g HAVING c > 10 AND COUNT(1) < 70;
// MIN
aggMinImplicit
SELECT MIN(emp_no) m FROM "emp.emp";
SELECT MIN(emp_no) m FROM "test_emp.emp";
aggMinImplicitWithCast
SELECT CAST(MIN(emp_no) AS SMALLINT) m FROM "emp.emp";
SELECT CAST(MIN(emp_no) AS SMALLINT) m FROM "test_emp.emp";
aggMin
SELECT gender g, MIN(emp_no) m FROM "emp.emp" GROUP BY gender;
SELECT gender g, MIN(emp_no) m FROM "test_emp.emp" GROUP BY gender;
aggMinWithCast
SELECT CAST(MIN(emp_no) AS SMALLINT) m FROM "emp.emp" GROUP BY gender;
SELECT CAST(MIN(emp_no) AS SMALLINT) m FROM "test_emp.emp" GROUP BY gender;
aggMinAndCount
SELECT MIN(emp_no) m, COUNT(1) c FROM "emp.emp" GROUP BY gender;
SELECT MIN(emp_no) m, COUNT(1) c FROM "test_emp.emp" GROUP BY gender;
aggMinAndCountWithFilter
SELECT MIN(emp_no) m, COUNT(1) c FROM "emp.emp" WHERE emp_no < 10020 GROUP BY gender ;
SELECT MIN(emp_no) m, COUNT(1) c FROM "test_emp.emp" WHERE emp_no < 10020 GROUP BY gender ;
aggMinAndCountWithFilterAndLimit
SELECT MIN(emp_no) m, COUNT(1) c FROM "emp.emp" WHERE emp_no < 10020 GROUP BY gender LIMIT 1;
SELECT MIN(emp_no) m, COUNT(1) c FROM "test_emp.emp" WHERE emp_no < 10020 GROUP BY gender LIMIT 1;
aggMinWithCastAndFilter
SELECT gender g, CAST(MIN(emp_no) AS SMALLINT) m, COUNT(1) c FROM "emp.emp" WHERE emp_no < 10020 GROUP BY gender;
SELECT gender g, CAST(MIN(emp_no) AS SMALLINT) m, COUNT(1) c FROM "test_emp.emp" WHERE emp_no < 10020 GROUP BY gender;
aggMinWithAlias
SELECT gender g, MIN(emp_no) m FROM "emp.emp" GROUP BY g;
SELECT gender g, MIN(emp_no) m FROM "test_emp.emp" GROUP BY g;
// Conditional MIN
aggMinWithHaving
SELECT gender g, MIN(emp_no) m FROM "emp.emp" GROUP BY g HAVING MIN(emp_no) > 10;
SELECT gender g, MIN(emp_no) m FROM "test_emp.emp" GROUP BY g HAVING MIN(emp_no) > 10;
aggMinWithHavingOnAlias
SELECT gender g, MIN(emp_no) m FROM "emp.emp" GROUP BY g HAVING m > 10;
SELECT gender g, MIN(emp_no) m FROM "test_emp.emp" GROUP BY g HAVING m > 10;
aggMinWithMultipleHaving
SELECT gender g, MIN(emp_no) m FROM "emp.emp" GROUP BY g HAVING m > 10 AND m < 99999;
SELECT gender g, MIN(emp_no) m FROM "test_emp.emp" GROUP BY g HAVING m > 10 AND m < 99999;
aggMinWithMultipleHavingWithLimit
SELECT gender g, MIN(emp_no) m FROM "emp.emp" GROUP BY g HAVING m > 10 AND m < 99999 LIMIT 1;
SELECT gender g, MIN(emp_no) m FROM "test_emp.emp" GROUP BY g HAVING m > 10 AND m < 99999 LIMIT 1;
aggMinWithMultipleHavingOnAliasAndFunction
SELECT gender g, MIN(emp_no) m FROM "emp.emp" GROUP BY g HAVING m > 10 AND MIN(emp_no) < 99999;
SELECT gender g, MIN(emp_no) m FROM "test_emp.emp" GROUP BY g HAVING m > 10 AND MIN(emp_no) < 99999;
// MAX
aggMaxImplicit
SELECT MAX(emp_no) c FROM "emp.emp";
SELECT MAX(emp_no) c FROM "test_emp.emp";
aggMaxImplicitWithCast
SELECT CAST(MAX(emp_no) AS SMALLINT) c FROM "emp.emp";
SELECT CAST(MAX(emp_no) AS SMALLINT) c FROM "test_emp.emp";
aggMax
SELECT gender g, MAX(emp_no) m FROM "emp.emp" GROUP BY gender ;
SELECT gender g, MAX(emp_no) m FROM "test_emp.emp" GROUP BY gender ;
aggMaxWithCast
SELECT gender g, CAST(MAX(emp_no) AS SMALLINT) m FROM "emp.emp" GROUP BY gender ;
SELECT gender g, CAST(MAX(emp_no) AS SMALLINT) m FROM "test_emp.emp" GROUP BY gender ;
aggMaxAndCount
SELECT MAX(emp_no) m, COUNT(1) c FROM "emp.emp" GROUP BY gender;
SELECT MAX(emp_no) m, COUNT(1) c FROM "test_emp.emp" GROUP BY gender;
aggMaxAndCountWithFilter
SELECT gender g, MAX(emp_no) m, COUNT(1) c FROM "emp.emp" WHERE emp_no > 10000 GROUP BY gender;
SELECT gender g, MAX(emp_no) m, COUNT(1) c FROM "test_emp.emp" WHERE emp_no > 10000 GROUP BY gender;
aggMaxAndCountWithFilterAndLimit
SELECT gender g, MAX(emp_no) m, COUNT(1) c FROM "emp.emp" WHERE emp_no > 10000 GROUP BY gender LIMIT 1;
SELECT gender g, MAX(emp_no) m, COUNT(1) c FROM "test_emp.emp" WHERE emp_no > 10000 GROUP BY gender LIMIT 1;
aggMaxWithAlias
SELECT gender g, MAX(emp_no) m FROM "emp.emp" GROUP BY g;
SELECT gender g, MAX(emp_no) m FROM "test_emp.emp" GROUP BY g;
// Conditional MAX
aggMaxWithHaving
SELECT gender g, MAX(emp_no) m FROM "emp.emp" GROUP BY g HAVING MAX(emp_no) > 10;
SELECT gender g, MAX(emp_no) m FROM "test_emp.emp" GROUP BY g HAVING MAX(emp_no) > 10;
aggMaxWithHavingOnAlias
SELECT gender g, MAX(emp_no) m FROM "emp.emp" GROUP BY g HAVING m > 10;
SELECT gender g, MAX(emp_no) m FROM "test_emp.emp" GROUP BY g HAVING m > 10;
aggMaxWithMultipleHaving
SELECT gender g, MAX(emp_no) m FROM "emp.emp" GROUP BY g HAVING m > 10 AND m < 99999;
SELECT gender g, MAX(emp_no) m FROM "test_emp.emp" GROUP BY g HAVING m > 10 AND m < 99999;
aggMaxWithMultipleHavingWithLimit
SELECT gender g, MAX(emp_no) m FROM "emp.emp" GROUP BY g HAVING m > 10 AND m < 99999 LIMIT 1;
SELECT gender g, MAX(emp_no) m FROM "test_emp.emp" GROUP BY g HAVING m > 10 AND m < 99999 LIMIT 1;
aggMaxWithMultipleHavingOnAliasAndFunction
SELECT gender g, MAX(emp_no) m FROM "emp.emp" GROUP BY g HAVING m > 10 AND MAX(emp_no) < 99999;
SELECT gender g, MAX(emp_no) m FROM "test_emp.emp" GROUP BY g HAVING m > 10 AND MAX(emp_no) < 99999;
// SUM
aggSumImplicitWithCast
SELECT CAST(SUM(emp_no) AS BIGINT) s FROM "emp.emp";
SELECT CAST(SUM(emp_no) AS BIGINT) s FROM "test_emp.emp";
aggSumWithCast
SELECT gender g, CAST(SUM(emp_no) AS BIGINT) s FROM "emp.emp" GROUP BY gender;
SELECT gender g, CAST(SUM(emp_no) AS BIGINT) s FROM "test_emp.emp" GROUP BY gender;
aggSumWithCastAndCount
SELECT gender g, CAST(SUM(emp_no) AS BIGINT) s, COUNT(1) c FROM "emp.emp" GROUP BY gender;
SELECT gender g, CAST(SUM(emp_no) AS BIGINT) s, COUNT(1) c FROM "test_emp.emp" GROUP BY gender;
aggSumWithCastAndCountWithFilter
SELECT gender g, CAST(SUM(emp_no) AS BIGINT) s, COUNT(1) c FROM "emp.emp" WHERE emp_no > 10000 GROUP BY gender;
SELECT gender g, CAST(SUM(emp_no) AS BIGINT) s, COUNT(1) c FROM "test_emp.emp" WHERE emp_no > 10000 GROUP BY gender;
aggSumWithCastAndCountWithFilterAndLimit
SELECT gender g, CAST(SUM(emp_no) AS BIGINT) s, COUNT(1) c FROM "emp.emp" WHERE emp_no > 10000 GROUP BY gender LIMIT 1;
SELECT gender g, CAST(SUM(emp_no) AS BIGINT) s, COUNT(1) c FROM "test_emp.emp" WHERE emp_no > 10000 GROUP BY gender LIMIT 1;
aggSumWithAlias
SELECT gender g, CAST(SUM(emp_no) AS BIGINT) s FROM "emp.emp" GROUP BY g;
SELECT gender g, CAST(SUM(emp_no) AS BIGINT) s FROM "test_emp.emp" GROUP BY g;
// Conditional SUM
aggSumWithHaving
SELECT gender g, CAST(SUM(emp_no) AS INT) s FROM "emp.emp" GROUP BY g HAVING SUM(emp_no) > 10;
SELECT gender g, CAST(SUM(emp_no) AS INT) s FROM "test_emp.emp" GROUP BY g HAVING SUM(emp_no) > 10;
aggSumWithHavingOnAlias
SELECT gender g, CAST(SUM(emp_no) AS INT) s FROM "emp.emp" GROUP BY g HAVING s > 10;
SELECT gender g, CAST(SUM(emp_no) AS INT) s FROM "test_emp.emp" GROUP BY g HAVING s > 10;
aggSumWithMultipleHaving
SELECT gender g, CAST(SUM(emp_no) AS INT) s FROM "emp.emp" GROUP BY g HAVING s > 10 AND s < 10000000;
SELECT gender g, CAST(SUM(emp_no) AS INT) s FROM "test_emp.emp" GROUP BY g HAVING s > 10 AND s < 10000000;
aggSumWithMultipleHavingWithLimit
SELECT gender g, CAST(SUM(emp_no) AS INT) s FROM "emp.emp" GROUP BY g HAVING s > 10 AND s < 10000000 LIMIT 1;
SELECT gender g, CAST(SUM(emp_no) AS INT) s FROM "test_emp.emp" GROUP BY g HAVING s > 10 AND s < 10000000 LIMIT 1;
aggSumWithMultipleHavingOnAliasAndFunction
SELECT gender g, CAST(SUM(emp_no) AS INT) s FROM "emp.emp" GROUP BY g HAVING s > 10 AND SUM(emp_no) > 10000000;
SELECT gender g, CAST(SUM(emp_no) AS INT) s FROM "test_emp.emp" GROUP BY g HAVING s > 10 AND SUM(emp_no) > 10000000;
// AVG
aggAvgImplicitWithCast
SELECT CAST(AVG(emp_no) AS FLOAT) a FROM "emp.emp";
SELECT CAST(AVG(emp_no) AS FLOAT) a FROM "test_emp.emp";
aggAvgWithCastToFloat
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a FROM "emp.emp" GROUP BY gender;
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a FROM "test_emp.emp" GROUP BY gender;
// casting to an exact type - varchar, bigint, etc... will likely fail due to rounding error
aggAvgWithCastToDouble
SELECT gender g, CAST(AVG(emp_no) AS DOUBLE) a FROM "emp.emp" GROUP BY gender;
SELECT gender g, CAST(AVG(emp_no) AS DOUBLE) a FROM "test_emp.emp" GROUP BY gender;
aggAvgWithCastAndCount
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a, COUNT(1) c FROM "emp.emp" GROUP BY gender;
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a, COUNT(1) c FROM "test_emp.emp" GROUP BY gender;
aggAvgWithCastAndCountWithFilter
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a, COUNT(1) c FROM "emp.emp" WHERE emp_no > 10000 GROUP BY gender ;
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a, COUNT(1) c FROM "test_emp.emp" WHERE emp_no > 10000 GROUP BY gender ;
aggAvgWithCastAndCountWithFilterAndLimit
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a, COUNT(1) c FROM "emp.emp" WHERE emp_no > 10000 GROUP BY gender LIMIT 1;
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a, COUNT(1) c FROM "test_emp.emp" WHERE emp_no > 10000 GROUP BY gender LIMIT 1;
aggAvgWithAlias
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a FROM "emp.emp" GROUP BY g;
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a FROM "test_emp.emp" GROUP BY g;
// Conditional AVG
aggAvgWithHaving
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a FROM "emp.emp" GROUP BY g HAVING AVG(emp_no) > 10;
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a FROM "test_emp.emp" GROUP BY g HAVING AVG(emp_no) > 10;
aggAvgWithHavingOnAlias
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a FROM "emp.emp" GROUP BY g HAVING a > 10;
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a FROM "test_emp.emp" GROUP BY g HAVING a > 10;
aggAvgWithMultipleHaving
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a FROM "emp.emp" GROUP BY g HAVING a > 10 AND a < 10000000;
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a FROM "test_emp.emp" GROUP BY g HAVING a > 10 AND a < 10000000;
aggAvgWithMultipleHavingWithLimit
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a FROM "emp.emp" GROUP BY g HAVING a > 10 AND a < 10000000 LIMIT 1;
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a FROM "test_emp.emp" GROUP BY g HAVING a > 10 AND a < 10000000 LIMIT 1;
aggAvgWithMultipleHavingOnAliasAndFunction
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a FROM "emp.emp" GROUP BY g HAVING a > 10 AND AVG(emp_no) > 10000000;
SELECT gender g, CAST(AVG(emp_no) AS FLOAT) a FROM "test_emp.emp" GROUP BY g HAVING a > 10 AND AVG(emp_no) > 10000000;

View File

@ -11,7 +11,13 @@ AVG |AGGREGATE
COUNT |AGGREGATE
MAX |AGGREGATE
MIN |AGGREGATE
SUM |AGGREGATE
SUM |AGGREGATE
MEAN |AGGREGATE
STDDEV_POP |AGGREGATE
VAR_POP |AGGREGATE
SUM_OF_SQUARES |AGGREGATE
SKEWNESS |AGGREGATE
KURTOSIS |AGGREGATE
DAY_OF_MONTH |SCALAR
DAY |SCALAR
DOM |SCALAR
@ -98,10 +104,10 @@ describe
DESCRIBE "test_emp.emp";
column | type
birth_date |TIMESTAMP_WITH_TIMEZONE
birth_date |TIMESTAMP
emp_no |INTEGER
first_name |VARCHAR
gender |VARCHAR
hire_date |TIMESTAMP_WITH_TIMEZONE
hire_date |TIMESTAMP
last_name |VARCHAR
;

View File

@ -6,11 +6,11 @@
// Time
//
dateTimeSecond
SELECT SECOND(birth_date) d, last_name l FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT SECOND(birth_date) d, last_name l FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
dateTimeMinute
SELECT MINUTE(birth_date) d, last_name l FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT MINUTE(birth_date) d, last_name l FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
dateTimeHour
SELECT HOUR(birth_date) d, last_name l FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT HOUR(birth_date) d, last_name l FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
//
@ -18,17 +18,17 @@ SELECT HOUR(birth_date) d, last_name l FROM "emp.emp" WHERE emp_no < 10010 ORDER
//
dateTimeDay
SELECT DAY(birth_date) d, last_name l FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT DAY(birth_date) d, last_name l FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
dateTimeDayOfMonth
SELECT DAY_OF_MONTH(birth_date) d, last_name l FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT DAY_OF_MONTH(birth_date) d, last_name l FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
// dateTimeDayOfWeek - disable since it starts at 0 not 1
// SELECT DAY_OF_WEEK(birth_date) d, last_name l FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
// SELECT DAY_OF_WEEK(birth_date) d, last_name l FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
dateTimeDayOfYear
SELECT DAY_OF_YEAR(birth_date) d, last_name l FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT DAY_OF_YEAR(birth_date) d, last_name l FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
dateTimeMonth
SELECT MONTH(birth_date) d, last_name l FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT MONTH(birth_date) d, last_name l FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
dateTimeYear
SELECT YEAR(birth_date) d, last_name l FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT YEAR(birth_date) d, last_name l FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
// NOCOMMIT figure out a way to test the aliases that are unsupported by h2 but are supported by us because they are like PostgreSQL
@ -37,19 +37,19 @@ SELECT YEAR(birth_date) d, last_name l FROM "emp.emp" WHERE emp_no < 10010 ORDER
// Filter
//
dateTimeFilterDayOfMonth
SELECT DAY_OF_MONTH(birth_date) AS d, last_name l FROM "emp.emp" WHERE DAY_OF_MONTH(birth_date) <= 10 ORDER BY emp_no LIMIT 5;
SELECT DAY_OF_MONTH(birth_date) AS d, last_name l FROM "test_emp.emp" WHERE DAY_OF_MONTH(birth_date) <= 10 ORDER BY emp_no LIMIT 5;
dateTimeFilterMonth
SELECT MONTH(birth_date) AS d, last_name l FROM "emp.emp" WHERE MONTH(birth_date) <= 5 ORDER BY emp_no LIMIT 5;
SELECT MONTH(birth_date) AS d, last_name l FROM "test_emp.emp" WHERE MONTH(birth_date) <= 5 ORDER BY emp_no LIMIT 5;
dateTimeFilterYear
SELECT YEAR(birth_date) AS d, last_name l FROM "emp.emp" WHERE YEAR(birth_date) <= 1960 ORDER BY emp_no LIMIT 5;
SELECT YEAR(birth_date) AS d, last_name l FROM "test_emp.emp" WHERE YEAR(birth_date) <= 1960 ORDER BY emp_no LIMIT 5;
//
// Aggregate
//
dateTimeAggByYear
SELECT YEAR(birth_date) AS d, CAST(SUM(emp_no) AS INT) s FROM "emp.emp" GROUP BY YEAR(birth_date) ORDER BY YEAR(birth_date) LIMIT 5;
SELECT YEAR(birth_date) AS d, CAST(SUM(emp_no) AS INT) s FROM "test_emp.emp" GROUP BY YEAR(birth_date) ORDER BY YEAR(birth_date) LIMIT 5;
// NOCOMMIT Elasticsearch doesn't line up
// dateTimeAggByMonth
// SELECT MONTH(birth_date) AS d, CAST(SUM(emp_no) AS INT) s FROM "emp.emp" GROUP BY MONTH(birth_date) ORDER BY MONTH(birth_date) LIMIT 5;
// SELECT MONTH(birth_date) AS d, CAST(SUM(emp_no) AS INT) s FROM "test_emp.emp" GROUP BY MONTH(birth_date) ORDER BY MONTH(birth_date) LIMIT 5;
// dateTimeAggByDayOfMonth
// SELECT DAY_OF_MONTH(birth_date) AS d, CAST(SUM(emp_no) AS INT) s FROM "emp.emp" GROUP BY DAY_OF_MONTH(birth_date) ORDER BY DAY_OF_MONTH(birth_date) DESC;
// SELECT DAY_OF_MONTH(birth_date) AS d, CAST(SUM(emp_no) AS INT) s FROM "test_emp.emp" GROUP BY DAY_OF_MONTH(birth_date) ORDER BY DAY_OF_MONTH(birth_date) DESC;

View File

@ -3,18 +3,18 @@
//
whereFieldQuality
SELECT last_name l FROM "emp.emp" WHERE emp_no = 10000 LIMIT 5;
SELECT last_name l FROM "test_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;
SELECT last_name l FROM "test_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;
SELECT last_name l FROM "test_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;
SELECT last_name l FROM "test_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;
SELECT last_name l FROM "test_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';
SELECT last_name l FROM "test_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%';
SELECT last_name l FROM "test_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;
SELECT last_name l FROM "test_emp.emp" WHERE emp_no < 10003 AND (gender = 'M' AND NOT FALSE OR last_name LIKE 'K%') ORDER BY emp_no;

View File

@ -3,73 +3,73 @@
//
mathAbs
SELECT ABS(emp_no) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT ABS(emp_no) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathACos
SELECT ACOS(emp_no) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT ACOS(emp_no) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathASin
SELECT ASIN(emp_no) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT ASIN(emp_no) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathATan
SELECT ATAN(emp_no) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT ATAN(emp_no) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
//mathCbrt
//SELECT CBRT(emp_no) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
//SELECT CBRT(emp_no) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathCeil
SELECT CEIL(emp_no) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT CEIL(emp_no) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathCos
SELECT COS(emp_no) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT COS(emp_no) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathCosh
SELECT COSH(emp_no) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT COSH(emp_no) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathDegrees
SELECT DEGREES(emp_no) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT DEGREES(emp_no) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathFloor
SELECT CAST(FLOOR(emp_no) AS INT) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT CAST(FLOOR(emp_no) AS INT) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathLog
SELECT LOG(emp_no) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT LOG(emp_no) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathLog10
SELECT LOG10(emp_no) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT LOG10(emp_no) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathRadians
SELECT RADIANS(emp_no) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT RADIANS(emp_no) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathRound
SELECT CAST(ROUND(emp_no) AS INT) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT CAST(ROUND(emp_no) AS INT) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathSin
SELECT SIN(emp_no) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT SIN(emp_no) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathSinH
SELECT SINH(emp_no) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT SINH(emp_no) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathSqrt
SELECT SQRT(emp_no) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT SQRT(emp_no) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathTan
SELECT TAN(emp_no) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT TAN(emp_no) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
//
// Combined methods
//
mathAbsOfSin
SELECT ABS(SIN(emp_no)) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT ABS(SIN(emp_no)) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathAbsOfCeilOfSin
SELECT EXP(ABS(CEIL(SIN(DEGREES(emp_no))))) m, first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
SELECT EXP(ABS(CEIL(SIN(DEGREES(emp_no))))) m, first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
mathAbsOfCeilOfSinWithFilter
SELECT EXP(ABS(CEIL(SIN(DEGREES(emp_no))))) m, first_name FROM "emp.emp" WHERE EXP(ABS(CEIL(SIN(DEGREES(emp_no))))) < 10 ORDER BY emp_no;
SELECT EXP(ABS(CEIL(SIN(DEGREES(emp_no))))) m, first_name FROM "test_emp.emp" WHERE EXP(ABS(CEIL(SIN(DEGREES(emp_no))))) < 10 ORDER BY emp_no;
//
// Filter by Scalar
//
mathAbsFilterAndOrder
SELECT emp_no, ABS(emp_no) m, first_name FROM "emp.emp" WHERE ABS(emp_no) < 10010 ORDER BY ABS(emp_no);
SELECT emp_no, ABS(emp_no) m, first_name FROM "test_emp.emp" WHERE ABS(emp_no) < 10010 ORDER BY ABS(emp_no);
mathACosFilterAndOrder
SELECT emp_no, ACOS(emp_no) m, first_name FROM "emp.emp" WHERE ACOS(emp_no) < 10010 ORDER BY ACOS(emp_no);
SELECT emp_no, ACOS(emp_no) m, first_name FROM "test_emp.emp" WHERE ACOS(emp_no) < 10010 ORDER BY ACOS(emp_no);
mathASinFilterAndOrder
SELECT emp_no, ASIN(emp_no) m, first_name FROM "emp.emp" WHERE ASIN(emp_no) < 10010 ORDER BY ASIN(emp_no);
SELECT emp_no, ASIN(emp_no) m, first_name FROM "test_emp.emp" WHERE ASIN(emp_no) < 10010 ORDER BY ASIN(emp_no);
//mathATanFilterAndOrder
//SELECT emp_no, ATAN(emp_no) m, first_name FROM "emp.emp" WHERE ATAN(emp_no) < 10010 ORDER BY ATAN(emp_no);
//SELECT emp_no, ATAN(emp_no) m, first_name FROM "test_emp.emp" WHERE ATAN(emp_no) < 10010 ORDER BY ATAN(emp_no);
mathCeilFilterAndOrder
SELECT emp_no, CEIL(emp_no) m, first_name FROM "emp.emp" WHERE CEIL(emp_no) < 10010 ORDER BY CEIL(emp_no);
SELECT emp_no, CEIL(emp_no) m, first_name FROM "test_emp.emp" WHERE CEIL(emp_no) < 10010 ORDER BY CEIL(emp_no);
//mathCosFilterAndOrder
//SELECT emp_no, COS(emp_no) m, first_name FROM "emp.emp" WHERE COS(emp_no) < 10010 ORDER BY COS(emp_no);
//SELECT emp_no, COS(emp_no) m, first_name FROM "test_emp.emp" WHERE COS(emp_no) < 10010 ORDER BY COS(emp_no);
//mathCoshFilterAndOrder
//SELECT emp_no, COSH(emp_no) m, first_name FROM "emp.emp" WHERE COSH(emp_no) < 10010 ORDER BY COSH(emp_no);
//SELECT emp_no, COSH(emp_no) m, first_name FROM "test_emp.emp" WHERE COSH(emp_no) < 10010 ORDER BY COSH(emp_no);
//
// constants - added when folding will be supported
//
//mathConstantPI
//SELECT ABS(emp_no) m, PI(), first_name FROM "emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;
//SELECT ABS(emp_no) m, PI(), first_name FROM "test_emp.emp" WHERE emp_no < 10010 ORDER BY emp_no;

View File

@ -3,36 +3,36 @@
//
wildcardWithOrder
SELECT * FROM "emp.emp" ORDER BY emp_no;
SELECT * FROM "test_emp.emp" ORDER BY emp_no;
column
SELECT last_name FROM "emp.emp" ORDER BY emp_no;
SELECT last_name FROM "test_emp.emp" ORDER BY emp_no;
columnWithAlias
SELECT last_name AS l FROM "emp.emp" ORDER BY emp_no;
SELECT last_name AS l FROM "test_emp.emp" ORDER BY emp_no;
columnWithAliasNoAs
SELECT last_name l FROM "emp.emp" ORDER BY emp_no;
SELECT last_name l FROM "test_emp.emp" ORDER BY emp_no;
multipleColumnsNoAlias
SELECT first_name, last_name FROM "emp.emp" ORDER BY emp_no;
SELECT first_name, last_name FROM "test_emp.emp" ORDER BY emp_no;
multipleColumnWithAliasWithAndWithoutAs
SELECT first_name f, last_name AS l FROM "emp.emp" ORDER BY emp_no;
SELECT first_name f, last_name AS l FROM "test_emp.emp" ORDER BY emp_no;
//
// SELECT with LIMIT
//
wildcardWithLimit
SELECT * FROM "emp.emp" ORDER BY emp_no LIMIT 5;
SELECT * FROM "test_emp.emp" ORDER BY emp_no LIMIT 5;
wildcardWithOrderWithLimit
SELECT * FROM "emp.emp" ORDER BY emp_no LIMIT 5;
SELECT * FROM "test_emp.emp" ORDER BY emp_no LIMIT 5;
columnWithLimit
SELECT last_name FROM "emp.emp" ORDER BY emp_no LIMIT 5;
SELECT last_name FROM "test_emp.emp" ORDER BY emp_no LIMIT 5;
columnWithAliasWithLimit
SELECT last_name AS l FROM "emp.emp" ORDER BY emp_no LIMIT 5;
SELECT last_name AS l FROM "test_emp.emp" ORDER BY emp_no LIMIT 5;
columnWithAliasNoAsWithLimit
SELECT last_name l FROM "emp.emp" ORDER BY emp_no LIMIT 5;
SELECT last_name l FROM "test_emp.emp" ORDER BY emp_no LIMIT 5;
multipleColumnsNoAliasWithLimit
SELECT first_name, last_name FROM "emp.emp" ORDER BY emp_no LIMIT 5;
SELECT first_name, last_name FROM "test_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 first_name f, last_name AS l FROM "test_emp.emp" ORDER BY emp_no LIMIT 5;
//
@ -41,16 +41,16 @@ SELECT first_name f, last_name AS l FROM "emp.emp" ORDER BY emp_no LIMIT 5;
//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;
SELECT CAST(emp_no AS VARCHAR) AS emp_no_cast FROM "test_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;
SELECT CAST(emp_no AS BIGINT) AS emp_no_cast FROM "test_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;
SELECT CAST(emp_no AS SMALLINT) AS emp_no_cast FROM "test_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;
SELECT CAST(emp_no AS INT) AS emp_no_cast FROM "test_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;
SELECT CAST(emp_no AS REAL) AS emp_no_cast FROM "test_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;
SELECT CAST(emp_no AS DOUBLE) AS emp_no_cast FROM "test_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;
SELECT CAST(emp_no AS BOOL) AS emp_no_cast FROM "test_emp.emp" ORDER BY emp_no LIMIT 5;

View File

@ -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());

View File

@ -47,8 +47,7 @@ public class JdbcServer {
public JdbcServer(PlanExecutor executor, String clusterName, Supplier<String> nodeName, Version version, Build build) {
this.executor = executor;
// Delay building the response until runtime because the node name is not available at startup
this.infoResponse = () -> new InfoResponse(nodeName.get(), clusterName, version.major, version.minor, version.toString(),
build.shortHash(), build.date());
this.infoResponse = () -> new InfoResponse(nodeName.get(), clusterName, version.major, version.minor, version.toString(), build.shortHash(), build.date());
}
public void handle(Request req, ActionListener<Response> listener) {

View File

@ -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) {

View File

@ -12,33 +12,40 @@ import org.elasticsearch.client.Client;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
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;
private ExecutorService executor;
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 {
// similar to Executors.newCached but with a smaller bound and much smaller keep-alive
executor = new ThreadPoolExecutor(0, 10, 250, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>());
server = HttpServer.create(new InetSocketAddress(InetAddress.getLoopbackAddress(), port), 0);
server.createContext(defaultPrefix, new RootHttpHandler());
server.createContext(defaultPrefix + protoPrefix, handler);
server.setExecutor(Executors.newCachedThreadPool());
server.createContext(protoSuffix, handler);
server.setExecutor(executor);
server.start();
}
public void stop() {
server.stop(1);
server = null;
executor.shutdownNow();
executor = null;
}
public InetSocketAddress address() {
@ -46,7 +53,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() {

View File

@ -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();
}
}