Search in sources :

Example 21 with PSM

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

the class InstOps method visit.

@Override
public Pair<List<PSM>, Object> visit(String dst, Plus e) {
    SigExp k = e.type(prog);
    Signature s = k.toSig(prog);
    List<PSM> ret = new LinkedList<>();
    for (Node n : s.nodes) {
        List<Flower> l = new LinkedList<>();
        l.add(new CopyFlower(e.a + "_" + n.string, "c0", "c1"));
        l.add(new CopyFlower(e.b + "_" + n.string, "c0", "c1"));
        ret.add(new InsertSQL(dst + "_" + n.string, new Union(l), "c0", "c1"));
    }
    for (Attribute<Node> n : s.attrs) {
        List<Flower> l = new LinkedList<>();
        l.add(new CopyFlower(e.a + "_" + n.name, "c0", "c1"));
        l.add(new CopyFlower(e.b + "_" + n.name, "c0", "c1"));
        ret.add(new InsertSQL(dst + "_" + n.name, new Union(l), "c0", "c1"));
    }
    for (Edge n : s.edges) {
        List<Flower> l = new LinkedList<>();
        l.add(new CopyFlower(e.a + "_" + n.name, "c0", "c1"));
        l.add(new CopyFlower(e.b + "_" + n.name, "c0", "c1"));
        ret.add(new InsertSQL(dst + "_" + n.name, new Union(l), "c0", "c1"));
    }
    ret.addAll(PSMGen.guidify(dst, s, true));
    ret.addAll(PSMGen.makeTables(dst + "_inl", s, false));
    ret.addAll(PSMGen.makeTables(dst + "_inr", s, false));
    for (Node n : s.nodes) {
        SQL f = PSMGen.compose(e.a + "_" + n.string, dst + "_" + n.string + "_subst");
        ret.add(new InsertSQL(dst + "_inl_" + n.string, f, "c0", "c1"));
        SQL f0 = PSMGen.compose(e.b + "_" + n.string, dst + "_" + n.string + "_subst");
        ret.add(new InsertSQL(dst + "_inr_" + n.string, f0, "c0", "c1"));
    }
    // (f+g) : A+B -> C f : A -> C g : B -> C
    Fn<Quad<String, String, String, String>, List<PSM>> fn = x -> {
        // e.a -> x.third
        String f = x.first;
        // e.b -> x.third
        String g = x.second;
        // String C = x.third;
        String dst0 = x.fourth;
        // must be a map dst -> x.third
        List<PSM> ret1 = new LinkedList<>();
        for (Node n : s.nodes) {
            Flower sql1 = PSMGen.compose(dst + "_" + n.string + "_subst_inv", f + "_" + n.string);
            Flower sql2 = PSMGen.compose(dst + "_" + n.string + "_subst_inv", g + "_" + n.string);
            List<Flower> flowers = new LinkedList<>();
            flowers.add(sql1);
            flowers.add(sql2);
            ret1.add(new InsertSQL(dst0 + "_" + n.string, new Union(flowers), "c0", "c1"));
        }
        return ret1;
    };
    return new Pair<>(ret, fn);
}
Also used : Inr(catdata.fql.decl.TransExp.Inr) Case(catdata.fql.decl.TransExp.Case) TransEval(catdata.fql.decl.TransExp.TransEval) Snd(catdata.fql.decl.TransExp.Snd) TransIso(catdata.fql.decl.TransExp.TransIso) Kernel(catdata.fql.decl.InstExp.Kernel) TransCurry(catdata.fql.decl.TransExp.TransCurry) Inl(catdata.fql.decl.TransExp.Inl) Coreturn(catdata.fql.decl.TransExp.Coreturn) PSMStep(catdata.fql.sql.PSMStep) CopyFlower(catdata.fql.sql.CopyFlower) Map(java.util.Map) Or(catdata.fql.decl.TransExp.Or) Squash(catdata.fql.decl.TransExp.Squash) TT(catdata.fql.decl.TransExp.TT) And(catdata.fql.decl.TransExp.And) Exp(catdata.fql.decl.InstExp.Exp) Fn(catdata.fql.Fn) Pair(catdata.Pair) Not(catdata.fql.decl.TransExp.Not) FullSigma(catdata.fql.decl.InstExp.FullSigma) PSMAnd(catdata.fql.sql.PSMAnd) Plus(catdata.fql.decl.InstExp.Plus) Quad(catdata.Quad) FullSigmaCounit(catdata.fql.sql.FullSigmaCounit) PropPSM(catdata.fql.sql.PropPSM) FullEval(catdata.fql.decl.InstExp.FullEval) Set(java.util.Set) PSMGen(catdata.fql.sql.PSMGen) FullQueryVisitor(catdata.fql.decl.FullQuery.FullQueryVisitor) Eval(catdata.fql.decl.InstExp.Eval) InsertSQL2(catdata.fql.sql.InsertSQL2) PSMUnChi(catdata.fql.sql.PSMUnChi) Times(catdata.fql.decl.InstExp.Times) Fst(catdata.fql.decl.TransExp.Fst) PSMNot(catdata.fql.sql.PSMNot) List(java.util.List) Delta(catdata.fql.decl.InstExp.Delta) ExpPSM(catdata.fql.sql.ExpPSM) TransExpVisitor(catdata.fql.decl.TransExp.TransExpVisitor) PSMBool(catdata.fql.sql.PSMBool) Triple(catdata.Triple) Flower(catdata.fql.sql.Flower) Implies(catdata.fql.decl.TransExp.Implies) Id(catdata.fql.decl.TransExp.Id) External(catdata.fql.decl.InstExp.External) InsertKeygen(catdata.fql.sql.InsertKeygen) Chi(catdata.fql.decl.TransExp.Chi) FullSigmaTrans(catdata.fql.sql.FullSigmaTrans) HashMap(java.util.HashMap) Var(catdata.fql.decl.TransExp.Var) SQL(catdata.fql.sql.SQL) FQLException(catdata.fql.FQLException) Two(catdata.fql.decl.InstExp.Two) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) PSM(catdata.fql.sql.PSM) FF(catdata.fql.decl.TransExp.FF) LinkedList(java.util.LinkedList) UnChi(catdata.fql.decl.TransExp.UnChi) SimpleCreateTable(catdata.fql.sql.SimpleCreateTable) Comp(catdata.fql.decl.TransExp.Comp) PSMIso(catdata.fql.sql.PSMIso) CreateTable(catdata.fql.sql.CreateTable) InsertValues(catdata.fql.sql.InsertValues) Prod(catdata.fql.decl.TransExp.Prod) Const(catdata.fql.decl.InstExp.Const) Relationalize(catdata.fql.decl.InstExp.Relationalize) PSMCurry(catdata.fql.sql.PSMCurry) One(catdata.fql.decl.InstExp.One) Zero(catdata.fql.decl.InstExp.Zero) Pi(catdata.fql.decl.InstExp.Pi) DropTable(catdata.fql.sql.DropTable) InstExpVisitor(catdata.fql.decl.InstExp.InstExpVisitor) Step(catdata.fql.decl.InstExp.Step) Arr(catdata.fql.cat.Arr) Return(catdata.fql.decl.TransExp.Return) InsertSQL(catdata.fql.sql.InsertSQL) Union(catdata.fql.sql.Union) Sigma(catdata.fql.decl.InstExp.Sigma) Bool(catdata.fql.decl.TransExp.Bool) PSMEval(catdata.fql.sql.PSMEval) Relationalizer(catdata.fql.sql.Relationalizer) PSMChi(catdata.fql.sql.PSMChi) Quad(catdata.Quad) CopyFlower(catdata.fql.sql.CopyFlower) Flower(catdata.fql.sql.Flower) CopyFlower(catdata.fql.sql.CopyFlower) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) LinkedList(java.util.LinkedList) Union(catdata.fql.sql.Union) SQL(catdata.fql.sql.SQL) InsertSQL(catdata.fql.sql.InsertSQL) InsertSQL(catdata.fql.sql.InsertSQL) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Example 22 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.Pi e) {
    try {
        List<PSM> ret = new LinkedList<>();
        Pair<String, String> ht = e.h.type(prog);
        Signature sig = prog.insts.get(ht.first).type(prog).toSig(prog);
        Mapping F = ((Pi) prog.insts.get(e.src)).F.toMap(prog);
        Map<String, Triple<Node, Node, Arr<Node, Path>>[]> colmap1x = PSMGen.pi(F, e.h.type(prog).first, e.src).second;
        String next = next();
        ret.addAll(PSMGen.makeTables(next, sig, false));
        ret.addAll(e.h.accept(next, this));
        Signature sig2 = prog.insts.get(e.src).type(prog).toSig(prog);
        for (Node n : sig2.nodes) {
            List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
            Map<String, String> from = new HashMap<>();
            from.put("limit1", e.src + "_" + n.string + "_limit");
            from.put("limit2", e.dst + "_" + n.string + "_limit");
            LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
            int i = 0;
            for (Triple<Node, Node, Arr<Node, Path>> col : colmap1x.get(n.string)) {
                from.put("l" + i, next + "_" + col.second.string);
                where.add(new Pair<>(new Pair<>("l" + i, "c0"), new Pair<>("limit1", "c" + i)));
                where.add(new Pair<>(new Pair<>("l" + i, "c1"), new Pair<>("limit2", "c" + i)));
                i++;
            }
            // check
            for (@SuppressWarnings("unused") Attribute<Node> a : sig2.attrsFor(n)) {
                where.add(new Pair<>(new Pair<>("limit1", "c" + i), new Pair<>("limit2", "c" + i)));
                i++;
            }
            select.put("c0", new Pair<>("limit1", "guid"));
            select.put("c1", new Pair<>("limit2", "guid"));
            Flower f = new Flower(select, from, where);
            ret.add(new InsertSQL(dst + "_" + n.string, f, "c0", "c1"));
        }
        return ret;
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getLocalizedMessage());
    }
}
Also used : Arr(catdata.fql.cat.Arr) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) 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) InsertSQL(catdata.fql.sql.InsertSQL)

Example 23 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, Squash e) {
    List<PSM> ret = new LinkedList<>();
    InstExp s = prog.insts.get(e.src);
    Signature ty = s.type(prog).toSig(prog);
    for (Node n : ty.nodes) {
        ret.add(new InsertSQL(dst + "_" + n.string, PSMGen.compose(e.src + "_" + n.string + "_squash", e.src + "_" + n.string + "_subst"), "c0", "c1"));
    }
    return ret;
}
Also used : InsertSQL(catdata.fql.sql.InsertSQL) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) LinkedList(java.util.LinkedList)

Example 24 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, And 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, "and"));
    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 25 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.Relationalize e) {
    List<PSM> ret = new LinkedList<>();
    Pair<String, String> ht = e.h.type(prog);
    Signature sig = prog.insts.get(ht.first).type(prog).toSig(prog);
    String next = next();
    ret.addAll(PSMGen.makeTables(next, sig, false));
    ret.addAll(e.h.accept(next, this));
    Map<String, String> attrs = new HashMap<>();
    attrs.put("c0", PSM.VARCHAR());
    attrs.put("c1", PSM.VARCHAR());
    for (Node n : sig.nodes) {
        ret.add(new CreateTable(n.string + "xxx_temp", attrs, false));
        ret.add(new CreateTable(n.string + "yyy_temp", attrs, false));
        LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
        select.put("c0", new Pair<>("l", "c0"));
        select.put("c1", new Pair<>("r", "c0"));
        Map<String, String> from = new HashMap<>();
        from.put("l", e.src + "_" + n.string + "_subst_inv");
        from.put("r", e.src + "_" + n.string + "_squash");
        List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
        where.add(new Pair<>(new Pair<>("l", "c1"), new Pair<>("r", "c1")));
        Flower jk = new Flower(select, from, where);
        ret.add(new InsertSQL(n.string + "yyy_temp", jk, "c0", "c1"));
        ret.add(new InsertSQL(n.string + "xxx_temp", PSMGen.compose(next + "_" + n.string, e.dst + "_" + n.string + "_squash", e.dst + "_" + n.string + "_subst"), "c0", "c1"));
        ret.add(new InsertSQL(dst + "_" + n.string, PSMGen.compose(n.string + "yyy_temp", n.string + "xxx_temp"), "c0", "c1"));
        ret.add(new DropTable(n.string + "xxx_temp"));
        ret.add(new DropTable(n.string + "yyy_temp"));
    }
    ret.addAll(PSMGen.dropTables(next, sig));
    return ret;
}
Also used : CopyFlower(catdata.fql.sql.CopyFlower) Flower(catdata.fql.sql.Flower) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SimpleCreateTable(catdata.fql.sql.SimpleCreateTable) CreateTable(catdata.fql.sql.CreateTable) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) DropTable(catdata.fql.sql.DropTable) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) InsertSQL(catdata.fql.sql.InsertSQL) Pair(catdata.Pair)

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