001package gudusoft.gsqlparser.nodes.snowflake; 002 003 004import gudusoft.gsqlparser.TSourceToken; 005import gudusoft.gsqlparser.nodes.TConstant; 006import gudusoft.gsqlparser.nodes.TExpression; 007import gudusoft.gsqlparser.nodes.TParseTreeNode; 008import gudusoft.gsqlparser.nodes.TParseTreeVisitor; 009 010/** 011 * Snowflake Time Travel SQL extensions 012 * https://docs.snowflake.com/en/user-guide/data-time-travel 013 * 014 * The clause uses one of the following parameters to pinpoint the exact historical data you want to access: 015 * 016 * <br>TIMESTAMP 017 * 018 * <br>OFFSET (time difference in seconds from the present time) 019 * 020 * <br>STATEMENT (query ID for statement) 021 */ 022public class TAtBeforeClause extends TParseTreeNode { 023 public enum TimeTravelType { 024 TIMESTAMP, 025 OFFSET, 026 STATEMENT 027 } 028 029 public enum ClauseType { 030 AT, 031 BEFORE, 032 CHANGES 033 } 034 035 private ClauseType clauseType; // Distinguishes AT, BEFORE, and CHANGES 036 private TimeTravelType type; // Type of Time Travel 037 private TExpression timestamp; // For TIMESTAMP type 038 private TExpression offset; // For OFFSET type 039 private TConstant statementId; // For STATEMENT type 040 private TSourceToken changesInformation; 041 042 043 public void init(Object arg1, Object arg2) { 044 clauseType = (ClauseType) arg1; 045 if (clauseType == ClauseType.CHANGES) { 046 changesInformation = (TSourceToken) arg2; 047 } else { 048 type = (TimeTravelType) arg2; 049 } 050 } 051 052 public void init(Object arg1, Object arg2, Object arg3) { 053 init(arg1, arg2); 054 switch (type) { 055 case TIMESTAMP: 056 timestamp = (TExpression) arg3; 057 break; 058 case OFFSET: 059 offset = (TExpression) arg3; 060 break; 061 case STATEMENT: 062 statementId = (TConstant) arg3; 063 break; 064 } 065 } 066 067 public ClauseType getClauseType() { 068 return clauseType; 069 } 070 071 public TimeTravelType getType() { 072 return type; 073 } 074 075 public TExpression getTimestamp() { 076 return timestamp; 077 } 078 079 public TExpression getOffset() { 080 return offset; 081 } 082 083 public TConstant getStatementId() { 084 return statementId; 085 } 086 087 /** 088 * Returns DEFAULT or APPEND_ONLY when this table reference uses CHANGES. 089 */ 090 public TSourceToken getChangesInformation() { 091 return changesInformation; 092 } 093 094 public void setChangesInformation(TSourceToken changesInformation) { 095 this.changesInformation = changesInformation; 096 } 097 098 099 public void accept(TParseTreeVisitor v) 100 { 101 v.preVisit(this); 102 v.postVisit(this); 103 } 104 105 public void acceptChildren(TParseTreeVisitor v) { 106 v.preVisit(this); 107 v.postVisit(this); 108 } 109}