OmniSciDB  6686921089
 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 <thrift/protocol/TBinaryProtocol.h>
62 #include <thrift/protocol/TJSONProtocol.h>
63 #include <thrift/transport/TBufferTransports.h>
64 #include <thrift/transport/THttpClient.h>
65 #include <thrift/transport/TSocket.h>
66 #include "CopyParams.h"
67 #include "gen-cpp/OmniSci.h"
68 #include "gen-cpp/omnisci_types.h"
69 
70 using namespace ::apache::thrift;
71 using namespace ::apache::thrift::protocol;
72 using namespace ::apache::thrift::transport;
73 
75  public:
76  RowToColumnLoader(const ThriftClientConnection& conn_details,
77  const std::string& user_name,
78  const std::string& passwd,
79  const std::string& db_name,
80  const std::string& table_name);
82  void do_load(int& nrows, int& nskipped, import_export::CopyParams copy_params);
83  bool convert_string_to_column(std::vector<TStringValue> row,
84  const import_export::CopyParams& copy_params);
85  TRowDescriptor get_row_descriptor();
86  std::string print_row_with_delim(std::vector<TStringValue> row,
87  const import_export::CopyParams& copy_params);
88 
89  private:
90  std::string user_name_;
91  std::string passwd_;
92  std::string db_name_;
93  std::string table_name_;
95 
96  std::vector<TColumn> input_columns_;
97  std::vector<SQLTypeInfo> column_type_info_;
98  std::vector<SQLTypeInfo> array_column_type_info_;
99 
100  TRowDescriptor row_desc_;
101 
102  std::shared_ptr<OmniSciClient> client_;
103  TSessionId session_;
104 
106  void closeConnection();
107  void wait_disconnect_reconnect_retry(size_t tries,
108  import_export::CopyParams copy_params);
109 };
110 
111 #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_