Merge lp:~wallyworld/storm/support-recursive-with into lp:~launchpad-committers/storm/lp

Proposed by Ian Booth
Status: Approved
Approved by: Ian Booth
Approved revision: 399
Proposed branch: lp:~wallyworld/storm/support-recursive-with
Merge into: lp:~launchpad-committers/storm/lp
Diff against target: 66 lines (+25/-3)
3 files modified
NEWS (+1/-0)
storm/expr.py (+10/-3)
tests/expr.py (+14/-0)
To merge this branch: bzr merge lp:~wallyworld/storm/support-recursive-with
Reviewer Review Type Date Requested Status
Free Ekanayaka (community) Approve
Launchpad Committers Pending
Review via email: mp+74327@code.launchpad.net

Commit message

Extend WITH expression to support recursion.

Description of the change

This branch extends with WITH expression to support recursion.

== Implementation ==

Add a new recursive attribute to With and change it's compiler to support it.

== Tests ==

There were no tests for With so I added some:
  expr.test_with()
  expr.test_with_recursive()

To post a comment you must log in.
397. By Ian Booth

Merge from mainline

Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Looks good to me with the 2 points below fixed. +1

[1]

+ def __init__(self, name, select, **kwargs):

Any particular reason for not writing this as:

+ def __init__(self, name, select, recursive=False):

?

It feels more explicit to me.

[2]

Please document the new recursive parameter in the class docstring, like:

class With(Expr):
     """Compiles to a simple (name AS expr) used in constructing WITH clauses.

     @param recursive: <description>
     """

and add a note about it in the NEWS file.

review: Approve
Revision history for this message
Ian Booth (wallyworld) wrote :

Hi

Thank you. I'll definitely make the changes you suggest below; I think
they are all excellent points.

On 08/11/11 21:17, Free Ekanayaka wrote:
> Review: Approve
>
> Looks good to me with the 2 points below fixed. +1
>
> [1]
>
> + def __init__(self, name, select, **kwargs):
>
> Any particular reason for not writing this as:
>
> + def __init__(self, name, select, recursive=False):
>
> ?
>
> It feels more explicit to me.
>
> [2]
>
> Please document the new recursive parameter in the class docstring, like:
>
> class With(Expr):
> """Compiles to a simple (name AS expr) used in constructing WITH clauses.
>
> @param recursive:<description>
> """
>
> and add a note about it in the NEWS file.
>

398. By Ian Booth

Merge from main devel

399. By Ian Booth

Tweaks from code review

Unmerged revisions

399. By Ian Booth

Tweaks from code review

398. By Ian Booth

Merge from main devel

397. By Ian Booth

Merge from mainline

396. By Ian Booth

Extend WITH expression to support recursion

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2011-10-19 09:10:03 +0000
3+++ NEWS 2011-11-09 01:59:22 +0000
4@@ -3,6 +3,7 @@
5
6 Improvements
7 ------------
8+- Add support for generating recursive WITH clauses.
9
10 Bug fixes
11 ---------
12
13=== modified file 'storm/expr.py'
14--- storm/expr.py 2011-10-19 09:10:03 +0000
15+++ storm/expr.py 2011-11-09 01:59:22 +0000
16@@ -1515,15 +1515,22 @@
17 from storm.expr import compile, Expr, SQL
18
19 class With(Expr):
20- """Compiles to a simple (name AS expr) used in constructing WITH clauses."""
21-
22- def __init__(self, name, select):
23+ """Compiles to a simple (name AS expr) used in constructing WITH clauses.
24+
25+ @param recursive: If true, a recursive WITH clause is generated.
26+ """
27+ __slots__ = ("name", "select", "recursive")
28+
29+ def __init__(self, name, select, recursive=False):
30 self.name = name
31 self.select = select
32+ self.recursive = recursive
33
34 @compile.when(With)
35 def compile_with(compile, with_expr, state):
36 tokens = []
37+ if with_expr.recursive:
38+ tokens.append(" RECURSIVE ")
39 tokens.append(compile(with_expr.name, state, token=True))
40 tokens.append(" AS ")
41 tokens.append(compile(with_expr.select, state))
42
43=== modified file 'tests/expr.py'
44--- tests/expr.py 2011-09-14 15:27:52 +0000
45+++ tests/expr.py 2011-11-09 01:59:22 +0000
46@@ -1839,6 +1839,20 @@
47 self.assertEquals(select2.context, SELECT)
48 self.assertEquals(order_by.context, COLUMN_NAME)
49
50+ def test_with(self):
51+ expr = With(elem2, Select(elem1))
52+ state = State()
53+ statement = compile(expr, state)
54+ self.assertEquals(statement, "elem2 AS (SELECT elem1)")
55+ self.assertEquals(state.parameters, [])
56+
57+ def test_with_recursive(self):
58+ expr = With(elem2, Select(elem1), recursive=True)
59+ state = State()
60+ statement = compile(expr, state)
61+ self.assertEquals(statement, " RECURSIVE elem2 AS (SELECT elem1)")
62+ self.assertEquals(state.parameters, [])
63+
64 def test_except(self):
65 expr = Except(Func1(), elem2, elem3)
66 state = State()

Subscribers

People subscribed via source and target branches