Search in sources :

Example 6 with PSM

use of catdata.fql.sql.PSM in project fql by CategoricalData.

the class InstOps method visit.

@Override
public List<PSM> visit(String env, TransIso e) {
    List<PSM> ret = new LinkedList<>();
    Signature sig = prog.insts.get(e.l).type(prog).toSig(prog);
    ret.add(new PSMIso(e.lToR, env, e.l, e.r, sig));
    return ret;
}
Also used : PSMIso(catdata.fql.sql.PSMIso) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) LinkedList(java.util.LinkedList)

Example 7 with PSM

use of catdata.fql.sql.PSM in project fql by CategoricalData.

the class InstOps method visit.

@Override
public List<PSM> visit(String env, Or e) {
    List<PSM> ret = new LinkedList<>();
    Times pr = (Times) prog.insts.get(e.prop);
    Signature sig = pr.type(prog).toSig(prog);
    ret.add(new PSMAnd(sig, env, e.prop, pr.a, "or"));
    return ret;
}
Also used : PSMAnd(catdata.fql.sql.PSMAnd) Times(catdata.fql.decl.InstExp.Times) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) LinkedList(java.util.LinkedList)

Example 8 with PSM

use of catdata.fql.sql.PSM in project fql by CategoricalData.

the class InstOps method visit.

@Override
public List<PSM> visit(String dst, TransExp.FullSigma e) {
    List<PSM> ret = new LinkedList<>();
    Mapping F0 = ((FullSigma) prog.insts.get(e.src)).F.toMap(prog);
    Pair<String, String> t = prog.transforms.get(e.h).type(prog);
    // String next = next();
    // ret.addAll(PSMGen.makeTables(next, F0.source, false));
    // ret.addAll(e.h.accept(next, this));
    ret.add(new FullSigmaTrans(F0, t.first, e.src, t.second, e.dst, e.h, dst));
    return ret;
}
Also used : FullSigmaTrans(catdata.fql.sql.FullSigmaTrans) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) LinkedList(java.util.LinkedList)

Example 9 with PSM

use of catdata.fql.sql.PSM in project fql by CategoricalData.

the class InstOps method visit.

@Override
public List<PSM> visit(String env, Return e) {
    // String xxx = "return_temp_xxx";
    List<PSM> ret = new LinkedList<>();
    InstExp i1 = prog.insts.get(e.inst);
    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 Sigma) {
            Sigma input0 = ((Sigma) i2);
            String input = input0.I;
            for (Node n : f.source.nodes) {
                ret.add(new InsertSQL(env + "_" + n.string, PSMGen.compose(input + "_" + n.string, middle + "_" + f.nm.get(n) + "_subst", e.inst + "_" + n.string + "_subst"), "c0", "c1"));
            }
        } else if (i2 instanceof FullSigma) {
            FullSigma input0 = ((FullSigma) i2);
            String input = input0.I;
            for (Node n : f.source.nodes) {
                ret.add(new InsertSQL(env + "_" + n.string, PSMGen.compose(input + "_" + n.string, middle + "_" + n.string + "_e", e.inst + "_" + n.string + "_subst"), "c0", "c1"));
            }
        } else {
            throw new RuntimeException();
        }
    } else if (i1 instanceof Pi) {
        String middle = ((Pi) i1).I;
        // can't be null
        InstExp i2 = prog.insts.get(middle);
        Mapping f = ((Pi) i1).F.toMap(prog);
        if (i2 instanceof Delta) {
            Delta input0 = ((Delta) i2);
            String input = input0.I;
            for (Node n : f.target.nodes) {
                try {
                    Map<String, Triple<Node, Node, Arr<Node, Path>>[]> colmap = PSMGen.pi(f, middle, e.inst).second;
                    Triple<Node, Node, Arr<Node, Path>>[] col = colmap.get(n.string);
                    if (col.length == 0) {
                        LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
                        Map<String, String> from = new HashMap<>();
                        List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
                        from.put("lim", e.inst + "_" + n.string + "_limit");
                        from.put("middle", input + "_" + n.string);
                        select.put("c0", new Pair<>("middle", "c0"));
                        select.put("c1", new Pair<>("lim", "guid"));
                        Flower flower = new Flower(select, from, where);
                        ret.add(new InsertSQL(env + "_" + n.string, flower, "c0", "c1"));
                        return ret;
                    }
                    // LinkedHashMap<String, String> attrs = new LinkedHashMap<>();
                    // attrs.put("guid", PSM.VARCHAR());
                    LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
                    Map<String, String> from = new HashMap<>();
                    from.put("lim", e.inst + "_" + n.string + "_limit");
                    List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
                    int i = 0;
                    for (Triple<Node, Node, Arr<Node, Path>> col0 : col) {
                        from.put("c" + i + "_subst_inv", middle + "_" + col0.second.string + "_subst_inv");
                        where.add(new Pair<>(new Pair<>("lim", "c" + i), new Pair<>("c" + i + "_subst_inv", "c0")));
                        // attrs.put("c" + i, PSM.VARCHAR());
                        i++;
                    }
                    // if (col.length > 1) {
                    for (int j = 0; j < col.length; j++) {
                        if (col[j].third.arr.equals(f.target.toCategory2().second.of(new Path(f.target, n)).arr)) {
                            where.add(new Pair<>(new Pair<>("c" + 0 + "_subst_inv", "c1"), new Pair<>("c" + j + "_subst_inv", "c1")));
                        }
                    }
                    select.put("c" + 0, new Pair<>("c" + 0 + "_subst_inv", "c1"));
                    select.put("c1", new Pair<>("lim", "guid"));
                    // }
                    // ret.add(new CreateTable(xxx, attrs, false));
                    Flower flower = new Flower(select, from, where);
                    ret.add(new InsertSQL(env + "_" + n.string, flower, "c0", "c1"));
                } catch (FQLException fe) {
                    fe.printStackTrace();
                    throw new RuntimeException(fe.getMessage());
                }
            }
        } else {
            throw new RuntimeException();
        }
    } else {
        throw new RuntimeException();
    }
    return ret;
}
Also used : Arr(catdata.fql.cat.Arr) FullSigma(catdata.fql.decl.InstExp.FullSigma) Sigma(catdata.fql.decl.InstExp.Sigma) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) Pi(catdata.fql.decl.InstExp.Pi) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) CopyFlower(catdata.fql.sql.CopyFlower) Flower(catdata.fql.sql.Flower) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) LinkedList(java.util.LinkedList) Triple(catdata.Triple) InsertSQL(catdata.fql.sql.InsertSQL) Delta(catdata.fql.decl.InstExp.Delta) FullSigma(catdata.fql.decl.InstExp.FullSigma) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 10 with PSM

use of catdata.fql.sql.PSM in project fql by CategoricalData.

the class InstOps method visit.

@Override
public List<PSM> visit(String env, Not e) {
    List<PSM> ret = new LinkedList<>();
    InstExp p = prog.insts.get(e.prop);
    Signature sig = p.type(prog).toSig(prog);
    ret.add(new PSMNot(sig, env, e.prop));
    return ret;
}
Also used : PSMNot(catdata.fql.sql.PSMNot) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) LinkedList(java.util.LinkedList)

Aggregations

ExpPSM (catdata.fql.sql.ExpPSM)37 PSM (catdata.fql.sql.PSM)37 PropPSM (catdata.fql.sql.PropPSM)37 LinkedList (java.util.LinkedList)36 InsertSQL (catdata.fql.sql.InsertSQL)18 CopyFlower (catdata.fql.sql.CopyFlower)14 Pair (catdata.Pair)12 HashMap (java.util.HashMap)12 LinkedHashMap (java.util.LinkedHashMap)12 Flower (catdata.fql.sql.Flower)9 Times (catdata.fql.decl.InstExp.Times)8 Map (java.util.Map)7 FQLException (catdata.fql.FQLException)6 Arr (catdata.fql.cat.Arr)6 Triple (catdata.Triple)5 Delta (catdata.fql.decl.InstExp.Delta)5 PSMAnd (catdata.fql.sql.PSMAnd)5 SimpleCreateTable (catdata.fql.sql.SimpleCreateTable)5 Exp (catdata.fql.decl.InstExp.Exp)4 FullSigma (catdata.fql.decl.InstExp.FullSigma)4