Skip to content

Commit

Permalink
update on java maven project
Browse files Browse the repository at this point in the history
  • Loading branch information
clarknerd committed Feb 23, 2017
1 parent b5fbdec commit 73eb0fd
Show file tree
Hide file tree
Showing 24 changed files with 2,544 additions and 239 deletions.
102 changes: 102 additions & 0 deletions SQLFeatureExtraction/data/ub_Aligon.csv

Large diffs are not rendered by default.

102 changes: 102 additions & 0 deletions SQLFeatureExtraction/data/ub_Aouiche.csv

Large diffs are not rendered by default.

102 changes: 102 additions & 0 deletions SQLFeatureExtraction/data/ub_Makiyama.csv

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public class CombinedRegularizer {
* @param input
*/
public static SelectBody regularize(SelectBody body){
body=PredicateNestingCoalescer.predicateNestingCoalesceSelectBody(body);
body=PredicateNestingCoalescer.predicateNestingCoalesceSelectBody(body, true);
body=FROMNestingCoalescer.FromNestingCoalesceSelectBody(body);
body=UNIONPULLer.UnionPullUpFromSelectBody(body, true);
return body;
body=UNIONPULLer.UnionPullUpFromSelectBody(body, true);
return body;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,12 @@ private static SelectBody FromNestingCoalescePlainSelect(PlainSelect ps){

if(from instanceof SubSelect){
SubSelect sub=(SubSelect) from;
//check whether it is an aggregation

boolean pass=true;
SelectBody body=sub.getSelectBody();
if(body instanceof PlainSelect){
PlainSelect pps=(PlainSelect) body;
//check whether it is an aggregation
if(QueryToolBox.ifContainAggregate(pps)){
//if this query has only this sub-select as FromItem
//we can safely merge
Expand All @@ -174,8 +175,8 @@ private static SelectBody FromNestingCoalescePlainSelect(PlainSelect ps){
}
}
else{
//we cannot coalece UNION directly, need to pull up UNION first
System.out.println("error, UNION should not happen in FromNesting step, need to be pulled up first! "+ps);
//TODO
System.out.println("UNION happens in FromNesting step, should be pulled up first! "+ps);
pass=false;
Union u=(Union) body;
@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -245,8 +246,8 @@ private static SelectBody FromNestingCoalescePlainSelect(PlainSelect ps){
}
}
else{
//we cannot coalece UNION directly, need to pull up UNION first
System.out.println("error, UNION should not happen in FromNesting step, need to be pulled up first! "+ps);
//TODO
System.out.println("UNION happens in FromNesting step, should be pulled up first! "+ps);
pass=false;
Union u=(Union) body;
@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

import com.google.common.collect.HashMultiset;

import net.sf.jsqlparser.expression.AllComparisonExpression;
import net.sf.jsqlparser.expression.AnyComparisonExpression;
import net.sf.jsqlparser.expression.BinaryExpression;
Expand Down Expand Up @@ -948,16 +949,16 @@ public void registerColumn(Column c){
Table t=c.getTable();
if(t!=null&&t.getName()!=null&&c.getColumnName()!=null){
//register table-col map
HashSet<String> columnset=SelectNamingResolver.schemaMap.get(t.getName());
HashMultiset<String> columnset=SelectNamingResolver.schemaMap.get(t.getName());
if(columnset==null){
columnset=new HashSet<String>();
columnset=HashMultiset.create();
SelectNamingResolver.schemaMap.put(t.getName(), columnset);
}
columnset.add(c.getColumnName());
//register col-table map
HashSet<String> tableset=SelectNamingResolver.antiSchemaMap.get(c.getColumnName());
HashMultiset<String> tableset=SelectNamingResolver.antiSchemaMap.get(c.getColumnName());
if(tableset==null){
tableset=new HashSet<String>();
tableset=HashMultiset.create();
SelectNamingResolver.antiSchemaMap.put(c.getColumnName(), tableset);
}
tableset.add(t.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ public class PredicateNestingCoalescer {
private static final Column c = new Column(new Table(), "Multiplicity");
private static final BooleanLiteral minusMark = new BooleanLiteral(new FixedOrderExpression(new EqualsTo(c, new LongValue(-1))));

public static SelectBody predicateNestingCoalesceSelectBody(SelectBody body) {
public static SelectBody predicateNestingCoalesceSelectBody(SelectBody body, boolean ignoreAggregate) {
//need to do DNFUNION Transformer first
body=DNFUNIONTransformer.UnionTransformSelectBody(body);
// System.out.println("after DNFUnionTransform: "+body);
if (body instanceof PlainSelect)
return predicateNestingCoalescePlainSelect((PlainSelect) body);
return predicateNestingCoalescePlainSelect((PlainSelect) body, true);
else {
Union u = (Union) body;
@SuppressWarnings("unchecked")
List<PlainSelect> plist = u.getPlainSelects();
List<PlainSelect> newplist = new ArrayList<PlainSelect>();
for (PlainSelect ps : plist) {
SelectBody b = predicateNestingCoalescePlainSelect(ps);
SelectBody b = predicateNestingCoalescePlainSelect(ps, true);
if (b instanceof PlainSelect)
newplist.add((PlainSelect) b);
else {
Expand All @@ -79,7 +79,7 @@ public static SelectBody predicateNestingCoalesceSelectBody(SelectBody body) {
}
}

private static SelectBody predicateNestingCoalescePlainSelect(PlainSelect ps) {
private static SelectBody predicateNestingCoalescePlainSelect(PlainSelect ps, boolean ignoreAggregate) {
// ignore having
// search through where clause since this query has already been DNF
// normalized
Expand All @@ -104,22 +104,30 @@ private static SelectBody predicateNestingCoalescePlainSelect(PlainSelect ps) {
// remove this literal first
it.remove();
//regularize exists first
sub.setSelectBody(predicateNestingCoalesceSelectBody(sub.getSelectBody()));
sub.setSelectBody(predicateNestingCoalesceSelectBody(sub.getSelectBody(), true));
//check if the sub-select body contains aggregation or not
SelectBody body=sub.getSelectBody();
boolean pass=true;
if(body instanceof PlainSelect){
PlainSelect pps=(PlainSelect) body;
if(QueryToolBox.ifContainAggregate(pps))
if(QueryToolBox.ifContainAggregate(pps)){
if(ignoreAggregate)
pass=true;
else
pass=false;
}
}
else{
Union u=(Union) body;
@SuppressWarnings("unchecked")
List<PlainSelect> plist=u.getPlainSelects();
for(PlainSelect pps: plist){
if(QueryToolBox.ifContainAggregate(pps)){
if(ignoreAggregate)
pass=true;
else
pass=false;

break;
}
}
Expand All @@ -136,7 +144,7 @@ private static SelectBody predicateNestingCoalescePlainSelect(PlainSelect ps) {
// for case of EXISTS
if (!exists.isNot()) {
//regularize host
SelectBody regularizedHost=predicateNestingCoalescePlainSelect(host);
SelectBody regularizedHost=predicateNestingCoalescePlainSelect(host, ignoreAggregate);

if(regularizedHost instanceof PlainSelect){
PlainSelect p=(PlainSelect) regularizedHost;
Expand Down Expand Up @@ -185,8 +193,8 @@ private static SelectBody predicateNestingCoalescePlainSelect(PlainSelect ps) {
else{
cfq.setWhere(exists);
}
SelectBody regularizedpfq=predicateNestingCoalescePlainSelect(pfq);
SelectBody regularizedcfq=predicateNestingCoalescePlainSelect(cfq);
SelectBody regularizedpfq=predicateNestingCoalescePlainSelect(pfq, ignoreAggregate);
SelectBody regularizedcfq=predicateNestingCoalescePlainSelect(cfq, ignoreAggregate);
//prepare result
Union u=new Union();
List<PlainSelect> plist=new ArrayList<PlainSelect>();
Expand Down Expand Up @@ -234,7 +242,7 @@ private static SelectBody predicateNestingCoalescePlainSelect(PlainSelect ps) {
host.setWhere(null);

//regularize the rest of the query besides this exists expression
SelectBody regularizedHost=predicateNestingCoalescePlainSelect(host);
SelectBody regularizedHost=predicateNestingCoalescePlainSelect(host, ignoreAggregate);
//add this exists expression back
if(regularizedHost instanceof PlainSelect){
PlainSelect pps=(PlainSelect) regularizedHost;
Expand Down Expand Up @@ -283,7 +291,7 @@ private static SelectBody predicateNestingCoalescePlainSelect(PlainSelect ps) {
private static void predicateNestingCoalesceFromItem(FromItem from){
if(from instanceof SubSelect){
SubSelect sub=(SubSelect) from;
sub.setSelectBody(predicateNestingCoalesceSelectBody(sub.getSelectBody()));
sub.setSelectBody(predicateNestingCoalesceSelectBody(sub.getSelectBody(), true));
}
else if(from instanceof SubJoin){
SubJoin sub=(SubJoin) from;
Expand Down Expand Up @@ -353,7 +361,7 @@ private static ExistsExpression convertExistsFromBooleanLiteral(BooleanLiteral l
//do predicate nesting coalesce to the exists
SubSelect sub=(SubSelect) exist.getRightExpression();
SelectBody body=sub.getSelectBody();
sub.setSelectBody(PredicateNestingCoalescer.predicateNestingCoalesceSelectBody(body));
sub.setSelectBody(PredicateNestingCoalescer.predicateNestingCoalesceSelectBody(body, true));
return exist;
}
else if (exp instanceof InExpression){
Expand Down Expand Up @@ -463,14 +471,14 @@ private static ExistsExpression createExistsFromBinary(BinaryExpression bexp) {

if (right instanceof AllComparisonExpression) {
SubSelect sub = ((AllComparisonExpression) right).getSubSelect();
SelectBody body=PredicateNestingCoalescer.predicateNestingCoalesceSelectBody(sub.getSelectBody());
SelectBody body=PredicateNestingCoalescer.predicateNestingCoalesceSelectBody(sub.getSelectBody(), true);
adjustSelectBodyConsiderNotExists(body,bexp);
sub.setSelectBody(body);
exists.setNot(true);
exists.setRightExpression(sub);
} else if (right instanceof AnyComparisonExpression) {
SubSelect sub = ((AnyComparisonExpression) right).getSubSelect();
SelectBody body=PredicateNestingCoalescer.predicateNestingCoalesceSelectBody(sub.getSelectBody());
SelectBody body=PredicateNestingCoalescer.predicateNestingCoalesceSelectBody(sub.getSelectBody(), true);
adjustSelectBodyConsiderExists(body,bexp);
sub.setSelectBody(body);
exists.setNot(false);
Expand All @@ -479,7 +487,7 @@ private static ExistsExpression createExistsFromBinary(BinaryExpression bexp) {
// treated exactly as ANY comparison
else if (right instanceof SubSelect) {
SubSelect sub = (SubSelect) right;
SelectBody body=PredicateNestingCoalescer.predicateNestingCoalesceSelectBody(sub.getSelectBody());
SelectBody body=PredicateNestingCoalescer.predicateNestingCoalesceSelectBody(sub.getSelectBody(), true);
adjustSelectBodyConsiderExists(body,bexp);
sub.setSelectBody(body);
exists.setNot(false);
Expand Down
Loading

0 comments on commit 73eb0fd

Please sign in to comment.