Commit ec0aeeb1 authored by Ryan Wisnesky's avatar Ryan Wisnesky
Browse files

tweak to quotients

parent 3db29760
......@@ -510,6 +510,9 @@ as equations for performing the quotient.
\subsection{{\tt options}}
Allowed are {\tt timeout}, {\tt prover} and related options, {\tt always\_reload}, and {\tt require\_consistency}.
By default uses a chase-based algorithm; to disabled, set {\tt quotient\_use\_chase = false}
\section{{\tt import\_jdbc\_all [jdbcclass] [jdbcuri]}}
Imports a SQL database onto an autogenerated AQL schema. The AQL schema will have one attribute per column in the input DB, and one foreign key per foreign key in the input DB, and equations capturing the input DB's foreign key constraints. The type side will have a single type, ``dom''. When the [jdbcclass] and [jdbcuri] are the empty string, their values will be determined by the {\tt jdbc\_default\_class} and {\tt jdbc\_default\_string} options. See also option {\tt import\_col\_seperator}.
......@@ -1086,6 +1089,10 @@ Defines the SQL quasi-type to be used with CONVERT statements when emitting SQL
Either {\tt parallel} (faster, but uses more space) or {\tt leftkan} (slower, but uses less space). Note that parallel will not be compatible with sigma operations such as sigma on transforms, the co-unit, etc. Parallel is recommended only when data volume is too large for the other algorithms.
\subsection{{\tt quotient\_use\_chase}}
In doing instance quotients, determines whether or not to use chase-based algorithm.
\end{document}
......
......@@ -24,3 +24,10 @@ instance I = literal : S {
instance J = quotient_query I {
entity Element -> {from a:Element b:Element where a.num1 = b.num2}
}
instance J2 = quotient_query I {
entity Element -> {from a:Element b:Element where a.num1 = b.num2}
options
quotient_use_chase = false
}
......@@ -42,6 +42,7 @@ public final class AqlOptions {
//TODO: aql each typeside/instance/etc should make sure only appropriate options are given to it
public enum AqlOption {
quotient_use_chase,
chase_style,
maedmax_allow_empty_sorts_unsafe,
maedmax_path,
......@@ -124,7 +125,7 @@ public final class AqlOptions {
return false;
}
throw new RuntimeException("In " + map + ", neither true nor false: " + s);
}
}
/*
public String getMaybeString(Map<String, String> map) {
if (map.containsKey(this.toString())) {
......@@ -203,7 +204,8 @@ public final class AqlOptions {
//@SuppressWarnings("static-method")
private static Object getDefault(AqlOption option) {
switch (option) {
case quotient_use_chase:
return true;
case jdbc_no_distinct_unsafe:
return false;
case jdbc_export_truncate_after:
......@@ -382,6 +384,8 @@ public final class AqlOptions {
private static Object getFromMap(Map<String, String> map, Collage<Ty, En, Sym, Fk, Att, Gen, Sk> col, AqlOption op) {
switch (op) {
case quotient_use_chase:
return op.getBoolean(map);
case jdbc_query_export_convert_type:
return op.getString(map);
case jdbc_no_distinct_unsafe:
......
......@@ -5,6 +5,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiFunction;
......@@ -339,10 +340,14 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
private Instance<Ty, En1, Sym, Fk1, Att1, Gen, Sk, X, Y> I;
private Map<En1, Set<Pair<X,X>>> extra;
public Chase(Mapping<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2> F,
Instance<Ty, En1, Sym, Fk1, Att1, Gen, Sk, X, Y> I) {
Instance<Ty, En1, Sym, Fk1, Att1, Gen, Sk, X, Y> I,
Map<En1, Set<Pair<X,X>>> extra) {
this.F = F;
this.I = I;
this.extra = extra;
int i = 0;
T = new Content(I);
......@@ -384,6 +389,8 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
//}
doEqs(toAdd, ufs, ufs2, changed);
doExtra(toAdd, ufs, changed);
T.addAll(toAdd);
// System.out.println("E " + changed[0]);
......@@ -573,6 +580,21 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
return Util.anomaly();
}
public void doExtra(Content toAdd, Ctx<En2, UnionFind<Lineage<Void, En2, Void, Fk2, Void, Gen, Void>>> ufs,
Boolean[] changed) {
for (En1 en1 : extra.keySet()) {
for (Pair<X, X> x : extra.get(en1)) {
Lineage<Void, En2, Void, Fk2, Void, Gen, Void> a = T.us.get(en1).get(x.first);
Lineage<Void, En2, Void, Fk2, Void, Gen, Void> b = T.us.get(en1).get(x.second);
En2 en2 = F.ens.get(en1);
if (!a.equals(b)) {
changed[0] = true;
ufs.get(en2).union(a, b);
}
}
}
}
public void targetEqs(Content toAdd, Ctx<En2, UnionFind<Lineage<Void, En2, Void, Fk2, Void, Gen, Void>>> ufs,
Boolean[] changed) {
for (Triple<Pair<Var, En2>, Term<Ty, En2, Sym, Fk2, Att2, Void, Void>, Term<Ty, En2, Sym, Fk2, Att2, Void, Void>> eq : F.dst.eqs) {
......@@ -722,7 +744,7 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
public void moveObjects(Content toAdd, Boolean[] changed) {
// a : a -> F(a)
System.out.println("started");
//System.out.println("started");
for (En1 a : F.src.ens) {
// T_v(x) -> Ey. T_a(x,y)
// this is the 'loading' step in the Content constructor
......@@ -739,7 +761,7 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
}
}
}
System.out.println("started2");
//System.out.println("started2");
for (Ty a : F.src.typeSide.tys) {
// T_v(x) -> Ey. T_a(x,y) // this is the 'loading' step in the Content
......
......@@ -21,8 +21,8 @@ import catdata.graph.DAG;
public final class Schema<Ty, En, Sym, Fk, Att> implements Semantics {
public Schema<Ty, En, Sym, Void, Void> discretize() {
Schema<Ty, En, Sym, Fk, Att> x = new Schema<Ty, En, Sym, Fk, Att>(typeSide, ens, new HashMap<>(), new HashMap<>(), new HashSet<>(), dp, false);
public Schema<Ty, En, Sym, Void, Void> discretize(Set<En> ensX) {
Schema<Ty, En, Sym, Fk, Att> x = new Schema<Ty, En, Sym, Fk, Att>(typeSide, ensX, new HashMap<>(), new HashMap<>(), new HashSet<>(), dp, false);
return (Schema<Ty, En, Sym, Void, Void>) x;
}
......
......@@ -1344,7 +1344,7 @@ public abstract class InstExp<Ty, En, Sym, Fk, Att, Gen, Sk, X, Y>
(Boolean) op.getOrDefault(AqlOption.allow_java_eqs_unsafe));
} else if (type.equals("parallel")) {
SigmaChaseAlgebra<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> alg = new SigmaChaseAlgebra<>(
f, i);
f, i, new HashMap<>());
return new SaturatedInstance(alg, alg,
(Boolean) op.getOrDefault(AqlOption.require_consistency),
......
package catdata.aql.exp;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
......@@ -22,6 +23,7 @@ import catdata.aql.Instance;
import catdata.aql.It;
import catdata.aql.It.ID;
import catdata.aql.Kind;
import catdata.aql.Mapping;
import catdata.aql.Query;
import catdata.aql.RawTerm;
import catdata.aql.Schema;
......@@ -49,6 +51,8 @@ import catdata.aql.fdm.EvalAlgebra.Row;
import catdata.aql.fdm.EvalInstance;
import catdata.aql.fdm.InitialAlgebra;
import catdata.aql.fdm.LiteralInstance;
import catdata.aql.fdm.SaturatedInstance;
import catdata.aql.fdm.SigmaChaseAlgebra;
public class InstExpQueryQuotient<X, Y>
extends InstExp<Ty,En,Sym,Fk,Att,Gen,Sk,ID,Chc<Sk, Pair<ID, Att>>> implements Raw {
......@@ -115,7 +119,11 @@ extends InstExp<Ty,En,Sym,Fk,Att,Gen,Sk,ID,Chc<Sk, Pair<ID, Att>>> implements R
@Override
public Instance<Ty, En, Sym, Fk, Att, Gen, Sk, ID, Chc<Sk, Pair<ID, Att>>> eval(AqlEnv env) {
Instance<Ty, En, Sym, Fk, Att, Gen, Sk, X, Y> I0 = I.eval(env);
Schema<Ty, En, Sym, Void, Void> dst = I0.schema().discretize();
Set<En> ensX = new HashSet<>();
for (Block b : queries) {
ensX.add(b.en);
}
Schema<Ty, En, Sym, Void, Void> dst = I0.schema().discretize(ensX);
Ctx<En, Triple<Ctx<Var, En>, Collection<Eq<Ty, En, Sym, Fk, Att, Var, Var>>, AqlOptions>> ens = new Ctx<>();
Ctx<En, Collage<Ty, En, Sym, Fk, Att, Var, Var>> cols = new Ctx<>();
......@@ -129,6 +137,42 @@ extends InstExp<Ty,En,Sym,Fk,Att,Gen,Sk,ID,Chc<Sk, Pair<ID, Att>>> implements R
EvalInstance<Ty, En, Sym, Fk, Att, Gen, Sk, En, Void, Void, X, Y> J = new EvalInstance<>(q, I.eval(env), new AqlOptions(options, null, env.defaults));
AqlOptions op = new AqlOptions(options, null, env.defaults);
boolean useChase = (boolean) op.getOrDefault(AqlOption.quotient_use_chase);
if (useChase) {
Map<En, Set<Pair<X, X>>> mm = new HashMap<>();
for (Row<En, X> p : J.gens().keySet()) {
Map<Var, X> m = p.asMap();
List<Var> vs = new LinkedList<>(m.keySet());
Var v1 = vs.get(0);
Var v2 = vs.get(1);
X x1 = p.get(v1);
X x2 = p.get(v2);
En en = J.gens().get(p);
if (!mm.containsKey(en)) {
mm.put(en, new HashSet<>());
}
mm.get(en).add(new Pair<>(x1, x2));
}
SigmaChaseAlgebra<Ty, En, Sym, Fk, Att, En, Fk, Att, Gen, Sk, X, Y> alg = new SigmaChaseAlgebra<>(
Mapping.id(I0.schema()), I0, mm);
return new SaturatedInstance(alg, alg,
(Boolean) op.getOrDefault(AqlOption.require_consistency),
(Boolean) op.getOrDefault(AqlOption.allow_java_eqs_unsafe), false, null);
} else {
return evalProver(env, I0, J);
}
}
private Instance<Ty, En, Sym, Fk, Att, Gen, Sk, ID, Chc<Sk, Pair<ID, Att>>> evalProver(AqlEnv env,
Instance<Ty, En, Sym, Fk, Att, Gen, Sk, X, Y> I0,
EvalInstance<Ty, En, Sym, Fk, Att, Gen, Sk, En, Void, Void, X, Y> J) {
Collage<Ty, En, Sym, Fk, Att, Gen, Sk> col = new Collage<>(I0.collage());
Set<Pair<Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Term<Ty, En, Sym, Fk, Att, Gen, Sk>>>
......@@ -152,8 +196,7 @@ extends InstExp<Ty,En,Sym,Fk,Att,Gen,Sk,ID,Chc<Sk, Pair<ID, Att>>> implements R
InitialAlgebra<Ty, En, Sym, Fk, Att, Gen, Sk, ID> initial0 = new InitialAlgebra<>(strat, I0.schema(), col, new It(), Object::toString, Object::toString);
return new LiteralInstance<>(I0.schema(), col.gens.map, col.sks.map, eqs0, initial0.dp(), initial0, (Boolean) strat.getOrDefault(AqlOption.require_consistency), (Boolean) strat.getOrDefault(AqlOption.allow_java_eqs_unsafe));
return new LiteralInstance<>(I0.schema(), col.gens.map, col.sks.map, eqs0, initial0.dp(), initial0, (Boolean) strat.getOrDefault(AqlOption.require_consistency), (Boolean) strat.getOrDefault(AqlOption.allow_java_eqs_unsafe));
}
private String toString;
......
package catdata.aql.fdm;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import catdata.Chc;
......@@ -16,7 +14,6 @@ import catdata.aql.Algebra;
import catdata.aql.Chase;
import catdata.aql.Collage;
import catdata.aql.DP;
import catdata.aql.Head;
import catdata.aql.Instance;
import catdata.aql.Lineage;
import catdata.aql.Mapping;
......@@ -40,7 +37,7 @@ public class SigmaChaseAlgebra<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk,
// private Collage<Ty, Void, Sym, Void, Void, Void, Chc<Sk, Pair<Lineage<Void, En2, Void, Fk2, Void, Gen, Void>, Att2>>> talg;
public SigmaChaseAlgebra(Mapping<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2> f2,
Instance<Ty, En1, Sym, Fk1, Att1, Gen, Sk, X, Y> i2 /*, Collage<Ty, En2, Sym, Fk2, Att2, Gen, Sk> col */ ) {
Instance<Ty, En1, Sym, Fk1, Att1, Gen, Sk, X, Y> i2 /*, Collage<Ty, En2, Sym, Fk2, Att2, Gen, Sk> col */ , Map<En1, Set<Pair<X, X>>> e ) {
A = f2.src;
B = f2.dst;
F = f2;
......@@ -55,7 +52,8 @@ public class SigmaChaseAlgebra<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk,
}
chase = new Chase<Ty,En1,Sym,Fk1,Att1,En2,Fk2,Att2,Gen,Sk,X,Y>(F, X);
chase = new Chase<Ty,En1,Sym,Fk1,Att1,En2,Fk2,Att2,Gen,Sk,X,Y>(F, X, e);
for (En2 en2 : B.ens) {
Collection<Lineage<Void, En2, Void, Fk2, Void, Gen, Void>> s = chase.T.ens.get(en2).keySet();
......
......@@ -92,6 +92,7 @@
<keyword>quotient</keyword>
<keyword>quotient_jdbc</keyword>
<keyword>quotient_csv</keyword>
<keyword>quotient_query</keyword>
<keyword>random</keyword>
<keyword>remove</keyword>
<keyword>rename</keyword>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment