001package gudusoft.gsqlparser.nodes.starrocks; 002 003import gudusoft.gsqlparser.TSourceToken; 004import gudusoft.gsqlparser.nodes.*; 005 006/** 007 * AST node representing a pipe operator operation in StarRocks pipe query syntax. 008 * 009 * The pipe operator (|>) chains SQL operations together in a linear flow: 010 * FROM table |> SELECT * |> WHERE cond |> ORDER BY col |> LIMIT n 011 * 012 * Each TPipeOperator represents one operation after a |> symbol. 013 */ 014public class TPipeOperator extends TParseTreeNode { 015 016 /** 017 * Enum for different types of pipe operations 018 */ 019 public enum EPipeOperatorType { 020 SELECT, // |> SELECT columns 021 WHERE, // |> WHERE condition 022 ORDER_BY, // |> ORDER BY columns 023 LIMIT, // |> LIMIT n [OFFSET m] 024 AGGREGATE, // |> AGGREGATE expr GROUP BY ... 025 EXTEND, // |> EXTEND expr AS alias 026 SET, // |> SET col = expr 027 DROP, // |> DROP col 028 AS, // |> AS alias 029 JOIN, // |> JOIN table ON cond 030 UNION, // |> UNION [ALL] (query) 031 INTERSECT, // |> INTERSECT [ALL] (query) 032 EXCEPT, // |> EXCEPT [ALL] (query) 033 TABLESAMPLE, // |> TABLESAMPLE 034 PIVOT, // |> PIVOT 035 UNPIVOT // |> UNPIVOT 036 } 037 038 private TSourceToken pipeToken; // The |> token 039 private EPipeOperatorType operatorType; 040 041 // For SELECT operation 042 private TResultColumnList selectList; 043 private TSelectDistinct selectDistinct; 044 045 // For WHERE operation 046 private TExpression whereCondition; 047 048 // For ORDER BY operation 049 private TOrderBy orderByClause; 050 051 // For LIMIT operation 052 private TLimitClause limitClause; 053 054 // For AGGREGATE operation 055 private TResultColumnList aggregateList; 056 private TGroupBy groupByClause; 057 058 // For EXTEND/SET operations (expression list) 059 private TResultColumnList extendList; 060 061 // For DROP operation (column list) 062 private TObjectNameList dropColumns; 063 064 // For AS operation (table alias) 065 private TObjectName tableAlias; 066 067 // For JOIN operations 068 private TJoinExpr joinExpr; 069 private TFromTable joinTable; 070 private TExpression joinCondition; 071 private gudusoft.gsqlparser.EJoinType joinType; 072 073 // For set operations (UNION/INTERSECT/EXCEPT) 074 private TParseTreeNode setOperand; 075 private boolean setAll; 076 077 // Generic operator keyword token (SELECT, WHERE, etc.) 078 private TSourceToken operatorKeyword; 079 080 // Getters and setters 081 public TSourceToken getPipeToken() { 082 return pipeToken; 083 } 084 085 public void setPipeToken(TSourceToken pipeToken) { 086 this.pipeToken = pipeToken; 087 } 088 089 public EPipeOperatorType getOperatorType() { 090 return operatorType; 091 } 092 093 public void setOperatorType(EPipeOperatorType operatorType) { 094 this.operatorType = operatorType; 095 } 096 097 public TSourceToken getOperatorKeyword() { 098 return operatorKeyword; 099 } 100 101 public void setOperatorKeyword(TSourceToken operatorKeyword) { 102 this.operatorKeyword = operatorKeyword; 103 } 104 105 public TResultColumnList getSelectList() { 106 return selectList; 107 } 108 109 public void setSelectList(TResultColumnList selectList) { 110 this.selectList = selectList; 111 } 112 113 public TSelectDistinct getSelectDistinct() { 114 return selectDistinct; 115 } 116 117 public void setSelectDistinct(TSelectDistinct selectDistinct) { 118 this.selectDistinct = selectDistinct; 119 } 120 121 public TExpression getWhereCondition() { 122 return whereCondition; 123 } 124 125 public void setWhereCondition(TExpression whereCondition) { 126 this.whereCondition = whereCondition; 127 } 128 129 public TOrderBy getOrderByClause() { 130 return orderByClause; 131 } 132 133 public void setOrderByClause(TOrderBy orderByClause) { 134 this.orderByClause = orderByClause; 135 } 136 137 public TLimitClause getLimitClause() { 138 return limitClause; 139 } 140 141 public void setLimitClause(TLimitClause limitClause) { 142 this.limitClause = limitClause; 143 } 144 145 public TResultColumnList getAggregateList() { 146 return aggregateList; 147 } 148 149 public void setAggregateList(TResultColumnList aggregateList) { 150 this.aggregateList = aggregateList; 151 } 152 153 public TGroupBy getGroupByClause() { 154 return groupByClause; 155 } 156 157 public void setGroupByClause(TGroupBy groupByClause) { 158 this.groupByClause = groupByClause; 159 } 160 161 public TResultColumnList getExtendList() { 162 return extendList; 163 } 164 165 public void setExtendList(TResultColumnList extendList) { 166 this.extendList = extendList; 167 } 168 169 public TObjectNameList getDropColumns() { 170 return dropColumns; 171 } 172 173 public void setDropColumns(TObjectNameList dropColumns) { 174 this.dropColumns = dropColumns; 175 } 176 177 public TObjectName getTableAlias() { 178 return tableAlias; 179 } 180 181 public void setTableAlias(TObjectName tableAlias) { 182 this.tableAlias = tableAlias; 183 } 184 185 public TJoinExpr getJoinExpr() { 186 return joinExpr; 187 } 188 189 public void setJoinExpr(TJoinExpr joinExpr) { 190 this.joinExpr = joinExpr; 191 } 192 193 public TFromTable getJoinTable() { 194 return joinTable; 195 } 196 197 public void setJoinTable(TFromTable joinTable) { 198 this.joinTable = joinTable; 199 } 200 201 public TExpression getJoinCondition() { 202 return joinCondition; 203 } 204 205 public void setJoinCondition(TExpression joinCondition) { 206 this.joinCondition = joinCondition; 207 } 208 209 public gudusoft.gsqlparser.EJoinType getJoinType() { 210 return joinType; 211 } 212 213 public void setJoinType(gudusoft.gsqlparser.EJoinType joinType) { 214 this.joinType = joinType; 215 } 216 217 public TParseTreeNode getSetOperand() { 218 return setOperand; 219 } 220 221 public void setSetOperand(TParseTreeNode setOperand) { 222 this.setOperand = setOperand; 223 } 224 225 public boolean isSetAll() { 226 return setAll; 227 } 228 229 public void setSetAll(boolean setAll) { 230 this.setAll = setAll; 231 } 232 233 /** 234 * Initialize for SELECT pipe operation 235 */ 236 public void initSelect(TSourceToken pipeToken, TSourceToken selectKeyword, 237 TSelectDistinct distinct, TResultColumnList columns) { 238 this.pipeToken = pipeToken; 239 this.operatorKeyword = selectKeyword; 240 this.operatorType = EPipeOperatorType.SELECT; 241 this.selectDistinct = distinct; 242 this.selectList = columns; 243 } 244 245 /** 246 * Initialize for WHERE pipe operation 247 */ 248 public void initWhere(TSourceToken pipeToken, TSourceToken whereKeyword, TExpression condition) { 249 this.pipeToken = pipeToken; 250 this.operatorKeyword = whereKeyword; 251 this.operatorType = EPipeOperatorType.WHERE; 252 this.whereCondition = condition; 253 } 254 255 /** 256 * Initialize for ORDER BY pipe operation 257 */ 258 public void initOrderBy(TSourceToken pipeToken, TOrderBy orderBy) { 259 this.pipeToken = pipeToken; 260 this.operatorType = EPipeOperatorType.ORDER_BY; 261 this.orderByClause = orderBy; 262 } 263 264 /** 265 * Initialize for LIMIT pipe operation 266 */ 267 public void initLimit(TSourceToken pipeToken, TLimitClause limit) { 268 this.pipeToken = pipeToken; 269 this.operatorType = EPipeOperatorType.LIMIT; 270 this.limitClause = limit; 271 } 272 273 /** 274 * Initialize for AGGREGATE pipe operation 275 */ 276 public void initAggregate(TSourceToken pipeToken, TSourceToken aggKeyword, 277 TResultColumnList aggregates, TGroupBy groupBy) { 278 this.pipeToken = pipeToken; 279 this.operatorKeyword = aggKeyword; 280 this.operatorType = EPipeOperatorType.AGGREGATE; 281 this.aggregateList = aggregates; 282 this.groupByClause = groupBy; 283 } 284 285 /** 286 * Initialize for EXTEND pipe operation 287 */ 288 public void initExtend(TSourceToken pipeToken, TSourceToken extendKeyword, 289 TResultColumnList extendColumns) { 290 this.pipeToken = pipeToken; 291 this.operatorKeyword = extendKeyword; 292 this.operatorType = EPipeOperatorType.EXTEND; 293 this.extendList = extendColumns; 294 } 295 296 /** 297 * Initialize for JOIN pipe operation 298 */ 299 public void initJoin(TSourceToken pipeToken, TJoinExpr join) { 300 this.pipeToken = pipeToken; 301 this.operatorType = EPipeOperatorType.JOIN; 302 this.joinExpr = join; 303 } 304 305 /** 306 * Initialize for JOIN pipe operation with table and condition 307 */ 308 public void initJoin(TSourceToken pipeToken, gudusoft.gsqlparser.EJoinType joinType, 309 TFromTable table, TExpression condition) { 310 this.pipeToken = pipeToken; 311 this.operatorType = EPipeOperatorType.JOIN; 312 this.joinType = joinType; 313 this.joinTable = table; 314 this.joinCondition = condition; 315 } 316 317 /** 318 * Initialize for UNION pipe operation 319 */ 320 public void initUnion(TSourceToken pipeToken, TSourceToken unionKeyword, 321 TParseTreeNode operand, boolean all) { 322 this.pipeToken = pipeToken; 323 this.operatorKeyword = unionKeyword; 324 this.operatorType = EPipeOperatorType.UNION; 325 this.setOperand = operand; 326 this.setAll = all; 327 } 328 329 /** 330 * Initialize for INTERSECT pipe operation 331 */ 332 public void initIntersect(TSourceToken pipeToken, TSourceToken intersectKeyword, 333 TParseTreeNode operand, boolean all) { 334 this.pipeToken = pipeToken; 335 this.operatorKeyword = intersectKeyword; 336 this.operatorType = EPipeOperatorType.INTERSECT; 337 this.setOperand = operand; 338 this.setAll = all; 339 } 340 341 /** 342 * Initialize for EXCEPT pipe operation 343 */ 344 public void initExcept(TSourceToken pipeToken, TSourceToken exceptKeyword, 345 TParseTreeNode operand, boolean all) { 346 this.pipeToken = pipeToken; 347 this.operatorKeyword = exceptKeyword; 348 this.operatorType = EPipeOperatorType.EXCEPT; 349 this.setOperand = operand; 350 this.setAll = all; 351 } 352}