use of catdata.fql.decl.InstExp.Exp in project fql by CategoricalData.
the class JDBCBridge method maybeExecInstance.
private static List<PSM> maybeExecInstance(InstOps ops, FQLProgram prog, Statement Stmt, String k, InstExp v, PSMInterp interp, Map<String, Set<Map<Object, Object>>> ret) throws SQLException {
List<PSM> psm = new LinkedList<>();
psm.addAll(PSMGen.makeTables(k, v.type(prog).toSig(prog), false));
switch(DefunctGlobalOptions.debug.fql.sqlKind) {
case NATIVE:
psm.addAll(v.accept(k, ops).first);
interp.interpX(psm, ret);
break;
case H2:
case JDBC:
default:
if (v instanceof InstExp.FullSigma) {
List<PSM> xxx = v.accept(k, ops).first;
if (xxx.size() != 1) {
throw new RuntimeException();
}
FullSigma yyy = (FullSigma) xxx.get(0);
int theguid = getGuid(Stmt);
interp.guid = theguid;
yyy.exec(interp, ret);
Stmt.execute("SET @guid = " + interp.guid);
psm.addAll(makeInserts(k, ret, v.type(prog).toSig(prog), ((InstExp.FullSigma) v).F.toMap(prog).source));
} else if (v instanceof Exp) {
List<PSM> xxx = v.accept(k, ops).first;
if (xxx.size() != 1) {
throw new RuntimeException();
}
ExpPSM yyy = (ExpPSM) xxx.get(0);
int theguid = getGuid(Stmt);
interp.guid = theguid;
yyy.exec(interp, ret);
Stmt.execute("SET @guid = " + interp.guid);
psm.addAll(makeInserts(k, ret, v.type(prog).toSig(prog), null));
} else if (v instanceof Two) {
List<PSM> xxx = v.accept(k, ops).first;
if (xxx.size() != 1) {
throw new RuntimeException();
}
PropPSM yyy = (PropPSM) xxx.get(0);
int theguid = getGuid(Stmt);
interp.guid = theguid;
yyy.exec(interp, ret);
Stmt.execute("SET @guid = " + interp.guid);
psm.addAll(makeInserts(k, ret, v.type(prog).toSig(prog), null));
} else if (v instanceof Kernel) {
List<PSM> xxx = v.accept(k, ops).first;
if (xxx.size() != 1) {
throw new RuntimeException();
}
PSMUnChi yyy = (PSMUnChi) xxx.get(0);
int theguid = getGuid(Stmt);
interp.guid = theguid;
yyy.exec(interp, ret);
Stmt.execute("SET @guid = " + interp.guid);
psm.addAll(makeInserts(k, ret, v.type(prog).toSig(prog), null));
Signature ooo = v.type(prog).toSig(prog);
for (Node n : ooo.nodes) {
psm.add(new SimpleCreateTable(k + "_trans_" + n.string, PSM.VARCHAR(), false));
}
for (Edge n : ooo.edges) {
psm.add(new SimpleCreateTable(k + "_trans_" + n.name, PSM.VARCHAR(), false));
}
for (Attribute<Node> n : ooo.attrs) {
psm.add(new SimpleCreateTable(k + "_trans_" + n.name, n.target.psm(), false));
}
psm.addAll(makeInserts(k + "_trans", ret, v.type(prog).toSig(prog), null));
} else if (v instanceof External && DefunctGlobalOptions.debug.fql.sqlKind == SQLKIND.H2) {
} else {
psm.addAll(v.accept(k, ops).first);
}
for (PSM sql : psm) {
Stmt.execute(sql.toPSM());
}
if (!(v instanceof InstExp.FullSigma) && !(v instanceof Exp) && !(v instanceof Two) && !(v instanceof Kernel)) {
gatherInstance(prog, ret, Stmt, k, v);
}
if (v instanceof Delta) {
gatherSubstInv(prog, ret, Stmt, k, v);
} else if (v instanceof Times) {
gatherTransform(prog, ret, Stmt, k + "_fst", v.type(prog).toConst(prog));
gatherTransform(prog, ret, Stmt, k + "_snd", v.type(prog).toConst(prog));
} else if (v instanceof One) {
gatherSubstInv2(prog, ret, Stmt, k, v);
}
break;
}
return psm;
}
use of catdata.fql.decl.InstExp.Exp in project fql by CategoricalData.
the class TransChecker method visit.
@Override
public Pair<String, String> visit(FQLProgram env, TransEval e) {
InstExp k = env.insts.get(e.inst);
if (k == null) {
throw new RuntimeException("Missing instance: " + e.inst);
}
if (!(k instanceof Times)) {
throw new RuntimeException("Not a product: " + k + " in " + e);
}
Times t = (Times) k;
InstExp v = env.insts.get(t.a);
if (!(v instanceof Exp)) {
throw new RuntimeException("Not an exponential: " + v + " in " + e);
}
Exp i = (Exp) v;
if (!(t.b.equals(i.b))) {
throw new RuntimeException("Exponent and product do not match in " + e);
}
return new Pair<>(e.inst, i.a);
}
use of catdata.fql.decl.InstExp.Exp in project fql by CategoricalData.
the class TransChecker method visit.
@Override
public Pair<String, String> visit(FQLProgram env, TransCurry e) {
InstExp inst = env.insts.get(e.inst);
if (inst == null) {
throw new RuntimeException("Missing instance: " + e.inst);
}
if (!(inst instanceof Exp)) {
throw new RuntimeException("Instance is not an exponential");
}
Exp i = (Exp) inst;
if (seen.contains(e.trans)) {
throw new RuntimeException("Circular transform " + e);
}
seen.add(e.trans);
Pair<String, String> k = env.transforms.get(e.trans).accept(env, this);
InstExp ab = env.insts.get(k.first);
if (!(ab instanceof Times)) {
throw new RuntimeException("Source is not a product");
}
Times t = (Times) ab;
if (!i.a.equals(k.second)) {
throw new RuntimeException("Bases do not match");
}
if (!i.b.equals(t.b)) {
throw new RuntimeException("Exponents do not match");
}
return new Pair<>(t.a, e.inst);
}
use of catdata.fql.decl.InstExp.Exp in project fql by CategoricalData.
the class FqlDisplay method handleInstanceFlowEdge.
private void handleInstanceFlowEdge(Object o) {
InstExp i = (InstExp) o;
Object f = i.accept(new Unit(), new InstExpVisitor<Object, Unit>() {
@Override
public MapExp visit(Unit env, Zero e) {
return null;
}
@Override
public MapExp visit(Unit env, One e) {
return null;
}
@Override
public MapExp visit(Unit env, Two e) {
throw new RuntimeException();
}
@Override
public MapExp visit(Unit env, Plus e) {
return null;
}
@Override
public MapExp visit(Unit env, Times e) {
return null;
}
@Override
public MapExp visit(Unit env, Exp e) {
throw new RuntimeException();
}
@Override
public MapExp visit(Unit env, Const e) {
return null;
}
@Override
public MapExp visit(Unit env, Delta e) {
return e.F;
}
@Override
public MapExp visit(Unit env, Sigma e) {
return e.F;
}
@Override
public MapExp visit(Unit env, Pi e) {
return e.F;
}
@Override
public MapExp visit(Unit env, FullSigma e) {
return e.F;
}
@Override
public Unit visit(Unit env, Relationalize e) {
return null;
}
@Override
public Unit visit(Unit env, External e) {
return null;
}
@Override
public Object visit(Unit env, Eval e) {
return e.q;
}
@Override
public Object visit(Unit env, FullEval e) {
return e.q;
}
@Override
public Object visit(Unit env, Kernel e) {
return null;
}
@Override
public Object visit(Unit env, Step e) {
// (Step) this should return a pair
return null;
}
});
if (f == null) {
return;
}
if (f instanceof QueryExp) {
QueryExp q = (QueryExp) f;
if (q instanceof QueryExp.Var) {
QueryExp.Var qq = (QueryExp.Var) q;
yyy.setSelectedValue(indices.get(qq.v), true);
return;
}
String k = FQLProgram.revLookup(prog.queries, q);
if (k != null) {
yyy.setSelectedValue(indices.get(k), true);
return;
}
String str = q.toString();
if (!extraInsts.contains(str)) {
Query view = q.toQuery(prog);
JPanel p = showQuery(prog, env, view);
x.add(p, str);
extraInsts.add(str);
}
yyy.clearSelection();
cl.show(x, str);
} else if (f instanceof FullQueryExp) {
FullQueryExp q = (FullQueryExp) f;
if (q instanceof FullQueryExp.Var) {
FullQueryExp.Var qq = (FullQueryExp.Var) q;
yyy.setSelectedValue(indices.get(qq.v), true);
return;
}
String k = FQLProgram.revLookup(prog.full_queries, q);
if (k != null) {
yyy.setSelectedValue(indices.get(k), true);
return;
}
String str = q.toString();
if (!extraInsts.contains(str)) {
FullQuery view = q.toFullQuery(prog);
JPanel p = showFullQuery(prog, env, view, q);
x.add(p, str);
extraInsts.add(str);
}
yyy.clearSelection();
cl.show(x, str);
} else if (f instanceof MapExp) {
MapExp q = (MapExp) f;
if (q instanceof MapExp.Var) {
MapExp.Var qq = (MapExp.Var) q;
yyy.setSelectedValue(indices.get(qq.v), true);
return;
}
String k = FQLProgram.revLookup(prog.maps, q);
if (k != null) {
yyy.setSelectedValue(indices.get(k), true);
return;
}
String str = q.toString();
if (!extraInsts.contains(str)) {
Mapping view = q.toMap(prog);
JPanel p = showMapping(env, prog.smap(view.source.toConst()), prog.smap(view.target.toConst()), view);
x.add(p, str);
extraInsts.add(str);
}
yyy.clearSelection();
cl.show(x, str);
} else {
throw new RuntimeException();
}
}
use of catdata.fql.decl.InstExp.Exp in project fql by CategoricalData.
the class FQLParser method toInst.
@SuppressWarnings("rawtypes")
private static InstExp toInst(Object o) {
try {
Tuple4 t = (Tuple4) o;
Token z = (Token) t.a;
String y = z.toString();
if (y.equals("step")) {
return new Step(t.d.toString(), toMapping(t.b), toMapping(t.c));
}
} catch (RuntimeException cce) {
}
try {
Tuple3 t = (Tuple3) o;
Token z = (Token) t.a;
String y = z.toString();
switch(y) {
case "delta":
return new InstExp.Delta(toMapping(t.b), t.c.toString());
case "sigma":
return new InstExp.Sigma(toMapping(t.b), t.c.toString());
case "SIGMA":
return new FullSigma(toMapping(t.b), t.c.toString());
case "pi":
return new InstExp.Pi(toMapping(t.b), t.c.toString());
case "external":
return new External(toSchema(t.b), t.c.toString());
case "eval":
return new Eval(toQuery(t.b), t.c.toString());
case "EVAL":
return new FullEval(toFullQuery(t.b), t.c.toString());
default:
break;
}
} catch (RuntimeException cce) {
}
try {
Tuple3 t = (Tuple3) o;
Token z = (Token) t.b;
String y = z.toString();
if (y.equals("+")) {
return new Plus(t.a.toString(), t.c.toString());
} else if (y.equals("*")) {
return new Times(t.a.toString(), t.c.toString());
}
if (y.equals("^")) {
return new Exp(t.a.toString(), (t.c).toString());
}
} catch (RuntimeException cce) {
}
try {
org.jparsec.functors.Pair pr = (org.jparsec.functors.Pair) o;
if (pr.a.toString().equals("unit")) {
return new One(toSchema(pr.b));
} else if (pr.a.toString().equals("void")) {
return new Zero(toSchema(pr.b));
} else if (pr.a.toString().equals("prop")) {
return new Two(toSchema(pr.b));
} else if (pr.a.toString().equals("relationalize")) {
return new Relationalize(pr.b.toString());
} else if (pr.a.toString().equals("kernel")) {
return new Kernel(pr.b.toString());
}
throw new RuntimeException();
} catch (RuntimeException cce) {
}
return toInstConst(o);
}
Aggregations