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

Fixes singletons and wip on HBase GroupBy

parent 66cc4989
No related branches found
No related tags found
No related merge requests found
package qir.ast;
import com.oracle.truffle.api.source.SourceSection;
import qir.driver.IQIRVisitor;
import qir.util.QIRAny;
......@@ -9,20 +7,14 @@ import qir.util.QIRAny;
* This class represents the {@code null} value, it is therefore a singleton.
*/
public final class QIRNull extends QIRNode {
private QIRNull(final SourceSection source) {
super(source);
private QIRNull() {
super(null);
}
private static final QIRNull singleton = new QIRNull(null);
/**
* Use this method to refer to the {@code null} value.
*
* @return The unique representation of the {@code null} value.
* The unique representation of the {@code null} value.
*/
public static final QIRNull getInstance() {
return singleton;
}
public static final QIRNull instance = new QIRNull();
@Override
public final String toString() {
......@@ -31,7 +23,7 @@ public final class QIRNull extends QIRNode {
@Override
public boolean equals(Object other) {
return other instanceof QIRNull || other instanceof QIRAny;
return other == instance || other == QIRAny.instance;
}
@Override
......
package qir.ast.data;
import com.oracle.truffle.api.source.SourceSection;
import qir.driver.IQIRVisitor;
import qir.util.QIRAny;
......@@ -9,20 +7,14 @@ import qir.util.QIRAny;
* This class represents the empty {@link QIRList}, it is therefore a singleton.
*/
public final class QIRLnil extends QIRList {
private QIRLnil(final SourceSection source) {
super(source);
private QIRLnil() {
super(null);
}
private static final QIRLnil singleton = new QIRLnil(null);
/**
* Use this method to refer to the empty {@link QIRList}.
*
* @return The unique representation of the empty {@link QIRList}.
* The unique representation of the empty {@link QIRList}.
*/
public static final QIRLnil getInstance() {
return singleton;
}
public static final QIRLnil instance = new QIRLnil();
@Override
public final String toString() {
......@@ -31,7 +23,7 @@ public final class QIRLnil extends QIRList {
@Override
public boolean equals(Object other) {
return other instanceof QIRLnil || other instanceof QIRAny;
return other == QIRLnil.instance || other == QIRAny.instance;
}
@Override
......
package qir.ast.data;
import com.oracle.truffle.api.source.SourceSection;
import qir.driver.IQIRVisitor;
import qir.util.QIRAny;
......@@ -9,20 +7,14 @@ import qir.util.QIRAny;
* This class represents the empty {@link QIRTuple}, it is therefore a singleton.
*/
public final class QIRTnil extends QIRTuple {
private QIRTnil(final SourceSection source) {
super(source);
private QIRTnil() {
super(null);
}
private static final QIRTnil singleton = new QIRTnil(null);
/**
* Use this method to refer to the empty {@link QIRTuple}.
*
* @return The unique representation of the empty {@link QIRTuple}.
* The unique representation of the empty {@link QIRTuple}.
*/
public static final QIRTnil getInstance() {
return singleton;
}
public static final QIRTnil instance = new QIRTnil();
@Override
public final String toString() {
......@@ -31,7 +23,7 @@ public final class QIRTnil extends QIRTuple {
@Override
public boolean equals(Object other) {
return other instanceof QIRTnil || other instanceof QIRAny;
return other == QIRTnil.instance || other == QIRAny.instance;
}
@Override
......
package qir.ast.value;
import com.oracle.truffle.api.source.SourceSection;
import qir.driver.IQIRVisitor;
import qir.util.QIRAny;
......@@ -9,17 +7,16 @@ import qir.util.QIRAny;
* The {@link QIRBoolean} represents a boolean.
*/
public final class QIRBoolean extends QIRBaseValue<Boolean> {
public QIRBoolean(final SourceSection source, final boolean value) {
super(source, value);
private QIRBoolean(final boolean value) {
super(null, value);
}
public static final QIRBoolean qirTrue = new QIRBoolean(true);
public static final QIRBoolean qirFalse = new QIRBoolean(false);
@Override
public boolean equals(Object other) {
if (other instanceof QIRAny)
return true;
if (!(other instanceof QIRBoolean))
return false;
return value.equals(((QIRBoolean) other).value);
return this == other || other == QIRAny.instance;
}
@Override
......
......@@ -24,7 +24,7 @@ final class QIREvaluationVisitor implements IQIRVisitor<QIRNode> {
final QIRNode formatter = qirProject.formatter.accept(this);
final QIRNode input = qirProject.child.accept(this);
final Deque<QIRNode> tmp = new ArrayDeque<>();
QIRList result = QIRLnil.getInstance();
QIRList result = QIRLnil.instance;
if (input instanceof QIRLnil)
return input;
......@@ -39,7 +39,7 @@ final class QIREvaluationVisitor implements IQIRVisitor<QIRNode> {
@Override
public final QIRNode visit(final QIRScan qirScan) {
throw new QIRException("Unreachable code reached.");
throw new QIRException("Cannot perform scan in QIR evaluation.");
}
@Override
......@@ -47,7 +47,7 @@ final class QIREvaluationVisitor implements IQIRVisitor<QIRNode> {
final QIRNode filter = qirFilter.filter.accept(this);
final QIRNode input = qirFilter.child.accept(this);
final Deque<QIRNode> tmp = new ArrayDeque<>();
QIRList result = QIRLnil.getInstance();
QIRList result = QIRLnil.instance;
if (input instanceof QIRLnil)
return input;
......@@ -55,9 +55,9 @@ final class QIREvaluationVisitor implements IQIRVisitor<QIRNode> {
return new QIRFilter(qirFilter.sourceSection, filter, input);
for (QIRNode e = input; e instanceof QIRLcons; e = ((QIRLcons) e).tail) {
final QIRNode pass = new QIRApply(null, filter, ((QIRLcons) e).value).accept(this);
if (pass.equals(new QIRBoolean(null, true)))
if (pass.equals(QIRBoolean.qirTrue))
tmp.push(((QIRLcons) e).value);
else if (!pass.equals(new QIRBoolean(null, false)))
else if (!pass.equals(QIRBoolean.qirFalse))
return new QIRFilter(qirFilter.sourceSection, pass, input);
}
while (!tmp.isEmpty())
......@@ -81,7 +81,7 @@ final class QIREvaluationVisitor implements IQIRVisitor<QIRNode> {
final QIRNode left = qirJoin.left.accept(this);
final QIRNode right = qirJoin.right.accept(this);
final Deque<QIRNode> tmp = new ArrayDeque<>();
QIRList result = QIRLnil.getInstance();
QIRList result = QIRLnil.instance;
if (left instanceof QIRLnil)
return left;
......@@ -90,9 +90,9 @@ final class QIREvaluationVisitor implements IQIRVisitor<QIRNode> {
for (QIRNode l = left; l instanceof QIRLcons; l = ((QIRLcons) l).tail)
for (QIRNode r = right; r instanceof QIRLcons; r = ((QIRLcons) r).tail) {
final QIRNode pass = new QIRApply(null, new QIRApply(null, filter, ((QIRLcons) l).value), ((QIRLcons) r).value).accept(this);
if (pass.equals(new QIRBoolean(null, true))) {
if (pass.equals(QIRBoolean.qirTrue)) {
final Deque<QIRTcons> s = new ArrayDeque<>();
QIRNode res = QIRTnil.getInstance();
QIRNode res = QIRTnil.instance;
for (QIRNode t = ((QIRLcons) l).value; t instanceof QIRTcons; t = ((QIRTcons) t).tail)
s.push((QIRTcons) t);
for (QIRNode t = ((QIRLcons) r).value; t instanceof QIRTcons; t = ((QIRTcons) t).tail)
......@@ -100,7 +100,7 @@ final class QIREvaluationVisitor implements IQIRVisitor<QIRNode> {
for (QIRTcons t : s)
res = new QIRTcons(t.sourceSection, t.id, t.value, res);
tmp.push(res);
} else if (!pass.equals(new QIRBoolean(null, false)))
} else if (!pass.equals(QIRBoolean.qirFalse))
return new QIRJoin(qirJoin.sourceSection, pass, left, right);
}
while (!tmp.isEmpty())
......@@ -174,9 +174,9 @@ final class QIREvaluationVisitor implements IQIRVisitor<QIRNode> {
public final QIRNode visit(final QIRIf qirIf) {
final QIRNode cond = qirIf.condition.accept(this);
if (cond.equals(new QIRBoolean(null, true)))
if (cond.equals(QIRBoolean.qirTrue))
return qirIf.thenNode.accept(this);
if (cond.equals(new QIRBoolean(null, false)))
if (cond.equals(QIRBoolean.qirFalse))
return qirIf.elseNode.accept(this);
return new QIRIf(qirIf.sourceSection, cond, qirIf.thenNode, qirIf.elseNode);
}
......@@ -259,7 +259,7 @@ final class QIREvaluationVisitor implements IQIRVisitor<QIRNode> {
final QIRNode right = qirAnd.right.accept(this);
if (left instanceof QIRBoolean && right instanceof QIRBoolean)
return new QIRBoolean(qirAnd.sourceSection, ((QIRBoolean) left).value && ((QIRBoolean) right).value);
return ((QIRBoolean) left).value && ((QIRBoolean) right).value ? QIRBoolean.qirTrue : QIRBoolean.qirFalse;
if (left instanceof QIRBaseValue<?> && right instanceof QIRBaseValue<?>)
throw new QIRException("Typing error: binary operator && not defined for: " + left.getClass().getName() + " and " + right.getClass().getName() + ".");
return new QIRAnd(qirAnd.sourceSection, left, right);
......@@ -271,7 +271,7 @@ final class QIREvaluationVisitor implements IQIRVisitor<QIRNode> {
final QIRNode right = qirOr.right.accept(this);
if (left instanceof QIRBoolean && right instanceof QIRBoolean)
return new QIRBoolean(qirOr.sourceSection, ((QIRBoolean) left).value || ((QIRBoolean) right).value);
return ((QIRBoolean) left).value || ((QIRBoolean) right).value ? QIRBoolean.qirTrue : QIRBoolean.qirFalse;
if (left instanceof QIRBaseValue<?> && right instanceof QIRBaseValue<?>)
throw new QIRException("Typing error: binary operator || not defined for: " + left.getClass().getName() + " and " + right.getClass().getName() + ".");
return new QIROr(qirOr.sourceSection, left, right);
......@@ -283,13 +283,13 @@ final class QIREvaluationVisitor implements IQIRVisitor<QIRNode> {
final QIRNode right = qirEqual.right.accept(this);
if (left instanceof QIRNumber && right instanceof QIRNumber)
return new QIRBoolean(qirEqual.sourceSection, ((QIRNumber) left).value == ((QIRNumber) right).value);
return ((QIRNumber) left).value == ((QIRNumber) right).value ? QIRBoolean.qirTrue : QIRBoolean.qirFalse;
if (left instanceof QIRString && right instanceof QIRString)
return new QIRBoolean(qirEqual.sourceSection, ((QIRString) left).value.equals(((QIRString) right).value));
return ((QIRString) left).value.equals(((QIRString) right).value) ? QIRBoolean.qirTrue : QIRBoolean.qirFalse;
if (left instanceof QIRBoolean && right instanceof QIRBoolean)
return new QIRBoolean(qirEqual.sourceSection, ((QIRBoolean) left).value == ((QIRBoolean) right).value);
return ((QIRBoolean) left).value == ((QIRBoolean) right).value ? QIRBoolean.qirTrue : QIRBoolean.qirFalse;
if (left instanceof QIRBigNumber && right instanceof QIRBigNumber)
return new QIRBoolean(qirEqual.sourceSection, ((QIRBigNumber) left).value.equals(((QIRBigNumber) right).value));
return ((QIRBigNumber) left).value.equals(((QIRBigNumber) right).value) ? QIRBoolean.qirTrue : QIRBoolean.qirFalse;
if (left instanceof QIRBaseValue<?> && right instanceof QIRBaseValue<?>)
throw new QIRException("Typing error: binary operator == not defined for: " + left.getClass().getName() + " and " + right.getClass().getName() + ".");
return new QIREqual(qirEqual.sourceSection, left, right);
......@@ -301,11 +301,11 @@ final class QIREvaluationVisitor implements IQIRVisitor<QIRNode> {
final QIRNode right = qirLowerOrEqual.right.accept(this);
if (left instanceof QIRNumber && right instanceof QIRNumber)
return new QIRBoolean(qirLowerOrEqual.sourceSection, ((QIRNumber) left).value <= ((QIRNumber) right).value);
return ((QIRNumber) left).value <= ((QIRNumber) right).value ? QIRBoolean.qirTrue : QIRBoolean.qirFalse;
if (left instanceof QIRString && right instanceof QIRString)
return new QIRBoolean(qirLowerOrEqual.sourceSection, ((QIRString) left).value.compareTo(((QIRString) right).value) <= 0);
return ((QIRString) left).value.compareTo(((QIRString) right).value) <= 0 ? QIRBoolean.qirTrue : QIRBoolean.qirFalse;
if (left instanceof QIRBigNumber && right instanceof QIRBigNumber)
return new QIRBoolean(qirLowerOrEqual.sourceSection, ((QIRBigNumber) left).value.compareTo(((QIRBigNumber) right).value) <= 0);
return ((QIRBigNumber) left).value.compareTo(((QIRBigNumber) right).value) <= 0 ? QIRBoolean.qirTrue : QIRBoolean.qirFalse;
if (left instanceof QIRBaseValue<?> && right instanceof QIRBaseValue<?>)
throw new QIRException("Typing error: binary operator <= not defined for: " + left.getClass().getName() + " and " + right.getClass().getName() + ".");
return new QIRLowerOrEqual(qirLowerOrEqual.sourceSection, left, right);
......@@ -317,11 +317,11 @@ final class QIREvaluationVisitor implements IQIRVisitor<QIRNode> {
final QIRNode right = qirLowerThan.right.accept(this);
if (left instanceof QIRNumber && right instanceof QIRNumber)
return new QIRBoolean(qirLowerThan.sourceSection, ((QIRNumber) left).value < ((QIRNumber) right).value);
return ((QIRNumber) left).value < ((QIRNumber) right).value ? QIRBoolean.qirTrue : QIRBoolean.qirFalse;
if (left instanceof QIRString && right instanceof QIRString)
return new QIRBoolean(qirLowerThan.sourceSection, ((QIRString) left).value.compareTo(((QIRString) right).value) < 0);
return ((QIRString) left).value.compareTo(((QIRString) right).value) < 0 ? QIRBoolean.qirTrue : QIRBoolean.qirFalse;
if (left instanceof QIRBigNumber && right instanceof QIRBigNumber)
return new QIRBoolean(qirLowerThan.sourceSection, ((QIRBigNumber) left).value.compareTo(((QIRBigNumber) right).value) < 0);
return ((QIRBigNumber) left).value.compareTo(((QIRBigNumber) right).value) < 0 ? QIRBoolean.qirTrue : QIRBoolean.qirFalse;
if (left instanceof QIRBaseValue<?> && right instanceof QIRBaseValue<?>)
throw new QIRException("Typing error: binary operator < not defined for: " + left.getClass().getName() + " and " + right.getClass().getName() + ".");
return new QIRLowerThan(qirLowerThan.sourceSection, left, right);
......@@ -332,7 +332,7 @@ final class QIREvaluationVisitor implements IQIRVisitor<QIRNode> {
final QIRNode expr = qirNot.child.accept(this);
if (expr instanceof QIRBoolean)
return new QIRBoolean(qirNot.sourceSection, !((QIRBoolean) expr).value);
return ((QIRBoolean) expr).value ? QIRBoolean.qirFalse : QIRBoolean.qirTrue;
if (expr instanceof QIRBaseValue<?>)
throw new QIRException("Typing error: binary operator ! not defined for: " + expr.getClass().getName() + ".");
return new QIRNot(qirNot.sourceSection, expr);
......
......@@ -104,9 +104,9 @@ final class QIRGreedyReduceVisitor implements IQIRVisitor<QIRNode> {
public final QIRNode visit(final QIRIf qirIf) {
final QIRNode cond = qirIf.condition.accept(this);
if (cond.equals(new QIRBoolean(null, true)))
if (cond.equals(QIRBoolean.qirTrue))
return qirIf.thenNode.accept(this);
if (cond.equals(new QIRBoolean(null, false)))
if (cond.equals(QIRBoolean.qirFalse))
return qirIf.elseNode.accept(this);
return new QIRIf(qirIf.sourceSection, cond, qirIf.thenNode.accept(this), qirIf.elseNode.accept(this));
}
......@@ -152,9 +152,9 @@ final class QIRGreedyReduceVisitor implements IQIRVisitor<QIRNode> {
final QIRNode right = qirEqual.right.accept(this);
if (left.equals(right))
return new QIRBoolean(null, true);
return QIRBoolean.qirTrue;
if (left instanceof QIRBaseValue<?> && right instanceof QIRBaseValue<?>)
return new QIRBoolean(null, false);
return QIRBoolean.qirFalse;
return new QIREqual(qirEqual.sourceSection, left, right);
}
......
......@@ -35,6 +35,7 @@ import qir.util.QIRException;
*/
public final class HBaseDriver extends DBDriver<HBaseQuery, String> {
protected Connection conn;
private Configuration conf;
public HBaseDriver(final String configFile) {
super(configFile);
......@@ -44,8 +45,8 @@ public final class HBaseDriver extends DBDriver<HBaseQuery, String> {
public void openConnection(final String configFile) throws QIRException {
if (conn != null)
closeConnection();
final Configuration conf = HBaseConfiguration.create();
conf = HBaseConfiguration.create();
conf.addResource(configFile);
try {
conn = ConnectionFactory.createConnection(conf);
......@@ -76,20 +77,20 @@ public final class HBaseDriver extends DBDriver<HBaseQuery, String> {
@Override
public HBaseQuery translate(final QIRNode root) {
return root.accept(new QIRHBaseQueryVisitor());
return root.accept(new QIRHBaseQueryVisitor(conf));
}
@Override
public QIRList run(final HBaseQuery query) throws QIRException {
final ResultScanner rs;
final Deque<QIRTuple> tmp = new ArrayDeque<>();
QIRList result = QIRLnil.getInstance();
QIRList result = QIRLnil.instance;
QIRNode data;
try (final Table table = conn.getTable(TableName.valueOf(query.tableName))) {
rs = table.getScanner(query.scan);
for (Result r = rs.next(); r != null; r = rs.next()) {
QIRTuple newTuple = QIRTnil.getInstance();
QIRTuple newTuple = QIRTnil.instance;
for (final Cell cell : r.listCells()) {
final String value = Bytes.toString(CellUtil.cloneValue(cell));
try {
......
package qir.driver.hbase;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.mapreduce.TableReducer;
import org.apache.hadoop.mapreduce.Job;
import qir.ast.*;
import qir.ast.data.*;
......@@ -13,10 +22,16 @@ import qir.util.QIRException;
* Translation from a QIR query to a HBase query in {@link HBaseQuery} format.
*/
final class QIRHBaseQueryVisitor implements IQIRVisitor<HBaseQuery> {
final Configuration conf;
QIRHBaseQueryVisitor(final Configuration conf) {
this.conf = conf;
}
@Override
public final HBaseQuery visit(QIRProject qirProject) {
if (!(qirProject.formatter instanceof QIRLambda && ((QIRLambda) qirProject.formatter).body instanceof QIRTcons))
throw new QIRException("QIR SQL Project not implemented for formatter type: " + qirProject.formatter.getClass());
throw new QIRException("QIR HBase Project not implemented for formatter type: " + qirProject.formatter.getClass());
final HBaseQuery child = qirProject.child.accept(this);
for (QIRNode formatter = ((QIRLambda) qirProject.formatter).body; formatter instanceof QIRTcons; formatter = ((QIRTcons) formatter).tail)
......@@ -39,6 +54,37 @@ final class QIRHBaseQueryVisitor implements IQIRVisitor<HBaseQuery> {
return child;
}
private static class GroupByMapper extends TableMapper<String, String> {
@Override
public void map(ImmutableBytesWritable row, Result value, Context context) throws InterruptedException, IOException {
}
}
private static class GroupByReducer extends TableReducer<ImmutableBytesWritable, String, ImmutableBytesWritable> {
@Override
public void reduce(ImmutableBytesWritable key, Iterable<String> values, Context context) {
}
}
@Override
public final HBaseQuery visit(QIRGroupBy qirGroup) {
if (!(qirGroup.group instanceof QIRLambda))
throw new QIRException("QIR HBase Group not implemented for group type: " + qirGroup.group.getClass());
if (!(qirGroup.child instanceof QIRProject))
throw new QIRException("Invalid QIR HBase Group");
final HBaseQuery child = qirGroup.child.accept(this);
final Job job;
try {
job = Job.getInstance(conf);
job.setJarByClass(QIRHBaseQueryVisitor.class);
TableMapReduceUtil.initTableMapperJob(child.tableName, child.scan, GroupByMapper.class, String.class, String.class, job);
TableMapReduceUtil.initTableReducerJob(child.tableName, GroupByReducer.class, job);
} catch (IOException e) {
throw new QIRException(e.getMessage());
}
return child;
}
@Override
public final <DBRepr, ConnData> HBaseQuery visit(final QIRDBNode<DBRepr, ConnData> qirDBNode) {
return (HBaseQuery) qirDBNode.translation;
......
......@@ -73,10 +73,10 @@ final class QIRSQLStringVisitor implements IQIRVisitor<String> {
((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.accept(this).equals(new QIRBoolean(null, true)) ? "" : " desc");
String o = ((QIRLcons) rows).value.accept(this) + (((QIRLcons) ascs).value.accept(this).equals(QIRBoolean.qirTrue) ? "" : " 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.accept(this).equals(new QIRBoolean(null, true)) ? "" : " desc");
o += ", " + ((QIRLcons) rows).value.accept(this) + (((QIRLcons) ascs).value.accept(this).equals(QIRBoolean.qirTrue) ? "" : " desc");
return "select * from (" + qirOrder.child.accept(this) + ") as " + ((QIRLambda) qirOrder.order).var.accept(this) + " order by " + o;
}
throw new QIRException("QIR SQL OrderBy not implemented for: " + qirOrder.order.getClass() + " and " + qirOrder.isAscending.getClass());
......@@ -269,7 +269,7 @@ final class QIRSQLStringVisitor implements IQIRVisitor<String> {
@Override
public final String visit(final QIRLdestr qirLdestr) {
final QIRAny any = QIRAny.getInstance();
final QIRAny any = QIRAny.instance;
if (qirLdestr.equals(new QIRLdestr(null, any, any,
new QIRLambda(null, null, new QIRVariable(null, "head", null), new QIRLambda(null, null, new QIRVariable(null, "tail", null), new QIRVariable(null, "tail", null))))))
return "select * from (" + qirLdestr.list.accept(this) + ") as " + genFreshId() + " limit 1";
......
......@@ -47,11 +47,11 @@ public 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.getInstance();
QIRList result = QIRLnil.instance;
QIRNode data;
while (rs.next()) {
QIRTuple newTuple = QIRTnil.getInstance();
QIRTuple newTuple = QIRTnil.instance;
for (int i = rs.getMetaData().getColumnCount(); i >= 1; i--) {
int type = rs.getMetaData().getColumnType(i);
switch (type) {
......@@ -61,13 +61,13 @@ public abstract class SQLStringDriver extends SQLDriver<String> {
data = new QIRNumber(null, rs.getLong(i));
break;
case Types.BOOLEAN:
data = new QIRBoolean(null, rs.getBoolean(i));
data = rs.getBoolean(i) ? QIRBoolean.qirTrue : QIRBoolean.qirFalse;
break;
case Types.DOUBLE:
data = new QIRDouble(null, rs.getDouble(i));
break;
case Types.NULL:
data = QIRNull.getInstance();
data = QIRNull.instance;
break;
case Types.OTHER:
String v = rs.getString(i);
......@@ -81,7 +81,7 @@ public abstract class SQLStringDriver extends SQLDriver<String> {
if (value instanceof Long)
data = new QIRNumber(null, (Long) value);
else if (value instanceof Boolean)
data = new QIRBoolean(null, (Boolean) value);
data = (Boolean) value ? QIRBoolean.qirTrue : QIRBoolean.qirFalse;
else
data = new QIRString(null, value.toString());
} catch (IOException | ClassNotFoundException e) {
......
package qir.util;
import com.oracle.truffle.api.source.SourceSection;
import qir.ast.QIRNode;
import qir.driver.IQIRVisitor;
......@@ -9,23 +7,14 @@ import qir.driver.IQIRVisitor;
* This class represents any QIRNode.
*/
public final class QIRAny extends QIRNode {
private QIRAny(final SourceSection src) {
super(src);
private QIRAny() {
super(null);
}
/**
* The only instance of {@link QIRAny}.
*/
private static final QIRAny singleton = new QIRAny(null);
/**
* Use this method to refer to any QIRNode.
*
* @return The unique representation of QIRAny.
*/
public static final QIRAny getInstance() {
return singleton;
}
public static final QIRAny instance = new QIRAny();
@Override
public final String toString() {
......@@ -34,7 +23,7 @@ public final class QIRAny extends QIRNode {
@Override
public boolean equals(Object other) {
return other instanceof QIRAny;
return other instanceof QIRNode;
}
@Override
......
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