Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
context.h
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17 
18 #ifndef ARROW_COMPUTE_CONTEXT_H
19 #define ARROW_COMPUTE_CONTEXT_H
20 
21 #include <cstdint>
22 #include <memory>
23 
24 #include "arrow/memory_pool.h"
25 #include "arrow/status.h"
26 #include "arrow/util/macros.h"
27 #include "arrow/util/visibility.h"
28 
29 namespace arrow {
30 
31 class Buffer;
32 
33 namespace internal {
34 class CpuInfo;
35 } // namespace internal
36 
37 namespace compute {
38 
39 #define RETURN_IF_ERROR(ctx) \
40  if (ARROW_PREDICT_FALSE(ctx->HasError())) { \
41  Status s = ctx->status(); \
42  ctx->ResetStatus(); \
43  return s; \
44  }
45 
47 class ARROW_EXPORT FunctionContext {
48  public:
50  MemoryPool* memory_pool() const;
51 
53  Status Allocate(const int64_t nbytes, std::shared_ptr<Buffer>* out);
54 
60  void SetStatus(const Status& status);
61 
63  void ResetStatus();
64 
66  bool HasError() const { return !status_.ok(); }
67 
69  const Status& status() const { return status_; }
70 
71  internal::CpuInfo* cpu_info() const { return cpu_info_; }
72 
73  private:
74  Status status_;
75  MemoryPool* pool_;
76  internal::CpuInfo* cpu_info_;
77 };
78 
79 } // namespace compute
80 } // namespace arrow
81 
82 #endif // ARROW_COMPUTE_CONTEXT_H
#define ARROW_MEMORY_POOL_DEFAULT
Definition: memory_pool.h:117
bool HasError() const
Return true if an error has occurred.
Definition: context.h:66
Container for variables and options used by function evaluation.
Definition: context.h:47
Definition: status.h:95
internal::CpuInfo * cpu_info() const
Definition: context.h:71
Top-level namespace for Apache Arrow C++ API.
Definition: adapter.h:32
const Status & status() const
Return the current status of the context.
Definition: context.h:69
Base class for memory allocation.
Definition: memory_pool.h:34
::arrow::Buffer Buffer
Definition: memory.h:54