OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AbstractTextFileDataWrapper.h
Go to the documentation of this file.
1 /*
2  * Copyright 2021 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 <map>
20 #include <set>
21 
24 #include "Catalog/ForeignTable.h"
25 #include "DataMgr/Chunk/Chunk.h"
29 
30 namespace foreign_storage {
31 
33  public:
35 
36  AbstractTextFileDataWrapper(const int db_id, const ForeignTable* foreign_table);
37 
38  void populateChunkMetadata(ChunkMetadataVector& chunk_metadata_vector) override;
39 
40  void populateChunkBuffers(const ChunkToBufferMap& required_buffers,
41  const ChunkToBufferMap& optional_buffers) override;
42 
43  std::string getSerializedDataWrapper() const override;
44 
45  void restoreDataWrapperInternals(const std::string& file_path,
46  const ChunkMetadataVector& chunk_metadata) override;
47  bool isRestored() const override;
48 
50 
52  return INTRA_FRAGMENT;
53  }
54 
55  protected:
56  virtual const TextFileBufferParser& getFileBufferParser() const = 0;
57 
58  private:
59  AbstractTextFileDataWrapper(const ForeignTable* foreign_table);
60 
68  void populateChunks(std::map<int, Chunk_NS::Chunk>& column_id_to_chunk_map,
69  int fragment_id);
70 
71  void populateChunkMapForColumns(const std::set<const ColumnDescriptor*>& columns,
72  const int fragment_id,
73  const ChunkToBufferMap& buffers,
74  std::map<int, Chunk_NS::Chunk>& column_id_to_chunk_map);
75 
76  void updateMetadata(std::map<int, Chunk_NS::Chunk>& column_id_to_chunk_map,
77  int fragment_id);
78 
79  std::map<ChunkKey, std::shared_ptr<ChunkMetadata>> chunk_metadata_map_;
80  std::map<int, FileRegions> fragment_id_to_file_regions_map_;
81 
82  std::unique_ptr<FileReader> file_reader_;
83 
84  const int db_id_;
86 
87  // Data needed for append workflow
88  std::map<ChunkKey, std::unique_ptr<ForeignStorageBuffer>> chunk_encoder_buffers_;
89  // How many rows have been read
90  size_t num_rows_;
91  // What byte offset we left off at in the file_reader
93  // Is this datawrapper restored from disk
95 };
96 } // namespace foreign_storage
std::map< ChunkKey, AbstractBuffer * > ChunkToBufferMap
void populateChunkBuffers(const ChunkToBufferMap &required_buffers, const ChunkToBufferMap &optional_buffers) override
std::map< ChunkKey, std::unique_ptr< ForeignStorageBuffer > > chunk_encoder_buffers_
virtual const TextFileBufferParser & getFileBufferParser() const =0
void populateChunkMetadata(ChunkMetadataVector &chunk_metadata_vector) override
std::map< ChunkKey, std::shared_ptr< ChunkMetadata > > chunk_metadata_map_
void populateChunks(std::map< int, Chunk_NS::Chunk > &column_id_to_chunk_map, int fragment_id)
void updateMetadata(std::map< int, Chunk_NS::Chunk > &column_id_to_chunk_map, int fragment_id)
ParallelismLevel getNonCachedParallelismLevel() const override
std::vector< std::pair< ChunkKey, std::shared_ptr< ChunkMetadata >>> ChunkMetadataVector
ParallelismLevel getCachedParallelismLevel() const override
void restoreDataWrapperInternals(const std::string &file_path, const ChunkMetadataVector &chunk_metadata) override
void populateChunkMapForColumns(const std::set< const ColumnDescriptor * > &columns, const int fragment_id, const ChunkToBufferMap &buffers, std::map< int, Chunk_NS::Chunk > &column_id_to_chunk_map)