Search in sources :

Example 1 with Times

use of catdata.fql.decl.InstExp.Times 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;
}
Also used : ExpPSM(catdata.fql.sql.ExpPSM) Attribute(catdata.fql.decl.Attribute) Node(catdata.fql.decl.Node) One(catdata.fql.decl.InstExp.One) PSMUnChi(catdata.fql.sql.PSMUnChi) PSM(catdata.fql.sql.PSM) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PropPSM(catdata.fql.sql.PropPSM) Two(catdata.fql.decl.InstExp.Two) LinkedList(java.util.LinkedList) InstExp(catdata.fql.decl.InstExp) SimpleCreateTable(catdata.fql.sql.SimpleCreateTable) Delta(catdata.fql.decl.InstExp.Delta) Signature(catdata.fql.decl.Signature) Times(catdata.fql.decl.InstExp.Times) External(catdata.fql.decl.InstExp.External) FullSigma(catdata.fql.sql.FullSigma) LinkedList(java.util.LinkedList) List(java.util.List) Exp(catdata.fql.decl.InstExp.Exp) InstExp(catdata.fql.decl.InstExp) TransExp(catdata.fql.decl.TransExp) Kernel(catdata.fql.decl.InstExp.Kernel) Edge(catdata.fql.decl.Edge)

Example 2 with Times

use of catdata.fql.decl.InstExp.Times 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);
}
Also used : InstExp(catdata.fql.decl.InstExp) Times(catdata.fql.decl.InstExp.Times) Exp(catdata.fql.decl.InstExp.Exp) TransExp(catdata.fql.decl.TransExp) SigExp(catdata.fql.decl.SigExp) InstExp(catdata.fql.decl.InstExp) Pair(catdata.Pair)

Example 3 with Times

use of catdata.fql.decl.InstExp.Times in project fql by CategoricalData.

the class TransChecker method visit.

@Override
public Pair<String, String> visit(FQLProgram env, Prod e) {
    InstExp x = env.insts.get(e.obj);
    if (x == null) {
        throw new RuntimeException("Missing " + e.obj + " in " + e);
    }
    if (!(x instanceof Times)) {
        throw new RuntimeException(e.obj + " is not a times: " + x);
    }
    // InstExp.Times y = (InstExp.Times) x;
    Pair<String, String> a = e.l.accept(env, this);
    Pair<String, String> b = e.r.accept(env, this);
    if (!a.first.equals(b.first)) {
        throw new RuntimeException("Domain mismatch: " + e + " with " + a.first + " and " + b.first);
    }
    return new Pair<>(a.first, e.obj);
}
Also used : InstExp(catdata.fql.decl.InstExp) Times(catdata.fql.decl.InstExp.Times) Pair(catdata.Pair)

Example 4 with Times

use of catdata.fql.decl.InstExp.Times 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);
}
Also used : InstExp(catdata.fql.decl.InstExp) Times(catdata.fql.decl.InstExp.Times) Exp(catdata.fql.decl.InstExp.Exp) TransExp(catdata.fql.decl.TransExp) SigExp(catdata.fql.decl.SigExp) InstExp(catdata.fql.decl.InstExp) Pair(catdata.Pair)

Example 5 with Times

use of catdata.fql.decl.InstExp.Times in project fql by CategoricalData.

the class TransChecker method visit.

@Override
public Pair<String, String> visit(FQLProgram env, Snd e) {
    InstExp x = env.insts.get(e.obj);
    if (x == null) {
        throw new RuntimeException("Missing " + e.obj + " in " + e);
    }
    if (!(x instanceof Times)) {
        throw new RuntimeException(e.obj + " is not a times: " + x);
    }
    Times y = (Times) x;
    return new Pair<>(e.obj, y.b);
}
Also used : InstExp(catdata.fql.decl.InstExp) Times(catdata.fql.decl.InstExp.Times) Pair(catdata.Pair)

Aggregations

Times (catdata.fql.decl.InstExp.Times)16 Pair (catdata.Pair)9 InstExp (catdata.fql.decl.InstExp)9 Exp (catdata.fql.decl.InstExp.Exp)8 ExpPSM (catdata.fql.sql.ExpPSM)7 PSM (catdata.fql.sql.PSM)7 PropPSM (catdata.fql.sql.PropPSM)7 LinkedList (java.util.LinkedList)7 Two (catdata.fql.decl.InstExp.Two)6 External (catdata.fql.decl.InstExp.External)5 Kernel (catdata.fql.decl.InstExp.Kernel)5 One (catdata.fql.decl.InstExp.One)5 Delta (catdata.fql.decl.InstExp.Delta)4 Eval (catdata.fql.decl.InstExp.Eval)4 FullEval (catdata.fql.decl.InstExp.FullEval)4 FullSigma (catdata.fql.decl.InstExp.FullSigma)4 Plus (catdata.fql.decl.InstExp.Plus)4 Relationalize (catdata.fql.decl.InstExp.Relationalize)4 Step (catdata.fql.decl.InstExp.Step)4 Zero (catdata.fql.decl.InstExp.Zero)4