OmniSciDB  04ee39c94c
TargetValueConverters.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018, OmniSci, 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 "../Import/Importer.h"
22 #include "../QueryEngine/TargetMetaInfo.h"
23 #include "../QueryEngine/TargetValue.h"
24 #include "../Shared/sqldefs.h"
25 #include "../Shared/sqltypes.h"
26 
27 template <typename RETURN_TYPE>
28 class boost_variant_accessor : public boost::static_visitor<const RETURN_TYPE*> {
29  public:
30  const RETURN_TYPE* operator()(RETURN_TYPE const& operand) const { return &operand; }
31 
32  const RETURN_TYPE* operator()(void* operand) const { return nullptr; }
33 
34  template <typename T>
35  const RETURN_TYPE* operator()(T const& operand) const {
36  throw std::runtime_error("Unexpected data type");
37  }
38 };
39 
40 template <typename RETURN_TYPE, typename SOURCE_TYPE>
41 const RETURN_TYPE* checked_get(size_t row,
42  const SOURCE_TYPE* boost_variant,
44  return boost::apply_visitor(accessor, *boost_variant);
45 }
46 
47 template <typename TARGET_TYPE>
49  void operator()(TARGET_TYPE* p) { free(p); }
50 };
51 
53  public:
55 
59 
62 
63  TargetValueConverter(const ColumnDescriptor* cd) : column_descriptor_(cd){};
64 
65  virtual ~TargetValueConverter() {}
66 
67  virtual void allocateColumnarData(size_t num_rows) = 0;
68 
69  virtual void convertToColumnarFormat(size_t row, const TargetValue* value) = 0;
70 
72 
73  virtual void addDataBlocksToInsertData(
74  Fragmenter_Namespace::InsertData& insertData) = 0;
75 };
76 
77 #endif
void operator()(TARGET_TYPE *p)
const int8_t const int64_t * num_rows
TargetValueConverter(const ColumnDescriptor *cd)
const ColumnDescriptor * column_descriptor_
boost_variant_accessor< ScalarTargetValue > SCALAR_TARGET_VALUE_ACCESSOR
boost_variant_accessor< NullableString > NULLABLE_STRING_ACCESSOR
virtual void finalizeDataBlocksForInsertData()
const RETURN_TYPE * operator()(T const &operand) const
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()(void *operand) const
boost_variant_accessor< GeoTargetValue > GEO_TARGET_VALUE_ACCESSOR
The data to be inserted using the fragment manager.
Definition: Fragmenter.h:59
boost_variant_accessor< ArrayTargetValue > ARRAY_TARGET_VALUE_ACCESSOR
boost::variant< ScalarTargetValue, ArrayTargetValue, GeoTargetValue, GeoTargetValuePtr > TargetValue
Definition: TargetValue.h:167
const RETURN_TYPE * operator()(RETURN_TYPE const &operand) const