use of catdata.fql.sql.Flower in project fql by CategoricalData.
the class InstOps method visit.
@Override
public List<PSM> visit(String dst, TransExp.Sigma e) {
List<PSM> ret = new LinkedList<>();
Pair<String, String> ht = e.h.type(prog);
Signature sig = prog.insts.get(ht.first).type(prog).toSig(prog);
Mapping F = ((Sigma) prog.insts.get(e.src)).F.toMap(prog);
String next = next();
ret.addAll(PSMGen.makeTables(next, sig, false));
ret.addAll(e.h.accept(next, this));
Signature sig2 = prog.insts.get(e.src).type(prog).toSig(prog);
String xxx = "sigfunc";
ret.addAll(PSMGen.makeTables(xxx, sig2, false));
for (Node n : sig2.nodes) {
List<Flower> l = new LinkedList<>();
for (Node m : F.source.nodes) {
if (F.nm.get(m).equals(n)) {
l.add(new CopyFlower(next + "_" + m.string, "c0", "c1"));
}
}
String yyy = xxx + "_" + n.string;
if (l.isEmpty()) {
ret.add(new InsertSQL(yyy, l.get(0), "c0", "c1"));
} else {
ret.add(new InsertSQL(yyy, new Union(l), "c0", "c1"));
}
ret.add(new InsertSQL(dst + "_" + n.string, PSMGen.compose(e.src + "_" + n.string + "_subst_inv", yyy, e.dst + "_" + n.string + "_subst"), "c0", "c1"));
}
ret.addAll(PSMGen.dropTables(xxx, sig2));
ret.addAll(PSMGen.dropTables(next, sig));
return ret;
}
use of catdata.fql.sql.Flower in project fql by CategoricalData.
the class InstOps method visit.
@Override
public Pair<List<PSM>, Object> visit(String dst, Plus e) {
SigExp k = e.type(prog);
Signature s = k.toSig(prog);
List<PSM> ret = new LinkedList<>();
for (Node n : s.nodes) {
List<Flower> l = new LinkedList<>();
l.add(new CopyFlower(e.a + "_" + n.string, "c0", "c1"));
l.add(new CopyFlower(e.b + "_" + n.string, "c0", "c1"));
ret.add(new InsertSQL(dst + "_" + n.string, new Union(l), "c0", "c1"));
}
for (Attribute<Node> n : s.attrs) {
List<Flower> l = new LinkedList<>();
l.add(new CopyFlower(e.a + "_" + n.name, "c0", "c1"));
l.add(new CopyFlower(e.b + "_" + n.name, "c0", "c1"));
ret.add(new InsertSQL(dst + "_" + n.name, new Union(l), "c0", "c1"));
}
for (Edge n : s.edges) {
List<Flower> l = new LinkedList<>();
l.add(new CopyFlower(e.a + "_" + n.name, "c0", "c1"));
l.add(new CopyFlower(e.b + "_" + n.name, "c0", "c1"));
ret.add(new InsertSQL(dst + "_" + n.name, new Union(l), "c0", "c1"));
}
ret.addAll(PSMGen.guidify(dst, s, true));
ret.addAll(PSMGen.makeTables(dst + "_inl", s, false));
ret.addAll(PSMGen.makeTables(dst + "_inr", s, false));
for (Node n : s.nodes) {
SQL f = PSMGen.compose(e.a + "_" + n.string, dst + "_" + n.string + "_subst");
ret.add(new InsertSQL(dst + "_inl_" + n.string, f, "c0", "c1"));
SQL f0 = PSMGen.compose(e.b + "_" + n.string, dst + "_" + n.string + "_subst");
ret.add(new InsertSQL(dst + "_inr_" + n.string, f0, "c0", "c1"));
}
// (f+g) : A+B -> C f : A -> C g : B -> C
Fn<Quad<String, String, String, String>, List<PSM>> fn = x -> {
// e.a -> x.third
String f = x.first;
// e.b -> x.third
String g = x.second;
// String C = x.third;
String dst0 = x.fourth;
// must be a map dst -> x.third
List<PSM> ret1 = new LinkedList<>();
for (Node n : s.nodes) {
Flower sql1 = PSMGen.compose(dst + "_" + n.string + "_subst_inv", f + "_" + n.string);
Flower sql2 = PSMGen.compose(dst + "_" + n.string + "_subst_inv", g + "_" + n.string);
List<Flower> flowers = new LinkedList<>();
flowers.add(sql1);
flowers.add(sql2);
ret1.add(new InsertSQL(dst0 + "_" + n.string, new Union(flowers), "c0", "c1"));
}
return ret1;
};
return new Pair<>(ret, fn);
}
use of catdata.fql.sql.Flower in project fql by CategoricalData.
the class InstOps method visit.
@Override
public List<PSM> visit(String dst, TransExp.Pi e) {
try {
List<PSM> ret = new LinkedList<>();
Pair<String, String> ht = e.h.type(prog);
Signature sig = prog.insts.get(ht.first).type(prog).toSig(prog);
Mapping F = ((Pi) prog.insts.get(e.src)).F.toMap(prog);
Map<String, Triple<Node, Node, Arr<Node, Path>>[]> colmap1x = PSMGen.pi(F, e.h.type(prog).first, e.src).second;
String next = next();
ret.addAll(PSMGen.makeTables(next, sig, false));
ret.addAll(e.h.accept(next, this));
Signature sig2 = prog.insts.get(e.src).type(prog).toSig(prog);
for (Node n : sig2.nodes) {
List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
Map<String, String> from = new HashMap<>();
from.put("limit1", e.src + "_" + n.string + "_limit");
from.put("limit2", e.dst + "_" + n.string + "_limit");
LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
int i = 0;
for (Triple<Node, Node, Arr<Node, Path>> col : colmap1x.get(n.string)) {
from.put("l" + i, next + "_" + col.second.string);
where.add(new Pair<>(new Pair<>("l" + i, "c0"), new Pair<>("limit1", "c" + i)));
where.add(new Pair<>(new Pair<>("l" + i, "c1"), new Pair<>("limit2", "c" + i)));
i++;
}
// check
for (@SuppressWarnings("unused") Attribute<Node> a : sig2.attrsFor(n)) {
where.add(new Pair<>(new Pair<>("limit1", "c" + i), new Pair<>("limit2", "c" + i)));
i++;
}
select.put("c0", new Pair<>("limit1", "guid"));
select.put("c1", new Pair<>("limit2", "guid"));
Flower f = new Flower(select, from, where);
ret.add(new InsertSQL(dst + "_" + n.string, f, "c0", "c1"));
}
return ret;
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getLocalizedMessage());
}
}
use of catdata.fql.sql.Flower in project fql by CategoricalData.
the class InstOps method visit.
@Override
public List<PSM> visit(String dst, TransExp.Relationalize e) {
List<PSM> ret = new LinkedList<>();
Pair<String, String> ht = e.h.type(prog);
Signature sig = prog.insts.get(ht.first).type(prog).toSig(prog);
String next = next();
ret.addAll(PSMGen.makeTables(next, sig, false));
ret.addAll(e.h.accept(next, this));
Map<String, String> attrs = new HashMap<>();
attrs.put("c0", PSM.VARCHAR());
attrs.put("c1", PSM.VARCHAR());
for (Node n : sig.nodes) {
ret.add(new CreateTable(n.string + "xxx_temp", attrs, false));
ret.add(new CreateTable(n.string + "yyy_temp", attrs, false));
LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
select.put("c0", new Pair<>("l", "c0"));
select.put("c1", new Pair<>("r", "c0"));
Map<String, String> from = new HashMap<>();
from.put("l", e.src + "_" + n.string + "_subst_inv");
from.put("r", e.src + "_" + n.string + "_squash");
List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
where.add(new Pair<>(new Pair<>("l", "c1"), new Pair<>("r", "c1")));
Flower jk = new Flower(select, from, where);
ret.add(new InsertSQL(n.string + "yyy_temp", jk, "c0", "c1"));
ret.add(new InsertSQL(n.string + "xxx_temp", PSMGen.compose(next + "_" + n.string, e.dst + "_" + n.string + "_squash", e.dst + "_" + n.string + "_subst"), "c0", "c1"));
ret.add(new InsertSQL(dst + "_" + n.string, PSMGen.compose(n.string + "yyy_temp", n.string + "xxx_temp"), "c0", "c1"));
ret.add(new DropTable(n.string + "xxx_temp"));
ret.add(new DropTable(n.string + "yyy_temp"));
}
ret.addAll(PSMGen.dropTables(next, sig));
return ret;
}
use of catdata.fql.sql.Flower in project fql by CategoricalData.
the class InstOps method visit.
@Override
public List<PSM> visit(String dst, Comp e) {
List<PSM> ret = new LinkedList<>();
Pair<String, String> ty = e.l.type(prog);
InstExp inst = prog.insts.get(ty.first);
Signature inst_type = inst.type(prog).toSig(prog);
String el = next();
ret.addAll(PSMGen.makeTables(el, inst_type, false));
ret.addAll(e.l.accept(el, this));
String er = next();
ret.addAll(PSMGen.makeTables(er, inst_type, false));
ret.addAll(e.r.accept(er, this));
for (Node k : inst_type.nodes) {
Map<String, String> from = new HashMap<>();
from.put("lft", el + "_" + k);
from.put("rght", er + "_" + k);
List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
where.add(new Pair<>(new Pair<>("lft", "c1"), new Pair<>("rght", "c0")));
LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
select.put("c0", new Pair<>("lft", "c0"));
select.put("c1", new Pair<>("rght", "c1"));
Flower f = new Flower(select, from, where);
ret.add(new InsertSQL(dst + "_" + k, f, "c0", "c1"));
}
ret.addAll(PSMGen.dropTables(el, inst_type));
ret.addAll(PSMGen.dropTables(er, inst_type));
return ret;
}
Aggregations