Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
key-normalizer.h
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef IMPALA_UTIL_KEY_NORMALIZER_H_
16 #define IMPALA_UTIL_KEY_NORMALIZER_H_
17 
18 #include "exprs/expr.h"
19 
20 namespace impala {
21 
24 //
30 //
50 //
53  public:
56  KeyNormalizer(const std::vector<ExprContext*>& key_exprs_ctxs, int key_len,
57  const std::vector<bool>& is_asc, const std::vector<bool>& nulls_first)
58  : key_expr_ctxs_(key_expr_ctxs), key_len_(key_len), is_asc_(is_asc),
59  nulls_first_(nulls_first) {
60  }
61 
67  bool NormalizeKey(TupleRow* tuple_row, uint8_t* dst, int* key_idx_over_budget = NULL);
68 
69  private:
71  static bool WriteNullBit(uint8_t null_bit, uint8_t* value, uint8_t* dst,
72  int* bytes_left);
73 
77  template <typename ValueType>
78  static void StoreFinalValue(ValueType value, void* dst, bool is_asc);
79 
80  template <typename IntType>
81  static void NormalizeInt(void* src, void* dst, bool is_asc);
82 
85  template <typename FloatType, typename ResultType>
86  static void NormalizeFloat(void* src, void* dst, bool is_asc);
87 
88  static void NormalizeTimestamp(uint8_t* src, uint8_t* dst, bool is_asc);
89 
92  static bool WriteNormalizedKey(const ColumnType& type, bool is_asc,
93  uint8_t* value, uint8_t* dst, int* bytes_left);
94 
97  static bool NormalizeKeyColumn(const ColumnType& type, uint8_t null_bit, bool is_asc,
98  uint8_t* value, uint8_t* dst, int* bytes_left);
99 
100  std::vector<ExprContext*> key_expr_ctxs_;
101  int key_len_;
102  std::vector<bool> is_asc_;
103  std::vector<bool> nulls_first_;
104 };
105 
106 }
107 
108 #endif
Finally, we pad any remaining bytes of the key with zeroes.
bool NormalizeKey(TupleRow *tuple_row, uint8_t *dst, int *key_idx_over_budget=NULL)
static void NormalizeTimestamp(uint8_t *src, uint8_t *dst, bool is_asc)
static void NormalizeFloat(void *src, void *dst, bool is_asc)
static void NormalizeInt(void *src, void *dst, bool is_asc)
static bool NormalizeKeyColumn(const ColumnType &type, uint8_t null_bit, bool is_asc, uint8_t *value, uint8_t *dst, int *bytes_left)
static bool WriteNormalizedKey(const ColumnType &type, bool is_asc, uint8_t *value, uint8_t *dst, int *bytes_left)
std::vector< ExprContext * > key_expr_ctxs_
static void StoreFinalValue(ValueType value, void *dst, bool is_asc)
std::vector< bool > is_asc_
static bool WriteNullBit(uint8_t null_bit, uint8_t *value, uint8_t *dst, int *bytes_left)
Returns true if we went over the max key size while writing the null bit.
std::vector< bool > nulls_first_
KeyNormalizer(const std::vector< ExprContext * > &key_exprs_ctxs, int key_len, const std::vector< bool > &is_asc, const std::vector< bool > &nulls_first)