selectClause.h
Go to the documentation of this file.
1 // $Id$
2 // Author: John Wu <John.Wu at acm.org>
3 // Lawrence Berkeley National Laboratory
4 // Copyright (c) 2007-2016 the Regents of the University of California
8 #ifndef IBIS_SELECTCLAUSE_H
9 #define IBIS_SELECTCLAUSE_H
10 #include "qExpr.h"
11 #include "table.h"
12 
13 namespace ibis {
14  class selectLexer;
15  class selectParser;
16 }
17 
112 class FASTBIT_CXX_DLLSPEC ibis::selectClause {
113 public:
115  explicit selectClause(const char *cl=0);
118  ~selectClause();
119 
121  selectClause(const selectClause&);
122 
124  int parse(const char *cl);
125 
127  const char* getString(void) const {return clause_.c_str();}
129  const char* operator*(void) const {return clause_.c_str();}
130 
132  bool empty() const {return atms_.empty();}
133 
134  void printDetails(std::ostream&) const;
135  void print(std::ostream&) const;
136  int find(const char*) const;
137 
142  typedef std::vector<ibis::math::term*> mathTerms;
144  const mathTerms& getTerms() const {return xtms_;}
146  const ibis::math::term* termExpr(unsigned i) const {return xtms_[i];}
147 
149  uint32_t numTerms() const {return xtms_.size();}
153  const char* termName(unsigned i) const {return xnames_[i].c_str();}
154  std::string termDescription(unsigned i) const;
155  typedef std::map<const char*, const char*, ibis::lessi> nameMap;
156  int getAliases(nameMap&) const;
157  uint32_t numGroupbyKeys() const;
158  int getGroupbyKeys(std::vector<std::string>& keys) const;
160 
164  enum AGREGADO {NIL_AGGR, AVG, CNT, MAX, MIN, SUM, DISTINCT,
165  VARPOP, VARSAMP, STDPOP, STDSAMP, MEDIAN, CONCAT};
167  uint32_t aggSize() const {return atms_.size();}
169  AGREGADO getAggregator(uint32_t i) const {return aggr_[i];}
170 
174  const ibis::math::term* aggExpr(unsigned i) const {return atms_[i];}
179  const char* aggName(unsigned i) const {return names_[i].c_str();}
183  std::string aggDescription(unsigned i) const {
184  return aggDescription(aggr_[i], atms_[i]);}
185  std::string aggDescription(AGREGADO, const ibis::math::term*) const;
186 
187  bool needsEval(const ibis::part&) const;
188  bool isSeparable() const;
189  const char* isUnivariate() const;
190 
191  typedef std::map<std::string, unsigned> StringToInt;
192  const StringToInt& getOrdered() const {return ordered_;}
194 
195  int verify(const ibis::part&) const;
196  int verifySome(const std::vector<uint32_t>&, const ibis::part&) const;
197  static int verifyTerm(const ibis::math::term&, const ibis::part&,
198  const ibis::selectClause* =0);
199 
200  void getNullMask(const ibis::part&, ibis::bitvector&) const;
201  void clear();
202 
205  selectClause tmp(rhs);
206  swap(tmp);
207  return *this;
208  }
210  void swap(selectClause& rhs) {
211  atms_.swap(rhs.atms_);
212  aggr_.swap(rhs.aggr_);
213  names_.swap(rhs.names_);
214  ordered_.swap(rhs.ordered_);
215  xtms_.swap(rhs.xtms_);
216  xalias_.swap(rhs.xalias_);
217  xnames_.swap(rhs.xnames_);
218  clause_.swap(rhs.clause_);
219  }
220 
221  // forward declaration
222  class variable;
223  friend class variable;
224 
225 protected:
227  mathTerms atms_;
229  std::vector<AGREGADO> aggr_;
231  std::vector<std::string> names_;
233  StringToInt ordered_;
235  mathTerms xtms_;
237  StringToInt xalias_;
239  std::vector<std::string> xnames_;
240 
241  std::string clause_;
242 
244 
245  friend class ibis::selectParser;
246 
247  void fillNames();
250  uint64_t decodeAName(const char*) const;
251  void addTerm(ibis::math::term*, const std::string*);
252  ibis::math::term* addRecursive(ibis::math::term*&);
253  bool hasAggregation(const ibis::math::term *tm) const;
254 
255  typedef std::map<const char*, ibis::selectClause::variable*,
256  ibis::lessi> varMap;
257  void gatherVariables(varMap &vmap, ibis::math::term* t) const;
258 }; // class ibis::selectClause
259 
263 public:
264  variable(const char* s, const ibis::selectClause *c)
265  : ibis::math::variable(s), sc_(c) {};
266  variable(const variable &v) : ibis::math::variable(v), sc_(v.sc_) {};
267  virtual variable* dup() const {return new variable(*this);}
268  virtual void print(std::ostream&) const;
269  void updateReference(const ibis::selectClause *c) {sc_=c;}
270 
271 private:
272  const ibis::selectClause *sc_;
273 
274  variable();
275 }; // class ibis::selectClause::variable
276 
277 namespace std {
278  inline ostream& operator<<(ostream& out, const ibis::selectClause& sel) {
279  sel.print(out);
280  return out;
281  } // std::operator<<
282 }
283 #endif
const ibis::math::term * aggExpr(unsigned i) const
Fetch the ith term inside the select clause.
Definition: selectClause.h:174
const StringToInt & getOrdered() const
Functions related to internal aggregation operations.
Definition: selectClause.h:192
StringToInt xalias_
Aliases.
Definition: selectClause.h:237
const ibis::math::term * termExpr(unsigned i) const
Fetch the ith term visible to the outside. No array bound checking.
Definition: selectClause.h:146
std::string termDescription(unsigned i) const
Produce a string for the jth term of the select clause.
Definition: selectClause.cpp:594
int getGroupbyKeys(std::vector< std::string > &keys) const
Gather the implicit group-by keys into a vector.
Definition: selectClause.cpp:609
void print(std::ostream &) const
Write a string version of the select clause to the specified output stream.
Definition: selectClause.cpp:697
static int verifyTerm(const ibis::math::term &, const ibis::part &, const ibis::selectClause *=0)
Verify the specified term has valid column names.
Definition: selectClause.cpp:847
std::map< const char *, const char *, ibis::lessi > nameMap
Functions related to extenally visible portion of the select clause.
Definition: selectClause.h:155
uint32_t numTerms() const
Number of terms visible to the outside.
Definition: selectClause.h:149
A class to represent the select clause.
Definition: selectClause.h:112
STL namespace.
const char * isUnivariate() const
Is the select caluse univariate? If yes, return the pointer to the string value, otherwise return a n...
Definition: selectClause.cpp:405
The current implementation of FastBit is code named IBIS; most data structures and functions are in t...
Definition: bord.h:16
const mathTerms & getTerms() const
Retrieve all top-level arithmetic expressions.
Definition: selectClause.h:144
std::vector< std::string > names_
Names of the variables inside the aggregation functions.
Definition: selectClause.h:231
selectClause & operator=(const selectClause &rhs)
Assignment operator.
Definition: selectClause.h:204
int parse(const char *cl)
Parse a new string.
Definition: selectClause.cpp:86
const char * aggName(unsigned i) const
Name inside the aggregation function.
Definition: selectClause.h:179
uint64_t decodeAName(const char *) const
Determine if the name refers to a term in the list of aggregation functions.
Definition: selectClause.cpp:433
StringToInt ordered_
A ordered version of names_.
Definition: selectClause.h:233
Define the query expression.
virtual void print(std::ostream &) const
Print a human readable version of the expression.
Definition: selectClause.cpp:926
mathTerms atms_
Arithmetic expressions used by aggregators.
Definition: selectClause.h:227
void fillNames()
Fill array names_ and xnames_.
Definition: selectClause.cpp:183
int verify(const ibis::part &) const
Verify the select clause is valid against the given data partition.
Definition: selectClause.cpp:800
A variable.
Definition: qExpr.h:812
std::string aggDescription(unsigned i) const
Produce a string description for the ith aggregation expression.
Definition: selectClause.h:183
The class ibis::part represents a partition of a relational table.
Definition: part.h:27
void addTerm(ibis::math::term *, const std::string *)
Add a top-level term.
Definition: selectClause.cpp:447
int find(const char *) const
Locate the position of the string.
Definition: selectClause.cpp:628
bool isSeparable() const
Can the select clause be evaluated in separate parts? Return true if there is at least one aggregator...
Definition: selectClause.cpp:389
void swap(selectClause &rhs)
Swap the content of two select clauses.
Definition: selectClause.h:210
std::vector< AGREGADO > aggr_
Aggregators.
Definition: selectClause.h:229
std::vector< std::string > xnames_
Names of the top-level terms.
Definition: selectClause.h:239
uint32_t aggSize() const
The number of arithmetic expressions inside the select clause.
Definition: selectClause.h:167
std::vector< ibis::math::term * > mathTerms
Functions related to extenally visible portion of the select clause.
Definition: selectClause.h:142
Defines a new class with the desired lex function for C++ output of bison.
Definition: selectLexer.h:33
const char * operator*(void) const
Dereferences to the string form of the select clause.
Definition: selectClause.h:129
bool needsEval(const ibis::part &) const
Does the data partition need additional processing to process the select clause? If any of the (lower...
Definition: selectClause.cpp:378
void clear(ibis::array_t< ibis::bitvector * > &bv)
Clear an array of bit vectors.
Definition: bitvector.cpp:4662
std::map< std::string, unsigned > StringToInt
Functions related to internal aggregation operations.
Definition: selectClause.h:191
The abstract base class for arithmetic terms.
Definition: qExpr.h:728
int verifySome(const std::vector< uint32_t > &, const ibis::part &) const
Verify the selected terms.
Definition: selectClause.cpp:823
ibis::math::variable * addAgregado(ibis::selectClause::AGREGADO, ibis::math::term *)
Record an aggregation function.
Definition: selectClause.cpp:294
AGREGADO
Functions related to internal aggregation operations.
Definition: selectClause.h:164
A data structure to represent a sequence of bits.
Definition: bitvector.h:62
mathTerms xtms_
Top-level terms. Externally visible arithmetic expressions.
Definition: selectClause.h:235
const char * getString(void) const
Return a pointer to the string form of the select clause.
Definition: selectClause.h:127
FastBit Table Interface.
int getAliases(nameMap &) const
Map internal column names to external column names.
Definition: selectClause.cpp:272
AGREGADO getAggregator(uint32_t i) const
Return the aggregation function used for the ith term.
Definition: selectClause.h:169
ibis::selectLexer * lexer
!< String version of the select clause.
Definition: selectClause.h:243
virtual variable * dup() const
Make a duplicate copy of the term.
Definition: selectClause.h:267
bool hasAggregation(const ibis::math::term *tm) const
Does the math expression contain any aggregation operations?
Definition: selectClause.cpp:465
const char * termName(unsigned i) const
Name given to the top-level function.
Definition: selectClause.h:153
A specialization of ibis::math::variable.
Definition: selectClause.h:262
selectClause(const char *cl=0)
Parse a new string as a select clause.
Definition: selectClause.cpp:10
uint32_t numGroupbyKeys() const
Number of terms without aggregation functions.
Definition: selectClause.cpp:365
bool empty() const
Returns true if this select clause is empty.
Definition: selectClause.h:132

Make It A Bit Faster
Contact us
Disclaimers
FastBit source code
FastBit mailing list archive