OmniSciDB  16c4e035a1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RowToColumnLoader.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 #ifndef _ROWTOCOLUMNLOADER_H_
18 #define _ROWTOCOLUMNLOADER_H_
19 
29 #include "Logger/Logger.h"
30 
31 #include <boost/algorithm/string.hpp>
32 #include <boost/algorithm/string/trim.hpp>
33 
34 #if defined(_WIN32) && !defined(WIN32_LEAN_AND_MEAN)
35 // boost/regex.hpp on win32 includes Windows.h
36 // and we need to clean up macros such as ERROR and GetObject
37 #define WIN32_LEAN_AND_MEAN
38 #endif
39 
40 #include <boost/regex.hpp>
41 
42 #if defined(_WIN32) && defined(WIN32_LEAN_AND_MEAN)
44 #undef WIN32_LEAN_AND_MEAN
45 #endif
46 
47 #include <cstring>
48 #include <iostream>
49 #include <iterator>
50 #include <string>
51 
52 #include "Shared/ThriftClient.h"
53 #include "Shared/sqltypes.h"
54 
55 #include <chrono>
56 #include <thread>
57 
58 #include <boost/program_options.hpp>
59 
60 // include files for Thrift and MapD Thrift Services
61 #include "CopyParams.h"
62 #include "gen-cpp/OmniSci.h"
63 #include "gen-cpp/omnisci_types.h"
64 
65 using namespace ::apache::thrift;
66 using namespace ::apache::thrift::protocol;
67 using namespace ::apache::thrift::transport;
68 
70  public:
71  RowToColumnLoader(const ThriftClientConnection& conn_details,
72  const std::string& user_name,
73  const std::string& passwd,
74  const std::string& db_name,
75  const std::string& table_name);
77  void do_load(int& nrows, int& nskipped, import_export::CopyParams copy_params);
78  bool convert_string_to_column(std::vector<TStringValue> row,
79  const import_export::CopyParams& copy_params);
80  TRowDescriptor get_row_descriptor();
81  std::string print_row_with_delim(std::vector<TStringValue> row,
82  const import_export::CopyParams& copy_params);
83 
84  private:
85  std::string user_name_;
86  std::string passwd_;
87  std::string db_name_;
88  std::string table_name_;
90 
91  std::vector<TColumn> input_columns_;
92  std::vector<SQLTypeInfo> column_type_info_;
93  std::vector<SQLTypeInfo> array_column_type_info_;
94 
95  TRowDescriptor row_desc_;
96 
97  std::shared_ptr<OmniSciClient> client_;
98  TSessionId session_;
99 
101  void closeConnection();
102  void wait_disconnect_reconnect_retry(size_t tries,
103  import_export::CopyParams copy_params);
104 };
105 
106 #endif // _ROWTOCOLUMNLOADER_H_
TRowDescriptor get_row_descriptor()
std::string print_row_with_delim(std::vector< TStringValue > row, const import_export::CopyParams &copy_params)
std::string table_name_
Constants for Builtin SQL Types supported by OmniSci.
std::vector< SQLTypeInfo > column_type_info_
std::string user_name_
void do_load(int &nrows, int &nskipped, import_export::CopyParams copy_params)
TRowDescriptor row_desc_
std::vector< TColumn > input_columns_
std::vector< SQLTypeInfo > array_column_type_info_
RowToColumnLoader(const ThriftClientConnection &conn_details, const std::string &user_name, const std::string &passwd, const std::string &db_name, const std::string &table_name)
bool convert_string_to_column(std::vector< TStringValue > row, const import_export::CopyParams &copy_params)
void wait_disconnect_reconnect_retry(size_t tries, import_export::CopyParams copy_params)
void createConnection(const ThriftClientConnection &con)
ThriftClientConnection conn_details_
std::shared_ptr< OmniSciClient > client_