Skip to content
Snippets Groups Projects
Commit 38954661 authored by Julien Lopez's avatar Julien Lopez
Browse files

Moving to getters, because Java

parent 50dad48a
No related branches found
No related tags found
No related merge requests found
......@@ -57,96 +57,98 @@ class QIRSQLStringVisitor extends QIRTranslator<String> {
@Override
public final String visit(final QIRProject qirProject) {
if (qirProject.formatter instanceof QIRLambda)
return "select " + ((QIRLambda) qirProject.formatter).body.accept(this) + " from (" + qirProject.child.accept(this) + ") as " + ((QIRLambda) qirProject.formatter).var.accept(this);
throw new QIRException("QIR SQL Project not implemented for formatter type: " + qirProject.formatter.getClass());
if (qirProject.getFormatter() instanceof QIRLambda)
return "select " + ((QIRLambda) qirProject.getFormatter()).getBody().accept(this) + " from (" + qirProject.getChild().accept(this) + ") as " +
((QIRLambda) qirProject.getFormatter()).getVar().accept(this);
throw new QIRException("QIR SQL Project not implemented for formatter type: " + qirProject.getFormatter().getClass());
}
@Override
public final String visit(final QIRScan qirScan) {
if (qirScan.table instanceof QIRTable && ((QIRTable) qirScan.table).dbName instanceof QIRString && ((QIRTable) qirScan.table).configFile instanceof QIRString) {
final QIRTable table = (QIRTable) qirScan.table;
if (!((QIRString) table.dbName).value.equals(dbName) || !((QIRString) table.configFile).value.equals(dbConfig))
if (qirScan.getTable() instanceof QIRTable && ((QIRTable) qirScan.getTable()).getDbName() instanceof QIRString && ((QIRTable) qirScan.getTable()).getConfigFile() instanceof QIRString) {
final QIRTable table = (QIRTable) qirScan.getTable();
if (!((QIRString) table.getDbName()).getValue().equals(dbName) || !((QIRString) table.getConfigFile()).getValue().equals(dbConfig))
throw new QIRException("Subquery for another database detected.");
return "select * from " + qirScan.table.accept(this);
return "select * from " + qirScan.getTable().accept(this);
}
throw new QIRException("QIR SQL Scan not implemented for table type: " + qirScan.table.getClass());
throw new QIRException("QIR SQL Scan not implemented for table type: " + qirScan.getTable().getClass());
}
@Override
public final String visit(final QIRFilter qirFilter) {
if (qirFilter.filter instanceof QIRLambda)
return "select * from (" + qirFilter.child.accept(this) + ") as " + ((QIRLambda) qirFilter.filter).var.accept(this) + " where " + ((QIRLambda) qirFilter.filter).body.accept(this);
throw new QIRException("QIR SQL Filter not implemented for filter type: " + qirFilter.filter.getClass());
if (qirFilter.getFilter() instanceof QIRLambda)
return "select * from (" + qirFilter.getChild().accept(this) + ") as " + ((QIRLambda) qirFilter.getFilter()).getVar().accept(this) + " where " +
((QIRLambda) qirFilter.getFilter()).getBody().accept(this);
throw new QIRException("QIR SQL Filter not implemented for filter type: " + qirFilter.getFilter().getClass());
}
@Override
public final String visit(final QIRGroupBy qirGroup) {
if (qirGroup.group instanceof QIRLambda)
return qirGroup.child.accept(this) + " group by " + ((QIRLambda) qirGroup.group).body.accept(this);
throw new QIRException("QIR SQL GroupBy not implemented for group type: " + qirGroup.group.getClass());
if (qirGroup.getGroup() instanceof QIRLambda)
return qirGroup.getChild().accept(this) + " group by " + ((QIRLambda) qirGroup.getGroup()).getBody().accept(this);
throw new QIRException("QIR SQL GroupBy not implemented for group type: " + qirGroup.getGroup().getClass());
}
@Override
public final String visit(final QIRSortBy qirOrder) {
if (qirOrder.order instanceof QIRLambda && ((QIRLambda) qirOrder.order).body instanceof QIRLcons && qirOrder.isAscending instanceof QIRLambda &&
((QIRLambda) qirOrder.isAscending).body instanceof QIRLcons) {
QIRNode rows = ((QIRLambda) qirOrder.order).body;
QIRNode ascs = ((QIRLambda) qirOrder.isAscending).body;
String o = ((QIRLcons) rows).value.accept(this) + (((QIRLcons) ascs).value.equals(QIRBoolean.TRUE) ? "" : " desc");
for (rows = ((QIRLcons) rows).tail, ascs = ((QIRLcons) ascs).tail; rows instanceof QIRLcons; rows = ((QIRLcons) rows).tail, ascs = ((QIRLcons) ascs).tail)
o += ", " + ((QIRLcons) rows).value.accept(this) + (((QIRLcons) ascs).value.equals(QIRBoolean.TRUE) ? "" : " desc");
return "select * from (" + qirOrder.child.accept(this) + ") as " + ((QIRLambda) qirOrder.order).var.accept(this) + " order by " + o;
if (qirOrder.getOrder() instanceof QIRLambda && ((QIRLambda) qirOrder.getOrder()).getBody() instanceof QIRLcons && qirOrder.getIsAscending() instanceof QIRLambda &&
((QIRLambda) qirOrder.getIsAscending()).getBody() instanceof QIRLcons) {
QIRNode rows = ((QIRLambda) qirOrder.getOrder()).getBody();
QIRNode ascs = ((QIRLambda) qirOrder.getIsAscending()).getBody();
String o = ((QIRLcons) rows).getValue().accept(this) + (((QIRLcons) ascs).getValue().equals(QIRBoolean.TRUE) ? "" : " desc");
for (rows = ((QIRLcons) rows).getTail(), ascs = ((QIRLcons) ascs).getTail(); rows instanceof QIRLcons; rows = ((QIRLcons) rows).getTail(), ascs = ((QIRLcons) ascs).getTail())
o += ", " + ((QIRLcons) rows).getValue().accept(this) + (((QIRLcons) ascs).getValue().equals(QIRBoolean.TRUE) ? "" : " desc");
return "select * from (" + qirOrder.getChild().accept(this) + ") as " + ((QIRLambda) qirOrder.getOrder()).getVar().accept(this) + " order by " + o;
}
throw new QIRException("QIR SQL OrderBy not implemented for: " + qirOrder.order.getClass() + " and " + qirOrder.isAscending.getClass());
throw new QIRException("QIR SQL OrderBy not implemented for: " + qirOrder.getOrder().getClass() + " and " + qirOrder.getIsAscending().getClass());
}
@Override
public final String visit(final QIRJoin qirJoin) {
if (qirJoin.filter instanceof QIRLambda && ((QIRLambda) qirJoin.filter).body instanceof QIRLambda) {
final QIRLambda subFun = (QIRLambda) ((QIRLambda) qirJoin.filter).body;
return "select * from (" + qirJoin.left.accept(this) + ") as " + ((QIRLambda) qirJoin.filter).var.accept(this) + " inner join (" + qirJoin.right.accept(this) + ") as " +
subFun.var.accept(this) + " on " + subFun.body.accept(this);
if (qirJoin.getFilter() instanceof QIRLambda && ((QIRLambda) qirJoin.getFilter()).getBody() instanceof QIRLambda) {
final QIRLambda subFun = (QIRLambda) ((QIRLambda) qirJoin.getFilter()).getBody();
return "select * from (" + qirJoin.getLeft().accept(this) + ") as " + ((QIRLambda) qirJoin.getFilter()).getVar().accept(this) + " inner join (" + qirJoin.getRight().accept(this) +
") as " + subFun.getVar().accept(this) + " on " + subFun.getBody().accept(this);
}
throw new QIRException("QIR SQL Join not implemented for filter type: " + qirJoin.filter.getClass());
throw new QIRException("QIR SQL Join not implemented for filter type: " + qirJoin.getFilter().getClass());
}
@Override
public final String visit(final QIRLeftJoin qirJoin) {
if (qirJoin.filter instanceof QIRLambda && ((QIRLambda) qirJoin.filter).body instanceof QIRLambda) {
final QIRLambda subFun = (QIRLambda) ((QIRLambda) qirJoin.filter).body;
return "select * from (" + qirJoin.left.accept(this) + ") as " + ((QIRLambda) qirJoin.filter).var.accept(this) + " left join (" + qirJoin.right.accept(this) + ") as " +
subFun.var.accept(this) + " on " + subFun.body.accept(this);
if (qirJoin.getFilter() instanceof QIRLambda && ((QIRLambda) qirJoin.getFilter()).getBody() instanceof QIRLambda) {
final QIRLambda subFun = (QIRLambda) ((QIRLambda) qirJoin.getFilter()).getBody();
return "select * from (" + qirJoin.getLeft().accept(this) + ") as " + ((QIRLambda) qirJoin.getFilter()).getVar().accept(this) + " left join (" + qirJoin.getRight().accept(this) + ") as " +
subFun.getVar().accept(this) + " on " + subFun.getBody().accept(this);
}
throw new QIRException("QIR SQL Join not implemented for filter type: " + qirJoin.filter.getClass());
throw new QIRException("QIR SQL Join not implemented for filter type: " + qirJoin.getFilter().getClass());
}
@Override
public final String visit(final QIRRightJoin qirJoin) {
if (qirJoin.filter instanceof QIRLambda && ((QIRLambda) qirJoin.filter).body instanceof QIRLambda) {
final QIRLambda subFun = (QIRLambda) ((QIRLambda) qirJoin.filter).body;
return "select * from (" + qirJoin.left.accept(this) + ") as " + ((QIRLambda) qirJoin.filter).var.accept(this) + " right join (" + qirJoin.right.accept(this) + ") as " +
subFun.var.accept(this) + " on " + subFun.body.accept(this);
if (qirJoin.getFilter() instanceof QIRLambda && ((QIRLambda) qirJoin.getFilter()).getBody() instanceof QIRLambda) {
final QIRLambda subFun = (QIRLambda) ((QIRLambda) qirJoin.getFilter()).getBody();
return "select * from (" + qirJoin.getLeft().accept(this) + ") as " + ((QIRLambda) qirJoin.getFilter()).getVar().accept(this) + " right join (" + qirJoin.getRight().accept(this) +
") as " + subFun.getVar().accept(this) + " on " + subFun.getBody().accept(this);
}
throw new QIRException("QIR SQL Join not implemented for filter type: " + qirJoin.filter.getClass());
throw new QIRException("QIR SQL Join not implemented for filter type: " + qirJoin.getFilter().getClass());
}
@Override
public final String visit(final QIRLimit qirLimit) {
if (qirLimit.limit instanceof QIRLambda)
return qirLimit.child.accept(this) + " limit " + ((QIRLambda) qirLimit.limit).body.accept(this);
return qirLimit.child.accept(this) + " limit " + qirLimit.limit.accept(this);
if (qirLimit.getLimit() instanceof QIRLambda)
return qirLimit.getChild().accept(this) + " limit " + ((QIRLambda) qirLimit.getLimit()).getBody().accept(this);
return qirLimit.getChild().accept(this) + " limit " + qirLimit.getLimit().accept(this);
}
@Override
public final <DBRepr> String visit(final QIRDBNode<DBRepr> qirDBNode) {
return (String) qirDBNode.translation;
return (String) qirDBNode.getTranslation();
}
@Override
public final String visit(final QIRExternal qirBuiltin) {
return qirBuiltin.name;
return qirBuiltin.getName();
}
@Override
......@@ -165,16 +167,16 @@ class QIRSQLStringVisitor extends QIRTranslator<String> {
final Deque<QIRNode> args = new ArrayDeque<>();
final QIRNode fun;
if (qirApply.right != null) {
if (qirApply.getRight() != null) {
QIRNode curr = qirApply;
for (; curr instanceof QIRApply; curr = ((QIRApply) curr).left)
args.push(((QIRApply) curr).right);
for (; curr instanceof QIRApply; curr = ((QIRApply) curr).getLeft())
args.push(((QIRApply) curr).getRight());
fun = curr;
} else
fun = qirApply.left;
fun = qirApply.getLeft();
if (fun instanceof QIRTruffleNode) {
final Map<String, QIRNode> ids = new HashMap<>();
final String lName = ((QIRTruffleNode) fun).languageName;
final String lName = ((QIRTruffleNode) fun).getLanguageName();
final String array = args.stream().map(arg -> {
if (arg instanceof QIRVariable || arg instanceof QIRTdestr)
return lName + ".translateTo" + lName + "(" + arg.accept(this) + ")";
......@@ -188,7 +190,7 @@ class QIRSQLStringVisitor extends QIRTranslator<String> {
return res;
}
if (fun instanceof QIRExternal) {
final String name = ((QIRExternal) fun).name;
final String name = ((QIRExternal) fun).getName();
if (name.equals("interval") && args.size() == 2) {
final String arg1 = args.pop().accept(this);
final String arg2 = args.pop().accept(this);
......@@ -220,7 +222,7 @@ class QIRSQLStringVisitor extends QIRTranslator<String> {
@Override
public final String visit(final QIRIf qirIf) {
return "case when (" + qirIf.condition.accept(this) + ") then (" + qirIf.thenNode.accept(this) + ") else (" + qirIf.elseNode.accept(this) + ") end";
return "case when (" + qirIf.getCondition().accept(this) + ") then (" + qirIf.getThenNode().accept(this) + ") else (" + qirIf.getElseNode().accept(this) + ") end";
}
@Override
......@@ -280,7 +282,7 @@ class QIRSQLStringVisitor extends QIRTranslator<String> {
@Override
public final String visit(final QIRTable qirTable) {
return ((QIRString) qirTable.schemaName).value + "." + ((QIRString) qirTable.tableName).value;
return ((QIRString) qirTable.getSchemaName()).getValue() + "." + ((QIRString) qirTable.getTableName()).getValue();
}
/**
......@@ -293,8 +295,8 @@ class QIRSQLStringVisitor extends QIRTranslator<String> {
@Override
public final String visit(final QIRLcons qirLcons) {
final String value = qirLcons.value.accept(this);
final String tail = qirLcons.tail.accept(this);
final String value = qirLcons.getValue().accept(this);
final String tail = qirLcons.getTail().accept(this);
return tail == "" ? value : value + ", " + tail;
}
......@@ -304,7 +306,7 @@ class QIRSQLStringVisitor extends QIRTranslator<String> {
final QIRAny any = QIRAny.instance;
if (qirLdestr.equals(new QIRLdestr(null, any, any, new QIRLambda(null, null, new QIRVariable(null, "head"),
new QIRLambda(null, null, new QIRVariable(null, "tail"), new QIRVariable(null, "tail"), new FrameDescriptor()), new FrameDescriptor()))))
return "select * from (" + qirLdestr.list.accept(this) + ") as " + genFreshId() + " limit 1";
return "select * from (" + qirLdestr.getList().accept(this) + ") as " + genFreshId() + " limit 1";
throw new QIRException(this.getClass().getSimpleName() + " error: unsupported node.");
}
......@@ -318,9 +320,9 @@ class QIRSQLStringVisitor extends QIRTranslator<String> {
@Override
public final String visit(final QIRTcons qirTcons) {
final String id = qirTcons.id;
String value = qirTcons.value.accept(this);
final String tail = qirTcons.tail.accept(this);
final String id = qirTcons.getId();
String value = qirTcons.getValue().accept(this);
final String tail = qirTcons.getTail().accept(this);
value = value == id ? value : value + " as " + id;
if (tail == "")
......@@ -330,39 +332,39 @@ class QIRSQLStringVisitor extends QIRTranslator<String> {
@Override
public String visit(final QIRTdestr qirTdestr) {
QIRNode tuple = qirTdestr.tuple;
QIRNode tuple = qirTdestr.getTuple();
if (tuple instanceof QIRVariable)
return qirTdestr.toString();
if (tuple instanceof QIRLcons && ((QIRLcons) tuple).tail == QIRLnil.instance)
tuple = ((QIRLcons) tuple).value;
if (tuple instanceof QIRLcons && ((QIRLcons) tuple).getTail() == QIRLnil.getInstance())
tuple = ((QIRLcons) tuple).getValue();
final String id = genFreshId();
return "(select " + id + "." + qirTdestr.colName + " from (" + tuple.accept(this) + ") as " + id + ")";
return "(select " + id + "." + qirTdestr.getColName() + " from (" + tuple.accept(this) + ") as " + id + ")";
}
@Override
public final String visit(final QIRString qirString) {
return "'" + qirString.value + "'";
return "'" + qirString.getValue() + "'";
}
@Override
public final String visit(final QIRNumber qirNumber) {
return Long.toString(qirNumber.value);
return Long.toString(qirNumber.getValue());
}
@Override
public final String visit(final QIRBigNumber qirBigNumber) {
return qirBigNumber.value.toString();
return qirBigNumber.getValue().toString();
}
@Override
public final String visit(final QIRDouble qirDouble) {
return qirDouble.value.toString();
return qirDouble.getValue().toString();
}
@Override
public final String visit(final QIRBoolean qirBoolean) {
return qirBoolean.value ? "true" : "false";
return qirBoolean.getValue() ? "true" : "false";
}
@Override
......@@ -373,6 +375,6 @@ class QIRSQLStringVisitor extends QIRTranslator<String> {
@Override
public final String visit(final QIRExportableTruffleNode qirTruffleNode) {
// TODO: We need to set the classpath to the correct jar here.
return qirTruffleNode.languageName + ".execute('" + qirTruffleNode.code + "')";
return qirTruffleNode.getLanguageName() + ".execute('" + qirTruffleNode.getCode() + "')";
}
}
\ No newline at end of file
......@@ -37,11 +37,11 @@ abstract class SQLStringDriver extends SQLDriver<String> {
final Statement stmt = conn.createStatement();
final ResultSet rs = stmt.executeQuery(query);
final Deque<QIRTuple> tmp = new ArrayDeque<>();
QIRList result = QIRLnil.instance;
QIRList result = QIRLnil.getInstance();
QIRNode data;
while (rs.next()) {
QIRTuple newTuple = QIRTnil.instance;
QIRTuple newTuple = QIRTnil.getInstance();
for (int i = rs.getMetaData().getColumnCount(); i >= 1; i--) {
int type = rs.getMetaData().getColumnType(i);
switch (type) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment