Search in sources :

Example 1 with InsertSQL

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

the class InstOps method visit.

@Override
public List<PSM> visit(String dst, Inl e) {
    List<PSM> ret = new LinkedList<>();
    InstExp k = prog.insts.get(e.obj);
    Signature t = k.type(prog).toSig(prog);
    for (Node n : t.nodes) {
        ret.add(new InsertSQL(dst + "_" + n.string, new CopyFlower(e.obj + "_inl_" + n.string, "c0", "c1"), "c0", "c1"));
    }
    return ret;
}
Also used : InsertSQL(catdata.fql.sql.InsertSQL) CopyFlower(catdata.fql.sql.CopyFlower) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) LinkedList(java.util.LinkedList)

Example 2 with InsertSQL

use of catdata.fql.sql.InsertSQL 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 3 with InsertSQL

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

the class InstOps method visit.

@Override
public List<PSM> visit(String env, UnChi e) {
    List<PSM> ret = new LinkedList<>();
    Signature sig = prog.insts.get(e.a).type(prog).toSig(prog);
    for (Node n : sig.nodes) {
        ret.add(new InsertSQL(env + "_" + n.string, new CopyFlower(e.a + "_trans_" + n, "c0", "c1"), "c0", "c1"));
    }
    return ret;
}
Also used : InsertSQL(catdata.fql.sql.InsertSQL) CopyFlower(catdata.fql.sql.CopyFlower) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) LinkedList(java.util.LinkedList)

Example 4 with InsertSQL

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

the class InstOps method visit.

@Override
public List<PSM> visit(String dst, TT e) {
    try {
        List<PSM> ret = new LinkedList<>();
        Signature s = prog.insts.get(e.obj).type(prog).toSig(prog);
        String temp1 = next();
        ret.addAll(PSMGen.makeTables(temp1, s, false));
        String temp2 = next();
        ret.addAll(PSMGen.makeTables(temp2, s, false));
        Pair<Map<Node, List<Pair<Path, Attribute<Node>>>>, List<PSM>> xxx = Relationalizer.observations(s, temp1, e.tgt, false);
        Pair<Map<Node, List<Pair<Path, Attribute<Node>>>>, List<PSM>> yyy = Relationalizer.observations(s, temp2, e.obj, false);
        if (!xxx.first.equals(yyy.first)) {
            throw new RuntimeException("not equal: " + xxx + " and " + yyy);
        }
        ret.addAll(xxx.second);
        ret.addAll(yyy.second);
        for (Node n : s.nodes) {
            List<?> cols = xxx.first.get(n);
            Map<String, String> from = new HashMap<>();
            from.put("t1", e.tgt + "_" + n);
            from.put("t1_obs", temp1 + "_" + n + "_" + "observables");
            from.put("t2", e.obj + "_" + n);
            from.put("t2_obs", temp2 + "_" + n + "_" + "observables");
            List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
            where.add(new Pair<>(new Pair<>("t1", "c0"), new Pair<>("t1_obs", "id")));
            where.add(new Pair<>(new Pair<>("t2", "c0"), new Pair<>("t2_obs", "id")));
            for (int i = 0; i < cols.size(); i++) {
                where.add(new Pair<>(new Pair<>("t1_obs", "c" + i), new Pair<>("t2_obs", "c" + i)));
            }
            LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
            select.put("c0", new Pair<>("t1", "c0"));
            select.put("c1", new Pair<>("t2", "c0"));
            Flower f = new Flower(select, from, where);
            ret.add(new InsertSQL(dst + "_" + n, f, "c0", "c1"));
        }
        ret.addAll(PSMGen.dropTables(temp1, s));
        ret.addAll(PSMGen.dropTables(temp2, s));
        return ret;
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getLocalizedMessage());
    }
}
Also used : CopyFlower(catdata.fql.sql.CopyFlower) Flower(catdata.fql.sql.Flower) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) InsertSQL(catdata.fql.sql.InsertSQL) List(java.util.List) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Pair(catdata.Pair)

Example 5 with InsertSQL

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

the class InstOps method visit.

@Override
public List<PSM> visit(String dst, TransExp.Const e) {
    List<PSM> ret = new LinkedList<>();
    Signature s = prog.insts.get(e.src).type(prog).toConst(prog).toSig(prog);
    List<String> attrs = new LinkedList<>();
    attrs.add("c0");
    attrs.add("c1");
    ret.addAll(PSMGen.makeTables("pre_" + dst, s, false));
    for (Node k : s.nodes) {
        Set<Map<Object, Object>> values = convert(lookup(k.string, e.objs));
        if (!values.isEmpty()) {
            ret.add(new InsertValues("pre_" + dst + "_" + k.string, attrs, values));
        }
        SQL f = PSMGen.compose(e.src + "_" + k.string + "_subst_inv", "pre_" + dst + "_" + k.string, e.dst + "_" + k.string + "_subst");
        ret.add(new InsertSQL(dst + "_" + k.string, f, "c0", "c1"));
    }
    ret.addAll(PSMGen.dropTables("pre_" + dst, s));
    return ret;
}
Also used : InsertSQL(catdata.fql.sql.InsertSQL) InsertValues(catdata.fql.sql.InsertValues) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedList(java.util.LinkedList) SQL(catdata.fql.sql.SQL) InsertSQL(catdata.fql.sql.InsertSQL)

Aggregations

ExpPSM (catdata.fql.sql.ExpPSM)18 InsertSQL (catdata.fql.sql.InsertSQL)18 PSM (catdata.fql.sql.PSM)18 PropPSM (catdata.fql.sql.PropPSM)18 LinkedList (java.util.LinkedList)18 CopyFlower (catdata.fql.sql.CopyFlower)14 Flower (catdata.fql.sql.Flower)9 HashMap (java.util.HashMap)9 LinkedHashMap (java.util.LinkedHashMap)9 Pair (catdata.Pair)8 FQLException (catdata.fql.FQLException)6 Arr (catdata.fql.cat.Arr)5 Triple (catdata.Triple)4 Delta (catdata.fql.decl.InstExp.Delta)4 FullSigma (catdata.fql.decl.InstExp.FullSigma)4 Pi (catdata.fql.decl.InstExp.Pi)4 Sigma (catdata.fql.decl.InstExp.Sigma)4 DropTable (catdata.fql.sql.DropTable)4 SimpleCreateTable (catdata.fql.sql.SimpleCreateTable)4 Union (catdata.fql.sql.Union)4