Commits

Kirill Simonov committed 740fdd1

Fixes to nested segments, added tests.

  • Participants
  • Parent commits 6924f94

Comments (0)

Files changed (13)

File src/htsql/core/tr/compile.py

     adapt(SegmentCode)
 
     def __call__(self):
+        if not self.state.superflow.spans(self.expression.root):
+            raise CompileError("a singular expression is expected",
+                               self.expression.root.mark)
+        chain = self.state.superflow_stack + \
+                [self.state.superflow, self.expression.root,
+                 self.expression.flow]
         # Get the ordering of the segment flow.  We must respect the ordering
         # of the parent segment.
-        order = arrange(self.state.superflow) + arrange(self.expression.flow)
+        order = []
+        for flow in chain:
+            order.extend(arrange(flow))
         # List of expressions we need the term to export.
         codes = ([self.expression.code] +
                  [code for code, direction in order])
+        idx = 0
+        while idx+1 < len(chain):
+            parent_flow = chain[idx]
+            child_flow = chain[idx+1]
+            is_native = False
+            while child_flow is not None:
+                if parent_flow.dominates(child_flow):
+                    is_native = True
+                    break
+                child_flow = child_flow.base
+            if is_native:
+                del chain[idx]
+            else:
+                idx += 1
         # Construct a term corresponding to the segment flow.
-        is_native = False
-        segment_flow = self.expression.flow
-        while segment_flow is not None:
-            if self.state.superflow.dominates(segment_flow):
-                is_native = True
-                break
-            segment_flow = segment_flow.base
-        if is_native:
-            kid = self.state.compile(self.expression.flow)
-        else:
-            trunk_term = self.state.compile(self.state.superflow,
-                                            baseline=self.state.root)
-            shoot_term = self.compile_shoot(self.expression.flow, trunk_term)
+        trunk_term = self.state.compile(chain[0], baseline=self.state.root)
+        for flow in chain[1:]:
+            shoot_term = self.compile_shoot(flow, trunk_term)
             joints = self.glue_terms(trunk_term, shoot_term)
             trunk_term = self.inject_joints(trunk_term, joints)
             routes = {}
             routes.update(trunk_term.routes)
             routes.update(shoot_term.routes)
-            kid = JoinTerm(self.state.tag(), trunk_term, shoot_term,
-                           joints, False, False,
-                           shoot_term.flow, self.state.root, routes)
+            trunk_term = JoinTerm(self.state.tag(), trunk_term, shoot_term,
+                                  joints, False, False,
+                                  shoot_term.flow, self.state.root, routes)
+        kid = trunk_term
         # Inject the expressions into the term.
         kid = self.state.inject(kid, codes)
         # The compiler does not guarantee that the produced term respects
         for segment in self.expression.code.segments:
             if segment in subtrees:
                 continue
+            self.state.push_superflow(self.expression.root)
             self.state.push_superflow(self.expression.flow)
             term = self.state.compile(segment)
             self.state.pop_superflow()
