1 /**
2  * @file   strategy_base.h
3  *
4  * @section LICENSE
5  *
6  * The MIT License
7  *
8  * @copyright Copyright (c) 2017-2021 TileDB, Inc.
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a copy
11  * of this software and associated documentation files (the "Software"), to deal
12  * in the Software without restriction, including without limitation the rights
13  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14  * copies of the Software, and to permit persons to whom the Software is
15  * furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included in
18  * all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26  * THE SOFTWARE.
27  *
28  * @section DESCRIPTION
29  *
30  * This file defines class StrategyBase.
31  */
32 
33 #ifndef TILEDB_STRATEGY_BASE_H
34 #define TILEDB_STRATEGY_BASE_H
35 
36 #include "tiledb/common/logger_public.h"
37 #include "tiledb/common/status.h"
38 #include "tiledb/sm/array_schema/dimension.h"
39 #include "tiledb/sm/misc/types.h"
40 
41 namespace tiledb {
42 namespace sm {
43 
44 class Array;
45 class ArraySchema;
46 class StorageManager;
47 class Subarray;
48 
49 /** Processes read or write queries. */
50 class StrategyBase {
51  public:
52   /* ********************************* */
53   /*     CONSTRUCTORS & DESTRUCTORS    */
54   /* ********************************* */
55 
56   /** Constructor. */
57   StrategyBase(
58       stats::Stats* stats,
59       tdb_shared_ptr<Logger> logger,
60       StorageManager* storage_manager,
61       Array* array,
62       Config& config,
63       std::unordered_map<std::string, QueryBuffer>& buffers,
64       Subarray& subarray,
65       Layout layout);
66 
67   /** Destructor. */
68   ~StrategyBase() = default;
69 
70   /* ********************************* */
71   /*                 API               */
72   /* ********************************* */
73 
74   /** Returns `stats_`. */
75   stats::Stats* stats() const;
76 
77   /** Returns the configured offsets format mode. */
78   std::string offsets_mode() const;
79 
80   /** Sets the offsets format mode. */
81   Status set_offsets_mode(const std::string& offsets_mode);
82 
83   /** Returns `True` if offsets are configured to have an extra element. */
84   bool offsets_extra_element() const;
85 
86   /** Sets if offsets are configured to have an extra element. */
87   Status set_offsets_extra_element(bool add_extra_element);
88 
89   /** Returns the configured offsets bitsize */
90   uint32_t offsets_bitsize() const;
91 
92   /** Sets the bitsize of offsets */
93   Status set_offsets_bitsize(const uint32_t bitsize);
94 
95  protected:
96   /* ********************************* */
97   /*        PROTECTED ATTRIBUTES       */
98   /* ********************************* */
99 
100   /** The class stats. */
101   stats::Stats* stats_;
102 
103   /** The class logger. */
104   tdb_shared_ptr<Logger> logger_;
105 
106   /** The array. */
107   const Array* array_;
108 
109   /** The array schema. */
110   const ArraySchema* array_schema_;
111 
112   /** The config for query-level parameters only. */
113   Config& config_;
114 
115   /**
116    * Maps attribute/dimension names to their buffers.
117    * `TILEDB_COORDS` may be used for the special zipped coordinates
118    * buffer.
119    * */
120   std::unordered_map<std::string, QueryBuffer>& buffers_;
121 
122   /** The layout of the cells in the result of the subarray. */
123   Layout layout_;
124 
125   /** The storage manager. */
126   StorageManager* storage_manager_;
127 
128   /** The query subarray (initially the whole domain by default). */
129   Subarray& subarray_;
130 
131   /** The offset format used for variable-sized attributes. */
132   std::string offsets_format_mode_;
133 
134   /**
135    * If `true`, an extra element that points to the end of the values buffer
136    * will be added in the end of the offsets buffer of var-sized attributes
137    */
138   bool offsets_extra_element_;
139 
140   /** The offset bitsize used for variable-sized attributes. */
141   uint32_t offsets_bitsize_;
142 
143   /* ********************************* */
144   /*          PROTECTED METHODS        */
145   /* ********************************* */
146 
147   /**
148    * Gets statistics about the number of attributes and dimensions in
149    * the query.
150    */
151   void get_dim_attr_stats() const;
152 };
153 
154 }  // namespace sm
155 }  // namespace tiledb
156 
157 #endif  // TILEDB_STRATEGY_BASE_H