@@ -187,6 +187,13 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
187187| <K_NULLS: "NULLS">
188188| <K_FIRST: "FIRST">
189189| <K_LAST: "LAST">
190+ | <K_ROWS: "ROWS">
191+ | <K_RANGE: "RANGE">
192+ | <K_UNBOUNDED: "UNBOUNDED">
193+ | <K_PRECEDING: "PRECEDING">
194+ | <K_FOLLOWING: "FOLLOWING">
195+ | <K_CURRENT: "CURRENT">
196+ | <K_ROW: "ROW">
190197}
191198
192199TOKEN : /* Numeric Constants */
@@ -1679,25 +1686,76 @@ AnalyticExpression AnalyticExpression() :
16791686 Expression expr = null;
16801687 Expression offset = null;
16811688 Expression defaultValue = null;
1689+ WindowElement windowElement = null;
16821690}
16831691{
16841692 token=<S_IDENTIFIER> { retval.setName(token.image); }
16851693 "(" [ expr=SimpleExpression() ["," offset=SimpleExpression() ["," defaultValue=SimpleExpression() ]] | "*" { retval.setAllColumns(true); } ] ")" <K_OVER> "("
16861694 [<K_PARTITION> <K_BY> column=Column() {plist.add(column);} ("," column=Column() {plist.add(column);} )* ]
1687- [olist=OrderByElements() ]
1695+ [olist=OrderByElements() [windowElement = WindowElement() ] ]
1696+
16881697 {
16891698 retval.setExpression(expr);
16901699 retval.setOffset(offset);
16911700 retval.setDefaultValue(defaultValue);
16921701 retval.setPartitionByColumns(plist);
16931702 retval.setOrderByElements(olist);
1703+ retval.setWindowElement(windowElement);
16941704 }
16951705 ")"
16961706 {
16971707 return retval;
16981708 }
16991709}
17001710
1711+ WindowElement WindowElement():
1712+ {
1713+ WindowElement windowElement = new WindowElement();
1714+ WindowRange range = new WindowRange();
1715+ WindowOffset offset = null;
1716+ }
1717+ {
1718+ (<K_ROWS> { windowElement.setType(WindowElement.Type.ROWS); } | <K_RANGE> { windowElement.setType(WindowElement.Type.RANGE); } )
1719+ ( (
1720+ <K_BETWEEN> { windowElement.setRange(range); }
1721+ offset = WindowOffset() { range.setStart(offset); }
1722+ <K_AND> offset = WindowOffset() { range.setEnd(offset); }
1723+ )
1724+ |
1725+ offset = WindowOffset() { windowElement.setOffset(offset); }
1726+ )
1727+
1728+ {
1729+ return windowElement;
1730+ }
1731+ }
1732+
1733+ WindowOffset WindowOffset():
1734+ {
1735+ WindowOffset offset = new WindowOffset();
1736+ Expression expr = null;
1737+ }
1738+ {
1739+ (
1740+
1741+ <K_UNBOUNDED> (<K_PRECEDING> { offset.setType(WindowOffset.Type.PRECEDING); return offset; } |
1742+ <K_FOLLOWING> { offset.setType(WindowOffset.Type.FOLLOWING); return offset; } )
1743+ )
1744+ |
1745+ ( <K_CURRENT> <K_ROW> { offset.setType(WindowOffset.Type.CURRENT); return offset;} )
1746+ |
1747+ ( expr = SimpleExpression() {
1748+ offset.setType(WindowOffset.Type.EXPR);
1749+ offset.setExpression(expr);
1750+ }
1751+ (<K_PRECEDING> { offset.setType(WindowOffset.Type.PRECEDING); } | <K_FOLLOWING> { offset.setType(WindowOffset.Type.FOLLOWING); } )
1752+ )
1753+
1754+ {
1755+ return offset;
1756+ }
1757+ }
1758+
17011759ExtractExpression ExtractExpression() :
17021760{
17031761 ExtractExpression retval = new ExtractExpression();
0 commit comments