OmniSciDB  3a86f6ec37
ParquetDateInSecondsEncoder.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 "ParquetInPlaceEncoder.h"
20 
21 namespace foreign_storage {
24  public:
26  const ColumnDescriptor* column_desciptor,
27  const parquet::ColumnDescriptor* parquet_column_descriptor)
28  : TypedParquetInPlaceEncoder<int64_t, int32_t>(buffer,
29  column_desciptor,
30  parquet_column_descriptor) {
31  CHECK(parquet_column_descriptor->logical_type()->is_date());
32  }
33 
34  void encodeAndCopy(const int8_t* parquet_data_bytes,
35  int8_t* omnisci_data_bytes) override {
36  const auto& parquet_data_value =
37  reinterpret_cast<const int32_t*>(parquet_data_bytes)[0];
38  auto& omnisci_data_value = reinterpret_cast<int64_t*>(omnisci_data_bytes)[0];
39  omnisci_data_value = parquet_data_value * kSecsPerDay;
40  }
41 
42  void validate(std::shared_ptr<parquet::Statistics> stats,
43  const SQLTypeInfo& column_type) const override {
44  CHECK(column_type.is_date());
45  if (column_type.get_compression() ==
46  kENCODING_NONE) { // do not validate NONE ENCODED dates as it is impossible for
47  // bounds to be exceeded (the conversion done for this case is
48  // from a date in days as a 32-bit integer to a date in seconds
49  // as a 64-bit integer)
50  return;
51  }
52  auto [unencoded_stats_min, unencoded_stats_max] =
55  unencoded_stats_max * kSecsPerDay, column_type);
57  unencoded_stats_min * kSecsPerDay, column_type);
58  }
59 };
60 
61 } // namespace foreign_storage
static constexpr int64_t kSecsPerDay
bool is_date() const
Definition: sqltypes.h:715
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:319
void encodeAndCopy(const int8_t *parquet_data_bytes, int8_t *omnisci_data_bytes) override
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
static void validateValue(const D &data_value, const SQLTypeInfo &column_type)
#define CHECK(condition)
Definition: Logger.h:197
std::pair< T, T > getUnencodedStats(std::shared_ptr< parquet::Statistics > stats) const
ParquetDateInSecondsEncoder(Data_Namespace::AbstractBuffer *buffer, const ColumnDescriptor *column_desciptor, const parquet::ColumnDescriptor *parquet_column_descriptor)
void validate(std::shared_ptr< parquet::Statistics > stats, const SQLTypeInfo &column_type) const override