Arrow 之 Conditions

这篇博客探讨了C++中Arrow Dataset库的实现,特别是`Condition`类和`Expression`类。`Condition`类用于构建数据过滤条件,而`Expression`类则涉及表达式构造,包括函数调用、字段引用和常量。文章详细阐述了这些类的成员函数,如`Bind`、`IsBound`和`IsScalarExpression`,以及它们在数据处理和查询优化中的作用。
摘要由CSDN通过智能技术生成

#cpp/release-build/src/jni/dataset/DTypes.pb.h
#注意这是编译生存的代码

class Condition PROTOBUF_FINAL :
    public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:arrow.dataset.types.Condition) */ {
 public:
  inline Condition() : Condition(nullptr) {}
  virtual ~Condition();

  Condition(const Condition& from);
  Condition(Condition&& from) noexcept
    : Condition() {
    *this = ::std::move(from);
  }

  inline Condition& operator=(const Condition& from) {
    CopyFrom(from);
    return *this;
  }
  inline Condition& operator=(Condition&& from) noexcept {
    if (GetArena() == from.GetArena()) {
      if (this != &from) InternalSwap(&from);
    } else {
      CopyFrom(from);
    }
    return *this;
  }

arrow/cpp/src/arrow/dataset/expression.h

if (condition.has_root()) {
JniAssertOkOrThrow(scanner_builder->Filter(translateFilter(condition, env)));
}

/// An unbound expression which maps a single Datum to another Datum.
/// An expression is one of
/// - A literal Datum.
/// - A reference to a single (potentially nested) field of the input Datum.
/// - A call to a compute function, with arguments specified by other Expressions.
class ARROW_DS_EXPORT Expression {
 public:
  struct Call {
    std::string function_name;
    std::vector<Expression> arguments;
    std::shared_ptr<compute::FunctionOptions> options;
    std::shared_ptr<std::atomic<size_t>> hash;

    // post-Bind properties:
    std::shared_ptr<compute::Function> function;
    const compute::Kernel* kernel = NULLPTR;
    std::shared_ptr<compute::KernelState> kernel_state;
    ValueDescr descr;
  };

  std::string ToString() const;
  bool Equals(const Expression& other) const;
  size_t hash() const;
  struct Hash {
    size_t operator()(const Expression& expr) const { return expr.hash(); }
  };

  /// Bind this expression to the given input type, looking up Kernels and field types.
  /// Some expression simplification may be performed and implicit casts will be inserted.
  /// Any state necessary for execution will be initialized and returned.
  Result<Expression> Bind(ValueDescr in, compute::ExecContext* = NULLPTR) const;
  Result<Expression> Bind(const Schema& in_schema, compute::ExecContext* = NULLPTR) const;

  // XXX someday
  // Clone all KernelState in this bound expression. If any function referenced by this
  // expression has mutable KernelState, it is not safe to execute or apply simplification
  // passes to it (or copies of it!) from multiple threads. Cloning state produces new
  // KernelStates where necessary to ensure that Expressions may be manipulated safely
  // on multiple threads.
  // Result<ExpressionState> CloneState() const;
  // Status SetState(ExpressionState);

  /// Return true if all an expression's field references have explicit ValueDescr and all
  /// of its functions' kernels are looked up.
  bool IsBound() const;

  /// Return true if this expression is composed only of Scalar literals, field
  /// references, and calls to ScalarFunctions.
  bool IsScalarExpression() const;

  /// Return true if this expression is literal and entirely null.
  bool IsNullLiteral() const;

  /// Return true if this expression could evaluate to true.
  bool IsSatisfiable() const;

  // XXX someday
  // Result<PipelineGraph> GetPipelines();

  /// Access a Call or return nullptr if this expression is not a call
  const Call* call() const;
  /// Access a Datum or return nullptr if this expression is not a literal
  const Datum* literal() const;
  /// Access a FieldRef or return nullptr if this expression is not a field_ref
  const FieldRef* field_ref() const;

  /// The type and shape to which this expression will evaluate
  ValueDescr descr() const;
  std::shared_ptr<DataType> type() const { return descr().type; }
  // XXX someday
  // NullGeneralization::type nullable() const;

  struct Parameter {
    FieldRef ref;
    ValueDescr descr;
  };

  Expression() = default;
  explicit Expression(Call call);
  explicit Expression(Datum literal);
  explicit Expression(Parameter parameter);

 private:
  using Impl = util::Variant<Datum, Parameter, Call>;
  std::shared_ptr<Impl> impl_;

  ARROW_DS_EXPORT friend bool Identical(const Expression& l, const Expression& r);

  ARROW_DS_EXPORT friend void PrintTo(const Expression&, std::ostream*);
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值