Search in sources :

Example 1 with Varchar

use of catdata.fql.decl.Type.Varchar 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();
}
Also used : Node(catdata.fql.decl.Node) LinkedList(java.util.LinkedList) Varchar(catdata.fql.decl.Type.Varchar) Pair(catdata.Pair) HashSet(java.util.HashSet)

Aggregations

Pair (catdata.Pair)1 Node (catdata.fql.decl.Node)1 Varchar (catdata.fql.decl.Type.Varchar)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1