diff options
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas')
5 files changed, 159 insertions, 9 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Interpreter.java b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Interpreter.java index 6129f48..339fce6 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Interpreter.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Interpreter.java @@ -482,8 +482,7 @@ public class Interpreter { } public Result visit(RelOpEqC op, ValuesPair pair) { - // TODO - throw new UnsupportedOperationException("RelOpEqC Not yet implemented"); + return pair.left.isEqual(pair.right); } public Result visit(RelOpNeC op, ValuesPair pair) { @@ -495,8 +494,7 @@ public class Interpreter { } public Result visit(RelOpLeC op, ValuesPair pair) { - // TODO - throw new UnsupportedOperationException("RelOpLeC Not yet implemented"); + return pair.right.isLowerThan(pair.left).negate(); } public Result visit(RelOpGeC op, ValuesPair pair) { diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Result.java b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Result.java index 5c1a494..383c097 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Result.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Result.java @@ -135,6 +135,7 @@ abstract class Result { protected abstract Result binaryOperationTyped(BinaryOperation operation, ResultSingle right); protected abstract Result binaryOperationTyped(BinaryOperation operation, ResultColumn right); + protected abstract Result binaryOperationTyped(BinaryOperation operation, ResultList right); public Result binaryOperation(BinaryOperation operation, Result right) { return right.callMe(operation, this); @@ -151,12 +152,10 @@ abstract class Result { public abstract ValueList getColumn(); public ResultSingle aggregationOperation(AggregationOperation operation) { - // TODO throw new UnsupportedOperationException("aggregation Not yet implemented"); } public Result transformOperation(TransformOperation operation) { - // TODO throw new UnsupportedOperationException("transformation Not yet implemented"); } diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/ResultColumn.java b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/ResultColumn.java index 1c0db30..3e0b55a 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/ResultColumn.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/ResultColumn.java @@ -28,6 +28,10 @@ class ResultColumn extends Result { return new ResultColumn(results); } + protected Result binaryOperationTyped(BinaryOperation operation, ResultList right) { + throw new UnsupportedOperationException("Binary operation not supported on ResultColumn and ResultLists"); + } + protected ResultColumn binaryOperationTyped(BinaryOperation operation, ResultColumn right) { List<Value> results = new ArrayList<Value>(); @@ -75,8 +79,7 @@ class ResultColumn extends Result { @Override public Result transformOperation(TransformOperation operation) { - // TODO: this should be a ResultList - return new ResultColumn(operation.perform(getColumn())); + return new ResultList(operation.perform(getColumn())); } @Override @@ -125,7 +128,7 @@ class ResultColumn extends Result { @Override public ResultSingle isNull() { - return new ResultSingle(new ValueBoolean(true)); + return new ResultSingle(new ValueBoolean(false)); } @Override diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/ResultList.java b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/ResultList.java new file mode 100644 index 0000000..c79a984 --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/ResultList.java @@ -0,0 +1,139 @@ +package pl.edu.mimuw.cloudatlas.interpreter; + +import java.util.ArrayList; +import java.util.List; + +import pl.edu.mimuw.cloudatlas.model.Type; +import pl.edu.mimuw.cloudatlas.model.TypePrimitive; +import pl.edu.mimuw.cloudatlas.model.TypeCollection; +import pl.edu.mimuw.cloudatlas.model.Value; +import pl.edu.mimuw.cloudatlas.model.ValueBoolean; +import pl.edu.mimuw.cloudatlas.model.ValueList; + +class ResultList extends Result { + private final List<Value> list; + + public ResultList(List<Value> list) { + this.list = list; + } + + @Override + protected ResultList binaryOperationTyped(BinaryOperation operation, ResultSingle right) { + List<Value> results = new ArrayList<Value>(); + + for (Value value : list) { + results.add(operation.perform(value, right.getValue())); + } + + return new ResultList(results); + } + + protected Result binaryOperationTyped(BinaryOperation operation, ResultList right) { + throw new UnsupportedOperationException("Binary operation not supported on two ResultLists"); + } + + protected Result binaryOperationTyped(BinaryOperation operation, ResultColumn right) { + throw new UnsupportedOperationException("Binary operation not supported on ResultList and ResultColumn"); + } + + @Override + public ResultList unaryOperation(UnaryOperation operation) { + List<Value> results = new ArrayList<Value>(); + + for (Value value : list) { + results.add(operation.perform(value)); + } + return new ResultList(results); + } + + @Override + protected Result callMe(BinaryOperation operation, Result left) { + return left.binaryOperationTyped(operation, this); + } + + @Override + public Value getValue() { + throw new UnsupportedOperationException("ResultList: Not a ResultSingle."); + } + + @Override + public ValueList getList() { + return new ValueList(list, TypeCollection.computeElementType(list)); + } + + @Override + public ValueList getColumn() { + throw new UnsupportedOperationException("Not a ResultColumn."); + } + + @Override + public ResultSingle aggregationOperation(AggregationOperation operation) { + return new ResultSingle(operation.perform(getList())); + } + + @Override + public Result transformOperation(TransformOperation operation) { + return new ResultList(operation.perform(getList())); + } + + @Override + public Result filterNulls() { + throw new UnsupportedOperationException("Operation filterNulls not supported yet."); + } + + @Override + public Result first(int size) { + List<Value> subList = list.subList(0, Math.min(size, list.size())); + return new ResultSingle(new ValueList(subList, TypeCollection.computeElementType(subList))); + } + + @Override + public Result last(int size) { + List<Value> subList = list.subList( + Math.max(0, list.size() - size), + list.size() + ); + return new ResultSingle(new ValueList(subList, TypeCollection.computeElementType(subList))); + } + + @Override + public Result random(int size) { + return new ResultSingle( + randomList( + new ValueList( + list, + TypeCollection.computeElementType(list) + ), + size + ) + ); + } + + @Override + public ResultList convertTo(Type to) { + List<Value> results = new ArrayList<Value>(); + + for (Value value : list) { + results.add(value.convertTo(to)); + } + + return new ResultList(results); + } + + @Override + public ResultSingle isNull() { + return new ResultSingle(new ValueBoolean(true)); + } + + @Override + public Type getType() { + Type type = TypePrimitive.NULL; + for (Value value : list) { + if (value.getType() != TypePrimitive.NULL) { + type = value.getType(); + } + } + + return type; + } +} diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/ResultSingle.java b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/ResultSingle.java index 3d88bb0..4898161 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/ResultSingle.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/ResultSingle.java @@ -55,6 +55,17 @@ class ResultSingle extends Result { return new ResultColumn(results); } + protected ResultList binaryOperationTyped(BinaryOperation operation, ResultList right) { + List<Value> results = new ArrayList<Value>(); + + for (Value value : right.getList()) { + results.add(operation.perform(this.value, value)); + } + + return new ResultList(results); + + } + @Override public ResultSingle unaryOperation(UnaryOperation operation) { return new ResultSingle(operation.perform(value)); |