OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ForeignTableSchema.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, 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 #include "ForeignTableSchema.h"
18 #include "Catalog/Catalog.h"
19 
20 namespace foreign_storage {
22  const ForeignTable* foreign_table) {
24  CHECK(catalog_);
25  foreign_table_ = foreign_table;
27  catalog_->getAllColumnMetadataForTable(foreign_table->tableId, false, false, true);
29  catalog_->getAllColumnMetadataForTable(foreign_table->tableId, false, false, false);
30 
31  for (const auto column : logical_columns_) {
32  logical_column_ids_.emplace_back(column->columnId);
33  }
34 }
35 
37  const int column_id) const {
38  auto column = catalog_->getMetadataForColumn(foreign_table_->tableId, column_id);
39  CHECK(column);
40  return column;
41 }
42 
43 const ColumnDescriptor* ForeignTableSchema::getLogicalColumn(const int column_id) const {
44  auto logical_column_id = *getLogicalColumnIdIterator(column_id);
45  CHECK_LE(logical_column_id, column_id);
46  return getColumnDescriptor(logical_column_id);
47 }
48 
49 int ForeignTableSchema::getParquetColumnIndex(const int column_id) const {
50  auto column_index =
51  std::distance(logical_column_ids_.begin(), getLogicalColumnIdIterator(column_id));
52  CHECK_GE(column_index, 0);
53  return column_index;
54 }
55 
56 const std::list<const ColumnDescriptor*>&
59 }
60 
62  return logical_and_physical_columns_.size();
63 }
64 
65 const std::list<const ColumnDescriptor*>& ForeignTableSchema::getLogicalColumns() const {
66  return logical_columns_;
67 }
68 
70  return logical_columns_.size();
71 }
72 
74  return foreign_table_;
75 }
76 
77 std::vector<int>::const_iterator ForeignTableSchema::getLogicalColumnIdIterator(
78  const int column_id) const {
79  auto it =
80  std::upper_bound(logical_column_ids_.begin(), logical_column_ids_.end(), column_id);
81  CHECK(it != logical_column_ids_.begin());
82  it--;
83  return it;
84 }
85 } // namespace foreign_storage
DEVICE auto upper_bound(ARGS &&...args)
Definition: gpu_enabled.h:123
std::list< const ColumnDescriptor * > logical_and_physical_columns_
#define CHECK_GE(x, y)
Definition: Logger.h:306
int getParquetColumnIndex(const int column_id) const
const ForeignTable * getForeignTable() const
This file contains the class specification and related data structures for Catalog.
static SysCatalog & instance()
Definition: SysCatalog.h:343
ForeignTableSchema(const int32_t db_id, const ForeignTable *foreign_table)
specifies the content in-memory of a row in the column metadata table
const std::list< const ColumnDescriptor * > & getLogicalAndPhysicalColumns() const
std::shared_ptr< Catalog > getCatalog(const std::string &dbName)
std::shared_ptr< Catalog_Namespace::Catalog > catalog_
#define CHECK_LE(x, y)
Definition: Logger.h:304
const std::list< const ColumnDescriptor * > & getLogicalColumns() const
#define CHECK(condition)
Definition: Logger.h:291
const ColumnDescriptor * getLogicalColumn(const int column_id) const
std::list< const ColumnDescriptor * > logical_columns_
std::vector< int >::const_iterator getLogicalColumnIdIterator(const int column_id) const
const ColumnDescriptor * getColumnDescriptor(const int column_id) const