extract_predicate.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #include <yql/essentials/ast/yql_expr.h>
  3. #include <yql/essentials/core/yql_type_annotation.h>
  4. namespace NYql {
  5. struct TPredicateExtractorSettings {
  6. TMaybe<size_t> MaxRanges = 10000; // should be less than Max<size_t>() due to integer overflow
  7. bool MergeAdjacentPointRanges = true;
  8. bool HaveNextValueCallable = false;
  9. bool BuildLiteralRange = false;
  10. std::function<bool(const NYql::TExprNode::TPtr&)> IsValidForRange;
  11. };
  12. class IPredicateRangeExtractor {
  13. public:
  14. using TPtr = THolder<IPredicateRangeExtractor>;
  15. virtual bool Prepare(const TExprNode::TPtr& filterLambda, const TTypeAnnotationNode& rowType,
  16. THashSet<TString>& possibleIndexKeys, TExprContext& ctx, TTypeAnnotationContext& typesCtx) = 0;
  17. struct TBuildResult {
  18. TExprNode::TPtr ComputeNode;
  19. TExprNode::TPtr PrunedLambda;
  20. size_t UsedPrefixLen = 0;
  21. size_t PointPrefixLen = 0;
  22. TMaybe<size_t> ExpectedMaxRanges;
  23. struct TLiteralRange {
  24. struct TLiteralRangeBound {
  25. bool Inclusive = false;
  26. TVector<TExprNode::TPtr> Columns;
  27. };
  28. TLiteralRangeBound Left;
  29. TLiteralRangeBound Right;
  30. };
  31. TMaybe<TLiteralRange> LiteralRange;
  32. };
  33. virtual TBuildResult BuildComputeNode(const TVector<TString>& indexKeys, TExprContext& ctx, TTypeAnnotationContext& typesCtx) const = 0;
  34. virtual ~IPredicateRangeExtractor() = default;
  35. };
  36. IPredicateRangeExtractor::TPtr MakePredicateRangeExtractor(const TPredicateExtractorSettings& settings = {});
  37. TExprNode::TPtr BuildPointsList(const IPredicateRangeExtractor::TBuildResult&, TConstArrayRef<TString> keyColumns, NYql::TExprContext& expCtx);
  38. }