25 const std::vector<Parser::SharedDictionaryDef>& shared_dict_defs) {
27 for (; idx < shared_dict_defs.size(); idx++) {
28 if (!shared_dict_defs[idx].get_column().compare(cur_node.
get_column()) &&
29 !shared_dict_defs[idx].get_foreign_table().compare(
31 !shared_dict_defs[idx].get_foreign_column().compare(
37 CHECK_LT(idx, shared_dict_defs.size());
39 size_t ret_val_idx = idx;
40 for (
size_t j = 0; j < shared_dict_defs.size(); j++) {
41 for (
size_t i = 0; i < shared_dict_defs.size(); ++i) {
42 if (!shared_dict_defs[i].get_column().compare(
43 shared_dict_defs[ret_val_idx].get_foreign_column())) {
48 if (shared_dict_defs[ret_val_idx].get_foreign_table().compare(
56 return shared_dict_defs[ret_val_idx];
63 const std::vector<Parser::SharedDictionaryDef>& shared_dict_defs,
64 const std::list<ColumnDescriptor>& columns) {
65 std::string reference_col_qualified_name =
68 throw std::runtime_error(
69 "Dictionary cannot be shared with itself. For dictionary : " +
70 reference_col_qualified_name);
74 auto col = std::find_if(
75 columns.rbegin(), columns.rend(), [shared_dict_def](
const ColumnDescriptor& elem) {
76 return !elem.columnName.compare(shared_dict_def->
get_column());
78 CHECK(col != columns.rend());
80 std::find_if(col, columns.rend(), [shared_dict_def](
const ColumnDescriptor& elem) {
84 if (ref_col == columns.rend()) {
85 throw std::runtime_error(
"Dictionary dependencies might create a cycle for " +
86 shared_dict_def->
get_column() +
"referencing " +
87 reference_col_qualified_name);
93 const std::list<ColumnDescriptor>& columns) {
94 for (
const auto& cd : columns) {
95 if (cd.columnName == name) {
103 const std::list<const ColumnDescriptor*>& columns) {
104 for (
const auto& cd : columns) {
105 if (cd->columnName == name) {
113 const std::string&
name,
114 const std::list<std::unique_ptr<Parser::TableElement>>& table_element_list) {
115 for (
const auto& e : table_element_list) {
117 if (!col_def || *col_def->get_column_name() !=
name) {
132 const std::list<ColumnDescriptor>& columns,
133 const std::vector<Parser::SharedDictionaryDef>& shared_dict_defs_so_far,
135 CHECK(shared_dict_def);
138 const auto col_qualified_name = *table_name +
"." + shared_dict_def->
get_column();
140 throw std::runtime_error(
"Column " + col_qualified_name +
" doesn't exist");
142 if (!cd_ptr->columnType.is_string() ||
144 throw std::runtime_error(
"Column " + col_qualified_name +
145 " must be a dictionary encoded string");
147 const std::list<std::unique_ptr<Parser::TableElement>>& table_element_list =
150 throw std::runtime_error(
151 "Column " + col_qualified_name +
152 " shouldn't specify an encoding, it borrows it from the referenced column");
163 if (!foreign_td && table_name->compare(foreign_table_name)) {
164 throw std::runtime_error(
"Table " + foreign_table_name +
" doesn't exist");
168 if (foreign_td->isForeignTable()) {
172 throw std::runtime_error(
173 "Attempting to share dictionary with foreign table " + foreign_table_name +
174 ". Foreign table dictionaries cannot currently be shared.");
176 const auto reference_columns =
178 const auto reference_cd_ptr =
180 if (!reference_cd_ptr) {
181 throw std::runtime_error(
"Could not find referenced column " +
183 foreign_td->tableName);
185 if (!reference_cd_ptr->columnType.is_string() ||
186 reference_cd_ptr->columnType.get_compression() !=
kENCODING_DICT) {
187 const auto reference_col_qualified_name =
189 throw std::runtime_error(
"Referenced column " + reference_col_qualified_name +
190 " must be a dictionary encoded string column");
194 const auto reference_col_qualified_name =
196 const auto reference_cd_ptr =
198 if (!reference_cd_ptr) {
199 throw std::runtime_error(
"Column " + reference_col_qualified_name +
202 if (!reference_cd_ptr->columnType.is_string() ||
203 reference_cd_ptr->columnType.get_compression() !=
kENCODING_DICT) {
204 throw std::runtime_error(
"Column " + reference_col_qualified_name +
205 " must be a dictionary encoded string");
208 stmt, shared_dict_def, shared_dict_defs_so_far, columns);
211 std::find_if(shared_dict_defs_so_far.begin(),
212 shared_dict_defs_so_far.end(),
214 return elem.get_column() == shared_dict_def->
get_column();
216 if (it != shared_dict_defs_so_far.end()) {
217 throw std::runtime_error(
"Duplicate shared dictionary hint for column " +
218 *table_name +
"." + shared_dict_def->
get_column());
const Parser::SharedDictionaryDef compress_reference_path(Parser::SharedDictionaryDef cur_node, const std::vector< Parser::SharedDictionaryDef > &shared_dict_defs)
class for a per-database catalog. also includes metadata for the current database and the current use...
virtual const std::list< std::unique_ptr< TableElement > > & get_table_element_list() const =0
const std::string & get_foreign_table() const
const std::string & get_column() const
void validate_shared_dictionary_order(const Parser::CreateTableBaseStmt *stmt, const Parser::SharedDictionaryDef *shared_dict_def, const std::vector< Parser::SharedDictionaryDef > &shared_dict_defs, const std::list< ColumnDescriptor > &columns)
const ColumnDescriptor * lookup_column(const std::string &name, const std::list< ColumnDescriptor > &columns)
const Parser::CompressDef * get_compression_for_column(const std::string &name, const std::list< std::unique_ptr< Parser::TableElement >> &table_element_list)
virtual const std::string * get_table() const =0
const std::string & get_foreign_column() const
specifies the content in-memory of a row in the column metadata table
const CompressDef * get_compression() const
std::list< const ColumnDescriptor * > getAllColumnMetadataForTable(const int tableId, const bool fetchSystemColumns, const bool fetchVirtualColumns, const bool fetchPhysicalColumns) const
Returns a list of pointers to constant ColumnDescriptor structs for all the columns from a particular...
void validate_shared_dictionary(const Parser::CreateTableBaseStmt *stmt, const Parser::SharedDictionaryDef *shared_dict_def, const std::list< ColumnDescriptor > &columns, const std::vector< Parser::SharedDictionaryDef > &shared_dict_defs_so_far, const Catalog_Namespace::Catalog &catalog)
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.