+            self.state.pop_superflow()
             subtrees[segment] = term
         # Construct keys for segment merging.
         superkeys = [code for code, direction in arrange(self.state.superflow,

File src/htsql/core/tr/encode.py

     adapt(SegmentBinding)
 
     def __call__(self):
+        root = self.state.relate(self.binding.base)
         code = self.state.encode(self.binding.seed)
         # List of all unit expressions.
         units = code.units
             # Otherwise, `flows` contains a single maximal flow node.
             else:
                 [flow] = flows
+        if not flow.spans(root):
+            raise EncodeError("a descendant segment flow is expected",
+                              self.binding.mark)
         if coerce(code.domain) is not None:
             filter = FormulaCode(IsNullSig(-1), coerce(BooleanDomain()),
                                  code.binding, op=code)
             flow = FilteredFlow(flow, filter, flow.binding)
-        return SegmentCode(flow, code, self.binding)
+        return SegmentCode(root, flow, code, self.binding)
 
 
 class RelateRoot(Relate):
         if base.spans(seed):
             raise EncodeError("a plural expression is expected", seed.mark)
         if not seed.spans(base):
-            raise EncodeError("a valid plural expression is expected",
+            raise EncodeError("a descendant expression is expected",
                               seed.mark)
         # Encode the kernel expressions.
         kernels = [self.state.encode(binding)

File src/htsql/core/tr/flow.py

         The output flow of the segment.
     """
 
-    def __init__(self, flow, code, binding):
+    def __init__(self, root, flow, code, binding):
+        assert isinstance(root, Flow)
         assert isinstance(flow, Flow)
         assert isinstance(code, Code)
         assert isinstance(binding, SegmentBinding)
         super(SegmentCode, self).__init__(
                 domain=ListDomain(code.domain),
                 binding=binding)
+        self.root = root
         self.flow = flow
         self.code = code
 
     def __basis__(self):
-        return (self.flow, self.code)
+        return (self.root, self.flow, self.code)
 
     @property
     def segments(self):

File src/htsql/core/tr/fn/encode.py

         if flow.spans(plural_flow):
             raise EncodeError("a plural operand is expected", op.mark)
         if not plural_flow.spans(flow):
-            raise EncodeError("a valid plural operand is expected",
+            raise EncodeError("a descendant operand is expected",
                               op.mark)
         # FIXME: handled by the compiler.
         #if not all(plural_flow.spans(unit.flow)
         #           for unit in plural_units):
-        #    raise EncodeError("a valid plural operand is expected",
+        #    raise EncodeError("a descendant operand is expected",
         #                      op.mark)
         return plural_flow
 

File src/htsql/core/tr/rewrite.py

 
     def __call__(self):
         # Rewrite the output flow and output record.
+        root = self.state.rewrite(self.expression.root)
         flow = self.state.rewrite(self.expression.flow)
         code = self.state.rewrite(self.expression.code)
-        return self.expression.clone(flow=flow, code=code)
+        return self.expression.clone(root=root, flow=flow, code=code)
 
 
 class UnmaskSegment(Unmask):
         code = self.state.unmask(self.expression.code,
                                  mask=self.expression.flow)
         # Unmask the flow itself.
-        flow = self.state.unmask(self.expression.flow)
+        flow = self.state.unmask(self.expression.flow,
+                                 mask=self.expression.root)
+        root = self.state.unmask(self.expression.root)
         # Produce a clone of the segment with new flow and output columns.
-        return self.expression.clone(flow=flow, code=code)
+        return self.expression.clone(root=root, flow=flow, code=code)
 
 
 class CollectSegment(Collect):
     def __call__(self):
         # Recombine the content of the segment against a blank state.
         substate = self.state.spawn()
+        substate.collect(self.expression.root)
         substate.collect(self.expression.flow)
         substate.collect(self.expression.code)
         substate.recombine()
+        root = substate.replace(self.expression.root)
         flow = substate.replace(self.expression.flow)
         code = substate.replace(self.expression.code)
-        return self.expression.clone(flow=flow, code=code)
+        return self.expression.clone(root=root, flow=flow, code=code)
 
 
 class RewriteFlow(Rewrite):

File src/htsql/tweak/shell/command.py

             yield token
         yield u"data"
         product_to_raw = to_raw(product.meta.domain)
-        for token in product_to_raw(product.data):
+        data = product.data
+        if limit is not None and isinstance(data, list) and len(data) > limit:
+            data = data[:limit]
+        for token in product_to_raw(data):
             yield token
         yield u"more"
         yield (limit is not None and

File test/input/format.yaml

            '%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%7F',
            '%CE%BE', '\/%25''"&<>#', ''}/:txt
 
+- title: Nested Segments
+  tests:
+  - uri: /{/null, /school.limit(3), /department.limit(5)}/:raw
+  - uri: /{/null, /school.limit(3), /department.limit(5)}/:json
+  - uri: /{/null, /school.limit(3), /department.limit(5)}/:csv
+  - uri: /{/null, /school.limit(3), /department.limit(5)}/:tsv
+  - uri: /{/null, /school.limit(3), /department.limit(5)}/:xml
+  - uri: /{/null, /school.limit(3), /department.limit(5)}/:html
+  - uri: /{/null, /school.limit(3), /department.limit(5)}/:txt
+  - uri: /school?code={'edu','mus','sc'}
+                {name, /program{degree, title},
+                 /department{name, /course{no, title}}}/:raw
+  - uri: /school?code={'edu','mus','sc'}
+                {name, /program{degree, title},
+                 /department{name, /course{no, title}}}/:json
+  - uri: /school?code={'edu','mus','sc'}
+                {name, /program{degree, title},
+                 /department{name, /course{no, title}}}/:csv
+  - uri: /school?code={'edu','mus','sc'}
+                {name, /program{degree, title},
+                 /department{name, /course{no, title}}}/:tsv
+  - uri: /school?code={'edu','mus','sc'}
+                {name, /program{degree, title},
+                 /department{name, /course{no, title}}}/:xml
+  - uri: /school?code={'edu','mus','sc'}
+                {name, /program{degree, title},
+                 /department{name, /course{no, title}}}/:html
+  - uri: /school?code={'edu','mus','sc'}
+                {name, /program{degree, title},
+                 /department{name, /course{no, title}}}/:txt
+  - uri: /(/(/(/(/true))))/:raw
+  - uri: /(/(/(/(/true))))/:json
+  - uri: /(/(/(/(/true))))/:csv
+  - uri: /(/(/(/(/true))))/:tsv
+  - uri: /(/(/(/(/true))))/:xml
+  - uri: /(/(/(/(/true))))/:html
+  - uri: /(/(/(/(/true))))/:txt
+
 - title: Commands
   tests:
   - uri: /school/:retrieve

File test/input/translation.yaml

     - uri: /{(school^campus).campus}
       expect: 400
 
+  - title: Nested Segments
+    tests:
+    - uri: /school{code, /department{name}, /program{title}}
+    - uri: /school{code, /department{name}, /program{title}}?code={'bus','mus','sc'}
+    - uri: /school.filter(code={'bus','mus','sc'}){code, /department{name}, /program{title}}
+    - uri: /school{code, /department{name}.limit(3), /program{title}.limit(3)}.limit(3)
+    - uri: /{/school.limit(3), /department.limit(3)}
+    - uri: /school{code, /department{name}.sort(count(course))}.sort(count(program))
+    - uri: /school{code,
+                   /department{name,
+                               /course{title,
+                                       /class{year, season, section}.sort(count(enrollment))}
+                                      .filter(credits>=5)
+                                      .sort(count(class))}
+                              .sort(count(course))}
+                  .filter(code='art')
+    - uri: /school^campus{campus, count(school)+, /school}
+    - uri: /school^campus{campus, count(school)+,
+                          /school{name, count(program^degree)+, count(program),
+                                  /program^degree{degree, /program{title}}}}?campus='old'
+    - uri: /department{code, /school.program{title}, school{/program{title}}}
+    - uri: /department{code,
+                       /(school?code='bus').program{title},
+                       (school?code='bus').(/program{title}),
+                       school?code='bus'{/program{title}}}.limit(3)/:json
+    - uri: /department{code, /school{code}}?count(course)>=20
+    - uri: /school{*, /@school}
+    - uri: /school?exists(program){*, /fork(campus)}
+    - uri: /school{code, department.(/course)}
+      expect: 400
+    - uri: /school{code, department{/course}}
+      expect: 400
+    - uri: /school{code, /root().department}
+      expect: 400
+
 - title: Known issues
   tests:
   # Should produce a row for each record of `school`.

File test/output/mssql.yaml

               compile error: a singular expression is expected:
                   /{(school^campus).campus}
                                     ^^^^^^
+        - id: nested-segments
+          tests:
+          - uri: /school{code, /department{name}, /program{title}}
+            status: 200 OK
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            - [Vary, Accept]
+            body: |2
+               | school                                                           |
+               +------+------------------------+----------------------------------+
+               |      | department             | program                          |
+               |      +------------------------+----------------------------------+
+               | code | name                   | title                            |
+              -+------+------------------------+----------------------------------+-
+               | art  | Art History            | Post Baccalaureate in Art        |
+               :      | Studio Art             | History                          :
+               :      :                        | Bachelor of Arts in Art History  |
+               :      :                        | Bachelor of Arts in Studio Art   |
+               | bus  | Accounting             | Master of Arts in Economics      |
+               :      | Economics              | Graduate Certificate in          |
+               :      | Management & Marketing | Accounting                       :
+               :      :                        | Certificate in Business          |
+               :      :                        : Administration                   :
+               :      :                        | B.S. in Accounting               |
+               :      :                        | Bachelor of Business             |
+               :      :                        : Administration                   :
+               :      :                        | Bachelor of Arts in Economics    |
+               | edu  | Educational Policy     | Master of Arts in Education      |
+               :      | Teacher Education      | Leadership                       :
+               :      :                        | M.S. in Education                |
+               :      :                        | Master of Arts in Literacy       |
+               :      :                        : Education                        :
+               :      :                        | Master of Arts in Teaching       |
+               :      :                        | Certificate in Science Teaching  |
+               :      :                        | Bachelor of Arts in Math         |
+               :      :                        : Education                        :
+               :      :                        | Bachelor of Arts in Science      |
+               :      :                        : Education                        :
+               | eng  | Bioengineering         | M.S. in Bioengineering           |
+               :      | Computer Science       | M.S. in Business and Engineering |
+               :      | Electrical Engineering | M.S. in Electrical Engineering   |
+               :      | Mechanical Engineering | M.S. in Mechanical Engineering   |
+               :      :                        | B.S. in Bioengineering           |
+               :      :                        | B.S. in Computer Science         |
+               :      :                        | B.S. in Electrical Engineering   |
+               :      :                        | B.S. in Mechanical Engineering   |
+               | la   | English                | Master of Arts in English        |
+               :      | History                | Master of Arts in Modern         |
+               :      | Foreign Languages      | Languages                        :
+               :      | Political Science      | Master of Arts in Science        |
+               :      | Psychology             | Teaching                         :
+               :      :                        | Science Writing                  |
+               :      :                        | Bachelor of Arts in English      |
+               :      :                        | Bachelor of Arts in History      |
+               :      :                        | Bachelor of Arts in Political    |
+               :      :                        : Science                          :
+               :      :                        | Bachelor of Arts in Psychology   |
+               :      :                        | Bachelor of Arts in Spanish      |
+               | mus  | Piano                  |                                  :
+               :      | Strings                |                                  :
+               :      | Vocals                 |                                  :
+               :      | Wind                   |                                  :
+               | ns   | Astronomy              | Masters of Science in            |
+               :      | Chemistry              | Mathematics                      :
+               :      | Mathematics            | Doctorate of Science in          |
+               :      | Physics                | Mathematics                      :
+               :      :                        | Bachelor of Science in Astronomy |
+               :      :                        | Bachelor of Science in Chemistry |
+               :      :                        | Bachelor of Science in           |
+               :      :                        : Mathematics                      :
+               :      :                        | Bachelor of Science in Physics   |
+               | ph   |                        | Honorary PhD                     |
+               | sc   |                        :                                  :
+
+               ----
+               /school{code,/department{name},/program{title}}
+               SELECT [school].[code]
+               FROM [ad].[school]
+               ORDER BY 1 ASC
+
+                 SELECT [department].[name],
+                        [school].[code]
+                 FROM [ad].[school]
+                      INNER JOIN [ad].[department]
+                                 ON ([school].[code] = [department].[school_code])
+                 ORDER BY 2 ASC, [department].[code] ASC
+
+                 SELECT [program].[title],
+                        [school].[code]
+                 FROM [ad].[school]
+                      INNER JOIN [ad].[program]
+                                 ON ([school].[code] = [program].[school_code])
+                 ORDER BY 2 ASC, [program].[school_code] ASC, [program].[code] ASC
+          - uri: /school{code, /department{name}, /program{title}}?code={'bus','mus','sc'}
+            status: 200 OK
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            - [Vary, Accept]
+            body: |2
+               | school                                                        |
+               +------+------------------------+-------------------------------+
+               |      | department             | program                       |
+               |      +------------------------+-------------------------------+
+               | code | name                   | title                         |
+              -+------+------------------------+-------------------------------+-
+               | bus  | Accounting             | Master of Arts in Economics   |
+               :      | Economics              | Graduate Certificate in       |
+               :      | Management & Marketing | Accounting                    :
+               :      :                        | Certificate in Business       |
+               :      :                        : Administration                :
+               :      :                        | B.S. in Accounting            |
+               :      :                        | Bachelor of Business          |
+               :      :                        : Administration                :
+               :      :                        | Bachelor of Arts in Economics |
+               | mus  | Piano                  |                               :
+               :      | Strings                |                               :
+               :      | Vocals                 |                               :
+               :      | Wind                   |                               :
+               | sc   |                        :                               :
+
+               ----
+               /school{code,/department{name},/program{title}}?code={'bus','mus','sc'}
+               SELECT [school].[code]
+               FROM [ad].[school]
+               WHERE ([school].[code] IN ('bus', 'mus', 'sc'))
+               ORDER BY 1 ASC
+
+                 SELECT [department].[name],
+                        [school].[code]
+                 FROM [ad].[school]
+                      INNER JOIN [ad].[department]
+                                 ON ([school].[code] = [department].[school_code])
+                 WHERE ([school].[code] IN ('bus', 'mus', 'sc'))
+                 ORDER BY 2 ASC, [department].[code] ASC
+
+                 SELECT [program].[title],
+                        [school].[code]
+                 FROM [ad].[school]
+                      INNER JOIN [ad].[program]
+                                 ON ([school].[code] = [program].[school_code])
+                 WHERE ([school].[code] IN ('bus', 'mus', 'sc'))
+                 ORDER BY 2 ASC, [program].[school_code] ASC, [program].[code] ASC
+          - uri: /school.filter(code={'bus','mus','sc'}){code, /department{name},
+              /program{title}}
+            status: 200 OK
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            - [Vary, Accept]
+            body: |2
+               | school                                                        |
+               +------+------------------------+-------------------------------+
+               |      | department             | program                       |
+               |      +------------------------+-------------------------------+
+               | code | name                   | title                         |
+              -+------+------------------------+-------------------------------+-
+               | bus  | Accounting             | Master of Arts in Economics   |
+               :      | Economics              | Graduate Certificate in       |
+               :      | Management & Marketing | Accounting                    :
+               :      :                        | Certificate in Business       |
+               :      :                        : Administration                :
+               :      :                        | B.S. in Accounting            |
+               :      :                        | Bachelor of Business          |
+               :      :                        : Administration                :
+               :      :                        | Bachelor of Arts in Economics |
+               | mus  | Piano                  |                               :
+               :      | Strings                |                               :
+               :      | Vocals                 |                               :
+               :      | Wind                   |                               :
+               | sc   |                        :                               :
+
+               ----
+               /school.filter(code={'bus','mus','sc'}){code,/department{name},/program{title}}
+               SELECT [school].[code]
+               FROM [ad].[school]
+               WHERE ([school].[code] IN ('bus', 'mus', 'sc'))
+               ORDER BY 1 ASC
+
+                 SELECT [department].[name],
+                        [school].[code]
+                 FROM [ad].[school]
+                      INNER JOIN [ad].[department]
+                                 ON ([school].[code] = [department].[school_code])
+                 WHERE ([school].[code] IN ('bus', 'mus', 'sc'))
+                 ORDER BY 2 ASC, [department].[code] ASC
+
+                 SELECT [program].[title],
+                        [school].[code]
+                 FROM [ad].[school]
+                      INNER JOIN [ad].[program]
+                                 ON ([school].[code] = [program].[school_code])
+                 WHERE ([school].[code] IN ('bus', 'mus', 'sc'))
+                 ORDER BY 2 ASC, [program].[school_code] ASC, [program].[code] ASC
+          - uri: /school{code, /department{name}.limit(3), /program{title}.limit(3)}.limit(3)
+            status: 200 OK
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            - [Vary, Accept]
+            body: |2
+               | school                                               |
+               +------+-------------+---------------------------------+
+               |      | department  | program                         |
+               |      +-------------+---------------------------------+
+               | code | name        | title                           |
+              -+------+-------------+---------------------------------+-
+               | art  | Art History | Post Baccalaureate in Art       |
+               :      | Studio Art  | History                         :
+               :      :             | Bachelor of Arts in Art History |
+               :      :             | Bachelor of Arts in Studio Art  |
+               | bus  | Accounting  |                                 :
+               | edu  |             :                                 :
+
+               ----
+               /school{code,/department{name}.limit(3),/program{title}.limit(3)}.limit(3)
+               SELECT TOP 3
+                      [school].[code]
+               FROM [ad].[school]
+               ORDER BY 1 ASC
+
+                 SELECT [department].[name],
+                        [department].[code_1]
+                 FROM (SELECT TOP 3
+                              [school].[code]
+                       FROM [ad].[school]
+                       ORDER BY 1 ASC) AS [school]
+                      INNER JOIN (SELECT TOP 3
+                                         [department].[name],
+                                         [school].[code] AS [code_1],
+                                         [department].[code] AS [code_2]
+                                  FROM [ad].[school]
+                                       INNER JOIN [ad].[department]
+                                                  ON ([school].[code] = [department].[school_code])
+                                  ORDER BY 2 ASC, 3 ASC) AS [department]
+                                 ON ([school].[code] = [department].[code_1])
+                 ORDER BY 2 ASC, [department].[code_2] ASC
+
+                 SELECT [program].[title],
+                        [program].[code_1]
+                 FROM (SELECT TOP 3
+                              [school].[code]
+                       FROM [ad].[school]
+                       ORDER BY 1 ASC) AS [school]
+                      INNER JOIN (SELECT TOP 3
+                                         [program].[title],
+                                         [school].[code] AS [code_1],
+                                         [program].[school_code],
+                                         [program].[code] AS [code_2]
+                                  FROM [ad].[school]
+                                       INNER JOIN [ad].[program]
+                                                  ON ([school].[code] = [program].[school_code])
+                                  ORDER BY 2 ASC, 3 ASC, 4 ASC) AS [program]
+                                 ON ([school].[code] = [program].[code_1])
+                 ORDER BY 2 ASC, [program].[school_code] ASC, [program].[code_2] ASC
+          - uri: /{/school.limit(3), /department.limit(3)}
+            status: 200 OK
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            - [Vary, Accept]
+            body: |2
+               | school                                 | department                         |
+               +------+------------------------+--------+--------+-------------+-------------+
+               | code | name                   | campus | code   | name        | school_code |
+              -+------+------------------------+--------+--------+-------------+-------------+-
+               | art  | School of Art & Design | old    | acc    | Accounting  | bus         |
+               | bus  | School of Business     | south  | arthis | Art History | art         |
+               | edu  | College of Education   | old    | astro  | Astronomy   | ns          |
+
+               ----
+               /{/school.limit(3),/department.limit(3)}
+               SELECT 1
+
+                 SELECT TOP 3
+                        [school].[code],
+                        [school].[name],
+                        [school].[campus]
+                 FROM [ad].[school]
+                 ORDER BY 1 ASC
+
+                 SELECT TOP 3
+                        [department].[code],
+                        [department].[name],
+                        [department].[school_code]
+                 FROM [ad].[department]
+                 ORDER BY 1 ASC
+          - uri: /school{code, /department{name}.sort(count(course))}.sort(count(program))
+            status: 200 OK
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            - [Vary, Accept]
+            body: |2
+               | school                        |
+               +------+------------------------+
+               |      | department             |
+               |      +------------------------+
+               | code | name                   |
+              -+------+------------------------+-
+               | mus  | Piano                  |
+               :      | Strings                |
+               :      | Vocals                 |
+               :      | Wind                   |
+               | sc   |                        :
+               | ph   |                        :
+               | art  | Studio Art             |
+               :      | Art History            |
+               | bus  | Accounting             |
+               :      | Economics              |
+               :      | Management & Marketing |
+               | ns   | Mathematics            |
+               :      | Chemistry              |
+               :      | Astronomy              |
+               :      | Physics                |
+               | edu  | Educational Policy     |
+               :      | Teacher Education      |
+               | eng  | Electrical Engineering |
+               :      | Bioengineering         |
+               :      | Mechanical Engineering |
+               :      | Computer Science       |
+               | la   | History                |
+               :      | Psychology             |
+               :      | Political Science      |
+               :      | English                |
+               :      | Foreign Languages      |
+
+               ----
+               /school{code,/department{name}.sort(count(course))}.sort(count(program))
+               SELECT [school].[code]
+               FROM [ad].[school]
+                    LEFT OUTER JOIN (SELECT COUNT(1) AS [count],
+                                            [program].[school_code]
+                                     FROM [ad].[program]
+                                     GROUP BY [program].[school_code]) AS [program]
+                                    ON ([school].[code] = [program].[school_code])
+               ORDER BY COALESCE([program].[count], 0) ASC, 1 ASC
+
+                 SELECT [department].[name],
+                        [school].[code]
+                 FROM [ad].[school]
+                      INNER JOIN [ad].[department]
+                                 ON ([school].[code] = [department].[school_code])
+                      LEFT OUTER JOIN (SELECT COUNT(1) AS [count],
+                                              [program].[school_code]
+                                       FROM [ad].[program]
+                                       GROUP BY [program].[school_code]) AS [program]
+                                      ON ([school].[code] = [program].[school_code])
+                      LEFT OUTER JOIN (SELECT COUNT(1) AS [count],
+                                              [course].[department_code]
+                                       FROM [ad].[course]
+                                       GROUP BY [course].[department_code]) AS [course]
+                                      ON ([department].[code] = [course].[department_code])
+                 ORDER BY COALESCE([program].[count], 0) ASC, 2 ASC, COALESCE([course].[count], 0) ASC, [department].[code] ASC
+          - uri: /school{code, /department{name, /course{title, /class{year, season,
+              section}.sort(count(enrollment))} .filter(credits>=5) .sort(count(class))}
+              .sort(count(course))} .filter(code='art')
+            status: 200 OK
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            - [Vary, Accept]
+            body: |2
+               | school                                                                      |
+               +------+----------------------------------------------------------------------+
+               |      | department                                                           |
+               |      +-------------+--------------------------------------------------------+
+               |      |             | course                                                 |
+               |      |             +------------------------------+-------------------------+
+               |      |             |                              | class                   |
+               |      |             |                              +------+--------+---------+
+               | code | name        | title                        | year | season | section |
+              -+------+-------------+------------------------------+------+--------+---------+-
+               | art  | Studio Art  | Drawing Master Class         | 2009 | spring | 001     |
+               :      :             :                              | 2010 | spring | 001     |
+               :      :             | Advanced Painting            | 2009 | spring | 001     |
+               :      :             :                              | 2010 | fall   | 001     |
+               :      :             :                              | 2010 | spring | 001     |
+               :      :             | Photography                  | 2007 | fall   | 001     |
+               :      :             :                              | 2009 | fall   | 001     |
+               :      :             :                              | 2008 | fall   | 001     |
+               :      :             :                              | 2010 | fall   | 001     |
+               :      | Art History | Antique Art: Greece and Rome | 2007 | fall   | 001     |
+               :      :             :                              | 2009 | fall   | 001     |
+               :      :             :                              | 2010 | fall   | 001     |
+               :      :             | Islamic Art                  | 2007 | spring | 001     |
+               :      :             :                              | 2008 | spring | 001     |
+               :      :             :                              | 2009 | spring | 001     |
+               :      :             :                              | 2010 | spring | 001     |
+               :      :             | Art of Photography           | 2008 | spring | 001     |
+               :      :             :                              | 2009 | spring | 001     |
+               :      :             :                              | 2010 | spring | 001     |
+               :      :             :                              | 2008 | fall   | 001     |
+               :      :             :                              | 2009 | fall   | 001     |
+               :      :             :                              | 2010 | fall   | 001     |
+
+               ----
+               /school{code,/department{name,/course{title,/class{year,season,section}.sort(count(enrollment))}.filter(credits>=5).sort(count(class))}.sort(count(course))}.filter(code='art')
+               SELECT [school].[code]
+               FROM [ad].[school]
+               WHERE ([school].[code] = 'art')
+               ORDER BY 1 ASC
+
+                 SELECT [department].[name],
+                        [school].[code],
+                        [department].[code]
+                 FROM [ad].[school]
+                      INNER JOIN (SELECT [department].[name],
+                                         [department].[code],
+                                         [department].[school_code]
+                                  FROM [ad].[department]) AS [department]
+                                 ON ([school].[code] = [department].[school_code])
+                      LEFT OUTER JOIN (SELECT COUNT(1) AS [count],
+                                              [course].[department_code]
+                                       FROM [ad].[course]
+                                       GROUP BY [course].[department_code]) AS [course]
+                                      ON ([department].[code] = [course].[department_code])
+                 WHERE ([school].[code] = 'art')
+                 ORDER BY 2 ASC, COALESCE([course].[count], 0) ASC, 3 ASC
+
+                   SELECT [course_1].[title],
+                          [school].[code],
+                          [course_1].[code],
+                          [course_1].[department_code],
+                          [course_1].[no]
+                   FROM [ad].[school]
+                        INNER JOIN (SELECT [course].[title],
+                                           [department].[code],
+                                           [course].[department_code],
+                                           [course].[no],
+                                           [department].[school_code]
+                                    FROM [ad].[department]
+                                         INNER JOIN [ad].[course]
+                                                    ON ([department].[code] = [course].[department_code])
+                                    WHERE ([course].[credits] >= 5)) AS [course_1]
+                                   ON ([school].[code] = [course_1].[school_code])
+                        LEFT OUTER JOIN (SELECT COUNT(1) AS [count],
+                                                [course].[department_code]
+                                         FROM [ad].[course]
+                                         GROUP BY [course].[department_code]) AS [course_2]
+                                        ON ([course_1].[code] = [course_2].[department_code])
+                        LEFT OUTER JOIN (SELECT COUNT(1) AS [count],
+                                                [class].[department_code],
+                                                [class].[course_no]
+                                         FROM [cd].[class]
+                                         GROUP BY [class].[department_code], [class].[course_no]) AS [class]
+                                        ON (([course_1].[department_code] = [class].[department_code]) AND ([course_1].[no] = [class].[course_no]))
+                   WHERE ([school].[code] = 'art')
+                   ORDER BY 2 ASC, COALESCE([course_2].[count], 0) ASC, 3 ASC, COALESCE([class].[count], 0) ASC, 4 ASC, 5 ASC
+
+                     SELECT [class_1].[year],
+                            [class_1].[season],
+                            [class_1].[section],
+                            [school].[code],
+                            [course_1].[code],
+                            [course_1].[department_code],
+                            [course_1].[no]
+                     FROM [ad].[school]
+                          INNER JOIN (SELECT [department].[code],
+                                             [course].[department_code],
+                                             [course].[no],
+                                             [department].[school_code]
+                                      FROM [ad].[department]
+                                           INNER JOIN [ad].[course]
+                                                      ON ([department].[code] = [course].[department_code])
+                                      WHERE ([course].[credits] >= 5)) AS [course_1]
+                                     ON ([school].[code] = [course_1].[school_code])
+                          INNER JOIN (SELECT [class].[year],
+                                             [class].[season],
+                                             [class].[section],
+                                             [class].[department_code],
+                                             [class].[course_no],
+                                             [class].[class_seq]
+                                      FROM [cd].[class]) AS [class_1]
+                                     ON (([course_1].[department_code] = [class_1].[department_code]) AND ([course_1].[no] = [class_1].[course_no]))
+                          LEFT OUTER JOIN (SELECT COUNT(1) AS [count],
+                                                  [course].[department_code]
+                                           FROM [ad].[course]
+                                           GROUP BY [course].[department_code]) AS [course_2]
+                                          ON ([course_1].[code] = [course_2].[department_code])
+                          LEFT OUTER JOIN (SELECT COUNT(1) AS [count],
+                                                  [class].[department_code],
+                                                  [class].[course_no]
+                                           FROM [cd].[class]
+                                           GROUP BY [class].[department_code], [class].[course_no]) AS [class_2]
+                                          ON (([course_1].[department_code] = [class_2].[department_code]) AND ([course_1].[no] = [class_2].[course_no]))
+                          LEFT OUTER JOIN (SELECT COUNT(1) AS [count],
+                                                  [enrollment].[class_seq]
+                                           FROM [ed].[enrollment]
+                                           GROUP BY [enrollment].[class_seq]) AS [enrollment]
+                                          ON ([class_1].[class_seq] = [enrollment].[class_seq])
+                     WHERE ([school].[code] = 'art')
+                     ORDER BY 4 ASC, COALESCE([course_2].[count], 0) ASC, 5 ASC, COALESCE([class_2].[count], 0) ASC, 6 ASC, 7 ASC, COALESCE([enrollment].[count], 0) ASC, [class_1].[department_code] ASC, [class_1].[course_no] ASC, 1 ASC, 2 ASC, 3 ASC
+          - uri: /school^campus{campus, count(school)+, /school}
+            status: 200 OK
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            - [Vary, Accept]
+            body: |2
+               | school^campus                                                          |
+               +--------+---------------+-----------------------------------------------+
+               |        |               | school                                        |
+               |        |               +------+-------------------------------+--------+
+               | campus | count(school) | code | name                          | campus |
+              -+--------+---------------+------+-------------------------------+--------+-
+               | north  |             1 | eng  | School of Engineering         | north  |
+               | south  |             2 | bus  | School of Business            | south  |
+               :        :               | mus  | School of Music & Dance       | south  |
+               | old    |             4 | art  | School of Art & Design        | old    |
+               :        :               | edu  | College of Education          | old    |
+               :        :               | la   | School of Arts and Humanities | old    |
+               :        :               | ns   | School of Natural Sciences    | old    |
+
+               ----
+               /school^campus{campus,count(school)+,/school}
+               SELECT [school].[campus],
+                      COUNT(1)
+               FROM [ad].[school]
+               WHERE ([school].[campus] IS NOT NULL)
+               GROUP BY [school].[campus]
+               ORDER BY 2 ASC, 1 ASC
+
+                 SELECT [school_1].[code],
+                        [school_1].[name],
+                        [school_1].[campus]
+                 FROM [ad].[school] AS [school_1]
+                      LEFT OUTER JOIN (SELECT COUNT(1) AS [count],
+                                              [school].[campus]
+                                       FROM [ad].[school]
+                                       GROUP BY [school].[campus]) AS [school_2]
+                                      ON ([school_1].[campus] = [school_2].[campus])
+                 WHERE ([school_1].[campus] IS NOT NULL)
+                 ORDER BY COALESCE([school_2].[count], 0) ASC, 3 ASC, 1 ASC
+          - uri: /school^campus{campus, count(school)+, /school{name, count(program^degree)+,
+              count(program), /program^degree{degree, /program{title}}}}?campus='old'
+            status: 200 OK
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            - [Vary, Accept]
+            body: |2
+               | school^campus                                                                                                                               |
+               +--------+---------------+--------------------------------------------------------------------------------------------------------------------+
+               |        |               | school                                                                                                             |
+               |        |               +-------------------------------+-----------------------+----------------+-------------------------------------------+
+               |        |               |                               |                       |                | program^degree                            |
+               |        |               |                               |                       |                +--------+----------------------------------+
+               |        |               |                               |                       |                |        | program                          |
+               |        |               |                               |                       |                |        +----------------------------------+
+               | campus | count(school) | name                          | count(program^degree) | count(program) | degree | title                            |
+              -+--------+---------------+-------------------------------+-----------------------+----------------+--------+----------------------------------+-
+               | old    |             4 | School of Art & Design        |                     2 |              3 | ba     | Bachelor of Arts in Art History  |
+               :        :               :                               :                       :                :        | Bachelor of Arts in Studio Art   |
+               :        :               :                               :                       :                | pb     | Post Baccalaureate in Art        |
+               :        :               :                               :                       :                :        : History                          :
+               :        :               | School of Arts and Humanities |                     3 |              9 | ba     | Bachelor of Arts in English      |
+               :        :               :                               :                       :                :        | Bachelor of Arts in History      |
+               :        :               :                               :                       :                :        | Bachelor of Arts in Political    |
+               :        :               :                               :                       :                :        : Science                          :
+               :        :               :                               :                       :                :        | Bachelor of Arts in Psychology   |
+               :        :               :                               :                       :                :        | Bachelor of Arts in Spanish      |
+               :        :               :                               :                       :                | ct     | Science Writing                  |
+               :        :               :                               :                       :                | ma     | Master of Arts in English        |
+               :        :               :                               :                       :                :        | Master of Arts in Modern         |
+               :        :               :                               :                       :                :        : Languages                        :
+               :        :               :                               :                       :                :        | Master of Arts in Science        |
+               :        :               :                               :                       :                :        : Teaching                         :
+               :        :               | School of Natural Sciences    |                     3 |              6 | bs     | Bachelor of Science in Astronomy |
+               :        :               :                               :                       :                :        | Bachelor of Science in Chemistry |
+               :        :               :                               :                       :                :        | Bachelor of Science in           |
+               :        :               :                               :                       :                :        : Mathematics                      :
+               :        :               :                               :                       :                :        | Bachelor of Science in Physics   |
+               :        :               :                               :                       :                | ms     | Masters of Science in            |
+               :        :               :                               :                       :                :        : Mathematics                      :
+               :        :               :                               :                       :                | ph     | Doctorate of Science in          |
+               :        :               :                               :                       :                :        : Mathematics                      :
+               :        :               | College of Education          |                     4 |              7 | ba     | Bachelor of Arts in Math         |
+               :        :               :                               :                       :                :        : Education                        :
+               :        :               :                               :                       :                :        | Bachelor of Arts in Science      |
+               :        :               :                               :                       :                :        : Education                        :
+               :        :               :                               :                       :                | ct     | Certificate in Science Teaching  |
+               :        :               :                               :                       :                | ma     | Master of Arts in Education      |
+               :        :               :                               :                       :                :        : Leadership                       :
+               :        :               :                               :                       :                :        | Master of Arts in Literacy       |
+               :        :               :                               :                       :                :        : Education                        :
+               :        :               :                               :                       :                :        | Master of Arts in Teaching       |
+               :        :               :                               :                       :                | ms     | M.S. in Education                |
+
+               ----
+               /school^campus{campus,count(school)+,/school{name,count(program^degree)+,count(program),/program^degree{degree,/program{title}}}}?campus='old'
+               SELECT [school].[campus],
+                      COUNT(1)
+               FROM [ad].[school]
+               WHERE ([school].[campus] IS NOT NULL)
+               GROUP BY [school].[campus]
+               HAVING ([school].[campus] = 'old')
+               ORDER BY 2 ASC, 1 ASC
+
+                 SELECT [school_2].[name],
+                        COALESCE([program_1].[count], 0),
+                        COALESCE([program_2].[count], 0),
+                        [school_1].[campus],
+                        [school_2].[code]
+                 FROM (SELECT [school].[campus],
+                              COUNT(1) AS [count]
+                       FROM [ad].[school]
+                       WHERE ([school].[campus] IS NOT NULL)
+                       GROUP BY [school].[campus]) AS [school_1]
+                      INNER JOIN (SELECT [school].[name],
+                                         [school].[code],
+                                         [school].[campus]
+                                  FROM [ad].[school]) AS [school_2]
+                                 ON ([school_1].[campus] = [school_2].[campus])
+                      LEFT OUTER JOIN (SELECT COUNT(1) AS [count],
+                                              [program].[school_code]
+                                       FROM (SELECT [program].[school_code]
+                                             FROM [ad].[program]
+                                             WHERE ([program].[degree] IS NOT NULL)
+                                             GROUP BY [program].[school_code], [program].[degree]) AS [program]
+                                       GROUP BY [program].[school_code]) AS [program_1]
+                                      ON ([school_2].[code] = [program_1].[school_code])
+                      LEFT OUTER JOIN (SELECT COUNT(1) AS [count],
+                                              [program].[school_code]
+                                       FROM [ad].[program]
+                                       GROUP BY [program].[school_code]) AS [program_2]
+                                      ON ([school_2].[code] = [program_2].[school_code])
+                 WHERE ([school_1].[campus] = 'old')
+                 ORDER BY [school_1].[count] ASC, 4 ASC, 2 ASC, 5 ASC
+
+                   SELECT [program_1].[degree],
+                          [school].[campus],
+                          [program_1].[code]
+                   FROM (SELECT [school].[campus],
+                                COUNT(1) AS [count]
+                         FROM [ad].[school]
+                         WHERE ([school].[campus] IS NOT NULL)
+                         GROUP BY [school].[campus]) AS [school]
+                        INNER JOIN (SELECT [program].[degree],
+                                           [school].[code],
+                                           [school].[campus]
+                                    FROM [ad].[school]
+                                         INNER JOIN (SELECT [program].[degree],
+                                                            [program].[school_code]
+                                                     FROM [ad].[program]
+                                                     WHERE ([program].[degree] IS NOT NULL)
+                                                     GROUP BY [program].[school_code], [program].[degree]) AS [program]
+                                                    ON ([school].[code] = [program].[school_code])) AS [program_1]
+                                   ON ([school].[campus] = [program_1].[campus])
+                        LEFT OUTER JOIN (SELECT COUNT(1) AS [count],
+                                                [program].[school_code]
+                                         FROM (SELECT [program].[school_code]
+                                               FROM [ad].[program]
+                                               WHERE ([program].[degree] IS NOT NULL)
+                                               GROUP BY [program].[school_code], [program].[degree]) AS [program]
+                                         GROUP BY [program].[school_code]) AS [program_2]
+                                        ON ([program_1].[code] = [program_2].[school_code])
+                   WHERE ([school].[campus] = 'old')
+                   ORDER BY [school].[count] ASC, 2 ASC, COALESCE([program_2].[count], 0) ASC, 3 ASC, 1 ASC
+
+                     SELECT [program_1].[title],
+                            [school].[campus],
+                            [program_1].[code_1],
+                            [program_1].[degree]
+                     FROM (SELECT [school].[campus],
+                                  COUNT(1) AS [count]
+                           FROM [ad].[school]
+                           WHERE ([school].[campus] IS NOT NULL)
+                           GROUP BY [school].[campus]) AS [school]
+                          INNER JOIN (SELECT [program].[title],
+                                             [school].[code] AS [code_1],
+                                             [program].[degree],
+                                             [program].[school_code],
+                                             [program].[code] AS [code_2],
+                                             [school].[campus]
+                                      FROM [ad].[school]
+                                           INNER JOIN (SELECT [program].[title],
+                                                              [program].[degree],
+                                                              [program].[school_code],
+                                                              [program].[code]
+                                                       FROM [ad].[program]
+                                                       WHERE ([program].[degree] IS NOT NULL)) AS [program]
+                                                      ON ([school].[code] = [program].[school_code])) AS [program_1]
+                                     ON ([school].[campus] = [program_1].[campus])
+                          LEFT OUTER JOIN (SELECT COUNT(1) AS [count],
+                                                  [program].[school_code]
+                                           FROM (SELECT [program].[school_code]
+                                                 FROM [ad].[program]
+                                                 WHERE ([program].[degree] IS NOT NULL)
+                                                 GROUP BY [program].[school_code], [program].[degree]) AS [program]
+                                           GROUP BY [program].[school_code]) AS [program_2]
+                                          ON ([program_1].[code_1] = [program_2].[school_code])
+                     WHERE ([school].[campus] = 'old')
+                     ORDER BY [school].[count] ASC, 2 ASC, COALESCE([program_2].[count], 0) ASC, 3 ASC, 4 ASC, [program_1].[school_code] ASC, [program_1].[code_2] ASC
+          - uri: /department{code, /school.program{title}, school{/program{title}}}
+            status: 200 OK
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            - [Vary, Accept]
+            body: |2
+               | department                                                                   |
+               +--------+----------------------------------+----------------------------------+
+               |        | program                          | school                           |
+               |        +----------------------------------+----------------------------------+
+               |        |                                  | program                          |
+               |        |                                  +----------------------------------+
+               | code   | title                            | title                            |
+              -+--------+----------------------------------+----------------------------------+-
+               | acc    | Master of Arts in Economics      | Master of Arts in Economics      |
+               :        | Graduate Certificate in          | Graduate Certificate in          |
+               :        : Accounting                       : Accounting                       :
+               :        | Certificate in Business          | Certificate in Business          |
+               :        : Administration                   : Administration                   :
+               :        | B.S. in Accounting               | B.S. in Accounting               |
+               :        | Bachelor of Business             | Bachelor of Business             |
+               :        : Administration                   : Administration                   :
+               :        | Bachelor of Arts in Economics    | Bachelor of Arts in Economics    |
+               | arthis | Post Baccalaureate in Art        | Post Baccalaureate in Art        |
+               :        : History                          : History                          :
+               :        | Bachelor of Arts in Art History  | Bachelor of Arts in Art History  |
+               :        | Bachelor of Arts in Studio Art   | Bachelor of Arts in Studio Art   |
+               | astro  | Masters of Science in            | Masters of Science in            |
+               :        : Mathematics                      : Mathematics                      :
+               :        | Doctorate of Science in          | Doctorate of Science in          |
+               :        : Mathematics                      : Mathematics                      :
+               :        | Bachelor of Science in Astronomy | Bachelor of Science in Astronomy |
+               :        | Bachelor of Science in Chemistry | Bachelor of Science in Chemistry |
+               :        | Bachelor of Science in           | Bachelor of Science in           |
+               :        : Mathematics                      : Mathematics                      :
+               :        | Bachelor of Science in Physics   | Bachelor of Science in Physics   |
+               | be     | M.S. in Bioengineering           | M.S. in Bioengineering           |
+               :        | M.S. in Business and Engineering | M.S. in Business and Engineering |
+               :        | M.S. in Electrical Engineering   | M.S. in Electrical Engineering   |
+               :        | M.S. in Mechanical Engineering   | M.S. in Mechanical Engineering   |
+               :        | B.S. in Bioengineering           | B.S. in Bioengineering           |
+               :        | B.S. in Computer Science         | B.S. in Computer Science         |
+               :        | B.S. in Electrical Engineering   | B.S. in Electrical Engineering   |
+               :        | B.S. in Mechanical Engineering   | B.S. in Mechanical Engineering   |
+               | bursar |                                  :                                  :
+               | career |                                  :                                  :
+               | chem   | Masters of Science in            | Masters of Science in            |
+               :        : Mathematics                      : Mathematics                      :
+               :        | Doctorate of Science in          | Doctorate of Science in          |
+               :        : Mathematics                      : Mathematics                      :
+               :        | Bachelor of Science in Astronomy | Bachelor of Science in Astronomy |
+               :        | Bachelor of Science in Chemistry | Bachelor of Science in Chemistry |
+               :        | Bachelor of Science in           | Bachelor of Science in           |
+               :        : Mathematics                      : Mathematics                      :
+               :        | Bachelor of Science in Physics   | Bachelor of Science in Physics   |
+               | comp   | M.S. in Bioengineering           | M.S. in Bioengineering           |
+               :        | M.S. in Business and Engineering | M.S. in Business and Engineering |
+               :        | M.S. in Electrical Engineering   | M.S. in Electrical Engineering   |
+               :        | M.S. in Mechanical Engineering   | M.S. in Mechanical Engineering   |
+               :        | B.S. in Bioengineering           | B.S. in Bioengineering           |
+               :        | B.S. in Computer Science         | B.S. in Computer Science         |
+               :        | B.S. in Electrical Engineering   | B.S. in Electrical Engineering   |
+               :        | B.S. in Mechanical Engineering   | B.S. in Mechanical Engineering   |
+               | econ   | Master of Arts in Economics      | Master of Arts in Economics      |
+               :        | Graduate Certificate in          | Graduate Certificate in          |
+               :        : Accounting                       : Accounting                       :
+               :        | Certificate in Business          | Certificate in Business          |
+               :        : Administration                   : Administration                   :
+               :        | B.S. in Accounting               | B.S. in Accounting               |
+               :        | Bachelor of Business             | Bachelor of Business             |
+               :        : Administration                   : Administration                   :
+               :        | Bachelor of Arts in Economics    | Bachelor of Arts in Economics    |
+               | edpol  | Master of Arts in Education      | Master of Arts in Education      |
+               :        : Leadership                       : Leadership                       :
+               :        | M.S. in Education                | M.S. in Education                |
+               :        | Master of Arts in Literacy       | Master of Arts in Literacy       |
+               :        : Education                        : Education                        :
+               :        | Master of Arts in Teaching       | Master of Arts in Teaching       |
+               :        | Certificate in Science Teaching  | Certificate in Science Teaching  |
+               :        | Bachelor of Arts in Math         | Bachelor of Arts in Math         |
+               :        : Education                        : Education                        :
+               :        | Bachelor of Arts in Science      | Bachelor of Arts in Science      |
+               :        : Education                        : Education                        :
+               | ee     | M.S. in Bioengineering           | M.S. in Bioengineering           |
+               :        | M.S. in Business and Engineering | M.S. in Business and Engineering |
+               :        | M.S. in Electrical Engineering   | M.S. in Electrical Engineering   |
+               :        | M.S. in Mechanical Engineering   | M.S. in Mechanical Engineering   |
+               :        | B.S. in Bioengineering           | B.S. in Bioengineering           |
+               :        | B.S. in Computer Science         | B.S. in Computer Science         |
+               :        | B.S. in Electrical Engineering   | B.S. in Electrical Engineering   |
+               :        | B.S. in Mechanical Engineering   | B.S. in Mechanical Engineering   |
+               | eng    | Master of Arts in English        | Master of Arts in English        |
+               :        | Master of Arts in Modern         | Master of Arts in Modern         |
+               :        : Languages                        : Languages                        :
+               :        | Master of Arts in Science        | Master of Arts in Science        |
+               :        : Teaching                         : Teaching                         :
+               :        | Science Writing                  | Science Writing                  |
+               :        | Bachelor of Arts in English      | Bachelor of Arts in English      |
+               :        | Bachelor of Arts in History      | Bachelor of Arts in History      |
+               :        | Bachelor of Arts in Political    | Bachelor of Arts in Political    |
+               :        : Science                          : Science                          :
+               :        | Bachelor of Arts in Psychology   | Bachelor of Arts in Psychology   |
+               :        | Bachelor of Arts in Spanish      | Bachelor of Arts in Spanish      |
+               | hist   | Master of Arts in English        | Master of Arts in English        |
+               :        | Master of Arts in Modern         | Master of Arts in Modern         |
+               :        : Languages                        : Languages                        :
+               :        | Master of Arts in Science        | Master of Arts in Science        |
+               :        : Teaching                         : Teaching                         :
+               :        | Science Writing                  | Science Writing                  |
+               :        | Bachelor of Arts in English      | Bachelor of Arts in English      |
+               :        | Bachelor of Arts in History      | Bachelor of Arts in History      |
+               :        | Bachelor of Arts in Political    | Bachelor of Arts in Political    |
+               :        : Science                          : Science                          :
+               :        | Bachelor of Arts in Psychology   | Bachelor of Arts in Psychology   |
+               :        | Bachelor of Arts in Spanish      | Bachelor of Arts in Spanish      |
+               | lang   | Master of Arts in English        | Master of Arts in English        |
+               :        | Master of Arts in Modern         | Master of Arts in Modern         |
+               :        : Languages                        : Languages                        :
+               :        | Master of Arts in Science        | Master of Arts in Science        |
+               :        : Teaching                         : Teaching                         :
+               :        | Science Writing                  | Science Writing                  |
+               :        | Bachelor of Arts in English      | Bachelor of Arts in English      |
+               :        | Bachelor of Arts in History      | Bachelor of Arts in History      |
+               :        | Bachelor of Arts in Political    | Bachelor of Arts in Political    |
+               :        : Science                          : Science                          :
+               :        | Bachelor of Arts in Psychology   | Bachelor of Arts in Psychology   |
+               :        | Bachelor of Arts in Spanish      | Bachelor of Arts in Spanish      |
+               | me     | M.S. in Bioengineering           | M.S. in Bioengineering           |
+               :        | M.S. in Business and Engineering | M.S. in Business and Engineering |
+               :        | M.S. in Electrical Engineering   | M.S. in Electrical Engineering   |
+               :        | M.S. in Mechanical Engineering   | M.S. in Mechanical Engineering   |
+               :        | B.S. in Bioengineering           | B.S. in Bioengineering           |
+               :        | B.S. in Computer Science         | B.S. in Computer Science         |
+               :        | B.S. in Electrical Engineering   | B.S. in Electrical Engineering   |
+               :        | B.S. in Mechanical Engineering   | B.S. in Mechanical Engineering   |
+               | mm     | Master of Arts in Economics      | Master of Arts in Economics      |
+               :        | Graduate Certificate in          | Graduate Certificate in          |
+               :        : Accounting                       : Accounting                       :
+               :        | Certificate in Business          | Certificate in Business          |
+               :        : Administration                   : Administration                   :
+               :        | B.S. in Accounting               | B.S. in Accounting               |
+               :        | Bachelor of Business             | Bachelor of Business             |
+               :        : Administration                   : Administration                   :
+               :        | Bachelor of Arts in Economics    | Bachelor of Arts in Economics    |
+               | mth    | Masters of Science in            | Masters of Science in            |
+               :        : Mathematics                      : Mathematics                      :
+               :        | Doctorate of Science in          | Doctorate of Science in          |
+               :        : Mathematics                      : Mathematics                      :
+               :        | Bachelor of Science in Astronomy | Bachelor of Science in Astronomy |
+               :        | Bachelor of Science in Chemistry | Bachelor of Science in Chemistry |
+               :        | Bachelor of Science in           | Bachelor of Science in           |
+               :        : Mathematics                      : Mathematics                      :
+               :        | Bachelor of Science in Physics   | Bachelor of Science in Physics   |
+               | parent |                                  :                                  :
+               | phys   | Masters of Science in            | Masters of Science in            |
+               :        : Mathematics                      : Mathematics                      :
+               :        | Doctorate of Science in          | Doctorate of Science in          |
+               :        : Mathematics                      : Mathematics                      :
+               :        | Bachelor of Science in Astronomy | Bachelor of Science in Astronomy |
+               :        | Bachelor of Science in Chemistry | Bachelor of Science in Chemistry |
+               :        | Bachelor of Science in           | Bachelor of Science in           |
+               :        : Mathematics                      : Mathematics                      :
+               :        | Bachelor of Science in Physics   | Bachelor of Science in Physics   |
+               | pia    |                                  :                                  :
+               | poli   | Master of Arts in English        | Master of Arts in English        |
+               :        | Master of Arts in Modern         | Master of Arts in Modern         |
+               :        : Languages                        : Languages                        :
+               :        | Master of Arts in Science        | Master of Arts in Science        |
+               :        : Teaching                         : Teaching                         :
+               :        | Science Writing                  | Science Writing                  |
+               :        | Bachelor of Arts in English      | Bachelor of Arts in English      |
+               :        | Bachelor of Arts in History      | Bachelor of Arts in History      |
+               :        | Bachelor of Arts in Political    | Bachelor of Arts in Political    |
+               :        : Science                          : Science                          :
+               :        | Bachelor of Arts in Psychology   | Bachelor of Arts in Psychology   |
+               :        | Bachelor of Arts in Spanish      | Bachelor of Arts in Spanish      |
+               | psych  | Master of Arts in English        | Master of Arts in English        |
+               :        | Master of Arts in Modern         | Master of Arts in Modern         |
+               :        : Languages                        : Languages                        :
+               :        | Master of Arts in Science        | Master of Arts in Science        |
+               :        : Teaching                         : Teaching                         :
+               :        | Science Writing                  | Science Writing                  |
+               :        | Bachelor of Arts in English      | Bachelor of Arts in English      |
+               :        | Bachelor of Arts in History      | Bachelor of Arts in History      |
+               :        | Bachelor of Arts in Political    | Bachelor of Arts in Political    |
+               :        : Science                          : Science                          :
+               :        | Bachelor of Arts in Psychology   | Bachelor of Arts in Psychology   |
+               :        | Bachelor of Arts in Spanish      | Bachelor of Arts in Spanish      |
+               | stdart | Post Baccalaureate in Art        | Post Baccalaureate in Art        |
+               :        : History                          : History                          :
+               :        | Bachelor of Arts in Art History  | Bachelor of Arts in Art History  |
+               :        | Bachelor of Arts in Studio Art   | Bachelor of Arts in Studio Art   |
+               | str    |                                  :                                  :
+               | tched  | Master of Arts in Education      | Master of Arts in Education      |
+               :        : Leadership                       : Leadership                       :
+               :        | M.S. in Education                | M.S. in Education                |
+               :        | Master of Arts in Literacy       | Master of Arts in Literacy       |
+               :        : Education                        : Education                        :
+               :        | Master of Arts in Teaching       | Master of Arts in Teaching       |
+               :        | Certificate in Science Teaching  | Certificate in Science Teaching  |
+               :        | Bachelor of Arts in Math         | Bachelor of Arts in Math         |
+               :        : Education                        : Education                        :
+               :        | Bachelor of Arts in Science      | Bachelor of Arts in Science      |
+               :        : Education                        : Education                        :
+               | voc    |                                  :                                  :
+               | win    |                                  :                                  :
+
+               ----
+               /department{code,/school.program{title},school{/program{title}}}
+               SELECT [department].[code],
+                      [school].[!]
+               FROM [ad].[department]
+                    LEFT OUTER JOIN (SELECT 1 AS [!],
+                                            [school].[code]
+                                     FROM [ad].[school]) AS [school]
+                                    ON ([department].[school_code] = [school].[code])
+               ORDER BY 1 ASC
+
+                 SELECT [program].[title],
+                        [department].[code]
+                 FROM [ad].[department]
+                      INNER JOIN [ad].[school]
+                                 ON ([department].[school_code] = [school].[code])
+                      INNER JOIN [ad].[program]
+                                 ON ([school].[code] = [program].[school_code])
+                 ORDER BY 2 ASC, [program].[school_code] ASC, [program].[code] ASC
+
+                 SELECT [program].[title],
+                        [department].[code]
+                 FROM [ad].[department]
+                      INNER JOIN [ad].[school]
+                                 ON ([department].[school_code] = [school].[code])
+                      INNER JOIN [ad].[program]
+                                 ON ([school].[code] = [program].[school_code])
+                 ORDER BY 2 ASC, [program].[school_code] ASC, [program].[code] ASC
+          - uri: /department{code, /(school?code='bus').program{title}, (school?code='bus').(/program{title}),
+              school?code='bus'{/program{title}}}.limit(3)/:json
+            status: 200 OK
+            headers:
+            - [Content-Type, application/javascript]
+            - [Content-Disposition, inline; filename="department.js"]
+            body: |
+              {
+                "department": [
+                  {
+                    "code": "acc",
+                    "program": [
+                      {
+                        "title": "Master of Arts in Economics"
+                      },
+                      {
+                        "title": "Graduate Certificate in Accounting"
+                      },
+                      {
+                        "title": "Certificate in Business Administration"
+                      },
+                      {
+                        "title": "B.S. in Accounting"
+                      },
+                      {
+                        "title": "Bachelor of Business Administration"
+                      },
+                      {
+                        "title": "Bachelor of Arts in Economics"
+                      }
+                    ],
+                    "2": [
+                      {
+                        "title": "Master of Arts in Economics"
+                      },
+                      {
+                        "title": "Graduate Certificate in Accounting"
+                      },
+                      {
+                        "title": "Certificate in Business Administration"
+                      },
+                      {
+                        "title": "B.S. in Accounting"
+                      },
+                      {
+                        "title": "Bachelor of Business Administration"
+                      },
+                      {
+                        "title": "Bachelor of Arts in Economics"
+                      }
+                    ],
+                    "school": {
+                      "program": [
+                        {
+                          "title": "Master of Arts in Economics"
+                        },
+                        {
+                          "title": "Graduate Certificate in Accounting"
+                        },
+                        {
+                          "title": "Certificate in Business Administration"
+                        },
+                        {
+                          "title": "B.S. in Accounting"
+                        },
+                        {
+                          "title": "Bachelor of Business Administration"
+                        },
+                        {
+                          "title": "Bachelor of Arts in Economics"
+                        }
+                      ]
+                    }
+                  },
+                  {
+                    "code": "arthis",
+                    "program": [],
+                    "2": []
+                  },
+                  {
+                    "code": "astro",
+                    "program": [],
+                    "2": []
+                  }
+                ]
+              }
+          - uri: /department{code, /school{code}}?count(course)>=20
+            status: 200 OK
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            - [Vary, Accept]
+            body: |2
+               | department      |
+               +--------+--------+
+               |        | school |
+               |        +--------+
+               | code   | code   |
+              -+--------+--------+-
+               | arthis | art    |
+               | astro  | ns     |
+               | comp   | eng    |
+               | eng    | la     |
+               | lang   | la     |
+               | phys   | ns     |
+
+               ----
+               /department{code,/school{code}}?count(course)>=20
+               SELECT [department].[code]
+               FROM [ad].[department]
+                    LEFT OUTER JOIN (SELECT COUNT(1) AS [count],
+                                            [course].[department_code]
+                                     FROM [ad].[course]
+                                     GROUP BY [course].[department_code]) AS [course]
+                                    ON ([department].[code] = [course].[department_code])
+               WHERE (COALESCE([course].[count], 0) >= 20)
+               ORDER BY 1 ASC
+
+                 SELECT [school].[code],
+                        [department].[code]
+                 FROM [ad].[department]
+                      LEFT OUTER JOIN (SELECT COUNT(1) AS [count],
+                                              [course].[department_code]
+                                       FROM [ad].[course]
+                                       GROUP BY [course].[department_code]) AS [course]
+                                      ON ([department].[code] = [course].[department_code])
+                      INNER JOIN [ad].[school]
+                                 ON ([department].[school_code] = [school].[code])
+                 WHERE (COALESCE([course].[count], 0) >= 20)
+                 ORDER BY 2 ASC
+          - uri: /school{*, /@school}
+            status: 200 OK
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            - [Vary, Accept]
+            body: |2
+               | school                                                                                        |
+               +------+-------------------------------+--------+-----------------------------------------------+
+               |      |                               |        | school                                        |
+               |      |                               |        +------+-------------------------------+--------+
+               | code | name                          | campus | code | name                          | campus |
+              -+------+-------------------------------+--------+------+-------------------------------+--------+-
+               | art  | School of Art & Design        | old    | art  | School of Art & Design        | old    |
+               :      :                               :        | bus  | School of Business            | south  |
+               :      :                               :        | edu  | College of Education          | old    |
+               :      :                               :        | eng  | School of Engineering         | north  |
+               :      :                               :        | la   | School of Arts and Humanities | old    |
+               :      :                               :        | mus  | School of Music & Dance       | south  |
+               :      :                               :        | ns   | School of Natural Sciences    | old    |
+               :      :                               :        | ph   | Public Honorariums            |        |
+               :      :                               :        | sc   | School of Continuing Studies  |        |
+               | bus  | School of Business            | south  | art  | School of Art & Design        | old    |
+               :      :                               :        | bus  | School of Business            | south  |
+               :      :                               :        | edu  | College of Education          | old    |
+               :      :                               :        | eng  | School of Engineering         | north  |
+               :      :                               :        | la   | School of Arts and Humanities | old    |
+               :      :                               :        | mus  | School of Music & Dance       | south  |
+               :      :                               :        | ns   | School of Natural Sciences    | old    |
+               :      :                               :        | ph   | Public Honorariums            |        |
+               :      :                               :        | sc   | School of Continuing Studies  |        |
+               | edu  | College of Education          | old    | art  | School of Art & Design        | old    |
+               :      :                               :        | bus  | School of Business            | south  |
+               :      :                               :        | edu  | College of Education          | old    |
+               :      :                               :        | eng  | School of Engineering         | north  |
+               :      :                               :        | la   | School of Arts and Humanities | old    |
+               :      :                               :        | mus  | School of Music & Dance       | south  |
+               :      :                               :        | ns   | School of Natural Sciences    | old    |
+               :      :                               :        | ph   | Public Honorariums            |        |
+               :      :                               :        | sc   | School of Continuing Studies  |        |
+               | eng  | School of Engineering         | north  | art  | School of Art & Design        | old    |
+               :      :                               :        | bus  | School of Business            | south  |
+               :      :                               :        | edu  | College of Education          | old    |
+               :      :                               :        | eng  | School of Engineering         | north  |
+               :      :                               :        | la   | School of Arts and Humanities | old    |
+               :      :                               :        | mus  | School of Music & Dance       | south  |
+               :      :                               :        | ns   | School of Natural Sciences    | old    |
+               :      :                               :        | ph   | Public Honorariums            |        |
+               :      :                               :        | sc   | School of Continuing Studies  |        |
+               | la   | School of Arts and Humanities | old    | art  | School of Art & Design        | old    |
+               :      :                               :        | bus  | School of Business            | south  |
+               :      :                               :        | edu  | College of Education          | old    |
+               :      :                               :        | eng  | School of Engineering         | north  |
+               :      :                               :        | la   | School of Arts and Humanities | old    |
+               :      :                               :        | mus  | School of Music & Dance       | south  |
+               :      :                               :        | ns   | School of Natural Sciences    | old    |
+               :      :                               :        | ph   | Public Honorariums            |        |
+               :      :                               :        | sc   | School of Continuing Studies  |        |
+               | mus  | School of Music & Dance       | south  | art  | School of Art & Design        | old    |
+               :      :                               :        | bus  | School of Business            | south  |
+               :      :                               :        | edu  | College of Education          | old    |
+               :      :                               :        | eng  | School of Engineering         | north  |
+               :      :                               :        | la   | School of Arts and Humanities | old    |
+               :      :                               :        | mus  | School of Music & Dance       | south  |
+               :      :                               :        | ns   | School of Natural Sciences    | old    |
+               :      :                               :        | ph   | Public Honorariums            |        |
+               :      :                               :        | sc   | School of Continuing Studies  |        |
+               | ns   | School of Natural Sciences    | old    | art  | School of Art & Design        | old    |
+               :      :                               :        | bus  | School of Business            | south  |
+               :      :                               :        | edu  | College of Education          | old    |
+               :      :                               :        | eng  | School of Engineering         | north  |
+               :      :                               :        | la   | School of Arts and Humanities | old    |
+               :      :                               :        | mus  | School of Music & Dance       | south  |
+               :      :                               :        | ns   | School of Natural Sciences    | old    |
+               :      :                               :        | ph   | Public Honorariums            |        |
+               :      :                               :        | sc   | School of Continuing Studies  |        |
+               | ph   | Public Honorariums            |        | art  | School of Art & Design        | old    |
+               :      :                               :        | bus  | School of Business            | south  |
+               :      :                               :        | edu  | College of Education          | old    |
+               :      :                               :        | eng  | School of Engineering         | north  |
+               :      :                               :        | la   | School of Arts and Humanities | old    |
+               :      :                               :        | mus  | School of Music & Dance       | south  |
+               :      :                               :        | ns   | School of Natural Sciences    | old    |
+               :      :                               :        | ph   | Public Honorariums            |        |
+               :      :                               :        | sc   | School of Continuing Studies  |        |
+               | sc   | School of Continuing Studies  |        | art  | School of Art & Design        | old    |
+               :      :                               :        | bus  | School of Business            | south  |
+               :      :                               :        | edu  | College of Education          | old    |
+               :      :                               :        | eng  | School of Engineering         | north  |
+               :      :                               :        | la   | School of Arts and Humanities | old    |
+               :      :                               :        | mus  | School of Music & Dance       | south  |
+               :      :                               :        | ns   | School of Natural Sciences    | old    |
+               :      :                               :        | ph   | Public Honorariums            |        |
+               :      :                               :        | sc   | School of Continuing Studies  |        |
+
+               ----
+               /school{*,/@school}
+               SELECT [school].[code],
+                      [school].[name],
+                      [school].[campus]
+               FROM [ad].[school]
+               ORDER BY 1 ASC
+
+                 SELECT [school_2].[code],
+                        [school_2].[name],
+                        [school_2].[campus],
+                        [school_1].[code]
+                 FROM [ad].[school] AS [school_1]
+                      CROSS JOIN [ad].[school] AS [school_2]
+                 ORDER BY 4 ASC, 1 ASC
+          - uri: /school?exists(program){*, /fork(campus)}
+            status: 200 OK
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            - [Vary, Accept]
+            body: |2
+               | school                                                                                        |
+               +------+-------------------------------+--------+-----------------------------------------------+
+               |      |                               |        | fork(campus)                                  |
+               |      |                               |        +------+-------------------------------+--------+
+               | code | name                          | campus | code | name                          | campus |
+              -+------+-------------------------------+--------+------+-------------------------------+--------+-
+               | art  | School of Art & Design        | old    | art  | School of Art & Design        | old    |
+               :      :                               :        | edu  | College of Education          | old    |
+               :      :                               :        | la   | School of Arts and Humanities | old    |
+               :      :                               :        | ns   | School of Natural Sciences    | old    |
+               | bus  | School of Business            | south  | bus  | School of Business            | south  |
+               | edu  | College of Education          | old    | art  | School of Art & Design        | old    |
+               :      :                               :        | edu  | College of Education          | old    |
+               :      :                               :        | la   | School of Arts and Humanities | old    |
+               :      :                               :        | ns   | School of Natural Sciences    | old    |
+               | eng  | School of Engineering         | north  | eng  | School of Engineering         | north  |
+               | la   | School of Arts and Humanities | old    | art  | School of Art & Design        | old    |
+               :      :                               :        | edu  | College of Education          | old    |
+               :      :                               :        | la   | School of Arts and Humanities | old    |
+               :      :                               :        | ns   | School of Natural Sciences    | old    |
+               | ns   | School of Natural Sciences    | old    | art  | School of Art & Design        | old    |
+               :      :                               :        | edu  | College of Education          | old    |
+               :      :                               :        | la   | School of Arts and Humanities | old    |
+               :      :                               :        | ns   | School of Natural Sciences    | old    |
+               | ph   | Public Honorariums            |        |      :                               :        :
+
+               ----
+               /school?exists(program){*,/fork(campus)}
+               SELECT [school].[code],
+                      [school].[name],
+                      [school].[campus]
+               FROM [ad].[school]
+               WHERE EXISTS(SELECT 1
+                            FROM [ad].[program]
+                            WHERE ([school].[code] = [program].[school_code])
+                                  AND (1 <> 0))
+               ORDER BY 1 ASC
+
+                 SELECT [school_2].[code],
+                        [school_2].[name],
+                        [school_2].[campus],
+                        [school_1].[code]
+                 FROM [ad].[school] AS [school_1]
+                      INNER JOIN (SELECT [school].[code],
+                                         [school].[name],
+                                         [school].[campus]
+                                  FROM [ad].[school]
+                                  WHERE EXISTS(SELECT 1
+                                               FROM [ad].[program]
+                                               WHERE ([school].[code] = [program].[school_code])
+                                                     AND (1 <> 0))) AS [school_2]
+                                 ON ([school_1].[campus] = [school_2].[campus])
+                 WHERE EXISTS(SELECT 1
+                              FROM [ad].[program]
+                              WHERE ([school_1].[code] = [program].[school_code])
+                                    AND (1 <> 0))
+                 ORDER BY 4 ASC, 1 ASC
+          - uri: /school{code, department.(/course)}
+            status: 400 Bad Request
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            body: |
+              compile error: a singular expression is expected:
+                  /school{code, department.(/course)}
+                                ^^^^^^^^^^
+          - uri: /school{code, department{/course}}
+            status: 400 Bad Request
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            body: |
+              compile error: a singular expression is expected:
+                  /school{code, department{/course}}
+                                ^^^^^^^^^^^^^^^^^^^
+          - uri: /school{code, /root().department}
+            status: 400 Bad Request
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            body: |
+              encode error: a descendant segment flow is expected:
+                  /school{code, /root().department}
+                                ^^^^^^^^^^^^^^^^^^
       - id: known-issues
         tests:
         - uri: /school.true()
             SELECT '\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\n \uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD',\n
             \       '\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD',\n
             \       '\u03BE',\n        '\\/%''\"&<>#',\n        ''\n"
+      - id: nested-segments
+        tests:
+        - uri: /{/null, /school.limit(3), /department.limit(5)}/:raw
+          status: 200 OK
+          headers:
+          - [Content-Type, application/javascript]
+          - [Content-Disposition, inline; filename="_.js"]
+          body: |
+            {
+              "meta": {
+                "domain": {
+                  "type": "list",
+                  "item": {
+                    "domain": {
+                      "type": "record",
+                      "fields": [
+                        {
+                          "domain": {
+                            "type": "list",
+                            "item": {
+                              "domain": {
+                                "type": "string"
+                              }
+                            }
+                          },
+                          "header": "null",
+                          "syntax": "\/null",
+                          "tag": "null"
+                        },
+                        {
+                          "domain": {
+                            "type": "list",
+                            "item": {
+                              "domain": {
+                                "type": "record",
+                                "fields": [
+                                  {
+                                    "domain": {
+                                      "type": "string"
+                                    },
+                                    "header": "code",
+                                    "path": "school.code",
+                                    "syntax": "code",
+                                    "tag": "code"
+                                  },
+                                  {
+                                    "domain": {
+                                      "type": "string"
+                                    },
+                                    "header": "name",
+                                    "path": "school.name",
+                                    "syntax": "name",
+                                    "tag": "name"
+                                  },
+                                  {
+                                    "domain": {
+                                      "type": "string"
+                                    },
+                                    "header": "campus",
+                                    "path": "school.campus",
+                                    "syntax": "campus",
+                                    "tag": "campus"
+                                  }
+                                ]
+                              }
+                            }
+                          },
+                          "header": "school",
+                          "path": "school",
+                          "syntax": "\/school.limit(3)",
+                          "tag": "school"
+                        },
+                        {
+                          "domain": {
+                            "type": "list",
+                            "item": {
+                              "domain": {
+                                "type": "record",
+                                "fields": [
+                                  {
+                                    "domain": {
+                                      "type": "string"
+                                    },
+                                    "header": "code",
+                                    "path": "department.code",
+                                    "syntax": "code",
+                                    "tag": "code"
+                                  },
+                                  {
+                                    "domain": {
+                                      "type": "string"
+                                    },
+                                    "header": "name",
+                                    "path": "department.name",
+                                    "syntax": "name",
+                                    "tag": "name"
+                                  },
+                                  {
+                                    "domain": {
+                                      "type": "string"
+                                    },
+                                    "header": "school_code",
+                                    "path": "department.school_code",
+                                    "syntax": "school_code",
+                                    "tag": "school_code"
+                                  }
+                                ]
+                              }
+                            }
+                          },
+                          "header": "department",
+                          "path": "department",
+                          "syntax": "\/department.limit(5)",
+                          "tag": "department"
+                        }
+                      ]
+                    }
+                  }
+                },
+                "path": "",
+                "syntax": "\/{\/null,\/school.limit(3),\/department.limit(5)}"
+              },
+              "data": [
+                [
+                  [],
+                  [
+                    [
+                      "art",
+                      "School of Art & Design",
+                      "old"
+                    ],
+                    [
+                      "bus",
+                      "School of Business",
+                      "south"
+                    ],
+                    [
+                      "edu",
+                      "College of Education",
+                      "old"
+                    ]
+                  ],
+                  [
+                    [
+                      "acc",
+                      "Accounting",
+                      "bus"
+                    ],
+                    [
+                      "arthis",
+                      "Art History",
+                      "art"
+                    ],
+                    [
+                      "astro",
+                      "Astronomy",
+                      "ns"
+                    ],
+                    [
+                      "be",
+                      "Bioengineering",
+                      "eng"
+                    ],
+                    [
+                      "bursar",
+                      "Bursar's Office",
+                      null
+                    ]
+                  ]
+                ]
+              ]
+            }
+        - uri: /{/null, /school.limit(3), /department.limit(5)}/:json
+          status: 200 OK
+          headers:
+          - [Content-Type, application/javascript]
+          - [Content-Disposition, inline; filename="_.js"]
+          body: |
+            {
+              "0": [
+                {
+                  "null": [],
+                  "school": [
+                    {
+                      "code": "art",
+                      "name": "School of Art & Design",
+                      "campus": "old"
+                    },
+                    {
+                      "code": "bus",
+                      "name": "School of Business",
+                      "campus": "south"
+                    },
+                    {
+                      "code": "edu",
+                      "name": "College of Education",
+                      "campus": "old"
+                    }
+                  ],
+                  "department": [
+                    {
+                      "code": "acc",
+                      "name": "Accounting",
+                      "school_code": "bus"
+                    },
+                    {
+                      "code": "arthis",
+                      "name": "Art History",
+                      "school_code": "art"
+                    },
+                    {
+                      "code": "astro",
+                      "name": "Astronomy",
+                      "school_code": "ns"
+                    },
+                    {
+                      "code": "be",
+                      "name": "Bioengineering",
+                      "school_code": "eng"
+                    },
+                    {
+                      "code": "bursar",
+                      "name": "Bursar's Office"
+                    }
+                  ]
+                }
+              ]
+            }
+        - uri: /{/null, /school.limit(3), /department.limit(5)}/:csv
+          status: 200 OK
+          headers:
+          - [Content-Type, text/csv; charset=UTF-8]
+          - [Content-Disposition, attachment; filename="_.csv"]
+          body: "null,code,name,campus,code,name,school_code\r\n,art,School of Art
+            & Design,old,acc,Accounting,bus\r\n,bus,School of Business,south,arthis,Art
+            History,art\r\n,edu,College of Education,old,astro,Astronomy,ns\r\n,,,,be,Bioengineering,eng\r\n,,,,bursar,Bursar's
+            Office,\r\n"
+        - uri: /{/null, /school.limit(3), /department.limit(5)}/:tsv
+          status: 200 OK
+          headers:
+          - [Content-Type, text/tab-separated-values; charset=UTF-8]
+          - [Content-Disposition, attachment; filename="_.tsv"]
+          body: "null\tcode\tname\tcampus\tcode\tname\tschool_code\r\n\tart\tSchool
+            of Art & Design\told\tacc\tAccounting\tbus\r\n\tbus\tSchool of Business\tsouth\tarthis\tArt
+            History\tart\r\n\tedu\tCollege of Education\told\tastro\tAstronomy\tns\r\n\t\t\t\tbe\tBioengineering\teng\r\n\t\t\t\tbursar\tBursar's
+            Office\t\r\n"
+        - uri: /{/null, /school.limit(3), /department.limit(5)}/:xml
+          status: 200 OK
+          headers:
+          - [Content-Type, application/xml]
+          - [Content-Disposition, inline; filename="_.xml"]
+          body: |
+            <?xml version="1.0" encoding="UTF-8" ?>
+            <htsql:result xmlns:htsql="http://htsql.org/2010/xml">
+              <_>
+                <school>
+                  <code>art</code>
+                  <name>School of Art &amp; Design</name>
+                  <campus>old</campus>
+                </school>
+                <school>
+                  <code>bus</code>
+                  <name>School of Business</name>
+                  <campus>south</campus>
+                </school>
+                <school>
+                  <code>edu</code>
+                  <name>College of Education</name>
+                  <campus>old</campus>
+                </school>
+                <department>
+                  <code>acc</code>
+                  <name>Accounting</name>
+                  <school_code>bus</school_code>
+                </department>
+                <department>
+                  <code>arthis</code>
+                  <name>Art History</name>
+                  <school_code>art</school_code>
+                </department>
+                <department>
+                  <code>astro</code>
+                  <name>Astronomy</name>
+                  <school_code>ns</school_code>
+                </department>
+                <department>
+                  <code>be</code>
+                  <name>Bioengineering</name>
+                  <school_code>eng</school_code>
+                </department>
+                <department>
+                  <code>bursar</code>
+                  <name>Bursar's Office</name>
+                </department>
+              </_>
+            </htsql:result>
+        - uri: /{/null, /school.limit(3), /department.limit(5)}/:html
+          status: 200 OK
+          headers:
+          - [Content-Type, text/html; charset=UTF-8]
+          body: |
+            <!DOCTYPE html>
+            <html>
+            <head>
+            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+            <title></title>
+            <style type="text/css">
+            table.htsql-output { font-family: "Arial", sans-serif; font-size: 13px; line-height: 1.3; margin: 1em auto; color: #000000; background-color: #ffffff; border-collapse: collapse; border: 1px double #f2f2f2; -moz-box-shadow: 1px 1px 3px rgba(0,0,0,0.25); -webkit-box-shadow: 1px 1px 3px rgba(0,0,0,0.25); box-shadow: 1px 1px 3px rgba(0,0,0,0.25) }
+            table.htsql-output > thead { background-color: #f2f2f2; border-bottom: 1px solid #1a1a1a }
+            table.htsql-output > thead > tr > th { font-weight: bold; padding: 0.2em 0.5em; text-align: center; vertical-align: bottom; overflow: hidden; word-wrap: break-word; border-top: 1px solid #999999; border-left: 1px solid #999999 }
+            table.htsql-output > thead > tr > th.htsql-empty-header:after { content: "\A0" }
+            table.htsql-output > tbody > tr.htsql-odd-row { background-color: #ffffff }
+            table.htsql-output > tbody > tr.htsql-even-row { background-color: #f2f2f2 }
+            table.htsql-output > tbody > tr:hover { color: #ffffff; background-color: #333333 }
+            table.htsql-output > tbody > tr > td { padding: 0.2em 0.5em; vertical-align: baseline; overflow: hidden; word-wrap: break-word; border-left: 1px solid #999999; border-right: 1px solid #999999 }
+            table.htsql-output > tbody > tr > td.htsql-integer-type { text-align: right }
+            table.htsql-output > tbody > tr > td.htsql-decimal-type { text-align: right }
+            table.htsql-output > tbody > tr > td.htsql-float-type { text-align: right }
+            table.htsql-output > tbody > tr > td.htsql-null-value:after { content: "\A0" }
+            table.htsql-output > tbody > tr > td.htsql-empty-value { color: #999999 }
+            table.htsql-output > tbody > tr > td.htsql-empty-value:after { content: "\2B1A" }
+            table.htsql-output > tbody > tr > td.htsql-false-value { font-style: italic }
+            table.htsql-output > tbody > tr > td.htsql-null-record-value { border-left-style: dashed; border-right-style: dashed }
+            table.htsql-output > tbody > tr > td.htsql-section { border-top: 1px dotted #999999 }
+            table.htsql-output > tbody > tr > td.htsql-index { font-size: 90%; font-weight: bold; text-align: right; width: 0; color: #999999; border-left-style: solid; border-right-color: #1a1a1a; -moz-user-select: none; -webkit-user-select: none; user-select: none }
+            div.htsql-welcome { font-family: "Arial", sans-serif; font-size: 13px; line-height: 1.3; text-align: center; margin: 1em auto; color: #000000; background-color: #ffffff }
+            div.htsql-welcome > h1 { font-size: 200%; font-weight: bold; margin: 1px 0 0 }
+            div.htsql-welcome > p { margin: 1px 0 0 }
+            </style>
+            </head>
+            <body>
+            <table class="htsql-output" summary="">
+            <thead>
+            <tr><th rowspan="2" class="htsql-empty-header"></th><th colspan="2" rowspan="2">null</th><th colspan="4">school</th><th colspan="4">department</th></tr>
+            <tr><th class="htsql-empty-header"></th><th>code</th><th>name</th><th>campus</th><th class="htsql-empty-header"></th><th>code</th><th>name</th><th>school_code</th></tr>
+            </thead>
+            <tbody>
+            <tr class="htsql-odd-row"><td rowspan="5" class="htsql-section htsql-index">1</td><td rowspan="5" class="htsql-section htsql-index htsql-null-record-value"></td><td rowspan="5" class="htsql-section htsql-null-record-value"></td><td class="htsql-section htsql-index">1</td><td class="htsql-section htsql-string-type">art</td><td class="htsql-section htsql-string-type">School of Art &amp; Design</td><td class="htsql-section htsql-string-type">old</td><td class="htsql-section htsql-index">1</td><td class="htsql-section htsql-string-type">acc</td><td class="htsql-section htsql-string-type">Accounting</td><td class="htsql-section htsql-string-type">bus</td></tr>
+            <tr class="htsql-even-row"><td class="htsql-index">2</td><td class="htsql-string-type">bus</td><td class="htsql-string-type">School of Business</td><td class="htsql-string-type">south</td><td class="htsql-index">2</td><td class="htsql-string-type">arthis</td><td class="htsql-string-type">Art History</td><td class="htsql-string-type">art</td></tr>
+            <tr class="htsql-odd-row"><td rowspan="3" class="htsql-index">3</td><td rowspan="3" class="htsql-string-type">edu</td><td rowspan="3" class="htsql-string-type">College of Education</td><td rowspan="3" class="htsql-string-type">old</td><td class="htsql-index">3</td><td class="htsql-string-type">astro</td><td class="htsql-string-type">Astronomy</td><td class="htsql-string-type">ns</td></tr>
+            <tr class="htsql-even-row"><td class="htsql-index">4</td><td class="htsql-string-type">be</td><td class="htsql-string-type">Bioengineering</td><td class="htsql-string-type">eng</td></tr>
+            <tr class="htsql-odd-row"><td class="htsql-index">5</td><td class="htsql-string-type">bursar</td><td class="htsql-string-type">Bursar's Office</td><td class="htsql-string-type htsql-null-value"></td></tr>
+            </tbody>
+            </table>
+            </body>
+            </html>
+        - uri: /{/null, /school.limit(3), /department.limit(5)}/:txt
+          status: 200 OK
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |2
+             |      | school                                 | department                             |
+             |      +------+------------------------+--------+--------+-----------------+-------------+
+             | null | code | name                   | campus | code   | name            | school_code |
+            -+------+------+------------------------+--------+--------+-----------------+-------------+-
+             :      | art  | School of Art & Design | old    | acc    | Accounting      | bus         |
+             :      | bus  | School of Business     | south  | arthis | Art History     | art         |
+             :      | edu  | College of Education   | old    | astro  | Astronomy       | ns          |
+             :      :      :                        :        | be     | Bioengineering  | eng         |
+             :      :      :                        :        | bursar | Bursar's Office |             |
+
+             ----
+             /{/null,/school.limit(3),/department.limit(5)}
+             SELECT 1
+
+               SELECT NULL
+               WHERE (0 <> 0)
+
+               SELECT TOP 3
+                      [school].[code],
+                      [school].[name],
+                      [school].[campus]
+               FROM [ad].[school]
+               ORDER BY 1 ASC
+
+               SELECT TOP 5
+                      [department].[code],
+                      [department].[name],
+                      [department].[school_code]
+               FROM [ad].[department]
+               ORDER BY 1 ASC
+        - uri: /school?code={'edu','mus','sc'} {name, /program{degree, title}, /department{name,
+            /course{no, title}}}/:raw
+          status: 200 OK
+          headers:
+          - [Content-Type, application/javascript]
+          - [Content-Disposition, inline; filename="school.js"]
+          body: |
+            {
+              "meta": {
+                "domain": {
+                  "type": "list",
+                  "item": {
+                    "domain": {
+                      "type": "record",
+                      "fields": [