OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TargetValueConverters.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef TARGET_VALUE_CONVERTERS_H_
18 #define TARGET_VALUE_CONVERTERS_H_
19 
20 #include "../Catalog/Catalog.h"
21 #include "../QueryEngine/TargetMetaInfo.h"
22 #include "../QueryEngine/TargetValue.h"
23 #include "../Shared/sqldefs.h"
24 #include "../Shared/sqltypes.h"
25 
26 template <typename RETURN_TYPE>
27 class boost_variant_accessor : public boost::static_visitor<const RETURN_TYPE*> {
28  public:
29  const RETURN_TYPE* operator()(RETURN_TYPE const& operand) const { return &operand; }
30 
31  const RETURN_TYPE* operator()(void* operand) const { return nullptr; }
32 
33  template <typename T>
34  const RETURN_TYPE* operator()(T const& operand) const {
35  throw std::runtime_error("Unexpected data type");
36  }
37 };
38 
39 template <typename RETURN_TYPE, typename SOURCE_TYPE>
40 const RETURN_TYPE* checked_get(size_t row,
41  const SOURCE_TYPE* boost_variant,
43  return boost::apply_visitor(accessor, *boost_variant);
44 }
45 
46 template <typename TARGET_TYPE>
48  void operator()(TARGET_TYPE* p) { free(p); }
49 };
50 
52  public:
54 
58 
61 
63 
64  virtual ~TargetValueConverter() {}
65 
66  virtual void allocateColumnarData(size_t num_rows) = 0;
67 
68  virtual void convertToColumnarFormat(size_t row, const TargetValue* value) = 0;
69 
71 
72  virtual void addDataBlocksToInsertData(
73  Fragmenter_Namespace::InsertData& insertData) = 0;
74 };
75 
76 #endif
void operator()(TARGET_TYPE *p)
TargetValueConverter(const ColumnDescriptor *cd)
const ColumnDescriptor * column_descriptor_
virtual void convertToColumnarFormat(size_t row, const TargetValue *value)=0
boost_variant_accessor< ScalarTargetValue > SCALAR_TARGET_VALUE_ACCESSOR
const RETURN_TYPE * operator()(void *operand) const
boost_variant_accessor< NullableString > NULLABLE_STRING_ACCESSOR
virtual void finalizeDataBlocksForInsertData()
virtual void allocateColumnarData(size_t num_rows)=0
virtual void addDataBlocksToInsertData(Fragmenter_Namespace::InsertData &insertData)=0
boost_variant_accessor< std::string > STRING_ACCESSOR
specifies the content in-memory of a row in the column metadata table
const RETURN_TYPE * checked_get(size_t row, const SOURCE_TYPE *boost_variant, boost_variant_accessor< RETURN_TYPE > &accessor)
const RETURN_TYPE * operator()(T const &operand) const
boost_variant_accessor< GeoTargetValue > GEO_TARGET_VALUE_ACCESSOR
The data to be inserted using the fragment manager.
Definition: Fragmenter.h:68
boost_variant_accessor< ArrayTargetValue > ARRAY_TARGET_VALUE_ACCESSOR
const RETURN_TYPE * operator()(RETURN_TYPE const &operand) const
boost::variant< ScalarTargetValue, ArrayTargetValue, GeoTargetValue, GeoTargetValuePtr > TargetValue
Definition: TargetValue.h:195