Search in sources :

Example 1 with LineException

use of catdata.LineException in project fql by CategoricalData.

the class XDriver method makeEnv.

@SuppressWarnings({ "rawtypes" })
public static XEnvironment makeEnv(String str, XProgram init, String... toUpdate) {
    if (DefunctGlobalOptions.debug.fpql.x_typing) {
        init.doTypes();
    }
    XEnvironment ret = new XEnvironment(init, str);
    Map<String, Integer> extra = new HashMap<>();
    int i = 0;
    for (String k : init.order) {
        XExp se = init.exps.get(k);
        try {
            XObject xxx = se.accept(init, new XOps(ret));
            if (xxx == null) {
                throw new RuntimeException();
            }
            if (se instanceof Flower) {
                Flower f = (Flower) se;
                if (ret.objs.containsKey(f.ty)) {
                    throw new RuntimeException("Duplicate: " + f.ty);
                }
                XCtx c = (XCtx) xxx;
                if (f.ty != null) {
                    ret.objs.put(f.ty, c.schema);
                    extra.put(f.ty, i);
                }
            }
            if (ret.objs.containsKey(k)) {
                throw new RuntimeException("Duplicate: " + k);
            }
            ret.objs.put(k, xxx);
            toUpdate[0] = "Last Processed: " + k;
            i++;
        } catch (Throwable t) {
            t.printStackTrace();
            throw new LineException(t.getLocalizedMessage(), k, "");
        }
    }
    int j = 0;
    for (Entry<String, Integer> e : extra.entrySet()) {
        init.order.add(e.getValue() + j, e.getKey());
        j++;
    }
    // : add to order
    return ret;
}
Also used : Flower(catdata.fpql.XExp.Flower) HashMap(java.util.HashMap) LineException(catdata.LineException)

Example 2 with LineException

use of catdata.LineException in project fql by CategoricalData.

the class MplDriver method makeEnv.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static Environment<MplObject> makeEnv(@SuppressWarnings("unused") String str, Program<MplExp<String, String>> init) {
    Environment<MplObject> ret = new Environment<>();
    for (String k : init.order) {
        MplExp se = init.exps.get(k);
        try {
            MplObject xxx = (MplObject) se.accept(new Unit(), new MplOps(ret));
            ret.put(k, xxx);
        } catch (Throwable t) {
            t.printStackTrace();
            throw new LineException(t.getLocalizedMessage(), k, "");
        }
    }
    return ret;
}
Also used : MplExp(catdata.mpl.Mpl.MplExp) LineException(catdata.LineException) Environment(catdata.Environment) Unit(catdata.Unit)

Example 3 with LineException

use of catdata.LineException in project fql by CategoricalData.

the class JDBCBridge method run.

