use of catdata.aql.fdm.EvalAlgebra.Row in project fql by CategoricalData.
the class EvalAlgebra method eval.
// TODO must convert back to original unfolded vars
private Pair<List<Var>, Collection<Row<En2, X>>> eval(En2 en2, Frozen<Ty, En1, Sym, Fk1, Att1> q, Connection conn, boolean useSql) {
Collection<Row<En2, X>> ret = null;
Integer k = maxTempSize();
if (useSql) {
Pair<List<Var>, Collection<Row<En2, X>>> ret2 = evalSql(en2, q, I.algebra().intifyX((int) options.getOrDefault(AqlOption.start_ids_at)), conn);
// TODO aql should also stop on max temp size?
return ret2;
} else {
ret = new LinkedList<>();
List<Var> plan = q.order(options, I);
boolean useIndices = useIndices() && q.gens.size() > 1 && I.algebra().hasFreeTypeAlgebra();
ret.add(new Row<>(en2));
for (Var v : plan) {
ret = Row.extend(en2, ret, v, q, I, k, useIndices);
}
return new Pair<>(plan, ret);
}
}
use of catdata.aql.fdm.EvalAlgebra.Row in project fql by CategoricalData.
the class Constraints method triggers.
public <X, Y, Gen, Sk> Collection<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>> triggers(Instance<Ty, En, Sym, Fk, Att, Gen, Sk, X, Y> I, AqlOptions options) {
Collection<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>> T = new LinkedList<>();
for (ED<Ty, En, Sym, Fk, Att> ed : eds) {
Query<Ty, En, Sym, Fk, Att, WHICH, Unit, Void> Q = ed.Q;
EvalInstance<Ty, En, Sym, Fk, Att, Gen, Sk, WHICH, Unit, Void, X, Y> QI = new EvalInstance<>(Q, I, options);
outer: for (Row<WHICH, X> e : QI.algebra().en(WHICH.FRONT)) {
for (Row<WHICH, X> a : QI.algebra().en(WHICH.BACK)) {
if (QI.algebra().fk(new Unit(), a).equals(e)) {
continue outer;
}
}
T.add(new Pair<>(ed, e));
}
}
return T;
}
use of catdata.aql.fdm.EvalAlgebra.Row in project fql by CategoricalData.
the class Constraints method step.
// TODO aql needs to be over all eds
public <Gen, Sk, X, Y> Instance<Ty, En, Sym, Fk, Att, ?, ?, ?, ?> step(Instance<Ty, En, Sym, Fk, Att, Gen, Sk, X, Y> I, AqlOptions options) {
Collection<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>> T = triggers(I, options);
if (T.isEmpty()) {
return null;
}
DMG<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Void> shape = new DMG<>(T, new HashMap<>());
Ctx<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Instance<Ty, En, Sym, Fk, Att, Var, Var, ID, Chc<Var, Pair<ID, Att>>>> nodesA = new Ctx<>();
Ctx<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Instance<Ty, En, Sym, Fk, Att, Var, Var, ID, Chc<Var, Pair<ID, Att>>>> nodesE = new Ctx<>();
Map<Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Term<Void, En, Void, Fk, Void, Gen, Void>> aaa = new HashMap<>();
Map<Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Term<Void, En, Void, Fk, Void, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Void>> xxx = new HashMap<>();
for (Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>> t : T) {
Query<Ty, En, Sym, Fk, Att, WHICH, Unit, Void> Q = t.first.Q;
Instance<Ty, En, Sym, Fk, Att, Var, Var, ID, Chc<Var, Pair<ID, Att>>> A = Q.ens.get(WHICH.FRONT);
Instance<Ty, En, Sym, Fk, Att, Var, Var, ID, Chc<Var, Pair<ID, Att>>> E = Q.ens.get(WHICH.BACK);
Transform<Ty, En, Sym, Fk, Att, Var, Var, Var, Var, ID, Chc<Var, Pair<ID, Att>>, ID, Chc<Var, Pair<ID, Att>>> AE = Q.fks.get(new Unit());
nodesA.put(t, A);
nodesE.put(t, E);
for (Var v : AE.src().gens().keySet()) {
// revisit after colimit fixed
xxx.put(new Pair<>(t, v), Term.Gen(new Pair<>(t, v)));
aaa.put(new Pair<>(t, v), I.algebra().repr(t.second.get(v)));
}
/*for (Void v : AE.src().sks().keySet()) {
yyy.put(v, Util.abort(v)); // revisit after colimit fixed
bbb.put(v, Util.abort(v));
}*/
}
ColimitInstance<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Void, Ty, En, Sym, Fk, Att, Var, Var, ID, Chc<Var, Pair<ID, Att>>> A0 = new ColimitInstance<>(schema, shape, nodesA, new Ctx<>(), options);
ColimitInstance<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Void, Ty, En, Sym, Fk, Att, Var, Var, ID, Chc<Var, Pair<ID, Att>>> E0 = new ColimitInstance<>(schema, shape, nodesE, new Ctx<>(), options);
LiteralTransform<Ty, En, Sym, Fk, Att, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, ID, Chc<Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<ID, Att>>, ID, Chc<Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<ID, Att>>> A0E0 = new LiteralTransform<>(xxx, new HashMap<>(), A0, E0, false);
LiteralTransform<Ty, En, Sym, Fk, Att, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Gen, Sk, ID, Chc<Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<ID, Att>>, X, Y> A0I = new LiteralTransform<>(aaa, new HashMap<>(), A0, I, false);
return pushout(A0E0, A0I, options);
// TODO aql disable checking for speed
}
use of catdata.aql.fdm.EvalAlgebra.Row in project fql by CategoricalData.
the class EvalAlgebra method evalSql.
private Pair<List<Var>, Collection<Row<En2, X>>> evalSql(En2 en2, Frozen<Ty, En1, Sym, Fk1, Att1> q, Pair<Map<X, Integer>, Map<Integer, X>> I, Connection conn) {
if (q.gens.isEmpty()) {
Collection<Row<En2, X>> ret = new LinkedList<>();
ret.add(new Row<>(en2));
return new Pair<>(Collections.emptyList(), ret);
}
List<Var> order = new LinkedList<>(q.gens().keySet());
try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery(Q.toSQL().get(en2));
Collection<Row<En2, X>> ret = new LinkedList<>();
// ResultSetMetaData rsmd = rs.getMetaData();
while (rs.next()) {
Row<En2, X> r = new Row<>(en2);
for (Var v : order) {
X x = I.second.get(rs.getInt(v.var));
if (x == null) {
stmt.close();
rs.close();
throw new RuntimeException("Encountered a NULL generator");
}
r = new Row<>(r, v, x);
}
ret.add(r);
}
rs.close();
stmt.close();
return new Pair<>(order, ret);
} catch (SQLException ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
Aggregations