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

parameterized query composition enhancement for Fred

Also the next to last version of sigma chase
parent bcab9f00
Loading
Loading
Loading
Loading
+102 −1
Changes for resources/examples/aql/Outer Join.aql: 102 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@

/*
This is not an outer join per se (it returns A*B rows, rather than A+B rows, 
when A and B don't join at all), but is similar in spirit. 
when A and B don't join at all), but is similar in spirit.  The pedantic version follows.
*/

typeside Ty = literal {
@@ -64,3 +64,104 @@ instance I = literal : S {
} 

instance J = eval OuterJoin I

////////////////////////////////////////////////////////////////////////////////////////

schema Sx = literal : sql {
	entities
		Left Right Middle
	foreign_keys
		f: Left -> Middle g: Right -> Middle
	attributes
		attL: Left -> Varchar
		attR: Right -> Varchar
		attM: Middle -> Varchar
} 

instance Ix = literal : Sx {
	generators
		l1 l2 l3 l4: Left
		r1 r2: Right
		m1: Middle
	equations
		l1.f=l2.f l2.f=r1.g l3.f=r2.g
		l1.attL="Bob" l1.f.attM="5"
		l2.attL="Carl" l3.attL="Alice" 
		l3.f.attM="10" r1.attR="Happy"
		r2.attR="Sad" m1.attM="7"
		l4.attL="Dave" l4.f.attM="6"
} 

//Let's do a left outer join

//Step 1: query, remembering the join and the Left

//Step 1a: make the appropriate schema

schema Helper = literal : sql {
	entities
		Joiner Left
	foreign_keys
		h: Joiner->Left
	attributes
		attL: Left->Varchar
		attR: Joiner-> Varchar
		attM: Joiner -> Varchar
} 

//Step 1b: query it

query findJoin = literal : Sx -> Helper {
 entity
  Joiner -> {
  	from l:Left r:Right 
	where 
		l.f=r.g 
	attributes
		attM -> l.f.attM
		attR -> r.attR 
	foreign_keys
		h -> {l -> l } 
  }
 entity
  Left -> {
	from l:Left
	attributes attL->l.attL
  }
  }

//Step 2: add it all up

//Step 2a: make the landing schema

schema Landing = literal : sql {
	entities
		Result
	attributes
		attL: Result->Varchar
		attM: Result->Varchar
		attR: Result->Varchar
} 

//Step 2b: make a mapping from helper to landing

mapping AddItUp = literal : Helper -> Landing {
	entity
		Joiner -> Result
	foreign_keys
		h -> Result
	attributes
		attM -> attM
		attR -> attR
	entity
		Left -> Result
	attributes
		attL -> attL

}

//Step 3: run

instance Joined = eval findJoin Ix

instance OuterJoinx = sigma AddItUp Joined
+1 −1
Changes for src/catdata/Ctx.java: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ public final class Ctx<K,V> implements Serializable {
		}
		V ret = map.get(k);
		if (ret == null) {
			throw new RuntimeException("Encountered " + k + " but was expecting one of " + map.keySet() );
			throw new RuntimeException("Attempt to lookup " + k + " failed; is not present in " + map.keySet() );
		}
		return ret;
	}
+6 −4
Changes for src/catdata/aql/Algebra.java: 6 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -34,13 +34,15 @@ public abstract class Algebra<Ty,En,Sym,Fk,Att,Gen,Sk,X,Y> /* implements DP<Ty,E
	
	//TODO aql cant validate algebras bc are not dps
	
	public boolean hasFreeTypeAlgebra() {
	 public abstract boolean hasFreeTypeAlgebra();
	 
	 /*{
		return talg().eqs.isEmpty();
	}
	} */
	
	public boolean hasFreeTypeAlgebraOnJava() {
	public abstract boolean hasFreeTypeAlgebraOnJava(); /* {
		return talg().eqs.stream().filter(x -> talg().java_tys.containsKey(talg().type(x.ctx, x.lhs).l)).collect(Collectors.toList()).isEmpty();
	}
	} */
	
	/**
	 * The Xs need be to be unique across ens, so that repr can invert.  Is it worth checking this? TODO aql
+8 −0
Changes for src/catdata/aql/Anonymized.java: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -82,6 +82,14 @@ public class Anonymized<Ty, En, Sym, Fk, Att, Gen, Sk, X, Y> extends Instance<Ty
			return col;
		}
		
		public boolean hasFreeTypeAlgebra() {
			return talg().eqs.isEmpty();
		}
		
		public boolean hasFreeTypeAlgebraOnJava() {
			return talg().eqs.stream().filter(x -> talg().java_tys.containsKey(talg().type(x.ctx, x.lhs).l)).collect(Collectors.toList()).isEmpty();
		}

		@Override
		public Term<Ty, En, Sym, Fk, Att, Gen, Sk> reprT_protected(Term<Ty, Void, Sym, Void, Void, Void, Y> y) {
			return iso1(I.algebra().reprT_protected(iso2(y.convert()).convert())).convert();
+2 −1
Changes for src/catdata/aql/AqlProver.java: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ public class AqlProver {
	//x = y and y = z -> x = z when java is involved.  
	public static <Ty, En, Sym, Fk, Att, Gen, Sk> DP<Ty, En, Sym, Fk, Att, Gen, Sk> create(AqlOptions ops, Collage<Ty, En, Sym, Fk, Att, Gen, Sk> col1, AqlJs<Ty, Sym> js) {
		ProverName name = (ProverName) ops.getOrDefault(AqlOption.prover);
		long timeout = (Long) ops.getOrDefault(AqlOption.timeout);
		
		if (name.equals(ProverName.auto)) {
			name = auto(ops, col1.simplify().first);
@@ -66,7 +67,7 @@ public class AqlProver {
			case maedmax:
				String exePath = (String) ops.getOrDefault(AqlOption.maedmax_path);
				Boolean b = (Boolean) ops.getOrDefault(AqlOption.maedmax_allow_empty_sorts_unsafe);
				return new KBtoDP<>(js, col1.simplify().second, new MaedmaxProver<>(exePath, col1.simplify().first.toKB(), b)); // use																																																		
				return new KBtoDP<>(js, col1.simplify().second, new MaedmaxProver<>(exePath, col1.simplify().first.toKB(), b, timeout)); // use																																																		
				
			default:
				throw new RuntimeException("Anomaly: please report");
Loading