public static Triple<Map<String, Set<Map<Object, Object>>>, String, List<Throwable>> run(FQLProgram prog) {
    Map<String, Set<Map<Object, Object>>> ret = new HashMap<>();
    List<Throwable> exns = new LinkedList<>();
    InstOps ops = new InstOps(prog);
    PSMInterp interp = new PSMInterp();
    Connection Conn;
    Statement Stmt = null;
    List<PSM> sqls = new LinkedList<>();
    try {
        switch(DefunctGlobalOptions.debug.fql.sqlKind) {
            case H2:
                Class.forName("org.h2.Driver");
                Conn = DriverManager.getConnection("jdbc:h2:mem:");
                Stmt = Conn.createStatement();
                Stmt.execute("SET @GUID = 0");
                break;
            case JDBC:
                Class.forName(DefunctGlobalOptions.debug.fql.jdbcClass);
                Conn = DriverManager.getConnection(DefunctGlobalOptions.debug.fql.jdbcUrl);
                Stmt = Conn.createStatement();
                String[] prel = DefunctGlobalOptions.debug.fql.prelude.split(";");
                for (String s : prel) {
                    Stmt.execute(s);
                }
                break;
            case NATIVE:
                break;
            default:
                throw new RuntimeException();
        }
        for (String k : prog.order) {
            InstExp v1 = prog.insts.get(k);
            TransExp v2 = prog.transforms.get(k);
            try {
                if (v1 != null) {
                    sqls.addAll(maybeExecInstance(ops, prog, Stmt, k, v1, interp, ret));
                } else if (v2 != null) {
                    sqls.addAll(maybeExecTransform(ops, prog, Stmt, k, v2, interp, ret));
                }
            } catch (Throwable re) {
                String thing = (v1 == null) ? "transform" : "instance";
                re.printStackTrace();
                LineException exn = new LineException(re.getLocalizedMessage(), k, thing);
                if (DefunctGlobalOptions.debug.fql.continue_on_error) {
                    exns.add(exn);
                } else {
                    if (DefunctGlobalOptions.debug.fql.sqlKind == SQLKIND.JDBC) {
                        String[] prel0 = DefunctGlobalOptions.debug.fql.afterlude.split(";");
                        for (String s : prel0) {
                            if (!s.trim().isEmpty()) {
                                if (Stmt == null) {
                                    throw new RuntimeException("Anomaly: please report");
                                }
                                Stmt.execute(s);
                            }
                        }
                    }
                    throw exn;
                }
            }
        }
        List<PSM> drops = Driver.computeDrops(prog);
        if (DefunctGlobalOptions.debug.fql.sqlKind == SQLKIND.JDBC) {
            for (PSM dr : drops) {
                if (Stmt == null) {
                    throw new RuntimeException("Anomaly: please report");
                }
                Stmt.execute(dr.toPSM());
            }
            String[] prel0 = DefunctGlobalOptions.debug.fql.afterlude.split(";");
            for (String s : prel0) {
                if (!s.trim().isEmpty()) {
                    if (Stmt == null) {
                        throw new RuntimeException("Anomaly: please report");
                    }
                    Stmt.execute(s);
                }
            }
        }
        String str;
        try {
            str = DefunctGlobalOptions.debug.fql.prelude + "\n\n" + PSMGen.prettyPrint(sqls) + "\n\n" + (drops.isEmpty() ? "" : PSMGen.prettyPrint(drops) + "\n\n") + DefunctGlobalOptions.debug.fql.afterlude + "\n\n";
        } catch (RuntimeException re) {
            str = re.getLocalizedMessage();
        }
        return new Triple<>(ret, str, exns);
    } catch (Exception exception) {
        if (exception instanceof LineException) {
            throw ((LineException) exception);
        }
        exception.printStackTrace();
        throw new RuntimeException(exception.getLocalizedMessage());
    }
}
Also used : HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) Set(java.util.Set) PSMInterp(catdata.fql.sql.PSMInterp) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Statement(java.sql.Statement) TransExp(catdata.fql.decl.TransExp) Connection(java.sql.Connection) InstOps(catdata.fql.decl.InstOps) PSM(catdata.fql.sql.PSM) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) LinkedList(java.util.LinkedList) LineException(catdata.LineException) SQLException(java.sql.SQLException) Triple(catdata.Triple) InstExp(catdata.fql.decl.InstExp) LineException(catdata.LineException)

Example 4 with LineException

use of catdata.LineException in project fql by CategoricalData.

the class Driver method makeEnv.

