Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version Bump: H2 1.x -> 2.x #444

Merged
merged 1 commit into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integ-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ dependencies {
include '*.jar'
builtBy 'compileJdbc'
}
testCompile group: 'com.h2database', name: 'h2', version: '1.4.200'
testCompile group: 'com.h2database', name: 'h2', version: '2.1.210'
testCompile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.28.0'
testCompile group: 'com.google.code.gson', name: 'gson', version: '2.8.9'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class JDBCConnection implements DBConnection {

private static final String SINGLE_QUOTE = "'";
private static final String DOUBLE_QUOTE = "''";
private static final String BACKTICK = "`";

/**
* Database name for display
Expand Down Expand Up @@ -103,7 +104,8 @@ public void drop(String tableName) {
@Override
public void insert(String tableName, String[] columnNames, List<Object[]> batch) {
try (Statement stmt = connection.createStatement()) {
String names = String.join(",", columnNames);
String names =
Arrays.stream(columnNames).map(this::delimited).collect(joining(","));
for (Object[] fieldValues : batch) {
stmt.addBatch(StringUtils.format(
"INSERT INTO %s(%s) VALUES (%s)", tableName, names, getValueList(fieldValues)));
Expand Down Expand Up @@ -143,7 +145,8 @@ public void close() {
private String parseColumnNameAndTypesInSchemaJson(String schema) {
JSONObject json = (JSONObject) new JSONObject(schema).query("/mappings/properties");
return json.keySet().stream().
map(colName -> colName + " " + mapToJDBCType(json.getJSONObject(colName).getString("type")))
map(colName -> delimited(colName) + " " + mapToJDBCType(json.getJSONObject(colName)
.getString("type")))
.collect(joining(","));
}

Expand Down Expand Up @@ -212,4 +215,8 @@ private boolean isOrderByQuery(String query) {
public void setConnection(Connection connection) {
this.connection = connection;
}

private String delimited(String columnName) {
return BACKTICK + columnName + BACKTICK;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ public class DBResult {

/**
* Possible types for floating point number
* H2 2.x use DOUBLE PRECISION instead of DOUBLE.
*/
private static final Set<String> FLOAT_TYPES = ImmutableSet.of("FLOAT", "DOUBLE", "REAL");
private static final Set<String> FLOAT_TYPES =
ImmutableSet.of("FLOAT", "DOUBLE", "REAL", "DOUBLE PRECISION", "DECFLOAT");

/**
* Possible types for varchar.
* H2 2.x use CHARACTER VARYING instead of VARCHAR.
*/
private static final Set<String> VARCHAR = ImmutableSet.of("CHARACTER VARYING", "VARCHAR");

/**
* Database name for display
Expand Down Expand Up @@ -81,6 +89,8 @@ public void addColumn(String name, String type) {
// Ignore float type by assigning all type names string to it.
if (FLOAT_TYPES.contains(type)) {
type = FLOAT_TYPES.toString();
} else if (VARCHAR.contains(type)) {
type = "VARCHAR";
}
schema.add(new Type(StringUtils.toUpper(name), type));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ private Object roundFloatNum(Object value) {
} else if (value instanceof Double) {
BigDecimal decimal = BigDecimal.valueOf((Double) value).setScale(2, RoundingMode.CEILING);
value = decimal.doubleValue();
} else if (value instanceof BigDecimal) {
value = ((BigDecimal) value).setScale(2, RoundingMode.CEILING).doubleValue();
}
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testCreateTable() throws SQLException {
verify(statement).executeUpdate(argCap.capture());
String actual = argCap.getValue();

assertEquals("CREATE TABLE test(name VARCHAR,age INT)", actual);
assertEquals("CREATE TABLE test(`name` VARCHAR,`age` INT)", actual);
}

@Test
Expand All @@ -92,8 +92,8 @@ public void testInsertData() throws SQLException {

assertEquals(
Arrays.asList(
"INSERT INTO test(name,age) VALUES ('John','25')",
"INSERT INTO test(name,age) VALUES ('Hank','30')"
"INSERT INTO test(`name`,`age`) VALUES ('John','25')",
"INSERT INTO test(`name`,`age`) VALUES ('Hank','30')"
), actual
);
}
Expand All @@ -112,9 +112,9 @@ public void testInsertNullData() throws SQLException {

assertEquals(
Arrays.asList(
"INSERT INTO test(name,age) VALUES ('John',NULL)",
"INSERT INTO test(name,age) VALUES (NULL,'25')",
"INSERT INTO test(name,age) VALUES ('Hank','30')"
"INSERT INTO test(`name`,`age`) VALUES ('John',NULL)",
"INSERT INTO test(`name`,`age`) VALUES (NULL,'25')",
"INSERT INTO test(`name`,`age`) VALUES ('Hank','30')"
), actual
);
}
Expand Down Expand Up @@ -178,7 +178,7 @@ public void testSelectQueryWithFloatInResultSet() throws SQLException {
assertEquals(
Arrays.asList(
new Type("NAME", "VARCHAR"),
new Type("BALANCE", "[FLOAT, DOUBLE, REAL]")
new Type("BALANCE", "[FLOAT, DOUBLE, REAL, DOUBLE PRECISION, DECFLOAT]")
),
result.getSchema()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ private void verifyQueries(String[] dirs, Function<String, String> converter) th
}
}

/**
* Comment start with #
*/
private void verifyQueries(Path file, Function<String, String> converter) {
try {
String[] queries = Files.lines(file)
.filter(line -> !line.startsWith("#"))
.map(converter)
.toArray(String[]::new);
verify(queries);
Expand Down
12 changes: 8 additions & 4 deletions integ-test/src/test/resources/correctness/expressions/cast.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ cast('01:01:01' as time) as castTime
cast('true' as boolean) as castBool
cast(1 as boolean) as castBool
cast(cast(1 as string) as int) castCombine
false = 'False' as implicitCast
false = 'true' as implicitCast
'TRUE' = true as implicitCast
'false' = true as implicitCast
# disable, H2 2.x does not support 'False' literal
#false = 'False' as implicitCast
# disable, H2 2.x does not support 'true' literal
#false = 'true' as implicitCast
# disable, H2 2.x does not support 'TRUE' literal
#'TRUE' = true as implicitCast
# disable, H2 2.x does not support 'false' literal
#'false' = true as implicitCast
CAST('2021-06-17 00:00:00' AS TIMESTAMP) = '2021-06-17 00:00:00' as implicitCast
'2021-06-18' < CAST('2021-06-17' AS DATE) as implicitCast
'10:20:00' <= CAST('11:00:00' AS TIME) as implicitCast
60 changes: 30 additions & 30 deletions integ-test/src/test/resources/correctness/queries/window.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,33 @@ SELECT FlightDelayMin, AvgTicketPrice, STDDEV_POP(AvgTicketPrice) OVER (ORDER BY
SELECT FlightDelayMin, AvgTicketPrice, STDDEV_SAMP(AvgTicketPrice) OVER (ORDER BY FlightDelayMin) AS num FROM opensearch_dashboards_sample_data_flights ORDER BY FlightDelayMin
SELECT FlightDelayMin, AvgTicketPrice, VAR_POP(AvgTicketPrice) OVER (ORDER BY FlightDelayMin) AS num FROM opensearch_dashboards_sample_data_flights ORDER BY FlightDelayMin
SELECT FlightDelayMin, AvgTicketPrice, VAR_SAMP(AvgTicketPrice) OVER (ORDER BY FlightDelayMin) AS num FROM opensearch_dashboards_sample_data_flights ORDER BY FlightDelayMin
SELECT user, RANK() OVER (ORDER BY user) AS rnk FROM opensearch_dashboards_sample_data_ecommerce
SELECT user, DENSE_RANK() OVER (ORDER BY user) AS rnk FROM opensearch_dashboards_sample_data_ecommerce
SELECT user, COUNT(day_of_week_i) OVER (ORDER BY user) AS cnt FROM opensearch_dashboards_sample_data_ecommerce
SELECT user, SUM(day_of_week_i) OVER (ORDER BY user) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT user, AVG(day_of_week_i) OVER (ORDER BY user) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT user, MAX(day_of_week_i) OVER (ORDER BY user) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT user, MIN(day_of_week_i) OVER (ORDER BY user) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT user, STDDEV_POP(day_of_week_i) OVER (ORDER BY user) AS num FROM opensearch_dashboards_sample_data_ecommerce ORDER BY user
SELECT user, VAR_POP(day_of_week_i) OVER (ORDER BY user) AS num FROM opensearch_dashboards_sample_data_ecommerce ORDER BY user
SELECT user, RANK() OVER (ORDER BY user DESC) AS rnk FROM opensearch_dashboards_sample_data_ecommerce
SELECT user, DENSE_RANK() OVER (ORDER BY user DESC) AS rnk FROM opensearch_dashboards_sample_data_ecommerce
SELECT user, COUNT(day_of_week_i) OVER (PARTITION BY user ORDER BY order_id) AS cnt FROM opensearch_dashboards_sample_data_ecommerce
SELECT user, SUM(day_of_week_i) OVER (PARTITION BY user ORDER BY order_id) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT user, AVG(day_of_week_i) OVER (PARTITION BY user ORDER BY order_id) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT user, MAX(day_of_week_i) OVER (PARTITION BY user ORDER BY order_id) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT user, MIN(day_of_week_i) OVER (PARTITION BY user ORDER BY order_id) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT user, STDDEV_POP(day_of_week_i) OVER (PARTITION BY user ORDER BY order_id) AS num FROM opensearch_dashboards_sample_data_ecommerce ORDER BY user
SELECT user, VAR_POP(day_of_week_i) OVER (PARTITION BY user ORDER BY order_id) AS num FROM opensearch_dashboards_sample_data_ecommerce ORDER BY user
SELECT customer_gender, user, ROW_NUMBER() OVER (PARTITION BY customer_gender ORDER BY user) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT customer_gender, user, RANK() OVER (PARTITION BY customer_gender ORDER BY user) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT customer_gender, user, DENSE_RANK() OVER (PARTITION BY customer_gender ORDER BY user) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT customer_gender, user, customer_id, ROW_NUMBER() OVER (PARTITION BY customer_gender, user ORDER BY customer_id) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT customer_gender, user, customer_id, RANK() OVER (PARTITION BY customer_gender, user ORDER BY customer_id) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT customer_gender, user, customer_id, DENSE_RANK() OVER (PARTITION BY customer_gender, user ORDER BY customer_id) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT customer_gender, user, ROW_NUMBER() OVER (ORDER BY customer_gender, user) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT customer_gender, user, RANK() OVER (ORDER BY customer_gender, user) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT customer_gender, user, DENSE_RANK() OVER (ORDER BY customer_gender, user) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT customer_gender, user, SUM(total_quantity), ROW_NUMBER() OVER (PARTITION BY customer_gender ORDER BY user) AS num FROM opensearch_dashboards_sample_data_ecommerce GROUP BY customer_gender, user
SELECT customer_gender, user, AVG(total_quantity), RANK() OVER (PARTITION BY customer_gender ORDER BY user) AS num FROM opensearch_dashboards_sample_data_ecommerce GROUP BY customer_gender, user
SELECT customer_gender, user, DENSE_RANK() OVER (PARTITION BY customer_gender ORDER BY user) AS num FROM opensearch_dashboards_sample_data_ecommerce GROUP BY customer_gender, user
SELECT `user`, RANK() OVER (ORDER BY `user`) AS rnk FROM opensearch_dashboards_sample_data_ecommerce
SELECT `user`, DENSE_RANK() OVER (ORDER BY `user`) AS rnk FROM opensearch_dashboards_sample_data_ecommerce
SELECT `user`, COUNT(day_of_week_i) OVER (ORDER BY `user`) AS cnt FROM opensearch_dashboards_sample_data_ecommerce
SELECT `user`, SUM(day_of_week_i) OVER (ORDER BY `user`) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT `user`, AVG(day_of_week_i) OVER (ORDER BY `user`) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT `user`, MAX(day_of_week_i) OVER (ORDER BY `user`) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT `user`, MIN(day_of_week_i) OVER (ORDER BY `user`) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT `user`, STDDEV_POP(day_of_week_i) OVER (ORDER BY `user`) AS num FROM opensearch_dashboards_sample_data_ecommerce ORDER BY `user`
SELECT `user`, VAR_POP(day_of_week_i) OVER (ORDER BY `user`) AS num FROM opensearch_dashboards_sample_data_ecommerce ORDER BY `user`
SELECT `user`, RANK() OVER (ORDER BY `user` DESC) AS rnk FROM opensearch_dashboards_sample_data_ecommerce
SELECT `user`, DENSE_RANK() OVER (ORDER BY `user` DESC) AS rnk FROM opensearch_dashboards_sample_data_ecommerce
SELECT `user`, COUNT(day_of_week_i) OVER (PARTITION BY `user` ORDER BY order_id) AS cnt FROM opensearch_dashboards_sample_data_ecommerce
SELECT `user`, SUM(day_of_week_i) OVER (PARTITION BY `user` ORDER BY order_id) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT `user`, AVG(day_of_week_i) OVER (PARTITION BY `user` ORDER BY order_id) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT `user`, MAX(day_of_week_i) OVER (PARTITION BY `user` ORDER BY order_id) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT `user`, MIN(day_of_week_i) OVER (PARTITION BY `user` ORDER BY order_id) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT `user`, STDDEV_POP(day_of_week_i) OVER (PARTITION BY `user` ORDER BY order_id) AS num FROM opensearch_dashboards_sample_data_ecommerce ORDER BY `user`
SELECT `user`, VAR_POP(day_of_week_i) OVER (PARTITION BY `user` ORDER BY order_id) AS num FROM opensearch_dashboards_sample_data_ecommerce ORDER BY `user`
SELECT customer_gender, `user`, ROW_NUMBER() OVER (PARTITION BY customer_gender ORDER BY `user`) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT customer_gender, `user`, RANK() OVER (PARTITION BY customer_gender ORDER BY `user`) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT customer_gender, `user`, DENSE_RANK() OVER (PARTITION BY customer_gender ORDER BY `user`) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT customer_gender, `user`, customer_id, ROW_NUMBER() OVER (PARTITION BY customer_gender, `user` ORDER BY customer_id) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT customer_gender, `user`, customer_id, RANK() OVER (PARTITION BY customer_gender, `user` ORDER BY customer_id) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT customer_gender, `user`, customer_id, DENSE_RANK() OVER (PARTITION BY customer_gender, `user` ORDER BY customer_id) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT customer_gender, `user`, ROW_NUMBER() OVER (ORDER BY customer_gender, `user`) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT customer_gender, `user`, RANK() OVER (ORDER BY customer_gender, `user`) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT customer_gender, `user`, DENSE_RANK() OVER (ORDER BY customer_gender, `user`) AS num FROM opensearch_dashboards_sample_data_ecommerce
SELECT customer_gender, `user`, SUM(total_quantity), ROW_NUMBER() OVER (PARTITION BY customer_gender ORDER BY `user`) AS num FROM opensearch_dashboards_sample_data_ecommerce GROUP BY customer_gender, `user`
SELECT customer_gender, `user`, AVG(total_quantity), RANK() OVER (PARTITION BY customer_gender ORDER BY `user`) AS num FROM opensearch_dashboards_sample_data_ecommerce GROUP BY customer_gender, `user`
SELECT customer_gender, `user`, DENSE_RANK() OVER (PARTITION BY customer_gender ORDER BY `user`) AS num FROM opensearch_dashboards_sample_data_ecommerce GROUP BY customer_gender, `user`