Search in sources :

Example 1 with Block

use of catdata.opl.OplQuery.Block in project fql by CategoricalData.

the class OplParser method fromBlock.

private static Block<String, String, String, String, String, String> fromBlock(Object o) {
    Tuple4<List, List, List, List> t = (Tuple4<List, List, List, List>) o;
    LinkedHashMap<String, String> from = new LinkedHashMap<>();
    Set<Pair<OplTerm<String, String>, OplTerm<String, String>>> where = new HashSet<>();
    Map<String, Chc<Agg<String, String, String, String, String, String>, OplTerm<String, String>>> attrs = new HashMap<>();
    Map<String, Pair<Object, Map<String, OplTerm<String, String>>>> edges = new HashMap<>();
    for (Object x : t.a) {
        Tuple3 l = (Tuple3) x;
        if (from.containsKey(l.a.toString())) {
            throw new RuntimeException("Duplicate for: " + l.a);
        }
        from.put(l.a.toString(), l.c.toString());
    }
    for (Object x : t.b) {
        Tuple3 l = (Tuple3) x;
        where.add(new Pair(toTerm(from.keySet(), null, l.a, true), toTerm(from.keySet(), null, l.c, true)));
    }
    for (Object x : t.c) {
        Tuple3 l = (Tuple3) x;
        if (attrs.containsKey(l.a.toString())) {
            throw new RuntimeException("Duplicate for: " + l.a);
        }
        if (l.c.toString().contains("agg") && l.c.toString().contains("{") && l.c.toString().contains("return") && l.c.toString().contains("}")) {
            attrs.put(l.a.toString(), Chc.inLeft(fromAgg(from.keySet(), null, l.c, true)));
        } else {
            attrs.put(l.a.toString(), Chc.inRight(toTerm(from.keySet(), null, l.c, true)));
        }
    }
    for (Object x : t.d) {
        Tuple5 l = (Tuple5) x;
        if (from.containsKey(l.a.toString())) {
            throw new RuntimeException("Duplicate for: " + l.a);
        }
        edges.put(l.a.toString(), new Pair(l.e.toString(), fromBlockHelper(from.keySet(), l.c)));
    }
    Block bl = new Block<>(from, where, attrs, edges);
    return bl;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) Block(catdata.opl.OplQuery.Block) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) HashSet(java.util.HashSet) Chc(catdata.Chc)

Example 2 with Block

use of catdata.opl.OplQuery.Block in project fql by CategoricalData.

the class OplParser method fromBlock2.

private static Block<String, String, String, String, String, String> fromBlock2(Object o) {
    Tuple3<List, List, List> t = (Tuple3<List, List, List>) o;
    LinkedHashMap<String, String> from = new LinkedHashMap<>();
    Set<Pair<OplTerm<String, String>, OplTerm<String, String>>> where = new HashSet<>();
    Map<String, Chc<Agg<String, String, String, String, String, String>, OplTerm<String, String>>> attrs = new HashMap<>();
    Map<String, Pair<Object, Map<String, OplTerm<String, String>>>> edges = new HashMap<>();
    // from
    for (Object x : (Iterable) ((org.jparsec.functors.Pair) t.b).b) {
        org.jparsec.functors.Pair l = (org.jparsec.functors.Pair) x;
        String gen;
        String ty;
        if (l.b == null) {
            gen = (String) l.a;
            ty = (String) l.a;
        } else {
            org.jparsec.functors.Pair g = (org.jparsec.functors.Pair) l.b;
            gen = (String) g.b;
            ty = (String) l.a;
        }
        if (from.containsKey(gen)) {
            throw new DoNotIgnore("In from clause, duplicate for: " + gen);
        }
        from.put(gen, ty);
    }
    // Object z = ((org.jparsec.functors.Pair)t.c).b;
    if (t.c != null) {
        for (Object x : (Iterable) ((org.jparsec.functors.Pair) t.c).b) {
            Tuple3 l = (Tuple3) x;
            where.add(new Pair(toTerm(from.keySet(), null, l.a, true), toTerm(from.keySet(), null, l.c, true)));
        }
    }
    // return
    for (Object x : (Iterable) ((org.jparsec.functors.Pair) t.a).b) {
        Tuple3 l = (Tuple3) x;
        String dst = (String) l.c;
        if (attrs.containsKey(dst) || edges.containsKey(dst)) {
            throw new DoNotIgnore("In select clause, duplicate for: " + dst);
        }
        if (l.a instanceof Tuple3 && ((org.jparsec.functors.Pair) l.a).a.toString().equals("(")) {
            edges.put(dst, new Pair(null, fromBlockHelper2(from.keySet(), l.a)));
        } else {
            attrs.put(dst, Chc.inRight(toTerm(from.keySet(), null, l.a, true)));
        }
    }
    Block bl = new Block<>(from, where, attrs, edges);
    return bl;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) Tuple3(org.jparsec.functors.Tuple3) Block(catdata.opl.OplQuery.Block) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) HashSet(java.util.HashSet) Chc(catdata.Chc)

Aggregations

Chc (catdata.Chc)2 Pair (catdata.Pair)2 Block (catdata.opl.OplQuery.Block)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Tuple3 (org.jparsec.functors.Tuple3)2 Tuple4 (org.jparsec.functors.Tuple4)1 Tuple5 (org.jparsec.functors.Tuple5)1