Commits

Kirill Simonov committed 145a791

Fixed rewriting of an ordered space.

Comments (0)

Files changed (7)

src/htsql/tr/rewrite.py

         if not self.space.is_expanding:
             return self.space.clone(order=order)
         base = self.state.rewrite(self.space.base)
-        return self.space.clone(base=base)
+        return self.space.clone(base=base, order=order)
 
 
 class RewriteCode(Rewrite):

test/regress/input/translation.yaml

     - uri: /program.school{code, root().program{code, degree},
                            count(root(){(program?degree='ba').school.department})}
                            ?code~'a'
+    - uri: /department{name,sum(course.credits)-,avg(course.credits)}?sum(course.credits)
 
   - title: Root, This, Direct and Fiber functions
     tests:

test/regress/output/mssql.yaml

                                     ON (([program].[school] = [department].[school]) AND ([program].[code] = [department].[code]))
                WHERE ([school].[code] LIKE '%a%' ESCAPE '\')
                ORDER BY [program].[school] ASC, 2 ASC
+          - uri: /department{name,sum(course.credits)-,avg(course.credits)}?sum(course.credits)
+            status: 200 OK
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            body: |2
+               | (department?sum(course.credits))                                    |
+              -+---------------------------------------------------------------------+-
+               | name                   | sum(course.credits)- | avg(course.credits) |
+              -+------------------------+----------------------+---------------------+-
+               | Computer Science       |                   22 |            3.142857 |
+               | Accounting             |                   19 |            3.166666 |
+               | Art History            |                   19 |            3.166666 |
+               | Political Science      |                   19 |            3.166666 |
+               | Studio Art             |                   19 |            3.166666 |
+               | Bioengineering         |                   17 |            4.250000 |
+               | Mechanical Engineering |                   17 |            3.400000 |
+               | Physics                |                   17 |            2.833333 |
+               | Psychology             |                   17 |            3.400000 |
+               | Electrical Engineering |                   16 |            3.200000 |
+               | English                |                   16 |            2.666666 |
+               | Teacher Education      |                   16 |            3.200000 |
+               | History                |                   15 |            3.000000 |
+               | Foreign Languages      |                   15 |            3.000000 |
+               | Chemistry              |                   14 |            2.800000 |
+               | Capital Markets        |                   12 |            3.000000 |
+               | Educational Policy     |                   12 |            3.000000 |
+               | Astronomy              |                    9 |            2.250000 |
+               | Corporate Finance      |                    9 |            3.000000 |
+               | Mathematics            |                    5 |            5.000000 |
+               | Bursar's Office        |                    0 |                     |
+               | Career Development     |                    0 |                     |
+               | Parents & Alumni       |                    0 |                     |
+               | Piano                  |                    0 |                     |
+               | Strings                |                    0 |                     |
+               | Vocals                 |                    0 |                     |
+               | Wind                   |                    0 |                     |
+                                                                             (27 rows)
+
+               ----
+               /department{name,sum(course.credits)-,avg(course.credits)}?sum(course.credits)
+               SELECT [department].[name],
+                      COALESCE([course_1].[sum], 0),
+                      [course_2].[avg]
+               FROM [ad].[department] AS [department]
+                    LEFT OUTER JOIN (SELECT SUM([course].[credits]) AS [sum],
+                                            [course].[department]
+                                     FROM [ad].[course] AS [course]
+                                     GROUP BY [course].[department]) AS [course_1]
+                                    ON ([department].[code] = [course_1].[department])
+                    LEFT OUTER JOIN (SELECT AVG(CAST([course].[credits] AS DECIMAL(38))) AS [avg],
+                                            [course].[department]
+                                     FROM [ad].[course] AS [course]
+                                     GROUP BY [course].[department]) AS [course_2]
+                                    ON ([department].[code] = [course_2].[department])
+               WHERE (COALESCE([course_1].[sum], 0) IS NOT NULL)
+               ORDER BY 2 DESC, [department].[code] ASC
         - id: root,-this,-direct-and-fiber-functions
           tests:
           - uri: /{count(school)*count(department),count(school.fiber(department))}

test/regress/output/mysql.yaml

                                     ON ((`program`.`school` = `department`.`school`) AND (`program`.`code` = `department`.`code`))
                WHERE (`school`.`code` LIKE '%a%')
                ORDER BY `program`.`school` ASC, 2 ASC
+          - uri: /department{name,sum(course.credits)-,avg(course.credits)}?sum(course.credits)
+            status: 200 OK
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            body: |2
+               | (department?sum(course.credits))                                                 |
+              -+----------------------------------------------------------------------------------+-
+               | name                   | sum(course.credits)- | avg(course.credits)              |
+              -+------------------------+----------------------+----------------------------------+-
+               | Computer Science       |                   22 | 3.142857142857142857142857142857 |
+               | Accounting             |                   19 | 3.166666666666666666666666666667 |
+               | Art History            |                   19 | 3.166666666666666666666666666667 |
+               | Political Science      |                   19 | 3.166666666666666666666666666667 |
+               | Studio Art             |                   19 | 3.166666666666666666666666666667 |
+               | Bioengineering         |                   17 | 4.250000000000000000000000000000 |
+               | Mechanical Engineering |                   17 | 3.400000000000000000000000000000 |
+               | Physics                |                   17 | 2.833333333333333333333333333333 |
+               | Psychology             |                   17 | 3.400000000000000000000000000000 |
+               | Electrical Engineering |                   16 | 3.200000000000000000000000000000 |
+               | English                |                   16 | 2.666666666666666666666666666667 |
+               | Teacher Education      |                   16 | 3.200000000000000000000000000000 |
+               | History                |                   15 | 3.000000000000000000000000000000 |
+               | Foreign Languages      |                   15 | 3.000000000000000000000000000000 |
+               | Chemistry              |                   14 | 2.800000000000000000000000000000 |
+               | Capital Markets        |                   12 | 3.000000000000000000000000000000 |
+               | Educational Policy     |                   12 | 3.000000000000000000000000000000 |
+               | Astronomy              |                    9 | 2.250000000000000000000000000000 |
+               | Corporate Finance      |                    9 | 3.000000000000000000000000000000 |
+               | Mathematics            |                    5 | 5.000000000000000000000000000000 |
+               | Bursar's Office        |                    0 |                                  |
+               | Career Development     |                    0 |                                  |
+               | Parents & Alumni       |                    0 |                                  |
+               | Piano                  |                    0 |                                  |
+               | Strings                |                    0 |                                  |
+               | Vocals                 |                    0 |                                  |
+               | Wind                   |                    0 |                                  |
+                                                                                          (27 rows)
+
+               ----
+               /department{name,sum(course.credits)-,avg(course.credits)}?sum(course.credits)
+               SELECT `department`.`name`,
+                      COALESCE(`course_1`.`sum`, 0),
+                      `course_2`.`avg`
+               FROM `htsql_regress`.`department` AS `department`
+                    LEFT OUTER JOIN (SELECT CAST(SUM(`course`.`credits`) AS SIGNED INTEGER) AS `sum`,
+                                            `course`.`department`
+                                     FROM `htsql_regress`.`course` AS `course`
+                                     GROUP BY 2) AS `course_1`
+                                    ON (`department`.`code` = `course_1`.`department`)
+                    LEFT OUTER JOIN (SELECT AVG(CAST(`course`.`credits` AS DECIMAL(65,30))) AS `avg`,
+                                            `course`.`department`
+                                     FROM `htsql_regress`.`course` AS `course`
+                                     GROUP BY 2) AS `course_2`
+                                    ON (`department`.`code` = `course_2`.`department`)
+               WHERE (COALESCE(`course_1`.`sum`, 0) IS NOT NULL)
+               ORDER BY 2 DESC, `department`.`code` ASC
         - id: root,-this,-direct-and-fiber-functions
           tests:
           - uri: /{count(school)*count(department),count(school.fiber(department))}

test/regress/output/oracle.yaml

                                     ON (("PROGRAM"."SCHOOL" = "DEPARTMENT"."SCHOOL") AND ("PROGRAM"."CODE" = "DEPARTMENT"."CODE"))
                WHERE ("SCHOOL"."CODE" LIKE '%a%' ESCAPE '\')
                ORDER BY "PROGRAM"."SCHOOL" ASC, 2 ASC
+          - uri: /department{name,sum(course.credits)-,avg(course.credits)}?sum(course.credits)
+            status: 200 OK
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            body: |2
+               | (department?sum(course.credits))                                                         |
+              -+------------------------------------------------------------------------------------------+-
+               | name                   | sum(course.credits)- | avg(course.credits)                      |
+              -+------------------------+----------------------+------------------------------------------+-
+               | Computer Science       |                   22 | 3.14285714285714285714285714285714285714 |
+               | Accounting             |                   19 | 3.16666666666666666666666666666666666667 |
+               | Art History            |                   19 | 3.16666666666666666666666666666666666667 |
+               | Political Science      |                   19 | 3.16666666666666666666666666666666666667 |
+               | Studio Art             |                   19 | 3.16666666666666666666666666666666666667 |
+               | Bioengineering         |                   17 |                                     4.25 |
+               | Mechanical Engineering |                   17 |                                      3.4 |
+               | Physics                |                   17 | 2.83333333333333333333333333333333333333 |
+               | Psychology             |                   17 |                                      3.4 |
+               | Electrical Engineering |                   16 |                                      3.2 |
+               | English                |                   16 | 2.66666666666666666666666666666666666667 |
+               | Teacher Education      |                   16 |                                      3.2 |
+               | History                |                   15 |                                        3 |
+               | Foreign Languages      |                   15 |                                        3 |
+               | Chemistry              |                   14 |                                      2.8 |
+               | Capital Markets        |                   12 |                                        3 |
+               | Educational Policy     |                   12 |                                        3 |
+               | Astronomy              |                    9 |                                     2.25 |
+               | Corporate Finance      |                    9 |                                        3 |
+               | Mathematics            |                    5 |                                        5 |
+               | Bursar's Office        |                    0 |                                          |
+               | Career Development     |                    0 |                                          |
+               | Parents & Alumni       |                    0 |                                          |
+               | Piano                  |                    0 |                                          |
+               | Strings                |                    0 |                                          |
+               | Vocals                 |                    0 |                                          |
+               | Wind                   |                    0 |                                          |
+                                                                                                  (27 rows)
+
+               ----
+               /department{name,sum(course.credits)-,avg(course.credits)}?sum(course.credits)
+               SELECT "DEPARTMENT"."NAME",
+                      COALESCE("COURSE_1"."sum", 0),
+                      "COURSE_2"."avg"
+               FROM "HTSQL_REGRESS"."DEPARTMENT" "DEPARTMENT"
+                    LEFT OUTER JOIN (SELECT SUM("COURSE"."CREDITS") AS "sum",
+                                            "COURSE"."DEPARTMENT"
+                                     FROM "HTSQL_REGRESS"."COURSE" "COURSE"
+                                     GROUP BY "COURSE"."DEPARTMENT") "COURSE_1"
+                                    ON ("DEPARTMENT"."CODE" = "COURSE_1"."DEPARTMENT")
+                    LEFT OUTER JOIN (SELECT AVG("COURSE"."CREDITS") AS "avg",
+                                            "COURSE"."DEPARTMENT"
+                                     FROM "HTSQL_REGRESS"."COURSE" "COURSE"
+                                     GROUP BY "COURSE"."DEPARTMENT") "COURSE_2"
+                                    ON ("DEPARTMENT"."CODE" = "COURSE_2"."DEPARTMENT")
+               WHERE (COALESCE("COURSE_1"."sum", 0) IS NOT NULL)
+               ORDER BY 2 DESC, "DEPARTMENT"."CODE" ASC
         - id: root,-this,-direct-and-fiber-functions
           tests:
           - uri: /{count(school)*count(department),count(school.fiber(department))}

test/regress/output/pgsql.yaml

                                     ON (("program"."school" = "department"."school") AND ("program"."code" = "department"."code"))
                WHERE ("school"."code" ILIKE '%a%')
                ORDER BY "program"."school" ASC, 2 ASC
+          - uri: /department{name,sum(course.credits)-,avg(course.credits)}?sum(course.credits)
+            status: 200 OK
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            body: |2
+               | (department?sum(course.credits))                                    |
+              -+---------------------------------------------------------------------+-
+               | name                   | sum(course.credits)- | avg(course.credits) |
+              -+------------------------+----------------------+---------------------+-
+               | Computer Science       |                   22 |  3.1428571428571429 |
+               | Accounting             |                   19 |  3.1666666666666667 |
+               | Art History            |                   19 |  3.1666666666666667 |
+               | Political Science      |                   19 |  3.1666666666666667 |
+               | Studio Art             |                   19 |  3.1666666666666667 |
+               | Bioengineering         |                   17 |  4.2500000000000000 |
+               | Mechanical Engineering |                   17 |  3.4000000000000000 |
+               | Physics                |                   17 |  2.8333333333333333 |
+               | Psychology             |                   17 |  3.4000000000000000 |
+               | Electrical Engineering |                   16 |  3.2000000000000000 |
+               | English                |                   16 |  2.6666666666666667 |
+               | Teacher Education      |                   16 |  3.2000000000000000 |
+               | History                |                   15 |  3.0000000000000000 |
+               | Foreign Languages      |                   15 |  3.0000000000000000 |
+               | Chemistry              |                   14 |  2.8000000000000000 |
+               | Capital Markets        |                   12 |  3.0000000000000000 |
+               | Educational Policy     |                   12 |  3.0000000000000000 |
+               | Astronomy              |                    9 |  2.2500000000000000 |
+               | Corporate Finance      |                    9 |  3.0000000000000000 |
+               | Mathematics            |                    5 |  5.0000000000000000 |
+               | Bursar's Office        |                    0 |                     |
+               | Career Development     |                    0 |                     |
+               | Parents & Alumni       |                    0 |                     |
+               | Piano                  |                    0 |                     |
+               | Strings                |                    0 |                     |
+               | Vocals                 |                    0 |                     |
+               | Wind                   |                    0 |                     |
+                                                                             (27 rows)
+
+               ----
+               /department{name,sum(course.credits)-,avg(course.credits)}?sum(course.credits)
+               SELECT "department"."name",
+                      COALESCE("course_1"."sum", 0),
+                      "course_2"."avg"
+               FROM "ad"."department" AS "department"
+                    LEFT OUTER JOIN (SELECT SUM("course"."credits") AS "sum",
+                                            "course"."department"
+                                     FROM "ad"."course" AS "course"
+                                     GROUP BY 2) AS "course_1"
+                                    ON ("department"."code" = "course_1"."department")
+                    LEFT OUTER JOIN (SELECT AVG(CAST("course"."credits" AS NUMERIC)) AS "avg",
+                                            "course"."department"
+                                     FROM "ad"."course" AS "course"
+                                     GROUP BY 2) AS "course_2"
+                                    ON ("department"."code" = "course_2"."department")
+               WHERE (COALESCE("course_1"."sum", 0) IS NOT NULL)
+               ORDER BY 2 DESC, "department"."code" ASC
         - id: root,-this,-direct-and-fiber-functions
           tests:
           - uri: /{count(school)*count(department),count(school.fiber(department))}

test/regress/output/sqlite.yaml

                                     ON (("program"."school" = "department"."school") AND ("program"."code" = "department"."code"))
                WHERE ("school"."code" LIKE '%a%' ESCAPE '\')
                ORDER BY "program"."school" ASC, 2 ASC
+          - uri: /department{name,sum(course.credits)-,avg(course.credits)}?sum(course.credits)
+            status: 200 OK
+            headers:
+            - [Content-Type, text/plain; charset=UTF-8]
+            body: |2
+               | (department?sum(course.credits))                                    |
+              -+---------------------------------------------------------------------+-
+               | name                   | sum(course.credits)- | avg(course.credits) |
+              -+------------------------+----------------------+---------------------+-
+               | Computer Science       |                   22 |       3.14285714286 |
+               | Accounting             |                   19 |       3.16666666667 |
+               | Art History            |                   19 |       3.16666666667 |
+               | Political Science      |                   19 |       3.16666666667 |
+               | Studio Art             |                   19 |       3.16666666667 |
+               | Bioengineering         |                   17 |                4.25 |
+               | Mechanical Engineering |                   17 |                 3.4 |
+               | Physics                |                   17 |       2.83333333333 |
+               | Psychology             |                   17 |                 3.4 |
+               | Electrical Engineering |                   16 |                 3.2 |
+               | English                |                   16 |       2.66666666667 |
+               | Teacher Education      |                   16 |                 3.2 |
+               | History                |                   15 |                 3.0 |
+               | Foreign Languages      |                   15 |                 3.0 |
+               | Chemistry              |                   14 |                 2.8 |
+               | Capital Markets        |                   12 |                 3.0 |
+               | Educational Policy     |                   12 |                 3.0 |
+               | Astronomy              |                    9 |                2.25 |
+               | Corporate Finance      |                    9 |                 3.0 |
+               | Mathematics            |                    5 |                 5.0 |
+               | Bursar's Office        |                    0 |                     |
+               | Career Development     |                    0 |                     |
+               | Parents & Alumni       |                    0 |                     |
+               | Piano                  |                    0 |                     |
+               | Strings                |                    0 |                     |
+               | Vocals                 |                    0 |                     |
+               | Wind                   |                    0 |                     |
+                                                                             (27 rows)
+
+               ----
+               /department{name,sum(course.credits)-,avg(course.credits)}?sum(course.credits)
+               SELECT "department"."name",
+                      COALESCE("course_1"."sum", 0),
+                      "course_2"."avg"
+               FROM "department" AS "department"
+                    LEFT OUTER JOIN (SELECT SUM("course"."credits") AS "sum",
+                                            "course"."department"
+                                     FROM "course" AS "course"
+                                     GROUP BY 2) AS "course_1"
+                                    ON ("department"."code" = "course_1"."department")
+                    LEFT OUTER JOIN (SELECT AVG(CAST("course"."credits" AS REAL)) AS "avg",
+                                            "course"."department"
+                                     FROM "course" AS "course"
+                                     GROUP BY 2) AS "course_2"
+                                    ON ("department"."code" = "course_2"."department")
+               WHERE (COALESCE("course_1"."sum", 0) IS NOT NULL)
+               ORDER BY 2 DESC, "department"."code" ASC
         - id: root,-this,-direct-and-fiber-functions
           tests:
           - uri: /{count(school)*count(department),count(school.fiber(department))}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.