OmniSciDB  a667adc9c8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CsvFileBufferParser.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 
21 #include "Geospatial/Types.h"
23 #include "Shared/misc.h"
24 
25 namespace foreign_storage {
26 namespace csv_file_buffer_parser {
27 static constexpr bool PROMOTE_POLYGON_TO_MULTIPOLYGON = true;
28 
29 std::map<int, DataBlockPtr> convert_import_buffers_to_data_blocks(
30  const std::vector<std::unique_ptr<import_export::TypedImportBuffer>>& import_buffers);
31 
33  ParseBufferRequest(const ParseBufferRequest& request) = delete;
34  ParseBufferRequest(ParseBufferRequest&& request) = default;
37  int db_id,
38  const ForeignTable* foreign_table,
39  const std::set<int> column_filter_set,
40  const std::string& full_path);
41 
42  inline std::shared_ptr<Catalog_Namespace::Catalog> getCatalog() const {
43  // MAT are we really doing any good wrapping this?
45  CHECK(catalog);
46  return catalog;
47  }
48 
49  inline std::list<const ColumnDescriptor*> getColumns() const {
50  return foreign_table_schema->getLogicalAndPhysicalColumns();
51  }
52 
53  inline int32_t getTableId() const {
54  return foreign_table_schema->getForeignTable()->tableId;
55  }
56 
57  inline std::string getTableName() const {
58  return foreign_table_schema->getForeignTable()->tableName;
59  }
60 
61  inline size_t getMaxFragRows() const {
62  return foreign_table_schema->getForeignTable()->maxFragRows;
63  }
64 
65  inline std::string getFilePath() const { return full_path; }
66 
67  // These must be initialized at construction (before parsing).
68  std::unique_ptr<char[]> buffer;
69  size_t buffer_size;
72  const int db_id;
73  std::unique_ptr<ForeignTableSchema> foreign_table_schema;
74  std::vector<std::unique_ptr<import_export::TypedImportBuffer>> import_buffers;
75 
76  // These are set during parsing.
78  size_t begin_pos;
79  size_t end_pos;
81  size_t file_offset;
83  std::string full_path;
84 };
85 
87  std::map<int, DataBlockPtr> column_id_to_data_blocks_map;
88  size_t row_count;
89  std::vector<size_t> row_offsets;
90 };
91 
92 inline bool skip_column_import(ParseBufferRequest& request, int column_idx) {
93  return request.import_buffers[column_idx] == nullptr;
94 }
95 
97  const std::string& row,
98  const import_export::CopyParams& copy_params,
99  size_t num_cols,
100  int point_cols,
101  const std::string& file_name);
102 
110 ParseBufferResult parse_buffer(ParseBufferRequest& request,
111  bool convert_data_blocks,
112  bool columns_are_pre_filtered = false);
113 
114 } // namespace csv_file_buffer_parser
115 } // namespace foreign_storage
std::vector< std::unique_ptr< import_export::TypedImportBuffer > > import_buffers
std::list< const ColumnDescriptor * > getColumns() const
static SysCatalog & instance()
Definition: SysCatalog.h:292
std::shared_ptr< Catalog_Namespace::Catalog > getCatalog() const
void parse_and_validate_expected_column_count(const std::string &row, const import_export::CopyParams &copy_params, size_t num_cols, int point_cols, const std::string &file_name)
ParseBufferResult parse_buffer(ParseBufferRequest &request, bool convert_data_blocks, bool columns_are_pre_filtered)
std::unique_ptr< ForeignTableSchema > foreign_table_schema
bool skip_column_import(ParseBufferRequest &request, int column_idx)
std::shared_ptr< Catalog > getCatalog(const std::string &dbName)
static constexpr bool PROMOTE_POLYGON_TO_MULTIPOLYGON
ParseBufferRequest(const ParseBufferRequest &request)=delete
#define CHECK(condition)
Definition: Logger.h:197
std::map< int, DataBlockPtr > convert_import_buffers_to_data_blocks(const std::vector< std::unique_ptr< import_export::TypedImportBuffer >> &import_buffers)