Search in sources :

Example 1 with Query

use of catdata.aql.Query in project fql by CategoricalData.

the class QueryExpRawSimple method eval.

// TODO aql merge with queryexpraw
@Override
public Query<Ty, En, Sym, Fk, Att, En, Fk, Att> eval(AqlEnv env) {
    Schema<Ty, En, Sym, Fk, Att> src0 = src.eval(env);
    Collage<Ty, En, Sym, Fk, Att, Void, Void> srcCol = src0.collage();
    En En = new En("Q");
    AqlOptions ops = new AqlOptions(block.options, null, env.defaults);
    boolean doNotCheckEqs = (Boolean) ops.getOrDefault(AqlOption.dont_validate_unsafe);
    boolean elimRed = (Boolean) ops.getOrDefault(AqlOption.query_remove_redundancy);
    boolean checkJava = !(Boolean) ops.getOrDefault(AqlOption.allow_java_eqs_unsafe);
    Ctx<En, Triple<Ctx<Var, En>, Collection<Eq<Ty, En, Sym, Fk, Att, Var, Var>>, AqlOptions>> ens0 = new Ctx<>();
    Ctx<Att, Term<Ty, En, Sym, Fk, Att, Var, Var>> atts0 = new Ctx<>();
    Ctx<Fk, Pair<Ctx<Var, Term<Void, En, Void, Fk, Void, Var, Void>>, Boolean>> fks0 = new Ctx<>();
    Ctx<En, Collage<Ty, En, Sym, Fk, Att, Var, Var>> cols = new Ctx<>();
    QueryExpRaw.processBlock(block.options, env, src0, ens0, cols, block, new Ctx<>());
    Collage<Ty, En, Sym, Fk, Att, Void, Void> colForDst = new Collage<>(src0.typeSide.collage());
    colForDst.ens.add(En);
    for (Pair<Att, RawTerm> p : block.atts) {
        Map<String, Chc<Ty, En>> s = QueryExpRaw.unVar(cols.get(En).gens).<Ty>inRight().map;
        Term<Ty, catdata.aql.exp.SchExpRaw.En, Sym, Fk, Att, Gen, Sk> term = RawTerm.infer1x(s, p.second, p.second, null, srcCol.convert(), "", src0.typeSide.js).second;
        Chc<Ty, En> ty = srcCol.type(new Ctx<>(s).map((k, v) -> new Pair<>(new Var(k), v)), term.convert());
        if (!ty.left) {
            throw new LocException(find("attributes", p), "In return clause for " + p.first + ", the type is " + ty.r + ", which is an entity.");
        }
        colForDst.atts.put(p.first, new Pair<>(En, ty.l));
    }
    DP<Ty, En, Sym, Fk, Att, Void, Void> dp = AqlProver.create(ops, colForDst, src0.typeSide.js);
    Schema<Ty, En, Sym, Fk, Att> dst0 = new Schema<Ty, En, Sym, Fk, Att>(src0.typeSide, colForDst.ens, colForDst.atts.map, colForDst.fks.map, new HashSet<>(), dp, checkJava);
    for (Pair<Att, RawTerm> p : block.atts) {
        try {
            QueryExpRaw.processAtt(src0, dst0, ens0, atts0, cols, p, new Ctx<>());
        } catch (RuntimeException ex) {
            ex.printStackTrace();
            throw new LocException(find("attributes", p), "In return clause for " + p.first + ", " + ex.getMessage());
        }
    }
    // TODO aql
    return Query.makeQuery(ens0, atts0, fks0, src0, dst0, doNotCheckEqs, elimRed);
}
Also used : Att(catdata.aql.exp.SchExpRaw.Att) AqlOptions(catdata.aql.AqlOptions) Ctx(catdata.Ctx) RawTerm(catdata.aql.RawTerm) En(catdata.aql.exp.SchExpRaw.En) Sym(catdata.aql.exp.TyExpRaw.Sym) Chc(catdata.Chc) Gen(catdata.aql.exp.InstExpRaw.Gen) AqlOption(catdata.aql.AqlOptions.AqlOption) AqlProver(catdata.aql.AqlProver) HashSet(java.util.HashSet) Map(java.util.Map) Collage(catdata.aql.Collage) DP(catdata.aql.DP) Eq(catdata.aql.Eq) Term(catdata.aql.Term) LinkedList(java.util.LinkedList) Pair(catdata.Pair) Fk(catdata.aql.exp.SchExpRaw.Fk) PreBlock(catdata.aql.exp.QueryExpRaw.PreBlock) Block(catdata.aql.exp.QueryExpRaw.Block) Collection(java.util.Collection) Kind(catdata.aql.Kind) Util(catdata.Util) Query(catdata.aql.Query) Att(catdata.aql.exp.SchExpRaw.Att) List(java.util.List) Schema(catdata.aql.Schema) Var(catdata.aql.Var) Sk(catdata.aql.exp.InstExpRaw.Sk) Triple(catdata.Triple) SchExpCod(catdata.aql.exp.SchExp.SchExpCod) Collections(java.util.Collections) Ty(catdata.aql.exp.TyExpRaw.Ty) Var(catdata.aql.Var) Ctx(catdata.Ctx) Schema(catdata.aql.Schema) En(catdata.aql.exp.SchExpRaw.En) Eq(catdata.aql.Eq) Pair(catdata.Pair) Ty(catdata.aql.exp.TyExpRaw.Ty) Fk(catdata.aql.exp.SchExpRaw.Fk) Sym(catdata.aql.exp.TyExpRaw.Sym) RawTerm(catdata.aql.RawTerm) Term(catdata.aql.Term) RawTerm(catdata.aql.RawTerm) Triple(catdata.Triple) Gen(catdata.aql.exp.InstExpRaw.Gen) Sk(catdata.aql.exp.InstExpRaw.Sk) AqlOptions(catdata.aql.AqlOptions) Collage(catdata.aql.Collage) Chc(catdata.Chc)

Aggregations

Chc (catdata.Chc)1 Ctx (catdata.Ctx)1 Pair (catdata.Pair)1 Triple (catdata.Triple)1 Util (catdata.Util)1 AqlOptions (catdata.aql.AqlOptions)1 AqlOption (catdata.aql.AqlOptions.AqlOption)1 AqlProver (catdata.aql.AqlProver)1 Collage (catdata.aql.Collage)1 DP (catdata.aql.DP)1 Eq (catdata.aql.Eq)1 Kind (catdata.aql.Kind)1 Query (catdata.aql.Query)1 RawTerm (catdata.aql.RawTerm)1 Schema (catdata.aql.Schema)1 Term (catdata.aql.Term)1 Var (catdata.aql.Var)1 Gen (catdata.aql.exp.InstExpRaw.Gen)1 Sk (catdata.aql.exp.InstExpRaw.Sk)1 Block (catdata.aql.exp.QueryExpRaw.Block)1