hqlcfilter.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef __HQLCFILTER_HPP_
  14. #define __HQLCFILTER_HPP_
  15. #include "hqlfilter.hpp"
  16. struct BuildFilterState
  17. {
  18. BuildFilterState(BuildCtx & _funcctx, const char * _listName) : funcctx(_funcctx)
  19. {
  20. listName = _listName;
  21. curFieldIdx = 0;
  22. curOffset = 0;
  23. wildOffset = (unsigned) -1;
  24. numActiveSets = 0;
  25. warnedAllConditionsWild = false;
  26. doneImplicitWarning = true;
  27. wildWasKeyed = false;
  28. }
  29. inline bool wildPending() { return wildOffset != (unsigned)-1; }
  30. inline void clearWild() { wildOffset = (unsigned) -1; }
  31. const char * getSetName(bool createValueSets);
  32. void popSetName();
  33. //Constant while building monitors
  34. BuildCtx & funcctx;
  35. const char * listName;
  36. //State variables used when generating
  37. OwnedHqlExpr implicitWildField;
  38. unsigned numActiveSets;
  39. CIArrayOf<StringAttrItem> setNames;
  40. bool doneImplicitWarning;
  41. bool warnedAllConditionsWild;
  42. bool wildWasKeyed;
  43. unsigned curFieldIdx;
  44. unsigned curOffset;
  45. unsigned wildOffset;
  46. };
  47. class CppFilterExtractor : public FilterExtractor
  48. {
  49. public:
  50. CppFilterExtractor(IHqlExpression * _tableExpr, HqlCppTranslator & _translator, int _numKeyableFields, bool isDiskRead, bool forceValueSets);
  51. void buildSegments(BuildCtx & ctx, const char * listName, bool _ignoreUnkeyed);
  52. bool createGroupingMonitor(BuildCtx ctx, const char * listName, IHqlExpression * select, unsigned & maxField);
  53. protected:
  54. void buildEmptyKeySegment(BuildFilterState & buildState, BuildCtx & ctx, KeySelectorInfo & selectorInfo);
  55. void buildKeySegment(BuildFilterState & buildState, BuildCtx & ctx, unsigned whichField, unsigned curSize);
  56. void buildKeySegmentExpr(BuildFilterState & buildState, KeySelectorInfo & selectorInfo, BuildCtx & ctx, const char * target, IHqlExpression & thisKey, MonitorFilterKind filterKind);
  57. void buildKeySegmentCompareExpr(BuildFilterState & buildState, KeySelectorInfo & selectorInfo, BuildCtx & ctx, const char * requiredSet, IHqlExpression & thisKey);
  58. void buildKeySegmentInExpr(BuildFilterState & buildState, KeySelectorInfo & selectorInfo, BuildCtx & ctx, const char * target, IHqlExpression & thisKey, MonitorFilterKind filterKind);
  59. bool buildSingleKeyMonitor(StringBuffer & createMonitorText, KeySelectorInfo & selectorInfo, BuildCtx & ctx, IHqlExpression & thisKey);
  60. void callAddAll(BuildCtx & ctx, IHqlExpression * targetVar);
  61. void createStringSet(BuildCtx & ctx, const char * target, unsigned size, IHqlExpression * selector);
  62. KeyCondition * createTranslatedCondition(IHqlExpression * cond, KeyedKind keyedKind);
  63. IHqlExpression * getMonitorValueAddress(BuildCtx & ctx, IHqlExpression * expandedSelector, IHqlExpression * value);
  64. void extractCompareInformation(BuildCtx & ctx, IHqlExpression * expr, SharedHqlExpr & compare, SharedHqlExpr & normalized, IHqlExpression * expandedSelector);
  65. void extractCompareInformation(BuildCtx & ctx, IHqlExpression * lhs, IHqlExpression * value, SharedHqlExpr & compare, SharedHqlExpr & normalized, IHqlExpression * expandedSelector);
  66. virtual IHqlExpression * getRangeLimit(ITypeInfo * fieldType, IHqlExpression * lengthExpr, IHqlExpression * value, int whichBoundary) override;
  67. protected:
  68. void spotSegmentCSE(BuildCtx & ctx);
  69. class SelectSpotter : public NewHqlTransformer
  70. {
  71. public:
  72. SelectSpotter(const HqlExprArray & _selects);
  73. void analyseExpr(IHqlExpression * expr);
  74. public:
  75. bool hasSelects;
  76. const HqlExprArray & selects;
  77. };
  78. protected:
  79. HqlCppTranslator & translator;
  80. IIdAtom * addRangeFunc;
  81. IIdAtom * killRangeFunc;
  82. };
  83. #endif