use of catdata.fql.decl.Node in project fql by CategoricalData.
the class LeftKanSigma method getFrom.
private static Object getFrom(Attribute<Node> attr, Map<Node, Map<Object, Integer>> etables, Map<Object, Object> saved, String newkey) {
List<Pair<Object, Object>> pre = new LinkedList<>();
for (Node kkk : etables.keySet()) {
Map<Object, Integer> nt = etables.get(kkk);
for (Object k : nt.keySet()) {
if (nt.get(k).toString().equals(newkey)) {
if (saved.get(k.toString()) == null) {
throw new RuntimeException();
}
pre.add(new Pair<>(k, saved.get(k.toString())));
}
}
}
if (pre.isEmpty()) {
if (!DefunctGlobalOptions.debug.fql.ALLOW_NULLS) {
throw new RuntimeException("Full sigma not surjective: transform is " + etables + " saved " + saved + " new key " + newkey);
}
}
Set<Object> x = new HashSet<>();
for (Pair<Object, Object> i : pre) {
x.add(i.second);
}
if (x.size() > 1) {
throw new RuntimeException("Full sigma not unique: transform is " + etables + " saved " + saved + " new key " + newkey);
}
for (Object ret : x) {
return ret;
}
if (DefunctGlobalOptions.debug.fql.ALLOW_NULLS) {
if (!(attr.target instanceof Varchar)) {
throw new RuntimeException("Cannot create nulls for any type but string");
}
// null hack
return "NULL" + newkey;
}
throw new RuntimeException();
}
use of catdata.fql.decl.Node in project fql by CategoricalData.
the class LeftKanSigma method sigma.
private static Pair<Instance, Map<Object, List<Pair<String, Object>>>> sigma(LeftKan lk) throws FQLException {
if (!lk.compute()) {
throw new FQLException("Too many sigma iterations.");
}
Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
for (Node e : lk.Pb.keySet()) {
Set<Pair<Integer, Integer>> t = lk.Pb.get(e);
data.put(e.string, conc(t));
}
for (Edge e : lk.Pg.keySet()) {
Set<Pair<Integer, Integer>> t = lk.Pg.get(e);
data.put(e.name, conc(t));
}
Instance ret = new Instance(lk.F.target, data);
return new Pair<>(ret, lk.lineage);
}
use of catdata.fql.decl.Node in project fql by CategoricalData.
the class LeftKanSigma method delta.
private static Pair<Instance, Map<Attribute<Node>, Map<Object, Object>>> delta(Mapping f0, Mapping f, Pair<Instance, Map<Attribute<Node>, Map<Object, Object>>> p) throws FQLException {
Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
for (Node n : f.source.nodes) {
data.put(n.string, p.first.data.get(f.nm.get(n).string));
}
for (Edge e : f.source.edges) {
data.put(e.name, p.first.evaluate(f.em.get(e)));
}
Instance J = new Instance(f.source, data);
Map<Attribute<Node>, Map<Object, Object>> m = new HashMap<>();
for (Attribute<Node> a : f0.source.attrs) {
m.put(a, p.second.get(f0.am.get(a)));
}
return new Pair<>(J, m);
}
use of catdata.fql.decl.Node in project fql by CategoricalData.
the class LeftKanSigma method deAttr.
private static Mapping deAttr(Mapping f) throws FQLException {
Mapping ret = f.clone();
deAttr(ret.source);
deAttr(ret.target);
for (Attribute<Node> k : ret.am.keySet()) {
Attribute<Node> v = ret.am.get(k);
Node src = new Node(k.name);
Node dst = new Node(v.name);
Edge srcE = new Edge(k.name + "_edge", k.source, src);
Edge dstE = new Edge(v.name + "_edge", v.source, dst);
ret.nm.put(src, dst);
ret.em.put(srcE, new Path(ret.target, dstE));
}
ret.am.clear();
return ret;
}
use of catdata.fql.decl.Node 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;
}
Aggregations