You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mrql.apache.org by fe...@apache.org on 2013/05/04 00:38:07 UTC
git commit: MRQL-8: Overload projections to work on JSON data
Updated Branches:
refs/heads/master 33c9361b4 -> 71a77cdfe
MRQL-8: Overload projections to work on JSON data
Project: http://git-wip-us.apache.org/repos/asf/incubator-mrql/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mrql/commit/71a77cdf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mrql/tree/71a77cdf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mrql/diff/71a77cdf
Branch: refs/heads/master
Commit: 71a77cdfe0ca4d701b827686a516a5dfb9dae5da
Parents: 33c9361
Author: fegaras <fe...@cse.uta.edu>
Authored: Fri May 3 17:37:06 2013 -0500
Committer: fegaras <fe...@cse.uta.edu>
Committed: Fri May 3 17:37:06 2013 -0500
----------------------------------------------------------------------
src/PlanGeneration.gen | 55 +++++++++++++++++++++++++++++++++-------
src/TypeInference.gen | 58 ++++++++++++++++++++++++++++---------------
2 files changed, 83 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/71a77cdf/src/PlanGeneration.gen
----------------------------------------------------------------------
diff --git a/src/PlanGeneration.gen b/src/PlanGeneration.gen
index fd2ff5c..daa4fb2 100644
--- a/src/PlanGeneration.gen
+++ b/src/PlanGeneration.gen
@@ -345,14 +345,9 @@ final public class PlanGeneration extends AlgebraicOptimization {
match tp {
case XML:
return makePlan(#<call(XMLchildren,`(new StringLeaf(a.toString())),`x)>);
- case persistent(XML):
- return makePlan(#<call(XMLchildren,`(new StringLeaf(a.toString())),`x)>);
case `S(XML):
if (is_collection(S))
return makePlan(#<call(XMLchildren,`(new StringLeaf(a.toString())),`x)>);
- case `S(persistent(XML)):
- if (is_collection(S))
- return makePlan(#<call(XMLchildren,`(new StringLeaf(a.toString())),`x)>);
};
match TypeInference.expand(tp) {
case record(...bl):
@@ -365,11 +360,6 @@ final public class PlanGeneration extends AlgebraicOptimization {
else fail
case _: i++;
};
- case `T(tuple(string,`tv)):
- if (is_collection(T))
- return #<map_index(`(makePlan(x)),
- `(new StringLeaf(a.toString())))>;
- else fail
case union(...tl):
for ( Tree t: tl )
match TypeInference.expand(t) {
@@ -388,6 +378,51 @@ final public class PlanGeneration extends AlgebraicOptimization {
`(new StringLeaf(a.toString())))>;
case `tt: error("wrong projection: "+e+" ("+tt+")");
};
+ case `S(`ttp):
+ if (!is_collection(S))
+ fail;
+ match TypeInference.expand(ttp) {
+ case tuple(string,`tv):
+ return #<map_index(`(makePlan(x)),
+ `(new StringLeaf(a.toString())))>;
+ case record(...bl):
+ Tree nv = new_var();
+ int i = 0;
+ for ( Tree b: bl )
+ match b {
+ case bind(`c,_):
+ if (a.equals(c))
+ return makePlan(#<cmap(lambda(`nv,nth(`nv,`i)),`x)>);
+ else fail
+ case _: i++;
+ };
+ case union(...tl):
+ Tree nv = new_var();
+ int j = 0;
+ for ( Tree t: tl ) {
+ match t {
+ case `c(record(...bl)):
+ int i = 0;
+ for ( Tree b: bl )
+ match b {
+ case bind(`w,_):
+ if (a.equals(w))
+ return makePlan(#<cmap(lambda(`nv,if(call(eq,union_tag(`nv),`j),
+ bag(nth(union_value(`nv),`i)),
+ bag())),`x)>);
+ else fail
+ case _: i++;
+ };
+ case `c(bag(tuple(string,`tv))):
+ return makePlan(#<cmap(lambda(`nv,if(call(eq,union_tag(`nv),`j),
+ bag(map_index(union_value(`nv),
+ `(new StringLeaf(a.toString())))),
+ bag())),`x)>);
+ case `tt: error("wrong projection: "+e+" ("+tt+")");
+ };
+ j++;
+ }
+ };
case `t: error("wrong projection: "+e+" ("+t+")");
};
case typed(`x,`tp):
http://git-wip-us.apache.org/repos/asf/incubator-mrql/blob/71a77cdf/src/TypeInference.gen
----------------------------------------------------------------------
diff --git a/src/TypeInference.gen b/src/TypeInference.gen
index cdf2b1c..d780df2 100644
--- a/src/TypeInference.gen
+++ b/src/TypeInference.gen
@@ -654,17 +654,11 @@ public class TypeInference extends Translator {
match ta {
case XML:
return #<list(XML)>;
- case persistent(XML):
- return #<List(XML)>;
case `S(XML):
if (is_collection(S))
return #<`S(XML)>;
- case `S(persistent(XML)):
- if (is_collection(S))
- return #<`S(persistent(XML))>;
};
- ta = expand(ta);
- match ta {
+ match expand(ta) {
case record(...ts):
for ( Tree t: ts )
match t {
@@ -673,19 +667,6 @@ public class TypeInference extends Translator {
return tp;
};
type_error(e,"Record "+print_query(a)+" does not have a component "+v);
- case `S(record(...ts)):
- if (!is_collection(S))
- fail;
- for ( Tree t: ts )
- match t {
- case bind(`w,`tp):
- if (equal_types(w,v))
- return #<`S(`tp)>;
- };
- type_error(e,"The record collection "+print_query(a)
- +" does not have a component "+v);
- case bag(tuple(string,`tv)):
- return tv;
case union(...tl):
Trees s = #[];
for ( Tree t: tl )
@@ -707,6 +688,43 @@ public class TypeInference extends Translator {
type_error(e,"Ambiguous record projection "+print_query(e)
+ " over the union "+print_type(ta));
return s.head();
+ case `S(`ttp):
+ if (!is_collection(S))
+ fail;
+ match expand(ttp) {
+ case record(...ts):
+ for ( Tree t: ts )
+ match t {
+ case bind(`w,`tp):
+ if (equal_types(w,v))
+ return #<`S(`tp)>;
+ };
+ type_error(e,"The record collection "+print_query(a)
+ +" does not have a component "+v);
+ case tuple(string,`tv):
+ return tv;
+ case union(...tl):
+ Trees s = #[];
+ for ( Tree t: tl )
+ match t {
+ case `c(record(...ts)):
+ for ( Tree tn: ts )
+ match tn {
+ case bind(`w,`tp):
+ if (equal_types(w,v))
+ s = s.append(tp);
+ };
+ case `c(bag(tuple(string,`tv))):
+ s = s.append(tv);
+ };
+ if (s.length() == 0)
+ type_error(e,"Wrong record projection "+print_query(e)
+ + " over the union "+print_type(ta));
+ else if (s.length() > 1)
+ type_error(e,"Ambiguous record projection "+print_query(e)
+ + " over the union "+print_type(ta));
+ return #<`S(...s)>;
+ };
case `t:
type_error(e,"The record projection "+print_query(e)
+ " cannot apply to the type "+print_type(t));