public static Triple<FqlEnvironment, String, List<Throwable>> makeEnv(FQLProgram prog, String... toUpdate) {
    List<Throwable> exns = new LinkedList<>();
    Map<String, Signature> sigs = new HashMap<>();
    Map<String, Mapping> maps = new HashMap<>();
    Map<String, Instance> insts = new HashMap<>();
    Map<String, Query> queries = new HashMap<>();
    Map<String, FullQuery> full_queries = new HashMap<>();
    for (String k : prog.sigs.keySet()) {
        try {
            SigExp v = prog.sigs.get(k);
            v.typeOf(prog);
            sigs.put(k, v.toSig(prog));
            toUpdate[0] = "Last Processed: " + k;
        } catch (RuntimeException re) {
            re.printStackTrace();
            LineException exn = new LineException(re.getLocalizedMessage(), k, "schema");
            if (DefunctGlobalOptions.debug.fql.continue_on_error) {
                exns.add(exn);
            } else {
                throw exn;
            }
        }
    }
    for (String k : prog.maps.keySet()) {
        try {
            MapExp v = prog.maps.get(k);
            v.type(prog);
            maps.put(k, v.toMap(prog));
            toUpdate[0] = "Last Processed: " + k;
        } catch (RuntimeException re) {
            re.printStackTrace();
            LineException exn = new LineException(re.getLocalizedMessage(), k, "mapping");
            if (DefunctGlobalOptions.debug.fql.continue_on_error) {
                exns.add(exn);
            } else {
                throw exn;
            }
        }
    }
    for (String k : prog.queries.keySet()) {
        try {
            QueryExp v = prog.queries.get(k);
            v.type(prog);
            queries.put(k, Query.toQuery(prog, v));
            toUpdate[0] = "Last Processed: " + k;
        } catch (RuntimeException re) {
            re.printStackTrace();
            LineException exn = new LineException(re.getLocalizedMessage(), k, "query");
            if (DefunctGlobalOptions.debug.fql.continue_on_error) {
                exns.add(exn);
            } else {
                throw exn;
            }
        }
    }
    for (String k : prog.full_queries.keySet()) {
        try {
            FullQueryExp v = prog.full_queries.get(k);
            v.type(prog);
            full_queries.put(k, FullQuery.toQuery(prog, v));
            toUpdate[0] = "Last Processed: " + k;
        } catch (RuntimeException re) {
            re.printStackTrace();
            LineException exn = new LineException(re.getLocalizedMessage(), k, "QUERY");
            if (DefunctGlobalOptions.debug.fql.continue_on_error) {
                exns.add(exn);
            } else {
                throw exn;
            }
        }
    }
    for (String k : prog.insts.keySet()) {
        try {
            InstExp v = prog.insts.get(k);
            v.type(prog);
            toUpdate[0] = "Last Processed: " + v + " (type-check only)";
        } catch (RuntimeException re) {
            re.printStackTrace();
            LineException exn = new LineException(re.getLocalizedMessage(), k, "instance");
            if (DefunctGlobalOptions.debug.fql.continue_on_error) {
                exns.add(exn);
            } else {
                throw exn;
            }
        }
    }
    for (String k : prog.transforms.keySet()) {
        try {
            TransExp v = prog.transforms.get(k);
            v.type(prog);
            toUpdate[0] = "Last Processed: " + v + " (type-check only)";
        } catch (RuntimeException re) {
            re.printStackTrace();
            LineException exn = new LineException(re.getLocalizedMessage(), k, "transform");
            if (DefunctGlobalOptions.debug.fql.continue_on_error) {
                exns.add(exn);
            } else {
                throw exn;
            }
        }
    }
    prog = rewriteQueries(prog);
    toUpdate[0] = "SQL generation complete, executing.";
    Triple<Map<String, Set<Map<Object, Object>>>, String, List<Throwable>> res = JDBCBridge.run(prog);
    toUpdate[0] = "SQL Execution Complete";
    exns.addAll(res.third);
    for (String k : prog.insts.keySet()) {
        try {
            Signature s = prog.insts.get(k).type(prog).toSig(prog);
            List<Pair<String, List<Pair<Object, Object>>>> b = PSMGen.gather(k, s, res.first);
            insts.put(k, new Instance(s, b));
            toUpdate[0] = "Last Processed: " + k;
        } catch (Exception re) {
            re.printStackTrace();
            LineException exn = new LineException(re.getLocalizedMessage(), k, "instance");
            if (DefunctGlobalOptions.debug.fql.continue_on_error) {
                exns.add(exn);
            } else {
                throw exn;
            }
        }
    }
    Map<String, Transform> transforms = new HashMap<>();
    for (String k : prog.transforms.keySet()) {
        try {
            Pair<String, String> val = prog.transforms.get(k).type(prog);
            InstExp i = prog.insts.get(val.first);
            Signature s = i.type(prog).toSig(prog);
            List<Pair<String, List<Pair<Object, Object>>>> b = PSMGen.gather(k, s, res.first);
            transforms.put(k, new Transform(insts.get(val.first), insts.get(val.second), b));
            toUpdate[0] = "Last Processed: " + k;
        } catch (Exception re) {
            re.printStackTrace();
            LineException exn = new LineException(re.getLocalizedMessage(), k, "transform");
            if (DefunctGlobalOptions.debug.fql.continue_on_error) {
                exns.add(exn);
            } else {
                throw exn;
            }
        }
    }
    toUpdate[0] = "Load of SQL data into FQL complete.";
    // check full sigmas with EDs
    if (DefunctGlobalOptions.debug.fql.VALIDATE_WITH_EDS) {
        try {
            validateWithEds(prog, insts);
        } catch (FQLException fe) {
            fe.printStackTrace();
            throw new RuntimeException(fe.getLocalizedMessage());
        }
    }
    String toRetStr = res.second.trim();
    if (containsFullSigma(prog)) {
        toRetStr = "Cannot generate SQL for full sigma";
    }
    return new Triple<>(new FqlEnvironment(sigs, maps, insts, queries, transforms, full_queries), toRetStr, dedup(exns));
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) LineException(catdata.LineException) LinkedList(java.util.LinkedList) List(java.util.List) Pair(catdata.Pair) LinkedList(java.util.LinkedList) LineException(catdata.LineException) FQLException(catdata.fql.FQLException) Triple(catdata.Triple) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with LineException

