m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Environment.java26
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Functions.java6
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Interpreter.java25
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Result.java4
4 files changed, 21 insertions, 40 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Environment.java b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Environment.java
index d45b600..dd94631 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Environment.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Environment.java
@@ -24,28 +24,6 @@
package pl.edu.mimuw.cloudatlas.interpreter;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import pl.edu.mimuw.cloudatlas.model.ValueNull;
-
-class Environment {
- private final TableRow row;
- private final Map<String, Integer> columns = new HashMap<String, Integer>();
-
- public Environment(TableRow row, List<String> columns) {
- this.row = row;
- int i = 0;
- for(String c : columns)
- this.columns.put(c, i++);
- }
-
- public Result getIdent(String ident) {
- try {
- return new ResultSingle(row.getIth(columns.get(ident)));
- } catch(NullPointerException exception) {
- return new ResultSingle(ValueNull.getInstance());
- }
- }
+abstract class Environment {
+ abstract public Result getIdent(String ident);
}
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Functions.java b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Functions.java
index dde84fe..2fcb9b3 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Functions.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Functions.java
@@ -78,7 +78,7 @@ class Functions {
@Override
public Value perform(Value v) {
// TODO
- throw new UnsupportedOperationException("Not yet implemented");
+ throw new UnsupportedOperationException("CEIL Not yet implemented");
}
};
@@ -97,7 +97,7 @@ class Functions {
@Override
public Value perform(ValueList values) {
// TODO
- throw new UnsupportedOperationException("Not yet implemented");
+ throw new UnsupportedOperationException("SUM Not yet implemented");
}
};
@@ -152,7 +152,7 @@ class Functions {
@Override
public ValueBoolean perform(ValueList values) { // lazy
// TODO
- throw new UnsupportedOperationException("Not yet implemented");
+ throw new UnsupportedOperationException("OR Not yet implemented");
}
};
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 71a300b..4241ce2 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Interpreter.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Interpreter.java
@@ -184,7 +184,7 @@ public class Interpreter {
public Table visit(WhereC where, Table table) {
Table result = new Table(table);
for(TableRow row : table) {
- Environment env = new Environment(row, table.getColumns());
+ Environment env = new EnvironmentRow(row, table.getColumns());
Value value = where.condexpr_.accept(new CondExprInterpreter(), env).getValue();
if(getBoolean(value))
result.appendRow(row);
@@ -215,9 +215,9 @@ public class Interpreter {
Comparator<TableRow> comparator = new Comparator<TableRow>() {
@Override
public int compare(TableRow row1, TableRow row2) {
- Environment env1 = new Environment(row1, table.getColumns());
+ Environment env1 = new EnvironmentRow(row1, table.getColumns());
Result expr1 = orderItem.condexpr_.accept(new CondExprInterpreter(), env1);
- Environment env2 = new Environment(row2, table.getColumns());
+ Environment env2 = new EnvironmentRow(row2, table.getColumns());
Result expr2 = orderItem.condexpr_.accept(new CondExprInterpreter(), env2);
ValuesPair pair = new ValuesPair(expr1, expr2);
int result = orderItem.nulls_.accept(new NullsInterpreter(), pair);
@@ -280,13 +280,13 @@ public class Interpreter {
public class SelItemInterpreter implements SelItem.Visitor<QueryResult, Table> {
public QueryResult visit(SelItemC selItem, Table table) {
- Environment env = null; // TODO
+ Environment env = new EnvironmentTable(table);
Result result = selItem.condexpr_.accept(new CondExprInterpreter(), env);
return new QueryResult(result.getValue());
}
public QueryResult visit(AliasedSelItemC selItem, Table table) {
- Environment env = null; // TODO
+ Environment env = new EnvironmentTable(table);
Result result = selItem.condexpr_.accept(new CondExprInterpreter(), env);
return new QueryResult(new Attribute(selItem.qident_), result.getValue());
}
@@ -330,7 +330,7 @@ public class Interpreter {
public Result visit(CondExprAndC expr, Environment env) {
// TODO
- throw new UnsupportedOperationException("Not yet implemented");
+ throw new UnsupportedOperationException("CondExprAndC Not yet implemented");
}
public Result visit(CondExprNotC expr, Environment env) {
@@ -406,16 +406,19 @@ public class Interpreter {
}
public Result visit(EIdentC expr, Environment env) {
- return env.getIdent(expr.qident_);
+ Result res = env.getIdent(expr.qident_);
+ return res;
}
public Result visit(EFunC expr, Environment env) {
try {
List<Result> arguments = new ArrayList<Result>(expr.listcondexpr_.size());
- for(CondExpr arg : expr.listcondexpr_)
+ for(CondExpr arg : expr.listcondexpr_) {
arguments.add(arg.accept(new CondExprInterpreter(), env));
+ }
- return Functions.getInstance().evaluate(expr.qident_, arguments);
+ Result res = Functions.getInstance().evaluate(expr.qident_, arguments);
+ return res;
} catch(Exception exception) {
throw new InsideQueryException(PrettyPrinter.print(expr), exception);
}
@@ -475,7 +478,7 @@ public class Interpreter {
public Result visit(RelOpEqC op, ValuesPair pair) {
// TODO
- throw new UnsupportedOperationException("Not yet implemented");
+ throw new UnsupportedOperationException("RelOpEqC Not yet implemented");
}
public Result visit(RelOpNeC op, ValuesPair pair) {
@@ -488,7 +491,7 @@ public class Interpreter {
public Result visit(RelOpLeC op, ValuesPair pair) {
// TODO
- throw new UnsupportedOperationException("Not yet implemented");
+ throw new UnsupportedOperationException("RelOpLeC Not yet implemented");
}
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 5afbe65..e3a0862 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Result.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/interpreter/Result.java
@@ -151,12 +151,12 @@ abstract class Result {
public ResultSingle aggregationOperation(AggregationOperation operation) {
// TODO
- throw new UnsupportedOperationException("Not yet implemented");
+ throw new UnsupportedOperationException("aggregation Not yet implemented");
}
public Result transformOperation(TransformOperation operation) {
// TODO
- throw new UnsupportedOperationException("Not yet implemented");
+ throw new UnsupportedOperationException("transforation Not yet implemented");
}
public Result isEqual(Result right) {