OmniSciDB  2e3a973ef4
ParquetDecimalEncoder.h
Go to the documentation of this file.
1 /*
2  * Copyright 2020 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 #pragma once
18 
19 #include <arrow/util/decimal.h>
20 #include "ParquetInPlaceEncoder.h"
21 
22 namespace foreign_storage {
23 template <typename V, typename T>
25  public:
27  const ColumnDescriptor* column_desciptor,
28  const parquet::ColumnDescriptor* parquet_column_descriptor)
29  : TypedParquetInPlaceEncoder<V, T>(buffer,
30  column_desciptor,
31  parquet_column_descriptor)
32  , parquet_column_type_length_(parquet_column_descriptor->type_length()) {}
33 
34  void encodeAndCopy(const int8_t* parquet_data_bytes,
35  int8_t* omnisci_data_bytes) override {
36  const auto& parquet_data_value = reinterpret_cast<const T*>(parquet_data_bytes)[0];
37  auto& omnisci_data_value = reinterpret_cast<V*>(omnisci_data_bytes)[0];
38  encodeAndCopy(parquet_data_value, omnisci_data_value);
39  }
40 
41  protected:
42  void encodeAndCopy(const int32_t& parquet_data_value, V& omnisci_data_value) {
43  omnisci_data_value = parquet_data_value;
44  }
45 
46  void encodeAndCopy(const int64_t& parquet_data_value, V& omnisci_data_value) {
47  omnisci_data_value = parquet_data_value;
48  }
49 
50  void encodeAndCopy(const parquet::FixedLenByteArray& parquet_data_value,
51  V& omnisci_data_value) {
52  omnisci_data_value =
54  }
55 
56  void encodeAndCopy(const parquet::ByteArray& parquet_data_value,
57  V& omnisci_data_value) {
58  omnisci_data_value =
59  convertDecimalByteArrayToInt(parquet_data_value.ptr, parquet_data_value.len);
60  }
61 
62  bool encodingIsIdentityForSameTypes() const override { return true; }
63 
64  private:
65  int64_t convertDecimalByteArrayToInt(const uint8_t* byte_array,
66  const int byte_array_size) {
67  auto result = arrow::Decimal128::FromBigEndian(byte_array, byte_array_size);
68  CHECK(result.ok()) << result.status().message();
69  auto& decimal = result.ValueOrDie();
70  return static_cast<int64_t>(decimal);
71  }
72 
74 };
75 } // namespace foreign_storage
void encodeAndCopy(const int8_t *parquet_data_bytes, int8_t *omnisci_data_bytes) override
void encodeAndCopy(const int64_t &parquet_data_value, V &omnisci_data_value)
int64_t convertDecimalByteArrayToInt(const uint8_t *byte_array, const int byte_array_size)
void encodeAndCopy(const parquet::ByteArray &parquet_data_value, V &omnisci_data_value)
bool encodingIsIdentityForSameTypes() const override
void encodeAndCopy(const int32_t &parquet_data_value, V &omnisci_data_value)
An AbstractBuffer is a unit of data management for a data manager.
specifies the content in-memory of a row in the column metadata table
void encodeAndCopy(const parquet::FixedLenByteArray &parquet_data_value, V &omnisci_data_value)
#define CHECK(condition)
Definition: Logger.h:197
ParquetDecimalEncoder(Data_Namespace::AbstractBuffer *buffer, const ColumnDescriptor *column_desciptor, const parquet::ColumnDescriptor *parquet_column_descriptor)