Commits

Kirill Simonov committed 05ce07f

Fixed an assertion error when top() gets a singular argument.

Comments (0)

Files changed (7)

src/htsql/core/tr/encode.py

     def __call__(self):
         base = self.state.relate(self.binding.base)
         seed = self.state.relate(self.binding.seed)
+        if not (seed.spans(base) and not base.spans(seed)):
+            raise EncodeError("a plural expression is expected",
+                              self.binding.seed.mark)
         return ClippedFlow(base, seed, self.binding.limit,
                            self.binding.offset, self.binding)
 

test/input/translation.yaml

     - uri: /school{name, count(program),
             /top(program,3,2){title, count(student)}}?campus='old'
     - uri: /school^campus{*, top(^)}
+    - uri: /department.top(school)
+      expect: 400
     - uri: /class^{year, season}
                 {*, /top(^.sort(count(enrollment)-),3).course{title}}
       ifndef: sqlite    # Too slow.

test/output/mssql.yaml

                                       AND ([school].[top] < 2)) AS [school_2]
                                ON ([school_1].[campus] = [school_2].[campus])
                ORDER BY 1 ASC
+          - uri: /department.top(school)
+            status: 400 Bad Request
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            body: |
+              encode error: a plural expression is expected:
+                  /department.top(school)
+                                  ^^^^^^
           - uri: /class^{year, season} {*, /top(^.sort(count(enrollment)-),3).course{title}}
             status: 200 OK
             headers:

test/output/mysql.yaml

                                       AND (`school`.`top_1` < 2)) AS `school_2`
                                ON (`school_1`.`campus` = `school_2`.`campus`)
                ORDER BY 1 ASC
+          - uri: /department.top(school)
+            status: 400 Bad Request
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            body: |
+              encode error: a plural expression is expected:
+                  /department.top(school)
+                                  ^^^^^^
           - uri: /class^{year, season} {*, /top(^.sort(count(enrollment)-),3).course{title}}
             status: 200 OK
             headers:

test/output/oracle.yaml

                                       AND ("SCHOOL"."top" < 2)) "SCHOOL_2"
                                ON ("SCHOOL_1"."CAMPUS" = "SCHOOL_2"."CAMPUS")
                ORDER BY 1 ASC NULLS FIRST
+          - uri: /department.top(school)
+            status: 400 Bad Request
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            body: |
+              encode error: a plural expression is expected:
+                  /department.top(school)
+                                  ^^^^^^
           - uri: /class^{year, season} {*, /top(^.sort(count(enrollment)-),3).course{title}}
             status: 200 OK
             headers:

test/output/pgsql.yaml

                                       AND ("school"."top" < 2)) AS "school_2"
                                ON ("school_1"."campus" = "school_2"."campus")
                ORDER BY 1 ASC NULLS FIRST
+          - uri: /department.top(school)
+            status: 400 Bad Request
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            body: |
+              encode error: a plural expression is expected:
+                  /department.top(school)
+                                  ^^^^^^
           - uri: /class^{year, season} {*, /top(^.sort(count(enrollment)-),3).course{title}}
             status: 200 OK
             headers:

test/output/sqlite.yaml

                                                            LIMIT 1))) AS "school_2"
                                ON ("school_1"."campus" = "school_2"."campus")
                ORDER BY 1 ASC
+          - uri: /department.top(school)
+            status: 400 Bad Request
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            body: |
+              encode error: a plural expression is expected:
+                  /department.top(school)
+                                  ^^^^^^
           - uri: /class^{year, season} {*, /top(^.sort(count(enrollment)-),3).course{title}}
             status: 200 OK
             headers: