1919package org .apache .hadoop .hive .ql ;
2020
2121
22+ import java .util .EnumSet ;
2223import java .util .HashSet ;
2324import java .util .Set ;
2425
@@ -56,6 +57,24 @@ public String getName() {
5657 }
5758 }
5859
60+ public enum QueryFeature {
61+ GROUP_BY ,
62+ ORDER_BY ,
63+ OUTER_ORDER_BY ,
64+ SORT_BY ,
65+ LIMIT ,
66+ JOIN_FOLLOWED_BY_GROUP_BY ,
67+ PTF ,
68+ WINDOWING ,
69+ QUALIFY ,
70+ EXCEPT ,
71+ INTERSECT ,
72+ USES_SCRIPT ,
73+ DISTRIBUTE_BY ,
74+ CLUSTER_BY ,
75+ MAP_GROUP_BY
76+ }
77+
5978 boolean query ;
6079 boolean analyzeCommand ;
6180 boolean noScanAnalyzeCommand ;
@@ -64,25 +83,8 @@ public String getName() {
6483 int outerQueryLimit ;
6584
6685 boolean hasJoin = false ;
67- boolean hasGroupBy = false ;
68- boolean hasOrderBy = false ;
69- boolean hasOuterOrderBy = false ;
70- boolean hasSortBy = false ;
71- boolean hasLimit = false ;
72- boolean hasJoinFollowedByGroupBy = false ;
73- boolean hasPTF = false ;
74- boolean hasWindowing = false ;
75- boolean hasQualify = false ;
76- boolean hasExcept = false ;
77- boolean hasIntersect = false ;
78-
79- // does the query have a using clause
80- boolean usesScript = false ;
81-
82- boolean hasDistributeBy = false ;
83- boolean hasClusterBy = false ;
86+ private final EnumSet <QueryFeature > features = EnumSet .noneOf (QueryFeature .class );
8487 boolean mapJoinRemoved = false ;
85- boolean hasMapGroupBy = false ;
8688
8789 private boolean hasLateralViews = false ;
8890 private boolean cboSupportedLateralViews = true ;
@@ -196,116 +198,124 @@ public boolean isCBOSupportedLateralViews() {
196198 return cboSupportedLateralViews ;
197199 }
198200
201+ public void addFeature (QueryFeature feature ) {
202+ features .add (feature );
203+ }
204+
205+ public boolean hasFeature (QueryFeature feature ) {
206+ return features .contains (feature );
207+ }
208+
199209 public boolean hasGroupBy () {
200- return hasGroupBy ;
210+ return hasFeature ( QueryFeature . GROUP_BY ) ;
201211 }
202212
203213 public void setHasGroupBy (boolean hasGroupBy ) {
204- this . hasGroupBy = hasGroupBy ;
214+ setFeature ( QueryFeature . GROUP_BY , hasGroupBy ) ;
205215 }
206216
207217 public boolean hasOrderBy () {
208- return hasOrderBy ;
218+ return hasFeature ( QueryFeature . ORDER_BY ) ;
209219 }
210220
211221 public void setHasOrderBy (boolean hasOrderBy ) {
212- this . hasOrderBy = hasOrderBy ;
222+ setFeature ( QueryFeature . ORDER_BY , hasOrderBy ) ;
213223 }
214224
215225 public boolean hasOuterOrderBy () {
216- return hasOuterOrderBy ;
226+ return hasFeature ( QueryFeature . OUTER_ORDER_BY ) ;
217227 }
218228
219229 public void setHasOuterOrderBy (boolean hasOuterOrderBy ) {
220- this . hasOuterOrderBy = hasOuterOrderBy ;
230+ setFeature ( QueryFeature . OUTER_ORDER_BY , hasOuterOrderBy ) ;
221231 }
222232
223233 public boolean hasSortBy () {
224- return hasSortBy ;
234+ return hasFeature ( QueryFeature . SORT_BY ) ;
225235 }
226236
227237 public void setHasSortBy (boolean hasSortBy ) {
228- this . hasSortBy = hasSortBy ;
238+ setFeature ( QueryFeature . SORT_BY , hasSortBy ) ;
229239 }
230240
231241 public void setHasLimit (boolean hasLimit ) {
232- this . hasLimit = hasLimit ;
242+ setFeature ( QueryFeature . LIMIT , hasLimit ) ;
233243 }
234244
235245 public boolean hasLimit () {
236- return hasLimit ;
246+ return hasFeature ( QueryFeature . LIMIT ) ;
237247 }
238248
239249 public boolean hasJoinFollowedByGroupBy () {
240- return hasJoinFollowedByGroupBy ;
250+ return hasFeature ( QueryFeature . JOIN_FOLLOWED_BY_GROUP_BY ) ;
241251 }
242252
243253 public void setHasJoinFollowedByGroupBy (boolean hasJoinFollowedByGroupBy ) {
244- this . hasJoinFollowedByGroupBy = hasJoinFollowedByGroupBy ;
254+ setFeature ( QueryFeature . JOIN_FOLLOWED_BY_GROUP_BY , hasJoinFollowedByGroupBy ) ;
245255 }
246256
247257 public boolean usesScript () {
248- return usesScript ;
258+ return hasFeature ( QueryFeature . USES_SCRIPT ) ;
249259 }
250260
251261 public void setUsesScript (boolean usesScript ) {
252- this . usesScript = usesScript ;
262+ setFeature ( QueryFeature . USES_SCRIPT , usesScript ) ;
253263 }
254264
255265 public boolean hasDistributeBy () {
256- return hasDistributeBy ;
266+ return hasFeature ( QueryFeature . DISTRIBUTE_BY ) ;
257267 }
258268
259269 public void setHasDistributeBy (boolean hasDistributeBy ) {
260- this . hasDistributeBy = hasDistributeBy ;
270+ setFeature ( QueryFeature . DISTRIBUTE_BY , hasDistributeBy ) ;
261271 }
262272
263273 public boolean hasClusterBy () {
264- return hasClusterBy ;
274+ return hasFeature ( QueryFeature . CLUSTER_BY ) ;
265275 }
266276
267277 public void setHasClusterBy (boolean hasClusterBy ) {
268- this . hasClusterBy = hasClusterBy ;
278+ setFeature ( QueryFeature . CLUSTER_BY , hasClusterBy ) ;
269279 }
270280
271281 public boolean hasPTF () {
272- return hasPTF ;
282+ return hasFeature ( QueryFeature . PTF ) ;
273283 }
274284
275285 public void setHasPTF (boolean hasPTF ) {
276- this . hasPTF = hasPTF ;
286+ setFeature ( QueryFeature . PTF , hasPTF ) ;
277287 }
278288
279289 public boolean hasWindowing () {
280- return hasWindowing ;
290+ return hasFeature ( QueryFeature . WINDOWING ) ;
281291 }
282292
283293 public void setHasWindowing (boolean hasWindowing ) {
284- this . hasWindowing = hasWindowing ;
294+ setFeature ( QueryFeature . WINDOWING , hasWindowing ) ;
285295 }
286296
287297 public boolean hasQualify () {
288- return hasQualify ;
298+ return hasFeature ( QueryFeature . QUALIFY ) ;
289299 }
290300
291301 public void setHasQualify (boolean hasQualify ) {
292- this . hasQualify = hasQualify ;
302+ setFeature ( QueryFeature . QUALIFY , hasQualify ) ;
293303 }
294304
295305 public boolean hasExcept () {
296- return hasExcept ;
306+ return hasFeature ( QueryFeature . EXCEPT ) ;
297307 }
298308
299309 public void setHasExcept (boolean hasExcept ) {
300- this . hasExcept = hasExcept ;
310+ setFeature ( QueryFeature . EXCEPT , hasExcept ) ;
301311 }
302312
303313 public boolean hasIntersect () {
304- return hasIntersect ;
314+ return hasFeature ( QueryFeature . INTERSECT ) ;
305315 }
306316
307317 public void setHasIntersect (boolean hasIntersect ) {
308- this . hasIntersect = hasIntersect ;
318+ setFeature ( QueryFeature . INTERSECT , hasIntersect ) ;
309319 }
310320
311321 public boolean isMapJoinRemoved () {
@@ -317,11 +327,11 @@ public void setMapJoinRemoved(boolean mapJoinRemoved) {
317327 }
318328
319329 public boolean isHasMapGroupBy () {
320- return hasMapGroupBy ;
330+ return hasFeature ( QueryFeature . MAP_GROUP_BY ) ;
321331 }
322332
323333 public void setHasMapGroupBy (boolean hasMapGroupBy ) {
324- this . hasMapGroupBy = hasMapGroupBy ;
334+ setFeature ( QueryFeature . MAP_GROUP_BY , hasMapGroupBy ) ;
325335 }
326336
327337 public boolean hasMultiDestQuery () {
@@ -386,24 +396,8 @@ public void clear() {
386396 isMaterializedView = false ;
387397
388398 hasJoin = false ;
389- hasGroupBy = false ;
390- hasOrderBy = false ;
391- hasOuterOrderBy = false ;
392- hasSortBy = false ;
393- hasJoinFollowedByGroupBy = false ;
394- hasPTF = false ;
395- hasWindowing = false ;
396- hasQualify = false ;
397- hasExcept = false ;
398- hasIntersect = false ;
399-
400- // does the query have a using clause
401- usesScript = false ;
402-
403- hasDistributeBy = false ;
404- hasClusterBy = false ;
399+ features .clear ();
405400 mapJoinRemoved = false ;
406- hasMapGroupBy = false ;
407401
408402 noOfJoins = 0 ;
409403 noOfOuterJoins = 0 ;
@@ -413,4 +407,12 @@ public void clear() {
413407
414408 usedTables .clear ();
415409 }
410+
411+ private void setFeature (QueryFeature feature , boolean enabled ) {
412+ if (enabled ) {
413+ addFeature (feature );
414+ } else {
415+ features .remove (feature );
416+ }
417+ }
416418}
0 commit comments