001package gudusoft.gsqlparser.nodes.functions;
002
003import gudusoft.gsqlparser.ESqlClause;
004import gudusoft.gsqlparser.TCustomSqlStatement;
005import gudusoft.gsqlparser.nodes.*;
006
007
008/**
009 * Teradata NPath table function for pattern matching on ordered data.
010 *
011 * Syntax:
012 * NPath(
013 *     ON table_ref | (subquery)
014 *     [PARTITION BY column_list]
015 *     [ORDER BY column_list]
016 *     USING
017 *     MODE (Overlapping | NonOverlapping)
018 *     PATTERN('pattern_string')
019 *     SYMBOLS(condition AS symbol_name, ...)
020 *     RESULT(
021 *         First|Last(column OF symbol) AS column_name,
022 *         ACCUMULATE(...) AS column_name,
023 *         ...
024 *     )
025 * ) [alias]
026 */
027public class TNPathFunction extends TTableFunction {
028
029    private TFromTable tableRef;
030    private TTable table;
031
032    public TTable getTable() {
033        return table;
034    }
035
036    public TFromTable getTableRef() {
037        return tableRef;
038    }
039
040    public void init(Object arg1, Object arg2){
041        functionName = (TObjectName)arg1;
042        tableRef = (TFromTable)arg2;
043    }
044
045    public void doParse(TCustomSqlStatement psql, ESqlClause plocation){
046        super.doParse(psql,plocation);
047        if (tableRef != null) {
048            table = psql.analyzeFromTable(tableRef, true);
049        }
050    }
051
052    public void accept(TParseTreeVisitor v){
053        v.preVisit(this);
054        v.postVisit(this);
055    }
056
057    public void acceptChildren(TParseTreeVisitor v) {
058        v.preVisit(this);
059        if (tableRef != null && tableRef.getSubquerynode() != null) {
060            tableRef.getSubquerynode().acceptChildren(v);
061        }
062        v.postVisit(this);
063    }
064}