OmniSciDB  2e3a973ef4
ForeignTableSchema.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 "Catalog/Catalog.h"
20 
21 namespace foreign_storage {
23  public:
24  ForeignTableSchema(const int32_t db_id, const ForeignTable* foreign_table) {
26  foreign_table_ = foreign_table;
27  logical_and_physical_columns_ = catalog_->getAllColumnMetadataForTableUnlocked(
28  foreign_table->tableId, false, false, true);
29  logical_columns_ = catalog_->getAllColumnMetadataForTableUnlocked(
30  foreign_table->tableId, false, false, false);
31 
32  for (const auto column : logical_columns_) {
33  logical_column_ids_.emplace_back(column->columnId);
34  }
35  }
36 
40  const ColumnDescriptor* getColumnDescriptor(const int column_id) const {
41  auto column =
42  catalog_->getMetadataForColumnUnlocked(foreign_table_->tableId, column_id);
43  CHECK(column);
44  return column;
45  }
46 
52  const ColumnDescriptor* getLogicalColumn(const int column_id) const {
53  auto logical_column_id = *getLogicalColumnIdIterator(column_id);
54  CHECK_LE(logical_column_id, column_id);
55  return getColumnDescriptor(logical_column_id);
56  }
57 
62  int getParquetColumnIndex(const int column_id) const {
63  auto column_index =
64  std::distance(logical_column_ids_.begin(), getLogicalColumnIdIterator(column_id));
65  CHECK_GE(column_index, 0);
66  return column_index;
67  }
68 
72  const std::list<const ColumnDescriptor*>& getLogicalAndPhysicalColumns() const {
74  }
75 
80  return logical_and_physical_columns_.size();
81  }
82 
86  const std::list<const ColumnDescriptor*>& getLogicalColumns() const {
87  return logical_columns_;
88  }
89 
93  int numLogicalColumns() const { return logical_columns_.size(); }
94 
98  const ForeignTable* getForeignTable() const { return foreign_table_; }
99 
100  private:
101  std::vector<int>::const_iterator getLogicalColumnIdIterator(const int column_id) const {
102  auto it = std::upper_bound(
103  logical_column_ids_.begin(), logical_column_ids_.end(), column_id);
104  CHECK(it != logical_column_ids_.begin());
105  it--;
106  return it;
107  }
108 
109  std::list<const ColumnDescriptor*> logical_and_physical_columns_;
110  std::list<const ColumnDescriptor*> logical_columns_;
111  std::vector<int> logical_column_ids_;
113  std::shared_ptr<Catalog_Namespace::Catalog> catalog_;
114 };
115 } // namespace foreign_storage
std::list< const ColumnDescriptor * > logical_and_physical_columns_
#define CHECK_GE(x, y)
Definition: Logger.h:210
This file contains the class specification and related data structures for Catalog.
ForeignTableSchema(const int32_t db_id, const ForeignTable *foreign_table)
const ColumnDescriptor * getColumnDescriptor(const int column_id) const
static std::shared_ptr< Catalog > checkedGet(const int32_t db_id)
Definition: Catalog.cpp:3770
specifies the content in-memory of a row in the column metadata table
const std::list< const ColumnDescriptor * > & getLogicalColumns() const
int getParquetColumnIndex(const int column_id) const
std::shared_ptr< Catalog_Namespace::Catalog > catalog_
#define CHECK_LE(x, y)
Definition: Logger.h:208
const std::list< const ColumnDescriptor * > & getLogicalAndPhysicalColumns() const
#define CHECK(condition)
Definition: Logger.h:197
std::vector< int >::const_iterator getLogicalColumnIdIterator(const int column_id) const
const ColumnDescriptor * getLogicalColumn(const int column_id) const
std::list< const ColumnDescriptor * > logical_columns_
const ForeignTable * getForeignTable() const