Database Reference
In-Depth Information
G2: (table1) DIVIDE (table2) ON {attributes}
G2a: (SELECT i..j,r..s,t..v
FROM table1
WHERE …)
DIVIDE
(SELECT *
FROM table2
WHERE …) ON {r..s}
Virtually all conceivable forms of G2 can be written as G1. That is, the on keyword is not needed,
but is included as a convenience. In fact, when implemented in Java, if the on keyword is present, the B
attributes will simply be replaced with them. This is different from Rantzau's proposed grammar (Harris
& Shadbolt, 2005) in which this on keyword is necessary.
DIVIDE GRAMMAR PARSER
In designing a custom SQL parser, several considerations are made. One of them is being able to handle
nested divide grammars. Another consideration is if the divide query can be part of another query, perhaps
as a join or union. As long as each select-from-where clause in the whole query is correct, then both of
these issues can be addressed simultaneously with the algorithm included in Section 4.1.
Iterative Parsing Algorithm
This is an overview of how nested divide queries may be identified and rewritten:
1. Are brackets matched?
2. Is a DIVIDE grammar present?
3. Find DIVIDE token
4. Find the correctly nested brackets before DIVIDE
5. Find the correctly nested brackets after DIVIDE
6. Find the ON attributes, if any
7. If DIVIDE grammar found in dividend, repeat steps 3-9 on it
8. If DIVIDE grammar found in divisor, repeat steps 3-9 on it
9. Rewrite sub-query in-place
Parse and Rewrite Example
Below is simple example of a query rewrite using the count method from the authors JUnit tests. A
more complicated example is presented in Section 4.3. The steps of the above algorithm are applied in
sequence as follows.
Search WWH ::




Custom Search