0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
HqlInterpreter.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
22 #ifndef Hypertable_Lib_HqlInterpreter_h
23 #define Hypertable_Lib_HqlInterpreter_h
24 
25 #include <Hypertable/Lib/Cells.h>
29 
30 #include <FsBroker/Lib/Client.h>
31 
33 
34 #include <memory>
35 #include <vector>
36 
37 namespace Hypertable {
38 
39  class Client;
40  using namespace std;
41 
42  namespace Hql { class ParserState; }
43 
48  public:
50  struct Callback {
51  FILE *output; // default is NULL
52  bool normal_mode; // default true
53  bool format_ts_in_nanos; // default false
54  // mutator stats
55  uint64_t total_cells,
56  total_keys_size,
58  file_size;
59 
60  Callback(bool normal = true) : output(0), normal_mode(normal),
61  format_ts_in_nanos(false), total_cells(0), total_keys_size(0),
62  total_values_size(0), file_size(0) { }
63  virtual ~Callback() { }
64 
66  virtual void on_parsed(Hql::ParserState &) { }
67 
71  virtual void on_return(const std::string &) { }
72 
74  virtual void on_scan(TableScannerPtr &) { }
75 
77  virtual void on_dump(TableDumper &) { }
78 
80  virtual void on_update(size_t total) { }
81 
83  virtual void on_progress(size_t amount) { }
84 
89  virtual void on_finish(TableMutatorPtr &mutator) {
90  if (mutator) {
91  try {
92  mutator->flush();
93  }
94  catch (Exception &e) {
95  mutator->show_failed(e);
96  throw;
97  }
98  }
99  }
100 
101  virtual void on_finish() { }
102 
104  virtual void on_finish(TableScannerPtr &scanner) { }
105 
106  };
107 
111  std::vector<String> &retstrs;
112 
113  SmallCallback(CellsBuilder &builder, std::vector<String> &strs)
114  : cells(builder), retstrs(strs) { }
115 
116  void on_return(const std::string &ret) override { retstrs.push_back(ret); }
117  void on_scan(TableScannerPtr &scanner) override { copy(*scanner, cells); }
118  void on_dump(TableDumper &dumper) override { copy(dumper, cells); }
119  };
120 
122  HqlInterpreter(Client *client, ConnectionManagerPtr &conn_mgr,
123  bool immutable_namespace=true);
124 
126  int execute(const std::string &str, Callback &);
127 
129  int execute(const std::string &str, CellsBuilder &output, std::vector<String> &ret) {
130  SmallCallback cb(output, ret);
131  return execute(str, cb);
132  }
133 
135  int execute(const std::string &cmd) {
136  CellsBuilder cb;
137  std::vector<String> res;
138  return execute(cmd, cb, res);
139  }
140 
141  void set_namespace(const std::string &ns);
142 
143  private:
146  uint32_t m_mutator_flags;
150  };
151 
153  typedef std::shared_ptr<HqlInterpreter> HqlInterpreterPtr;
154 
155 }
156 
157 #endif // Hypertable_Lib_HqlInterpreter_h
virtual void on_finish(TableMutatorPtr &mutator)
Called when interpreter is finished Note: mutator pointer maybe NULL in case of things like LOAD DATA...
void on_return(const std::string &ret) override
Called when interpreter returns a string result Maybe called multiple times for a list of string resu...
ConnectionManagerPtr m_conn_manager
Po::typed_value< String > * str(String *v=0)
Definition: Properties.h:166
STL namespace.
SmallCallback(CellsBuilder &builder, std::vector< String > &strs)
std::shared_ptr< TableScanner > TableScannerPtr
Smart pointer to TableScanner.
Definition: TableScanner.h:124
virtual void on_update(size_t total)
Called when interpreter is ready to update.
virtual void on_parsed(Hql::ParserState &)
Called when the hql string is parsed successfully.
std::shared_ptr< Namespace > NamespacePtr
Shared smart pointer to Namespace.
Definition: Namespace.h:333
std::shared_ptr< TableMutator > TableMutatorPtr
Smart pointer to TableMutator.
Definition: TableMutator.h:257
virtual void on_progress(size_t amount)
Called when interpreter updates progress for long running queries.
The API of HQL interpreter.
std::shared_ptr< Client > ClientPtr
Smart pointer to Client.
Definition: Client.h:233
void on_dump(TableDumper &dumper) override
Called when interpreter is ready to dump.
virtual void on_scan(TableScannerPtr &)
Called when interpreter is ready to scan.
virtual void on_dump(TableDumper &)
Called when interpreter is ready to dump.
Po::typed_value< Strings > * strs(Strings *v=0)
Definition: Properties.h:170
Hypertable definitions
std::shared_ptr< HqlInterpreter > HqlInterpreterPtr
Smart pointer to HqlInterpreter.
void copy(TableDumper &, CellsBuilder &)
Definition: TableDumper.cc:129
Callback interface/base class for execute.
virtual void on_finish(TableScannerPtr &scanner)
Called when scan is finished.
int execute(const std::string &cmd)
More convenient method for admin commands (create/drop table etc.)
Declarations for ConnectionManager.
virtual void on_return(const std::string &)
Called when interpreter returns a string result Maybe called multiple times for a list of string resu...
int execute(const std::string &str, CellsBuilder &output, std::vector< String > &ret)
A convenient method demonstrate the usage of the interface.
This is a generic exception class for Hypertable.
Definition: Error.h:314
std::shared_ptr< ConnectionManager > ConnectionManagerPtr
Smart pointer to ConnectionManager.
FsBroker::Lib::ClientPtr m_fs_client
An example for simple queries that returns small number of results.
Declarations for Client.
void on_scan(TableScannerPtr &scanner) override
Called when interpreter is ready to scan.