Search in sources :

Example 1 with SqlTypeSide

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

the class InstExpJdbcAll method makeSchema.

public Schema<Ty, En, Sym, Fk, Att> makeSchema(AqlEnv env, SqlSchema info, AqlOptions ops) {
    boolean checkJava = !(Boolean) ops.getOrDefault(AqlOption.allow_java_eqs_unsafe);
    TypeSide<Ty, Sym> typeSide = new SqlTypeSide(ops);
    // typeSide.validate(true);
    Collage<Ty, En, Sym, Fk, Att, Void, Void> col0 = new Collage<>(typeSide.collage());
    Set<Triple<Pair<Var, En>, Term<Ty, En, Sym, Fk, Att, Void, Void>, Term<Ty, En, Sym, Fk, Att, Void, Void>>> eqs = new HashSet<>();
    for (SqlTable table : info.tables) {
        col0.ens.add(new En(table.name));
        for (SqlColumn c : table.columns) {
            if (col0.atts.containsKey(new Att(new En(table.name), c.name))) {
                throw new RuntimeException("Name collision: table " + c.table.name + " col " + c.name + " against table " + col0.atts.get(new Att(new En(table.name), c.name)).first + "\n\n.Possible solution: set option jdbc_import_col_seperator so as to avoid name collisions.");
            }
            col0.atts.put(new Att(new En(table.name), c.name), new Pair<>(new En(table.name), new Ty(sqlTypeToAqlType(c.type.name))));
        }
    }
    for (SqlForeignKey fk : info.fks) {
        col0.fks.put(new Fk(new En(fk.source.name), fk.toString()), new Pair<>(new En(fk.source.name), new En(fk.target.name)));
        Var v = new Var("x");
        for (SqlColumn tcol : fk.map.keySet()) {
            SqlColumn scol = fk.map.get(tcol);
            Att l = new Att(new En(scol.table.name), scol.name);
            Att r = new Att(new En(tcol.table.name), tcol.name);
            Term<Ty, En, Sym, Fk, Att, Void, Void> lhs = Term.Att(l, Term.Var(v));
            Term<Ty, En, Sym, Fk, Att, Void, Void> rhs = Term.Att(r, Term.Fk(new Fk(new En(fk.source.name), fk.toString()), Term.Var(v)));
            eqs.add(new Triple<>(new Pair<>(v, new En(fk.source.name)), lhs, rhs));
            col0.eqs.add(new Eq<>(new Ctx<>(new Pair<>(v, Chc.inRight(new En(fk.source.name)))), lhs, rhs));
        }
    }
    DP<Ty, En, Sym, Fk, Att, Void, Void> dp = AqlProver.create(new AqlOptions(options, col0, env.defaults), col0, typeSide.js);
    Schema<Ty, En, Sym, Fk, Att> sch = new Schema<>(typeSide, col0.ens, col0.atts.map, col0.fks.map, eqs, dp, checkJava);
    return sch;
}
Also used : Att(catdata.aql.exp.SchExpRaw.Att) SqlTypeSide(catdata.aql.SqlTypeSide) Var(catdata.aql.Var) Ctx(catdata.Ctx) SqlSchema(catdata.sql.SqlSchema) Schema(catdata.aql.Schema) En(catdata.aql.exp.SchExpRaw.En) HashSet(java.util.HashSet) Pair(catdata.Pair) Ty(catdata.aql.exp.TyExpRaw.Ty) Fk(catdata.aql.exp.SchExpRaw.Fk) Sym(catdata.aql.exp.TyExpRaw.Sym) Triple(catdata.Triple) SqlForeignKey(catdata.sql.SqlForeignKey) SqlTable(catdata.sql.SqlTable) AqlOptions(catdata.aql.AqlOptions) Collage(catdata.aql.Collage) SqlColumn(catdata.sql.SqlColumn)

Aggregations

Ctx (catdata.Ctx)1 Pair (catdata.Pair)1 Triple (catdata.Triple)1 AqlOptions (catdata.aql.AqlOptions)1 Collage (catdata.aql.Collage)1 Schema (catdata.aql.Schema)1 SqlTypeSide (catdata.aql.SqlTypeSide)1 Var (catdata.aql.Var)1 Att (catdata.aql.exp.SchExpRaw.Att)1 En (catdata.aql.exp.SchExpRaw.En)1 Fk (catdata.aql.exp.SchExpRaw.Fk)1 Sym (catdata.aql.exp.TyExpRaw.Sym)1 Ty (catdata.aql.exp.TyExpRaw.Ty)1 SqlColumn (catdata.sql.SqlColumn)1 SqlForeignKey (catdata.sql.SqlForeignKey)1 SqlSchema (catdata.sql.SqlSchema)1 SqlTable (catdata.sql.SqlTable)1 HashSet (java.util.HashSet)1