Skip to content

Commit

Permalink
Upgrade libraries (#1156)
Browse files Browse the repository at this point in the history
* Upgrade h2, calcite, jooq

Signed-off-by: Mihai Budiu <[email protected]>
  • Loading branch information
Mihai Budiu authored Apr 22, 2022
1 parent 3468473 commit 675e45b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 30 deletions.
10 changes: 5 additions & 5 deletions sql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>3.13.1</version>
<version>3.14.15</version>
</dependency>
<dependency>
<groupId>com.facebook.presto</groupId>
Expand All @@ -22,19 +22,19 @@
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
<version>1.26.0</version>
<version>1.30.0</version>
</dependency>
<!-- Need this for Calcite DDL parsing -->
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-server</artifactId>
<version>1.26.0</version>
<version>1.30.0</version>
</dependency>
<!-- dynamically query db for schemas -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.199</version>
<version>2.1.210</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -47,7 +47,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>4.13.2</version>
</dependency>
</dependencies>
<properties>
Expand Down
4 changes: 0 additions & 4 deletions sql/src/main/java/com/vmware/ddlog/DDlogHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import com.vmware.ddlog.ir.DDlogProgram;
import com.vmware.ddlog.ir.DDlogRelationDeclaration;
import com.vmware.ddlog.ir.DDlogTUser;
import com.vmware.ddlog.ir.DDlogType;
import com.vmware.ddlog.translator.RelationName;
import com.vmware.ddlog.translator.Translator;
import com.vmware.ddlog.util.sql.SqlStatement;
import com.vmware.ddlog.util.sql.ToPrestoTranslator;
Expand All @@ -39,9 +37,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;

public class DDlogHandle {
Expand Down
6 changes: 3 additions & 3 deletions sql/src/main/java/com/vmware/ddlog/DDlogJooqHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ public List<String> visit(final SqlCall call) {
final SqlBasicCall expr = (SqlBasicCall) call;
switch (expr.getOperator().getKind()) {
case AND:
for (SqlNode node : expr.getOperands()) {
for (SqlNode node : expr.getOperandList()) {
visit((SqlBasicCall) node);
}
return identifiers;
case EQUALS: {
final SqlNode left = expr.getOperands()[0];
final SqlNode right = expr.getOperands()[1];
final SqlNode left = expr.getOperandList().get(0);
final SqlNode right = expr.getOperandList().get(1);
if (left instanceof SqlIdentifier) {
// Add left to the columns
identifiers.add(left.toString().toUpperCase(Locale.ROOT));
Expand Down
22 changes: 12 additions & 10 deletions sql/src/main/java/com/vmware/ddlog/DDlogJooqProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ private MockResult visitInsert(final SqlInsert insert) throws DDlogException {
if (insert.getSource().getKind() != SqlKind.VALUES || !(insert.getTargetTable() instanceof SqlIdentifier)) {
return exception(insert.toString());
}
final SqlNode[] values = ((SqlBasicCall) insert.getSource()).getOperands();
final List<SqlNode> values = ((SqlBasicCall) insert.getSource()).getOperandList();

final String tableName = ((SqlIdentifier) insert.getTargetTable()).getSimple();
DDlogJooqHelper.NormalizedTableName tn = new DDlogJooqHelper.NormalizedTableName(tableName);
Expand All @@ -412,11 +412,11 @@ private MockResult visitInsert(final SqlInsert insert) throws DDlogException {
if (value.getKind() != SqlKind.ROW) {
return exception(insert.toString());
}
final SqlNode[] rowElements = ((SqlBasicCall) value).operands;
final DDlogRecord[] recordsArray = new DDlogRecord[rowElements.length];
final List<SqlNode> rowElements = ((SqlBasicCall) value).getOperandList();
final DDlogRecord[] recordsArray = new DDlogRecord[rowElements.size()];
if (context.hasBinding()) {
// Is a statement with bound variables
for (int i = 0; i < rowElements.length; i++) {
for (int i = 0; i < rowElements.size(); i++) {
Field<?> fi = fields.get(i);
// final boolean isNullableField = fi.getDataType().nullable();
// fi.getDataType() is wrong for array fields.
Expand All @@ -427,13 +427,13 @@ private MockResult visitInsert(final SqlInsert insert) throws DDlogException {
}
} else {
// need to parse literals into DDLogRecords
for (int i = 0; i < rowElements.length; i++) {
for (int i = 0; i < rowElements.size(); i++) {
Field<?> fi = fields.get(i);
// final boolean isNullableField = fi.getDataType().nullable();
// fi.getDataType() is wrong for array fields.
String fieldName = fi.getName().toLowerCase();
boolean isNullableField = struct.getFieldType(fieldName).mayBeNull;
final DDlogRecord result = rowElements[i].accept(PARSE_LITERALS);
final DDlogRecord result = rowElements.get(i).accept(PARSE_LITERALS);
recordsArray[i] = maybeOption(isNullableField, result, fi.getName());
}
}
Expand Down Expand Up @@ -588,8 +588,8 @@ public DDlogRecord[] visit(final SqlCall call) {
super.visit(call);
return matchExpressions;
case EQUALS: {
final SqlNode left = expr.getOperands()[0];
final SqlNode right = expr.getOperands()[1];
final SqlNode left = expr.getOperandList().get(0);
final SqlNode right = expr.getOperandList().get(1);
if (context.hasBinding()) {
if (left instanceof SqlIdentifier && right instanceof SqlDynamicParam) {
return setMatchExpression((SqlIdentifier) left, context.nextBinding());
Expand Down Expand Up @@ -672,21 +672,23 @@ private static DDlogRecord toValue(final Field<?> field, final Object in) {
if (in == null)
return null;
final DataType<?> dataType = field.getDataType();
switch (dataType.getSQLType()) {
int sqlType = dataType.getSQLType();
switch (sqlType) {
case Types.BOOLEAN:
return new DDlogRecord((boolean) in);
case Types.INTEGER:
return new DDlogRecord((int) in);
case Types.BIGINT:
return new DDlogRecord((long) in);
case Types.OTHER: // For some reason I don't get VARCHAR is converted to OTHER
case Types.VARCHAR:
try {
return new DDlogRecord((String) in);
} catch (final DDlogException e) {
throw new DDlogJooqProviderException("Could not create String DDlogRecord for object: " + in);
}
default:
throw new DDlogJooqProviderException("Unknown datatype " + field);
throw new DDlogJooqProviderException("Unknown datatype " + sqlType + " for " + field);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ public String visit(SqlCall call) {
SqlColumnDeclaration castColumn = (SqlColumnDeclaration) call;
String type = castColumn.dataType.toString();

if (castColumn.dataType.getCollectionsTypeName() != null &&
castColumn.dataType.getCollectionsTypeName().toString().equals("ARRAY")) {
type = "array";
}

String nullOperand = (castColumn.strategy == ColumnStrategy.NULLABLE) ? "null" : "not null";
if (castColumn.expression != null) {
throw new UnsupportedOperationException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ protected String visitCreateTable(final CreateTable node, final String sql) {
final ColumnDefinition cd = (ColumnDefinition) element;
String h2Type = cd.getType();

// We need to strip the array subtype for H2
// We need to rewrite the array subtype for H2
final Pattern arrayType = Pattern.compile("ARRAY\\((.+)\\)");
Matcher m = arrayType.matcher(h2Type);
if (m.find()) {
h2Type = "array";
h2Type = m.group(1) + " array";
}

if (cd.getProperties().size() == 1) {
Expand Down
2 changes: 1 addition & 1 deletion sql/src/test/java/ddlog/DynamicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private DSLContext setup() {
properties.setProperty("foreign_keys", "true");
try {
// Create a fresh database
final String connectionURL = "jdbc:h2:mem:;create=true";
final String connectionURL = "jdbc:h2:mem:"; //create=true";
final Connection conn = DriverManager.getConnection(connectionURL, properties);
conn.setSchema("PUBLIC");
return DSL.using(conn, SQLDialect.H2);
Expand Down

0 comments on commit 675e45b

Please sign in to comment.