001package gudusoft.gsqlparser.nodes; 002 003 004import gudusoft.gsqlparser.ESqlClause; 005import gudusoft.gsqlparser.TCustomSqlStatement; 006 007 008/** 009 * Represents over clause in analytic function. 010 * <br> This class also including keep dense rank clause {@link TKeepDenseRankClause} and within group clause {@link TWithinGroup} of Oracle as well. 011 * <br> partition clause {@link #getPartitionClause()}, order by clause {@link #getOrderBy()} and window frame {@link #getWindowFrame()} is used in over clause. 012 * <p></p> 013 * class related to analytic function: 014 * <br>{@link gudusoft.gsqlparser.nodes.TPartitionClause} 015 * <br>{@link gudusoft.gsqlparser.nodes.TOrderBy} 016 * <br>{@link gudusoft.gsqlparser.nodes.TWindowFrame} 017 * <br>{@link gudusoft.gsqlparser.nodes.TWindowFrameBoundary} 018 * <br>{@link TFrameExclusionClause} 019 */ 020public class TWindowDef extends TParseTreeNode { 021 022 private TObjectName name; 023 private TObjectName referenceName; 024 025 private TOrderBy orderBy; 026 private TPartitionClause partitionClause; 027 private TWindowFrame windowFrame; 028 029 // Oracle 030 private TKeepDenseRankClause keepDenseRankClause = null; 031 private boolean includingOverClause = true; 032 private TWithinGroup withinGroup; 033 034 public void setWithinGroup(TWithinGroup withinGroup) { 035 if (withinGroup==null) return; 036 this.withinGroup = withinGroup; 037 } 038 039 public TWithinGroup getWithinGroup() { 040 041 return withinGroup; 042 } 043 044 public void setIncludingOverClause(boolean includingOverClause) { 045 this.includingOverClause = includingOverClause; 046 } 047 048 public boolean isIncludingOverClause() { 049 050 return includingOverClause; 051 } 052 053 public void setKeepDenseRankClause(TKeepDenseRankClause keepDenseRankClause) { 054 this.keepDenseRankClause = keepDenseRankClause; 055 } 056 057 public TKeepDenseRankClause getKeepDenseRankClause() { 058 059 return keepDenseRankClause; 060 } 061 062 //Hive 063 private TDistributeBy distributeBy; 064 private TClusterBy clusterBy; 065 private TSortBy sortBy; 066 067 public void init(Object arg1){ 068 name = (TObjectName)arg1; 069 } 070 071 public void setBySpec(TWindowPartitioningSpec partitioningSpec){ 072 if (partitioningSpec == null) return; 073 this.partitionClause = partitioningSpec.getPartitionClause(); 074 this.orderBy = partitioningSpec.getOrderBy(); 075 this.sortBy = partitioningSpec.getSortBy(); 076 this.clusterBy = partitioningSpec.getClusterBy(); 077 this.distributeBy = partitioningSpec.getDistributeBy(); 078 } 079 080 public void setWindowFrame(TWindowFrame windowFrame) { 081 this.windowFrame = windowFrame; 082 } 083 084 public void setDistributeBy(TDistributeBy distributeBy) { 085 this.distributeBy = distributeBy; 086 } 087 088 public void setClusterBy(TClusterBy clusterBy) { 089 this.clusterBy = clusterBy; 090 } 091 092 public void setSortBy(TSortBy sortBy) { 093 this.sortBy = sortBy; 094 } 095 096 public TWindowFrame getWindowFrame() { 097 098 return windowFrame; 099 } 100 101 public TDistributeBy getDistributeBy() { 102 return distributeBy; 103 } 104 105 public TClusterBy getClusterBy() { 106 return clusterBy; 107 } 108 109 public TSortBy getSortBy() { 110 return sortBy; 111 } 112 113 public void setName(TObjectName name) { 114 this.name = name; 115 } 116 117 118 public TObjectName getName() { 119 return name; 120 } 121 122 public TObjectName getReferenceName() { 123 return referenceName; 124 } 125 126 public TOrderBy getOrderBy() { 127 return orderBy; 128 } 129 130 public void setOrderBy(TOrderBy orderBy) { 131 this.orderBy = orderBy; 132 } 133 134 public void setPartitionClause(TPartitionClause partitionClause) { 135 this.partitionClause = partitionClause; 136 } 137 138 public TPartitionClause getPartitionClause() { 139 return partitionClause; 140 } 141 142 public void setReferenceName(TObjectName referenceName) { 143 this.referenceName = referenceName; 144 } 145 146 147 public void doParse(TCustomSqlStatement psql, ESqlClause plocation){ 148 if (keepDenseRankClause != null){ 149 keepDenseRankClause.doParse(psql,plocation); 150 } 151 152 if (withinGroup != null){ 153 withinGroup.doParse(psql,plocation); 154 } 155 156 if (partitionClause != null){ 157 partitionClause.doParse(psql,plocation); 158 } 159 if (orderBy != null){ 160 orderBy.doParse(psql,plocation); 161 } 162 } 163 164 public void accept(TParseTreeVisitor v){ 165 v.preVisit(this); 166 v.postVisit(this); 167 } 168 169 public void acceptChildren(TParseTreeVisitor v){ 170 v.preVisit(this); 171 if (keepDenseRankClause != null){ 172 keepDenseRankClause.acceptChildren(v); 173 } 174 175 if (withinGroup != null){ 176 withinGroup.acceptChildren(v); 177 } 178 179 if (partitionClause != null){ 180 partitionClause.acceptChildren(v); 181 } 182 if (orderBy != null){ 183 orderBy.acceptChildren(v); 184 } 185 v.postVisit(this); 186 } 187 188 189}