Search in sources :

Example 36 with Tuple3

use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.

the class XSqlToFql method toECreateTable.

@SuppressWarnings("rawtypes")
private static ECreateTable toECreateTable(Object decl) {
    Tuple4 t = (Tuple4) decl;
    String name = t.c.toString();
    Tuple3 t0 = (Tuple3) t.d;
    List t1 = (List) t0.b;
    List<Pair<String, String>> types = new LinkedList<>();
    List<Pair<String, String>> fks = new LinkedList<>();
    for (Object o : t1) {
        org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) o;
        if (p.a.toString().equals("FOREIGN")) {
            Tuple5 x = (Tuple5) o;
            Tuple3 y = (Tuple3) x.b;
            fks.add(new Pair<>(y.b.toString(), x.d.toString()));
        } else {
            // if (p.a.toString().toLowerCase().equals("id")) {
            types.add(new Pair<>(p.a.toString(), p.b.toString()));
        // } else {
        // types.add(new Pair<>(name + "_" + p.a.toString(), p.b.toString()));
        // }
        }
    }
    return new ECreateTable(name, types, fks);
}
Also used : LinkedList(java.util.LinkedList) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) LinkedList(java.util.LinkedList) List(java.util.List) Pair(catdata.Pair)

Example 37 with Tuple3

use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.

the class RaToFql method toECreateTable.

@SuppressWarnings("rawtypes")
private static ECreateTable toECreateTable(Object decl) {
    Tuple4 t = (Tuple4) decl;
    String name = t.c.toString();
    Tuple3 t0 = (Tuple3) t.d;
    List t1 = (List) t0.b;
    List<Pair<String, String>> types = new LinkedList<>();
    for (Object o : t1) {
        org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) o;
        types.add(new Pair<>(p.a.toString(), p.b.toString()));
    }
    return new ECreateTable(name, types);
}
Also used : Tuple4(org.jparsec.functors.Tuple4) Tuple3(org.jparsec.functors.Tuple3) Pair(catdata.Pair)

Example 38 with Tuple3

use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.

the class RaToFql method program.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static List<Pair<String, EExternal>> program(String s) {
    List<Pair<String, EExternal>> ret = new LinkedList<>();
    List<Tuple3> decls = (List<Tuple3>) program.parse(s);
    for (Tuple3 decl : decls) {
        if (decl.a.toString().equals("CREATE")) {
            ret.add(new Pair<>(null, toECreateTable(decl)));
        } else if (decl.toString().contains("INSERT")) {
            ret.add(new Pair<>(null, toEInsertValues(decl)));
        } else if (decl.toString().contains("SELECT")) {
            ret.add(new Pair<>(decl.a.toString(), toFlower(decl.c)));
        } else if (decl.toString().contains("UNION")) {
            ret.add(new Pair<>(decl.a.toString(), toUnion(decl.c)));
        } else if (decl.toString().contains("EXCEPT")) {
            ret.add(new Pair<>(decl.a.toString(), toDiff(decl.c)));
        } else if (decl.toString().contains("FORALL")) {
            ret.add(new Pair<>(decl.a.toString(), toEd(decl.c)));
        } else {
            throw new RuntimeException();
        }
    }
    return ret;
}
Also used : Tuple3(org.jparsec.functors.Tuple3) Pair(catdata.Pair)

Example 39 with Tuple3

use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.

the class RaToFql method toFlower.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static EFlower toFlower(Object decl) {
    Map<String, Pair<String, String>> select = new LinkedHashMap<>();
    Map<String, String> from = new LinkedHashMap<>();
    List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
    Tuple3 o = (Tuple3) decl;
    Tuple3 select0 = (Tuple3) o.a;
    org.jparsec.functors.Pair from0 = (org.jparsec.functors.Pair) o.b;
    org.jparsec.functors.Pair where0 = (org.jparsec.functors.Pair) o.c;
    boolean distinct;
    distinct = select0.b != null;
    List<Tuple3> select1 = (List<Tuple3>) select0.c;
    for (Tuple3 k : select1) {
        Tuple3 a = (Tuple3) k.a;
        String b = k.c.toString();
        select.put(b, new Pair<>(a.a.toString(), a.c.toString()));
    }
    List<Tuple3> from1 = (List<Tuple3>) from0.b;
    for (Tuple3 k : from1) {
        from.put(k.c.toString(), k.a.toString());
    }
    if (where0 != null) {
        List<Tuple3> where1 = (List<Tuple3>) where0.b;
        for (Tuple3 k : where1) {
            Tuple3 l = (Tuple3) k.a;
            Tuple3 r = (Tuple3) k.c;
            where.add(new Pair<>(new Pair<>(l.a.toString(), l.c.toString()), new Pair<>(r.a.toString(), r.c.toString())));
        }
    }
    return new EFlower(select, from, where, distinct);
}
Also used : Tuple3(org.jparsec.functors.Tuple3) Pair(catdata.Pair)

Example 40 with Tuple3

use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.

the class SqlToFql method program.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static List<EExternal> program(String s) {
    List<EExternal> ret = new LinkedList<>();
    List<Tuple3> decls = (List<Tuple3>) program.parse(s);
    for (Tuple3 decl : decls) {
        if (decl.a.toString().equals("CREATE")) {
            ret.add(toECreateTable(decl));
        } else if (decl.toString().startsWith("((INSERT")) {
            ret.add(toEInsertValues(decl));
        } else {
            throw new RuntimeException(decl.toString());
        }
    }
    return ret;
}
Also used : Tuple3(org.jparsec.functors.Tuple3) LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList)

Aggregations

Tuple3 (org.jparsec.functors.Tuple3)90 Pair (catdata.Pair)69 List (java.util.List)57 LinkedList (java.util.LinkedList)56 Tuple5 (org.jparsec.functors.Tuple5)41 HashMap (java.util.HashMap)33 Tuple4 (org.jparsec.functors.Tuple4)32 LinkedHashMap (java.util.LinkedHashMap)17 Triple (catdata.Triple)15 HashSet (java.util.HashSet)15 XPair (catdata.fpql.XExp.XPair)11 Map (java.util.Map)10 Set (java.util.Set)6 Chc (catdata.Chc)5 Var (catdata.fqlpp.FunctorExp.Var)5 Program (catdata.Program)4 Const (catdata.fql.decl.SigExp.Const)4 Plus (catdata.fqlpp.CatExp.Plus)4 Apply (catdata.fqlpp.FunctorExp.Apply)4 Zero (catdata.fqlpp.FunctorExp.Zero)4