use of catdata.fql.sql.PSM in project fql by CategoricalData.
the class InstOps method visit.
// src and dst will be guidified, hence, must apply that subst here
@Override
public List<PSM> visit(String env, TransExp.External e) {
List<PSM> ret = new LinkedList<>();
Signature sig = prog.insts.get(e.src).type(prog).toSig(prog);
ret.addAll(PSMGen.makeTables(e.name, sig, false));
for (Node n : sig.nodes) {
ret.add(new InsertSQL(e.name + "_" + n.string, PSMGen.compose(e.src + "_" + n.string + "_subst_inv", e.name + "_" + n.string, e.dst + "_" + n.string + "_subst"), "c0", "c1"));
}
return ret;
}
use of catdata.fql.sql.PSM in project fql by CategoricalData.
the class InstOps method visit.
@Override
public List<PSM> visit(String env, Bool e) {
List<PSM> ret = new LinkedList<>();
// .toSig(prog);
SigExp.Const sigX = prog.insts.get(e.unit).type(prog).toConst(prog);
Signature sig = sigX.toSig(prog);
Triple<Const, Map<Node, Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>>, Map<Node, Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object>>> kkk = Relationalizer.terminal(prog, sigX);
ret.add(new PSMBool(e.bool, e.unit, e.prop, sig, env, kkk.first, kkk.second, kkk.third));
return ret;
}
use of catdata.fql.sql.PSM in project fql by CategoricalData.
the class InstOps method visit.
@Override
public List<PSM> visit(String env, Coreturn e) {
String xxx = "coreturn_temp_xxx";
List<PSM> ret = new LinkedList<>();
InstExp i1 = prog.insts.get(e.inst);
if (i1 instanceof Sigma) {
String middle = ((Sigma) i1).I;
// can't be null
InstExp i2 = prog.insts.get(middle);
Mapping f = ((Sigma) i1).F.toMap(prog);
if (i2 instanceof Delta) {
for (Node n : f.target.nodes) {
List<Flower> u = new LinkedList<>();
for (Node m : f.source.nodes) {
if (!f.nm.get(m).equals(n)) {
continue;
}
u.add(new CopyFlower(middle + "_" + m.string + "_subst_inv", "c0", "c1"));
}
ret.add(new SimpleCreateTable(xxx, PSM.VARCHAR(), false));
ret.add(new InsertSQL(xxx, new Union(u), "c0", "c1"));
ret.add(new InsertSQL(env + "_" + n.string, PSMGen.compose(e.inst + "_" + n.string + "_subst_inv", xxx), "c0", "c1"));
ret.add(new DropTable(xxx));
}
}
} else if (i1 instanceof FullSigma) {
String middle = ((FullSigma) i1).I;
// can't be null
InstExp i2 = prog.insts.get(middle);
Mapping f = ((FullSigma) i1).F.toMap(prog);
if (i2 instanceof Delta) {
ret.add(new FullSigmaCounit(f, ((Delta) i2).I, middle, e.inst, env));
} else {
throw new RuntimeException();
}
} else if (i1 instanceof Delta) {
String middle = ((Delta) i1).I;
// can't be null
InstExp i2 = prog.insts.get(middle);
Mapping f = ((Delta) i1).F.toMap(prog);
if (i2 instanceof Pi) {
Pi input0 = ((Pi) i2);
String input = input0.I;
try {
Map<String, Triple<Node, Node, Arr<Node, Path>>[]> colmap = PSMGen.pi(f, input, middle).second;
for (Node m : f.source.nodes) {
Node n = f.nm.get(m);
Triple<Node, Node, Arr<Node, Path>>[] col = colmap.get(n.string);
Triple<Node, Node, Arr<Node, Path>> toFind = new Triple<>(n, m, new Arr<>(new Path(f.target, n), n, n));
int i = 0;
boolean found = false;
for (Triple<Node, Node, Arr<Node, Path>> cand : col) {
if (cand.equals(toFind)) {
found = true;
Map<String, String> from = new HashMap<>();
from.put("lim", middle + "_" + n + "_limit");
LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
select.put("c0", new Pair<>("lim", "guid"));
select.put("c1", new Pair<>("lim", "c" + i));
List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
Flower flower = new Flower(select, from, where);
ret.add(new SimpleCreateTable(xxx, PSM.VARCHAR(), false));
ret.add(new InsertSQL(xxx, flower, "c0", "c1"));
ret.add(new InsertSQL(env + "_" + m, PSMGen.compose(e.inst + "_" + m + "_subst_inv", xxx), "c0", "c1"));
ret.add(new DropTable(xxx));
break;
}
i++;
}
if (!found) {
throw new RuntimeException();
}
}
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getMessage());
}
} else {
throw new RuntimeException();
}
} else {
throw new RuntimeException();
}
return ret;
}
use of catdata.fql.sql.PSM in project fql by CategoricalData.
the class InstOps method visit.
@Override
public List<PSM> visit(String dst, Snd e) {
List<PSM> ret = new LinkedList<>();
InstExp k = prog.insts.get(e.obj);
Signature t = k.type(prog).toSig(prog);
for (Node n : t.nodes) {
ret.add(new InsertSQL(dst + "_" + n.string, new CopyFlower(e.obj + "_snd_" + n.string, "c0", "c1"), "c0", "c1"));
}
return ret;
}
use of catdata.fql.sql.PSM in project fql by CategoricalData.
the class InstOps method visit.
@Override
public List<PSM> visit(String env, TransCurry e) {
List<PSM> ret = new LinkedList<>();
Signature sig = prog.insts.get(e.inst).type(prog).toSig(prog);
Pair<String, String> k = prog.transforms.get(e.trans).type(prog);
Times t = (Times) prog.insts.get(k.first);
ret.add(new PSMCurry(env, t.a, e.inst, e.trans, k.first, k.second, t.b, sig));
return ret;
}
Aggregations