OmniSciDB  c07336695a
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 "Shared/Logger.h"
30 
31 #include <boost/algorithm/string.hpp>
32 #include <boost/algorithm/string/trim.hpp>
33 #include <boost/regex.hpp>
34 #include <cstring>
35 #include <iostream>
36 #include <iterator>
37 #include <string>
38 
39 #include "Shared/ThriftClient.h"
40 #include "Shared/mapd_shared_ptr.h"
41 #include "Shared/sqltypes.h"
42 
43 #include <chrono>
44 #include <thread>
45 
46 #include <boost/program_options.hpp>
47 
48 // include files for Thrift and MapD Thrift Services
49 #include <thrift/protocol/TBinaryProtocol.h>
50 #include <thrift/protocol/TJSONProtocol.h>
51 #include <thrift/transport/TBufferTransports.h>
52 #include <thrift/transport/THttpClient.h>
53 #include <thrift/transport/TSocket.h>
54 #include "Importer.h"
55 #include "gen-cpp/MapD.h"
56 #include "gen-cpp/mapd_types.h"
57 
58 using namespace ::apache::thrift;
59 using namespace ::apache::thrift::protocol;
60 using namespace ::apache::thrift::transport;
61 
63  public:
64  RowToColumnLoader(const ThriftClientConnection& conn_details,
65  const std::string& user_name,
66  const std::string& passwd,
67  const std::string& db_name,
68  const std::string& table_name);
70  void do_load(int& nrows, int& nskipped, Importer_NS::CopyParams copy_params);
71  bool convert_string_to_column(std::vector<TStringValue> row,
72  const Importer_NS::CopyParams& copy_params);
73  TRowDescriptor get_row_descriptor();
74  std::string print_row_with_delim(std::vector<TStringValue> row,
75  const Importer_NS::CopyParams& copy_params);
76 
77  private:
78  std::string user_name_;
79  std::string passwd_;
80  std::string db_name_;
81  std::string table_name_;
83 
84  std::vector<TColumn> input_columns_;
85  std::vector<SQLTypeInfo> column_type_info_;
86  std::vector<SQLTypeInfo> array_column_type_info_;
87 
88  TRowDescriptor row_desc_;
89 
90  mapd::shared_ptr<MapDClient> client_;
91  TSessionId session_;
92 
94  void closeConnection();
95  void wait_disconnet_reconnnect_retry(size_t tries, Importer_NS::CopyParams copy_params);
96 };
97 
98 #endif // _ROWTOCOLUMNLOADER_H_
mapd::shared_ptr< MapDClient > client_
TRowDescriptor get_row_descriptor()
void do_load(int &nrows, int &nskipped, Importer_NS::CopyParams copy_params)
bool convert_string_to_column(std::vector< TStringValue > row, const Importer_NS::CopyParams &copy_params)
std::string print_row_with_delim(std::vector< TStringValue > row, const Importer_NS::CopyParams &copy_params)
std::string table_name_
Constants for Builtin SQL Types supported by MapD.
std::vector< SQLTypeInfo > column_type_info_
std::string user_name_
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)
void wait_disconnet_reconnnect_retry(size_t tries, Importer_NS::CopyParams copy_params)
void createConnection(const ThriftClientConnection &con)
ThriftClientConnection conn_details_