use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class XParser method fromBlockHelper.
// {b2=a1.f, b3=a1.f}
private static Map<String, List<String>> fromBlockHelper(Object o) {
List<Tuple3> l = (List<Tuple3>) o;
Map<String, List<String>> ret = new HashMap<>();
for (Tuple3 t : l) {
if (ret.containsKey(t.a.toString())) {
throw new RuntimeException("Duplicate column: " + t.a);
}
ret.put(t.a.toString(), (List<String>) t.c);
}
return ret;
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class XRaToFpql method toEd.
@SuppressWarnings({ "rawtypes", "unchecked" })
private static EED toEd(Object decl) {
Map<String, String> from1 = new LinkedHashMap<>();
Map<String, String> from2 = new LinkedHashMap<>();
List<Pair<Pair<String, String>, Pair<String, String>>> where1 = new LinkedList<>();
List<Pair<Pair<String, String>, Pair<String, String>>> where2 = new LinkedList<>();
Tuple4 o = (Tuple4) decl;
org.jparsec.functors.Pair from10 = (org.jparsec.functors.Pair) o.a;
org.jparsec.functors.Pair where10 = (org.jparsec.functors.Pair) o.b;
org.jparsec.functors.Pair from11 = (org.jparsec.functors.Pair) o.c;
org.jparsec.functors.Pair where11 = (org.jparsec.functors.Pair) o.d;
List<Tuple3> from10x = (List<Tuple3>) from10.b;
for (Tuple3 k : from10x) {
from1.put(k.c.toString(), k.a.toString());
}
// if (where0 == null) {
//
// } else {
List<Tuple3> where10x = (List<Tuple3>) where10.b;
for (Tuple3 k : where10x) {
Tuple3 l = (Tuple3) k.a;
if (k.c instanceof Tuple3) {
Tuple3 r = (Tuple3) k.c;
where1.add(new Pair<>(new Pair<>(l.a.toString(), l.c.toString()), new Pair<>(r.a.toString(), r.c.toString())));
} else {
String r = (String) k.c;
where1.add(new Pair<>(new Pair<>(l.a.toString(), l.c.toString()), new Pair<>(r, null)));
}
}
// }
List<Tuple3> from11x = (List<Tuple3>) from11.b;
for (Tuple3 k : from11x) {
from2.put(k.c.toString(), k.a.toString());
}
// if (where0 == null) {
//
// } else {
List<Tuple3> where11x = (List<Tuple3>) where11.b;
for (Tuple3 k : where11x) {
Tuple3 l = (Tuple3) k.a;
if (k.c instanceof Tuple3) {
Tuple3 r = (Tuple3) k.c;
where2.add(new Pair<>(new Pair<>(l.a.toString(), l.c.toString()), new Pair<>(r.a.toString(), r.c.toString())));
} else {
String r = (String) k.c;
where2.add(new Pair<>(new Pair<>(l.a.toString(), l.c.toString()), new Pair<>(r, null)));
}
}
return new EED(from1, from2, where1, where2);
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class XRaToFpql method toEInsertValues.
@SuppressWarnings({ "rawtypes", "unchecked" })
private static EInsertValues toEInsertValues(Object decl) {
Tuple5 t = (Tuple5) decl;
String target = t.b.toString();
List<Tuple3> x = (List<Tuple3>) t.d;
List<List<String>> values = new LinkedList<>();
for (Tuple3 y : x) {
List<String> l = (List<String>) y.b;
values.add(l);
}
return new EInsertValues(target, values);
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class XRaToFpql 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;
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class XRaToFpql 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);
}
Aggregations