Changeset 829

Show
Ignore:
Timestamp:
11/17/08 05:48:11 (7 weeks ago)
Author:
xi
Message:

Added the hide() macro.

Location:
trunk
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/htsql/binders.py

    r804 r829  
    217217            title = binding.entitle() 
    218218            modifier = binding.modifier 
     219            if modifier.is_hidden: 
     220                title = None 
    219221            if isinstance(code.domain, domains.Tuple): 
    220222                code = functions.Id.wrap(binding, binding.mark).encode() 
     
    338340        for binding in subbindings: 
    339341            title = None 
    340             order = None 
    341             is_projection = False 
     342            order = binding.modifier.order 
     343            is_projection = binding.modifier.is_projection 
    342344            if is_composite: 
    343345                title = descriptions.CompositeTitle( 
     
    369371            if title is not None or order is not None or is_projection: 
    370372                is_projection |= binding.modifier.is_projection 
    371                 modifier = bindings.Modifier(order, is_projection) 
     373                modifier = bindings.Modifier(order, is_projection, 
     374                                             binding.modifier.is_hidden) 
    372375                yield bindings.Proxy(binding, title=title, modifier=modifier) 
    373376            else: 
  • trunk/htsql/bindings.py

    r806 r829  
    5757class Modifier(object): 
    5858 
    59     def __init__(self, order=None, is_projection=False): 
     59    def __init__(self, order=None, is_projection=False, is_hidden=False): 
    6060        assert order is None or order in [+1, -1] 
    6161        assert isinstance(is_projection, bool) 
     62        assert isinstance(is_hidden, bool) 
    6263        self.order = order 
    6364        self.is_projection = is_projection 
     65        self.is_hidden = is_hidden 
     66 
     67    def clone(self, order=None, is_projection=None, is_hidden=None): 
     68        if order is None: 
     69            order = self.order 
     70        if is_projection is None: 
     71            is_projection = self.is_projection 
     72        if is_hidden is None: 
     73            is_hidden = self.is_hidden 
     74        return Modifier(order, is_projection, is_hidden) 
    6475 
    6576 
     
    267278        assert field.parent.table is reference.table 
    268279        if code is None and field.is_column: 
    269             code = codes.Column(field.column, reference, mark) 
     280            optimized_column, optimized_reference = self.optimize( 
     281                                    parent.top, field.column, reference) 
     282            code = codes.Column(optimized_column, optimized_reference, mark) 
    270283        if title is None: 
    271284            title = str(field.identifier()) 
     
    273286        self.field = field 
    274287        self.reference = reference 
     288 
     289    def optimize(self, top, column, reference): 
     290        is_optimized = True 
     291        while is_optimized: 
     292            is_optimized = False 
     293            if reference.join is not None and reference.join.is_direct  \ 
     294            and (reference not in top.sieves or 
     295                                    not top.sieves[reference].filters): 
     296                for src, dst in reference.join.pairs: 
     297                    if dst is column: 
     298                        reference = reference.parent 
     299                        column = src 
     300                        is_optimized = True 
     301                        break 
     302        return column, reference 
    275303 
    276304    def lookup(self, identifier): 
  • trunk/htsql/codes.py

    r756 r829  
    163163        assert column.parent is reference.table 
    164164        super(Column, self).__init__(column.domain, mark) 
    165         #column, reference = self.optimize(column, reference) 
    166165        self.column = column 
    167166        self.reference = reference 
    168  
    169     def optimize(self, column, reference): 
    170         """ optimize fk column instances to prune joins (unused) 
    171  
    172         This mechanism replaces references in a table with corresponding  
    173         columns in the current table.  For example, it converts a link 
    174         like ``person.organization.org_id`` to ``person.org_id``. 
    175         """ 
    176         is_optimized = True 
    177         while is_optimized: 
    178             is_optimized = False 
    179             if reference.join is not None and reference.join.is_direct: 
    180                 for src, dst in reference.join.pairs: 
    181                     if dst is column: 
    182                         reference = reference.parent 
    183                         column = src 
    184                         is_optimized = True 
    185                         break 
    186         return column, reference 
    187167 
    188168    def get_references(self): 
  • trunk/htsql/functions.py

    r810 r829  
    28152815 
    28162816 
     2817class Hide(Function): 
     2818 
     2819    name = 'hide' 
     2820    declaration = [ 
     2821            ('unit', REQUIRED), 
     2822    ] 
     2823 
     2824    @classmethod 
     2825    def wrap(cls, parent, unit, mark, title=None, modifier=None): 
     2826        if modifier is None: 
     2827            modifier = bindings.Modifier() 
     2828        modifier = modifier.clone(is_hidden=True) 
     2829        return bindings.Proxy(unit, title=title, modifier=modifier) 
     2830 
     2831 
  • trunk/htsql_contrib/migrate_command.py

    r814 r829  
    2626        self.elements = base_elements 
    2727        self.self_references = self_references 
     28 
     29    def get_references(self): 
     30        references = super(DescendantSegment, self).get_references() 
     31        for reference in self.parent_references+self.self_references: 
     32            while reference is not None: 
     33                references.add(reference) 
     34                reference = reference.parent 
     35        return references 
    2836 
    2937 
  • trunk/test/expect.yaml

    r825 r829  
    18271827          \                                 |\n | smith.maggy   | [smak, smbl, smen]\ 
    18281828          \                                   |\n\n  -----\n  /person{id(),array(project)}/\n\ 
     1829          \  (10 rows)\n" 
     1830      - uri: /person{organization{name+},full_name+} 
     1831        status: 200 OK 
     1832        headers: 
     1833        - [Content-Type, text/plain; charset=UTF-8] 
     1834        body: " | person                                     |\n-+--------------------------------------------+-\n\ 
     1835          \ | organization{name}      | full_name        |\n-+-------------------------+------------------+-\n\ 
     1836          \ | Acorn Architecture      | WATANABE Hideo   |\n | Lake Shore Apartments\ 
     1837          \   | Tommy O'Mally    |\n | Lake Side Partners, LLC | Amy S. Buckworth\ 
     1838          \ |\n | Lake Side Partners, LLC | David Jones      |\n | Meyers Construction\ 
     1839          \     | Jack C. Meyers   |\n | Meyers Construction     | Jim Meyers    \ 
     1840          \   |\n | Meyers Construction     | Mark Thomas Hill |\n | Rudgen, Taupe,\ 
     1841          \ & Smith  | Jack Taupe       |\n | Rudgen, Taupe, & Smith  | José N. Marteñes\ 
     1842          \ |\n | Rudgen, Taupe, & Smith  | Margret N. Smith |\n\n  -----\n  /person{organization{name+},full_name+}/\n\ 
     1843          \  (10 rows)\n" 
     1844      - uri: /organization{*,hide(is_active)-} 
     1845        status: 200 OK 
     1846        headers: 
     1847        - [Content-Type, text/plain; charset=UTF-8] 
     1848        body: " | organization                                                   \ 
     1849          \ |\n-+-----------------------------------------------------------------+-\n\ 
     1850          \ | org_id      | name                    | is_active | division_of |\n\ 
     1851          -+-------------+-------------------------+-----------+-------------+-\n\ 
     1852          \ | lakeside    | Lake Side Partners, LLC |           |             |\n\ 
     1853          \ | acorn       | Acorn Architecture      | true      |             |\n\ 
     1854          \ | lake-carmen | Lake Carmen Towers      | true      | lakeside    |\n\ 
     1855          \ | meyers      | Meyers Construction     | true      |             |\n\ 
     1856          \ | meyers_elec | Meyers Electric         | true      | meyers      |\n\ 
     1857          \ | lake-apts   | Lake Shore Apartments   | false     | lakeside    |\n\ 
     1858          \ | smith       | Rudgen, Taupe, & Smith  | false     |             |\n\n\ 
     1859          \  -----\n  /organization{*,hide(is_active)-}/\n  (7 rows)\n" 
     1860      - uri: /organization{*,hide(is_active)-}/person{id()} 
     1861        status: 200 OK 
     1862        headers: 
     1863        - [Content-Type, text/plain; charset=UTF-8] 
     1864        body: " | organization                                                   \ 
     1865          \ | person        |\n-+-----------------------------------------------------------------+---------------+-\n\ 
     1866          \ | org_id      | name                    | is_active | division_of | id()\ 
     1867          \          |\n-+-------------+-------------------------+-----------+-------------+---------------+-\n\ 
     1868          \ | lakeside    | Lake Side Partners, LLC |           |             | lakeside.amy\ 
     1869          \  |\n |                                                               \ 
     1870          \  | lakeside.dave |\n | acorn       | Acorn Architecture      | true  \ 
     1871          \    |             | acorn.hideo   |\n | lake-carmen | Lake Carmen Towers\ 
     1872          \      | true      | lakeside    |               |\n | meyers      | Meyers\ 
     1873          \ Construction     | true      |             | meyers.hill   |\n |     \ 
     1874          \                                                            | meyers.jack\ 
     1875          \   |\n |                                                              \ 
     1876          \   | meyers.jim    |\n | meyers_elec | Meyers Electric         | true \ 
     1877          \     | meyers      |               |\n | lake-apts   | Lake Shore Apartments\ 
     1878          \   | false     | lakeside    | lake-apts.tom |\n | smith       | Rudgen,\ 
     1879          \ Taupe, & Smith  | false     |             | smith.jack    |\n |      \ 
     1880          \                                                           | smith.jose\ 
     1881          \    |\n |                                                             \ 
     1882          \    | smith.maggy   |\n\n  -----\n  /organization{*,hide(is_active)-}/person{id()}/\n\ 
     1883          \  (7 rows)\n" 
     1884      - uri: /person{organization{hide(name)+},hide(full_name)+,*} 
     1885        status: 200 OK 
     1886        headers: 
     1887        - [Content-Type, text/plain; charset=UTF-8] 
     1888        body: " | person                                                         \ 
     1889          \      |\n-+----------------------------------------------------------------------+-\n\ 
     1890          \ | org_id    | nickname | full_name        | email                    \ 
     1891          \  |\n-+-----------+----------+------------------+----------------------------+-\n\ 
     1892          \ | acorn     | hideo    | WATANABE Hideo   | hideo.watanabe@example.com\ 
     1893          \ |\n | lake-apts | tom      | Tommy O'Mally    |                      \ 
     1894          \      |\n | lakeside  | amy      | Amy S. Buckworth |                 \ 
     1895          \           |\n | lakeside  | dave     | David Jones      | david.joines@example.com\ 
     1896          \   |\n | meyers    | jack     | Jack C. Meyers   | jack.meyers@example.com\ 
     1897          \    |\n | meyers    | jim      | Jim Meyers       | jim.meyers@example.com\ 
     1898          \     |\n | meyers    | hill     | Mark Thomas Hill | mark.hill@example.com\ 
     1899          \      |\n | smith     | jack     | Jack Taupe       | jack.taupe@example.com\ 
     1900          \     |\n | smith     | jose     | José N. Marteñes | jose.martenes@example.com\ 
     1901          \  |\n | smith     | maggy    | Margret N. Smith | \"\"                \ 
     1902          \         |\n\n  -----\n  /person{organization{hide(name)+},hide(full_name)+,*}/\n\ 
    18291903          \  (10 rows)\n" 
    18301904    - id: comparison-tests 
     
    1338213456          SET SESSION AUTHORIZATION "htsql_regress.user"; 
    1338313457          SET ROLE "htsql_regress.admin"; 
    13384           $KEYS(string, string) <- UPDATE "op"."person" AS "_person_1" SET ("email") = (E'mary.elliott@example.com') FROM "op"."person" AS "_person_2" LEFT OUTER JOIN "op"."organization" AS "_organization_1" ON ("_person_2"."org_id" = "_organization_1"."org_id") WHERE ((("_person_1"."org_id", "_person_1"."nickname") = ("_person_2"."org_id", "_person_2"."nickname")) AND (("_organization_1"."org_id" = E'meyers') AND ("_person_2"."nickname" = E'mary'))) RETURNING "_person_1"."org_id", "_person_1"."nickname"; 
     13458          $KEYS(string, string) <- UPDATE "op"."person" AS "_person_1" SET ("email") = (E'mary.elliott@example.com') FROM "op"."person" AS "_person_2" WHERE ((("_person_1"."org_id", "_person_1"."nickname") = ("_person_2"."org_id", "_person_2"."nickname")) AND (("_person_2"."org_id" = E'meyers') AND ("_person_2"."nickname" = E'mary'))) RETURNING "_person_1"."org_id", "_person_1"."nickname"; 
    1338513459          INSERT INTO "hr"."private_info" ("_ppl_seq", "tax_ident") SELECT "_person_2"."_ppl_seq", E'XXX-YYY' FROM "op"."person" AS "_person_2" WHERE (ROW("_person_2"."org_id", "_person_2"."nickname") IN (%s)) <- $KEYS(string, string); 
    1338613460          UPDATE "hr"."private_info" AS "_private_info_1" SET ("tax_ident") = (E'XXX-YYY') FROM "op"."person" AS "_person_2" WHERE ((ROW("_person_2"."org_id", "_person_2"."nickname") IN (%s)) AND ("_person_2"."_ppl_seq" = "_private_info_1"."_ppl_seq")) <- $KEYS(string, string); 
     
    1339113465          SET ROLE "htsql_regress.admin"; 
    1339213466          $KEYS(string, string) <- INSERT INTO "op"."person" ("email", "org_id", "nickname") SELECT E'elliott.mary@example.com', (SELECT "_organization_1"."org_id" FROM "op"."organization" AS "_organization_1" WHERE ("_organization_1"."org_id" = E'meyers')), E'mary' RETURNING "org_id", "nickname"; 
    13393           $KEYS(string, string) <- UPDATE "op"."person" AS "_person_1" SET ("email") = (E'elliott.mary@example.com') FROM "op"."person" AS "_person_2" LEFT OUTER JOIN "op"."organization" AS "_organization_1" ON ("_person_2"."org_id" = "_organization_1"."org_id") WHERE ((("_person_1"."org_id", "_person_1"."nickname") = ("_person_2"."org_id", "_person_2"."nickname")) AND (("_organization_1"."org_id" = E'meyers') AND ("_person_2"."nickname" = E'mary'))) RETURNING "_person_1"."org_id", "_person_1"."nickname"; 
     13467          $KEYS(string, string) <- UPDATE "op"."person" AS "_person_1" SET ("email") = (E'elliott.mary@example.com') FROM "op"."person" AS "_person_2" WHERE ((("_person_1"."org_id", "_person_1"."nickname") = ("_person_2"."org_id", "_person_2"."nickname")) AND (("_person_2"."org_id" = E'meyers') AND ("_person_2"."nickname" = E'mary'))) RETURNING "_person_1"."org_id", "_person_1"."nickname"; 
    1339413468          INSERT INTO "hr"."private_info" ("_ppl_seq", "tax_ident") SELECT "_person_2"."_ppl_seq", E'YYY-XXX' FROM "op"."person" AS "_person_2" WHERE (ROW("_person_2"."org_id", "_person_2"."nickname") IN (%s)) <- $KEYS(string, string); 
    1339513469          UPDATE "hr"."private_info" AS "_private_info_1" SET ("tax_ident") = (E'YYY-XXX') FROM "op"."person" AS "_person_2" WHERE ((ROW("_person_2"."org_id", "_person_2"."nickname") IN (%s)) AND ("_person_2"."_ppl_seq" = "_private_info_1"."_ppl_seq")) <- $KEYS(string, string); 
     
    1349613570          SET SESSION AUTHORIZATION "htsql_regress.owner"; 
    1349713571          SET ROLE "htsql_regress.owner"; 
    13498           $KEYS(string, string) <- UPDATE "op"."person" AS "_person_1" SET ("email") = (E'mary.elliott@example.com') FROM "op"."person" AS "_person_2" LEFT OUTER JOIN "op"."organization" AS "_organization_1" ON ("_person_2"."org_id" = "_organization_1"."org_id") WHERE ((("_person_1"."org_id", "_person_1"."nickname") = ("_person_2"."org_id", "_person_2"."nickname")) AND (("_organization_1"."org_id" = E'meyers') AND ("_person_2"."nickname" = E'mary'))) RETURNING "_person_1"."org_id", "_person_1"."nickname"; 
     13572          $KEYS(string, string) <- UPDATE "op"."person" AS "_person_1" SET ("email") = (E'mary.elliott@example.com') FROM "op"."person" AS "_person_2" WHERE ((("_person_1"."org_id", "_person_1"."nickname") = ("_person_2"."org_id", "_person_2"."nickname")) AND (("_person_2"."org_id" = E'meyers') AND ("_person_2"."nickname" = E'mary'))) RETURNING "_person_1"."org_id", "_person_1"."nickname"; 
    1349913573          INSERT INTO "hr"."private_info" ("_ppl_seq", "tax_ident") SELECT "_person_2"."_ppl_seq", E'XXX-YYY' FROM "op"."person" AS "_person_2" WHERE (ROW("_person_2"."org_id", "_person_2"."nickname") IN (%s)) <- $KEYS(string, string); 
    1350013574          UPDATE "hr"."private_info" AS "_private_info_1" SET ("tax_ident") = (E'XXX-YYY') FROM "op"."person" AS "_person_2" WHERE ((ROW("_person_2"."org_id", "_person_2"."nickname") IN (%s)) AND ("_person_2"."_ppl_seq" = "_private_info_1"."_ppl_seq")) <- $KEYS(string, string); 
     
    1350513579          SET ROLE "htsql_regress.owner"; 
    1350613580          $KEYS(string, string) <- INSERT INTO "op"."person" ("email", "org_id", "nickname") SELECT E'elliott@example.com', (SELECT "_organization_1"."org_id" FROM "op"."organization" AS "_organization_1" WHERE ("_organization_1"."org_id" = E'meyers')), E'mary' RETURNING "org_id", "nickname"; 
    13507           $KEYS(string, string) <- UPDATE "op"."person" AS "_person_1" SET ("email") = (E'elliott@example.com') FROM "op"."person" AS "_person_2" LEFT OUTER JOIN "op"."organization" AS "_organization_1" ON ("_person_2"."org_id" = "_organization_1"."org_id") WHERE ((("_person_1"."org_id", "_person_1"."nickname") = ("_person_2"."org_id", "_person_2"."nickname")) AND (("_organization_1"."org_id" = E'meyers') AND ("_person_2"."nickname" = E'mary'))) RETURNING "_person_1"."org_id", "_person_1"."nickname"; 
     13581          $KEYS(string, string) <- UPDATE "op"."person" AS "_person_1" SET ("email") = (E'elliott@example.com') FROM "op"."person" AS "_person_2" WHERE ((("_person_1"."org_id", "_person_1"."nickname") = ("_person_2"."org_id", "_person_2"."nickname")) AND (("_person_2"."org_id" = E'meyers') AND ("_person_2"."nickname" = E'mary'))) RETURNING "_person_1"."org_id", "_person_1"."nickname"; 
    1350813582          INSERT INTO "hr"."private_info" ("_ppl_seq", "tax_ident") SELECT "_person_2"."_ppl_seq", E'YYY-XXX' FROM "op"."person" AS "_person_2" WHERE (ROW("_person_2"."org_id", "_person_2"."nickname") IN (%s)) <- $KEYS(string, string); 
    1350913583          UPDATE "hr"."private_info" AS "_private_info_1" SET ("tax_ident") = (E'YYY-XXX') FROM "op"."person" AS "_person_2" WHERE ((ROW("_person_2"."org_id", "_person_2"."nickname") IN (%s)) AND ("_person_2"."_ppl_seq" = "_private_info_1"."_ppl_seq")) <- $KEYS(string, string); 
     
    1351313587          SET SESSION AUTHORIZATION "htsql_regress.owner"; 
    1351413588          SET ROLE "htsql_regress.owner"; 
    13515           SELECT "_person_1"."org_id" AS "_e_1", "_person_1"."nickname" AS "_e_2", "_person_1"."full_name" AS "_e_3", "_person_1"."email" AS "_e_4", "_organization_1"."org_id" AS "_e_5", "_person_1"."nickname" AS "_e_6" FROM "op"."person" AS "_person_1" LEFT OUTER JOIN "op"."organization" AS "_organization_1" ON ("_person_1"."org_id" = "_organization_1"."org_id") WHERE (("_organization_1"."org_id" = E'meyers') AND ("_person_1"."nickname" = E'mary')) ORDER BY "_e_5" ASC, "_e_6" ASC; 
     13589          SELECT "_person_1"."org_id" AS "_e_1", "_person_1"."nickname" AS "_e_2", "_person_1"."full_name" AS "_e_3", "_person_1"."email" AS "_e_4", "_person_1"."org_id" AS "_e_5", "_person_1"."nickname" AS "_e_6" FROM "op"."person" AS "_person_1" WHERE (("_person_1"."org_id" = E'meyers') AND ("_person_1"."nickname" = E'mary')) ORDER BY "_e_5" ASC, "_e_6" ASC; 
    1351613590      - uri: /interact() 
    1351713591        status: 200 OK 
  • trunk/test/regress/selection.yaml

    r825 r829  
    774774  - uri: /project{id(),array(person)} 
    775775  - uri: /person{id(),array(project)} 
     776  - uri: /person{organization{name+},full_name+} 
     777  - uri: /organization{*,hide(is_active)-} 
     778  - uri: /organization{*,hide(is_active)-}/person{id()} 
     779  - uri: /person{organization{hide(name)+},hide(full_name)+,*} 
    776780-  
    777781  title: Comparison Tests