Search in sources :

Example 1 with InsertValues

use of catdata.fql.sql.InsertValues 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)

Example 2 with InsertValues

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

the class JDBCBridge method makeInserts.

private static List<PSM> makeInserts(String k, Map<String, Set<Map<Object, Object>>> state, Signature sig, Signature src_sig) {
    List<PSM> ret = new LinkedList<>();
    List<String> attrs = new LinkedList<>();
    attrs.add("c0");
    attrs.add("c1");
    if (src_sig != null) {
        for (Node n : src_sig.nodes) {
            Set<Map<Object, Object>> v = state.get(k + "_" + n.string + "_e");
            ret.add(new SimpleCreateTable(k + "_" + n.string + "_e", PSM.VARCHAR(), false));
            if (v.isEmpty()) {
                continue;
            }
            ret.add(new InsertValues(k + "_" + n.string + "_e", attrs, v));
        }
        Set<Map<Object, Object>> v = state.get(k + "_lineage");
        Map<String, String> at = new LinkedHashMap<>();
        at.put("c0", PSM.VARCHAR());
        at.put("c1", PSM.VARCHAR());
        at.put("c2", PSM.VARCHAR());
        at.put("c3", PSM.VARCHAR());
        ret.add(new CreateTable(k + "_lineage", at, false));
        if (!v.isEmpty()) {
            ret.add(new InsertValues(k + "_lineage", new LinkedList<>(at.keySet()), v));
        }
    }
    for (Node n : sig.nodes) {
        Set<Map<Object, Object>> v = state.get(k + "_" + n.string);
        if (v.isEmpty()) {
            continue;
        }
        ret.add(new InsertValues(k + "_" + n.string, attrs, v));
    }
    for (Edge e : sig.edges) {
        Set<Map<Object, Object>> v = state.get(k + "_" + e.name);
        if (v.isEmpty()) {
            continue;
        }
        ret.add(new InsertValues(k + "_" + e.name, attrs, v));
    }
    for (Attribute<Node> a : sig.attrs) {
        Set<Map<Object, Object>> v = state.get(k + "_" + a.name);
        if (v.isEmpty()) {
            continue;
        }
        ret.add(new InsertValues(k + "_" + a.name, attrs, v));
    }
    return ret;
}
Also used : Node(catdata.fql.decl.Node) SimpleCreateTable(catdata.fql.sql.SimpleCreateTable) CreateTable(catdata.fql.sql.CreateTable) PSM(catdata.fql.sql.PSM) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) SimpleCreateTable(catdata.fql.sql.SimpleCreateTable) InsertValues(catdata.fql.sql.InsertValues) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Edge(catdata.fql.decl.Edge)

Aggregations

ExpPSM (catdata.fql.sql.ExpPSM)2 InsertValues (catdata.fql.sql.InsertValues)2 PSM (catdata.fql.sql.PSM)2 PropPSM (catdata.fql.sql.PropPSM)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 Edge (catdata.fql.decl.Edge)1 Node (catdata.fql.decl.Node)1 CreateTable (catdata.fql.sql.CreateTable)1 InsertSQL (catdata.fql.sql.InsertSQL)1 SQL (catdata.fql.sql.SQL)1 SimpleCreateTable (catdata.fql.sql.SimpleCreateTable)1