30 namespace foreign_storage {
34 if (sys_catalog.getMetadataForDBById(db_id, db_metadata)) {
45 auto table_name = catalog->getTableName(table_id);
46 if (table_name.has_value()) {
47 return table_name.value();
56 std::map<std::string, import_export::TypedImportBuffer*>& import_buffers) {
57 if (import_buffers.find(
"node") != import_buffers.end()) {
60 import_buffers[
"node"]->addDictStringWithTruncation(leaf_string);
62 import_buffers[
"node"]->addDictStringWithTruncation(
"Server");
68 : db_id_(-1), foreign_table_(nullptr) {}
72 : db_id_(db_id), foreign_table_(foreign_table) {}
84 static const std::set<std::string_view> supported_table_options{};
85 return supported_table_options;
94 const std::set<std::string_view>&
96 static const std::set<std::string_view> supported_user_mapping_options{};
97 return supported_user_mapping_options;
104 std::set<const ColumnDescriptor*>& columns_to_parse,
107 for (
auto& [chunk_key, buffer] : buffers) {
115 if (column->columnType.is_varlen_indeed()) {
117 size_t index_offset_size{0};
118 if (column->columnType.is_string()) {
120 }
else if (column->columnType.is_array()) {
123 UNREACHABLE() <<
"Unexpected column type: " << column->columnType.to_string();
125 ChunkKey index_chunk_key = chunk_key;
127 CHECK(buffers.find(index_chunk_key) != buffers.end());
128 AbstractBuffer* index_buffer = buffers.find(index_chunk_key)->second;
129 index_buffer->
reserve(index_offset_size * row_count + 1);
130 chunks[chunk_key].setIndexBuffer(index_buffer);
133 if (!column->columnType.is_varlen_indeed()) {
134 buffer->reserve(column->columnType.get_size() * row_count);
136 chunks[chunk_key].setBuffer(buffer);
137 chunks[chunk_key].initEncoder();
138 columns_to_parse.emplace(column);
143 std::vector<std::unique_ptr<import_export::TypedImportBuffer>>& import_buffers,
144 std::map<std::string, import_export::TypedImportBuffer*>& import_buffers_map,
145 const std::set<const ColumnDescriptor*>& columns_to_parse,
147 for (
const auto column : columns_to_parse) {
149 if (column->columnType.is_dict_encoded_string() ||
150 (column->columnType.is_array() &&
IS_STRING(column->columnType.get_subtype()) &&
152 auto dict_descriptor =
154 string_dictionary = dict_descriptor->stringDict.get();
156 import_buffers.emplace_back(
157 std::make_unique<import_export::TypedImportBuffer>(column, string_dictionary));
158 import_buffers_map[column->columnName] = import_buffers.back().get();
166 auto catalog = sys_catalog.getCatalog(
db_id_);
173 "System table size exceeds the maximum supported size."};
178 if (column->columnType.is_varlen_indeed()) {
179 chunk_key.emplace_back(1);
181 chunk_metadata_vector.emplace_back(
191 CHECK(optional_buffers.empty());
194 auto catalog = sys_catalog.getCatalog(
db_id_);
200 <<
"In-memory system tables are expected to have a single fragment.";
202 std::map<ChunkKey, Chunk_NS::Chunk> chunks;
203 std::set<const ColumnDescriptor*> columns_to_parse;
205 chunks, required_buffers,
row_count_, columns_to_parse, fragment_id, *catalog);
208 std::vector<std::unique_ptr<import_export::TypedImportBuffer>> import_buffers;
209 std::map<std::string, import_export::TypedImportBuffer*> import_buffers_map;
211 import_buffers, import_buffers_map, columns_to_parse, *catalog);
214 auto column_id_to_data_blocks_map =
216 for (
auto& [chunk_key, chunk] : chunks) {
217 auto data_block_entry =
219 CHECK(data_block_entry != column_id_to_data_blocks_map.end());
220 chunk.appendData(data_block_entry->second,
row_count_, 0);
221 chunk.setBuffer(
nullptr);
222 chunk.setIndexBuffer(
nullptr);
231 const std::string& file_path,
std::vector< int > ChunkKey
std::string getSerializedDataWrapper() const override
class for a per-database catalog. also includes metadata for the current database and the current use...
virtual void initializeObjectsForTable(const std::string &table_name)=0
bool is_varlen_data_key(const ChunkKey &key)
constexpr const char * kDeletedValueIndicator
const std::set< std::string_view > & getSupportedTableOptions() const override
static std::map< int, DataBlockPtr > convertImportBuffersToDataBlocks(const std::vector< std::unique_ptr< import_export::TypedImportBuffer >> &import_buffers, const bool skip_dict_encoding=false)
#define CHUNK_KEY_FRAGMENT_IDX
std::map< ChunkKey, AbstractBuffer * > ChunkToBufferMap
const std::string kInfoSchemaDbName
bool isRestored() const override
void validateTableOptions(const ForeignTable *foreign_table) const override
This file contains the class specification and related data structures for Catalog.
InternalSystemDataWrapper()
void restoreDataWrapperInternals(const std::string &file_path, const ChunkMetadataVector &chunk_metadata) override
std::shared_ptr< ChunkMetadata > get_placeholder_metadata(const SQLTypeInfo &type, size_t num_elements)
static SysCatalog & instance()
This file contains the class specification and related data structures for SysCatalog.
void validateUserMappingOptions(const UserMapping *user_mapping, const ForeignServer *foreign_server) const override
void initialize_chunks(std::map< ChunkKey, Chunk_NS::Chunk > &chunks, const ChunkToBufferMap &buffers, size_t row_count, std::set< const ColumnDescriptor * > &columns_to_parse, int32_t fragment_id, const Catalog_Namespace::Catalog &catalog)
bool is_varlen_index_key(const ChunkKey &key)
void set_node_name(std::map< std::string, import_export::TypedImportBuffer * > &import_buffers)
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
#define CHUNK_KEY_TABLE_IDX
virtual void populateChunkBuffersForTable(const std::string &table_name, std::map< std::string, import_export::TypedImportBuffer * > &import_buffers)=0
An AbstractBuffer is a unit of data management for a data manager.
const DictDescriptor * getMetadataForDict(int dict_ref, bool loadDict=true) const
void populateChunkMetadata(ChunkMetadataVector &chunk_metadata_vector) override
void populateChunkBuffers(const ChunkToBufferMap &required_buffers, const ChunkToBufferMap &optional_buffers, AbstractBuffer *delete_buffer) override
std::shared_ptr< Catalog > getCatalog(const std::string &dbName)
int32_t g_distributed_leaf_idx
const ForeignTable * foreign_table_
const std::list< const ColumnDescriptor * > & getLogicalColumns() const
void validateServerOptions(const ForeignServer *foreign_server) const override
#define CHUNK_KEY_VARLEN_IDX
#define DEBUG_TIMER(name)
std::string get_db_name(int32_t db_id)
#define CHUNK_KEY_COLUMN_IDX
const std::set< std::string_view > & getSupportedUserMappingOptions() const override
void initialize_import_buffers(std::vector< std::unique_ptr< import_export::TypedImportBuffer >> &import_buffers, std::map< std::string, import_export::TypedImportBuffer * > &import_buffers_map, const std::set< const ColumnDescriptor * > &columns_to_parse, const Catalog_Namespace::Catalog &catalog)
virtual void reserve(size_t num_bytes)=0
std::string get_table_name(int32_t db_id, int32_t table_id)