Search in sources :

Example 6 with Signature

use of catdata.fql.decl.Signature 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 7 with Signature

use of catdata.fql.decl.Signature in project fql by CategoricalData.

the class JDBCBridge method maybeExecTransform.

private static List<PSM> maybeExecTransform(InstOps ops, FQLProgram prog, Statement Stmt, String k, TransExp v, PSMInterp interp, Map<String, Set<Map<Object, Object>>> ret) throws SQLException {
    List<PSM> psm = new LinkedList<>();
    Pair<String, String> val = prog.transforms.get(k).type(prog);
    InstExp i = prog.insts.get(val.first);
    Const ss = i.type(prog).toConst(prog);
    Signature s = ss.toSig(prog);
    psm.addAll(PSMGen.makeTables(k, s, false));
    switch(DefunctGlobalOptions.debug.fql.sqlKind) {
        case NATIVE:
            psm.addAll(v.accept(k, ops));
            interp.interpX(psm, ret);
            break;
        case H2:
        case JDBC:
        default:
            if (v instanceof TransExp.External && DefunctGlobalOptions.debug.fql.sqlKind == SQLKIND.H2) {
            } else {
                psm.addAll(v.accept(k, ops));
            }
            maybeExec(psm, Stmt, ret, interp, s);
            if (v.gather()) {
                gatherTransform(prog, ret, Stmt, k, ss);
            // have non SQL transform output into temps, so can gather them like any other
            }
            break;
    }
    return psm;
}
Also used : InstExp(catdata.fql.decl.InstExp) Const(catdata.fql.decl.SigExp.Const) Signature(catdata.fql.decl.Signature) TransExp(catdata.fql.decl.TransExp) PSM(catdata.fql.sql.PSM) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) LinkedList(java.util.LinkedList)

Example 8 with Signature

use of catdata.fql.decl.Signature in project fql by CategoricalData.

the class FinFunctor method toMapping.

/**
 * Converts a functor to a mapping by converting the source and target
 * categories
 *
 * @return the mapping, and a bunch of isomorphisms
 * @throws FQLException
 */
public Triple<Mapping, Quad<Signature, Pair<Map<ObjA, String>, Map<String, ObjA>>, Pair<Map<Arr<ObjA, ArrowA>, String>, Map<String, Arr<ObjA, ArrowA>>>, Pair<Map<Attribute<ObjA>, String>, Map<String, Attribute<ObjA>>>>, Quad<Signature, Pair<Map<ObjB, String>, Map<String, ObjB>>, Pair<Map<Arr<ObjB, ArrowB>, String>, Map<String, Arr<ObjB, ArrowB>>>, Pair<Map<Attribute<ObjB>, String>, Map<String, Attribute<ObjB>>>>> toMapping(Map<String, Type> types) throws FQLException {
    Quad<Signature, Pair<Map<ObjA, String>, Map<String, ObjA>>, Pair<Map<Arr<ObjA, ArrowA>, String>, Map<String, Arr<ObjA, ArrowA>>>, Pair<Map<Attribute<ObjA>, String>, Map<String, Attribute<ObjA>>>> src = srcCat.toSig(types);
    Quad<Signature, Pair<Map<ObjB, String>, Map<String, ObjB>>, Pair<Map<Arr<ObjB, ArrowB>, String>, Map<String, Arr<ObjB, ArrowB>>>, Pair<Map<Attribute<ObjB>, String>, Map<String, Attribute<ObjB>>>> dst = dstCat.toSig(types);
    Signature srcSig = src.first;
    Signature dstSig = dst.first;
    Map<Arr<ObjA, ArrowA>, String> srcM = src.third.first;
    Map<ObjA, String> srcM2 = src.second.first;
    Map<Attribute<ObjA>, String> srcMA = src.fourth.first;
    Map<Arr<ObjB, ArrowB>, String> dstM = dst.third.first;
    Map<ObjB, String> dstM2 = dst.second.first;
    Map<Attribute<ObjB>, String> dstMA = dst.fourth.first;
    List<Pair<String, String>> nm = new LinkedList<>();
    List<Pair<String, List<String>>> em = new LinkedList<>();
    for (Arr<ObjA, ArrowA> a : srcCat.arrows) {
        if (srcCat.isId(a)) {
            ObjA o = a.src;
            ObjB u = objMapping.get(o);
            nm.add(new Pair<>(srcM2.get(o), dstM2.get(u)));
        } else {
            Arr<ObjB, ArrowB> u = arrowMapping.get(a);
            List<String> t = new LinkedList<>();
            t.add(dstM2.get(u.src));
            if (!dstCat.isId(u)) {
                t.add(dstM.get(u));
            }
            em.add(new Pair<>(srcM.get(a), t));
        }
    }
    List<Pair<String, String>> am0 = new LinkedList<>();
    for (Attribute<ObjA> k : am.keySet()) {
        am0.add(new Pair<>(srcMA.get(k), dstMA.get(am.get(k))));
    }
    Mapping m = new Mapping(/*n,*/
    srcSig, dstSig, nm, am0, em);
    return new Triple<>(m, src, dst);
}
Also used : Attribute(catdata.fql.decl.Attribute) Mapping(catdata.fql.decl.Mapping) Pair(catdata.Pair) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Signature(catdata.fql.decl.Signature)

Example 9 with Signature

use of catdata.fql.decl.Signature in project fql by CategoricalData.

the class TransChecker method visit.

@SuppressWarnings("unused")
@Override
public Pair<String, String> visit(FQLProgram env, Const e) {
    InstExp src = env.insts.get(e.src);
    if (src == null) {
        throw new RuntimeException("Missing instance " + e.src);
    }
    InstExp dst = env.insts.get(e.dst);
    if (dst == null) {
        throw new RuntimeException("Missing instance " + e.src);
    }
    if (!(src instanceof InstExp.Const)) {
        throw new RuntimeException(e.src + " is not a constant.");
    }
    if (!(dst instanceof InstExp.Const)) {
        throw new RuntimeException(e.dst + " is not a constant.");
    }
    InstExp.Const src0 = (InstExp.Const) src;
    InstExp.Const dst0 = (InstExp.Const) dst;
    SigExp srct = src0.type(env);
    SigExp dstt = dst0.type(env);
    if (!srct.equals(dstt)) {
        throw new RuntimeException("Instances not of same type on " + e + " are " + srct + " and " + dstt);
    }
    Signature sig = srct.toSig(env);
    List<Pair<String, List<Pair<Object, Object>>>> bbb = e.objs;
    try {
        new Transform(new Instance(sig, src0.data), new Instance(sig, dst0.data), bbb);
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getLocalizedMessage());
    }
    return new Pair<>(e.src, e.dst);
}
Also used : InstExp(catdata.fql.decl.InstExp) FQLException(catdata.fql.FQLException) SigExp(catdata.fql.decl.SigExp) Instance(catdata.fql.decl.Instance) Const(catdata.fql.decl.TransExp.Const) Signature(catdata.fql.decl.Signature) Transform(catdata.fql.decl.Transform) Pair(catdata.Pair)

Example 10 with Signature

use of catdata.fql.decl.Signature in project fql by CategoricalData.

the class FqlDisplay method showQuery.

private static JPanel showQuery(FQLProgram prog, FqlEnvironment environment, Query view) {
    JTabbedPane px = new JTabbedPane();
    Mapping d = view.project;
    Mapping p = view.join;
    Mapping u = view.union;
    Signature s = d.target;
    Signature i1 = d.source;
    Signature i2 = p.target;
    Signature t = u.target;
    px.add("Source", showSchema("Source", environment, prog.smap(s.toConst()), s));
    px.add("Delta", showMapping(environment, prog.smap(i1.toConst()), prog.smap(s.toConst()), d));
    px.add("Intermediate 1", showSchema("Int1", environment, prog.smap(i1.toConst()), i1));
    px.add("Pi", showMapping(environment, prog.smap(i1.toConst()), prog.smap(i2.toConst()), p));
    px.add("Intermediate 2", showSchema("Int2", environment, prog.smap(i2.toConst()), i2));
    px.add("Sigma", showMapping(environment, prog.smap(i2.toConst()), prog.smap(t.toConst()), u));
    px.add("Target", showSchema("Target", environment, prog.smap(t.toConst()), t));
    JPanel top = new JPanel(new GridLayout(1, 1));
    top.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    top.add(px);
    return top;
}
Also used : JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) JTabbedPane(javax.swing.JTabbedPane) Signature(catdata.fql.decl.Signature) Mapping(catdata.fql.decl.Mapping)

Aggregations

Signature (catdata.fql.decl.Signature)19 LinkedList (java.util.LinkedList)14 Pair (catdata.Pair)13 Node (catdata.fql.decl.Node)13 FQLException (catdata.fql.FQLException)11 HashMap (java.util.HashMap)11 Attribute (catdata.fql.decl.Attribute)10 Instance (catdata.fql.decl.Instance)10 Edge (catdata.fql.decl.Edge)9 Map (java.util.Map)7 Arr (catdata.fql.cat.Arr)6 Path (catdata.fql.decl.Path)6 Transform (catdata.fql.decl.Transform)6 LinkedHashMap (java.util.LinkedHashMap)6 Triple (catdata.Triple)5 List (java.util.List)5 HashSet (java.util.HashSet)4 Fn (catdata.fql.Fn)3 FinCat (catdata.fql.cat.FinCat)3 InstExp (catdata.fql.decl.InstExp)3