OmniSciDB  a47db9e897
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JoinHashTableInterface.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 MapD Technologies, 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 #ifndef QUERYENGINE_JOINHASHTABLEINTERFACE_H
17 #define QUERYENGINE_JOINHASHTABLEINTERFACE_H
18 
19 #include <llvm/IR/Value.h>
20 #include <cstdint>
21 #include <set>
22 #include <string>
23 #include "Analyzer/Analyzer.h"
24 #include "CompilationOptions.h"
25 
26 class TooManyHashEntries : public std::runtime_error {
27  public:
29  : std::runtime_error("Hash tables with more than 2B entries not supported yet") {}
30 };
31 
32 class TableMustBeReplicated : public std::runtime_error {
33  public:
34  TableMustBeReplicated(const std::string& table_name)
35  : std::runtime_error("Hash join failed: Table '" + table_name +
36  "' must be replicated.") {}
37 };
38 
39 class HashJoinFail : public std::runtime_error {
40  public:
41  HashJoinFail(const std::string& reason) : std::runtime_error(reason) {}
42 };
43 
45  public:
47  : HashJoinFail("Not enough memory for columns involvde in join") {}
48 };
49 
51  public:
52  FailedToJoinOnVirtualColumn() : HashJoinFail("Cannot join on rowid") {}
53 };
54 
56  llvm::Value* elements;
57  llvm::Value* count;
58  llvm::Value* slot;
59 };
60 
62  std::vector<int64_t> key;
63  std::set<int32_t> payload;
64 
65  bool operator<(const DecodedJoinHashBufferEntry& other) const {
66  return std::tie(key, payload) < std::tie(other.key, other.payload);
67  }
68 
69  bool operator==(const DecodedJoinHashBufferEntry& other) const {
70  return key == other.key && payload == other.payload;
71  }
72 }; // struct DecodedJoinHashBufferEntry
73 
74 using InnerOuter = std::pair<const Analyzer::ColumnVar*, const Analyzer::Expr*>;
75 
77  public:
78  virtual int64_t getJoinHashBuffer(const ExecutorDeviceType device_type,
79  const int device_id) const noexcept = 0;
80 
81  virtual size_t getJoinHashBufferSize(const ExecutorDeviceType device_type,
82  const int device_id) const noexcept = 0; // bytes
83 
84  virtual std::string toString(const ExecutorDeviceType device_type,
85  const int device_id,
86  bool raw = false) const noexcept = 0;
87 
88  virtual std::string toStringFlat64(const ExecutorDeviceType device_type,
89  const int device_id) const noexcept;
90 
91  virtual std::string toStringFlat32(const ExecutorDeviceType device_type,
92  const int device_id) const noexcept;
93 
94  virtual std::set<DecodedJoinHashBufferEntry> decodeJoinHashBuffer(
95  const ExecutorDeviceType device_type,
96  const int device_id) const noexcept = 0;
97 
98  virtual llvm::Value* codegenSlot(const CompilationOptions&, const size_t) = 0;
99 
101  const size_t) = 0;
102 
103  virtual int getInnerTableId() const noexcept = 0;
104 
105  virtual int getInnerTableRteIdx() const noexcept = 0;
106 
107  enum class HashType { OneToOne, OneToMany };
108 
109  virtual HashType getHashType() const noexcept = 0;
110 
111  virtual size_t offsetBufferOff() const noexcept = 0;
112 
113  virtual size_t countBufferOff() const noexcept = 0;
114 
115  virtual size_t payloadBufferOff() const noexcept = 0;
116 };
117 
118 std::string decodeJoinHashBufferToString(
119  size_t key_component_count, // number of key parts
120  size_t key_component_width, // width of a key part
121  const int8_t* ptr1, // hash entries
122  const int8_t* ptr2, // offsets
123  const int8_t* ptr3, // counts
124  const int8_t* ptr4, // payloads (rowids)
125  size_t buffer_size,
126  bool raw = false);
127 
128 std::ostream& operator<<(std::ostream& os, const DecodedJoinHashBufferEntry& e);
129 
130 std::ostream& operator<<(std::ostream& os, const std::set<DecodedJoinHashBufferEntry>& s);
131 
133  size_t key_component_count, // number of key parts
134  size_t key_component_width, // width of a key part
135  const int8_t* ptr1, // hash entries
136  const int8_t* ptr2, // offsets
137  const int8_t* ptr3, // counts
138  const int8_t* ptr4, // payloads (rowids)
139  size_t buffer_size);
140 
141 #endif // QUERYENGINE_JOINHASHTABLEINTERFACE_H
Defines data structures for the semantic analysis phase of query processing.
ExecutorDeviceType
virtual int64_t getJoinHashBuffer(const ExecutorDeviceType device_type, const int device_id) const noexcept=0
virtual llvm::Value * codegenSlot(const CompilationOptions &, const size_t)=0
TableMustBeReplicated(const std::string &table_name)
std::string decodeJoinHashBufferToString(size_t key_component_count, size_t key_component_width, const int8_t *ptr1, const int8_t *ptr2, const int8_t *ptr3, const int8_t *ptr4, size_t buffer_size, bool raw)
std::pair< const Analyzer::ColumnVar *, const Analyzer::Expr * > InnerOuter
virtual size_t getJoinHashBufferSize(const ExecutorDeviceType device_type, const int device_id) const noexcept=0
virtual int getInnerTableId() const noexcept=0
virtual std::set< DecodedJoinHashBufferEntry > decodeJoinHashBuffer(const ExecutorDeviceType device_type, const int device_id) const noexcept=0
virtual std::string toStringFlat64(const ExecutorDeviceType device_type, const int device_id) const noexcept
HashJoinFail(const std::string &reason)
virtual int getInnerTableRteIdx() const noexcept=0
virtual std::string toStringFlat32(const ExecutorDeviceType device_type, const int device_id) const noexcept
virtual HashJoinMatchingSet codegenMatchingSet(const CompilationOptions &, const size_t)=0
virtual size_t payloadBufferOff() const noexcept=0
virtual HashType getHashType() const noexcept=0
bool g_enable_watchdog false
Definition: Execute.cpp:71
bool operator==(const DecodedJoinHashBufferEntry &other) const
std::set< int32_t > payload
virtual std::string toString(const ExecutorDeviceType device_type, const int device_id, bool raw=false) const noexcept=0
std::vector< int64_t > key
virtual size_t offsetBufferOff() const noexcept=0
virtual size_t countBufferOff() const noexcept=0
bool operator<(const DecodedJoinHashBufferEntry &other) const