use of catdata.LineException in project fql by CategoricalData.

the class FQLPPDriver method makeEnv.

public static FQLPPEnvironment makeEnv(String str, FQLPPProgram init, String... toUpdate) {
    Map<String, Fn<?, ?>> fns = new HashMap<>();
    Map<String, Set<?>> sets = new HashMap<>();
    Map<String, Category<?, ?>> cats = new HashMap<>();
    Map<String, Functor<?, ?, ?, ?>> ftrs = new HashMap<>();
    Map<String, Transform<?, ?, ?, ?>> trans = new HashMap<>();
    FQLPPEnvironment ret = new FQLPPEnvironment(init, str, sets, fns, cats, ftrs, trans);
    for (Entry<String, CatExp> k : init.cats.entrySet()) {
        init.cats.put(k.getKey(), k.getValue().accept(init, new PreProcessor()));
    }
    for (String k : init.order) {
        SetExp se = init.sets.get(k);
        if (se != null) {
            try {
                Set<?> xxx = se.accept(init, new SetOps(ret));
                sets.put(k, xxx);
            } catch (Throwable t) {
                t.printStackTrace();
                throw new LineException(t.getLocalizedMessage(), k, "set");
            }
            toUpdate[0] = "Last Processed: " + k;
        }
        FnExp fe = init.fns.get(k);
        if (fe != null) {
            try {
                Fn<?, ?> xxx = fe.accept(init, new SetOps(ret));
                fns.put(k, xxx);
                toUpdate[0] = "Last Processed: " + k;
            } catch (Throwable t) {
                t.printStackTrace();
                throw new LineException(t.getLocalizedMessage(), k, "function");
            }
        }
        CatExp ce = init.cats.get(k);
        // CatExp ce = ce0.accept(init, new PreProcessor());
        if (ce != null) {
            try {
                Category<?, ?> xxx = ce.accept(init, new CatOps(ret));
                cats.put(k, xxx);
                toUpdate[0] = "Last Processed: " + k;
            } catch (Throwable t) {
                t.printStackTrace();
                throw new LineException(t.getLocalizedMessage(), k, "category");
            }
        }
        FunctorExp FE = init.ftrs.get(k);
        if (FE != null) {
            try {
                Functor<?, ?, ?, ?> xxx = FE.accept(init, new CatOps(ret));
                ftrs.put(k, xxx);
                toUpdate[0] = "Last Processed: " + k;
            } catch (Throwable t) {
                t.printStackTrace();
                throw new LineException(t.getLocalizedMessage(), k, "functor");
            }
        }
        TransExp te = init.trans.get(k);
        if (te != null) {
            try {
                Transform<?, ?, ?, ?> xxx = te.accept(init, new CatOps(ret));
                trans.put(k, xxx);
                toUpdate[0] = "Last Processed: " + k;
            } catch (Throwable t) {
                t.printStackTrace();
                throw new LineException(t.getLocalizedMessage(), k, "transform");
            }
        }
    }
    return ret;
}
Also used : Set(java.util.Set) Category(catdata.fqlpp.cat.Category) HashMap(java.util.HashMap) LineException(catdata.LineException) Fn(catdata.fqlpp.cat.FinSet.Fn) Functor(catdata.fqlpp.cat.Functor) Transform(catdata.fqlpp.cat.Transform)

Aggregations

LineException (catdata.LineException)9 HashMap (java.util.HashMap)4 Environment (catdata.Environment)2 Triple (catdata.Triple)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 Set (java.util.Set)2 Pair (catdata.Pair)1 RuntimeInterruptedException (catdata.RuntimeInterruptedException)1 Unit (catdata.Unit)1 Kind (catdata.aql.Kind)1 LocException (catdata.aql.exp.LocException)1 Flower (catdata.fpql.XExp.Flower)1 XSchema (catdata.fpql.XExp.XSchema)1 FQLException (catdata.fql.FQLException)1 InstExp (catdata.fql.decl.InstExp)1 InstOps (catdata.fql.decl.InstOps)1 TransExp (catdata.fql.decl.TransExp)1 ExpPSM (catdata.fql.sql.ExpPSM)1