Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
math-functions.h
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 
16 #ifndef IMPALA_EXPRS_MATH_FUNCTIONS_H
17 #define IMPALA_EXPRS_MATH_FUNCTIONS_H
18 
19 #include <stdint.h>
21 #include "util/string-parser.h"
22 #include "udf/udf.h"
23 
24 using namespace impala_udf;
25 
26 namespace impala {
27 
28 class Expr;
29 struct ExprValue;
30 class TupleRow;
31 
33  public:
34  static DoubleVal Pi(FunctionContext*);
35  static DoubleVal E(FunctionContext*);
36  static BigIntVal Abs(FunctionContext*, const BigIntVal&);
37  static DoubleVal Abs(FunctionContext*, const DoubleVal&);
38  static FloatVal Abs(FunctionContext*, const FloatVal&);
39  static IntVal Abs(FunctionContext*, const IntVal&);
40  static SmallIntVal Abs(FunctionContext*, const SmallIntVal&);
41  static TinyIntVal Abs(FunctionContext*, const TinyIntVal&);
42  static DoubleVal Sin(FunctionContext*, const DoubleVal&);
43  static DoubleVal Asin(FunctionContext*, const DoubleVal&);
44  static DoubleVal Cos(FunctionContext*, const DoubleVal&);
45  static DoubleVal Acos(FunctionContext*, const DoubleVal&);
46  static DoubleVal Tan(FunctionContext*, const DoubleVal&);
47  static DoubleVal Atan(FunctionContext*, const DoubleVal&);
48  static DoubleVal Sqrt(FunctionContext*, const DoubleVal&);
49  static DoubleVal Exp(FunctionContext*, const DoubleVal&);
50  static BigIntVal Ceil(FunctionContext*, const DoubleVal&);
51  static BigIntVal Floor(FunctionContext*, const DoubleVal&);
52  static DoubleVal Ln(FunctionContext*, const DoubleVal&);
53  static DoubleVal Log10(FunctionContext*, const DoubleVal&);
54  static FloatVal Sign(FunctionContext*, const DoubleVal&);
55  static DoubleVal Radians(FunctionContext*, const DoubleVal&);
56  static DoubleVal Degrees(FunctionContext*, const DoubleVal&);
57  static BigIntVal Round(FunctionContext*, const DoubleVal&);
58  static DoubleVal RoundUpTo(FunctionContext*, const DoubleVal&, const IntVal&);
59  static DoubleVal Log2(FunctionContext*, const DoubleVal&);
60  static DoubleVal Log(FunctionContext*, const DoubleVal& base, const DoubleVal& val);
61  static DoubleVal Pow(FunctionContext*, const DoubleVal& base, const DoubleVal& val);
62 
64  static void RandPrepare(FunctionContext*, FunctionContext::FunctionStateScope);
66  static DoubleVal RandSeed(FunctionContext*, const BigIntVal& seed);
67 
68  static StringVal Bin(FunctionContext*, const BigIntVal&);
69  static StringVal HexInt(FunctionContext*, const BigIntVal&);
70  static StringVal HexString(FunctionContext*, const StringVal&);
71  static StringVal Unhex(FunctionContext*, const StringVal&);
72  static StringVal ConvInt(FunctionContext*, const BigIntVal& n,
73  const TinyIntVal& src_base, const TinyIntVal& dst_base);
74  static StringVal ConvString(FunctionContext*, const StringVal& s,
75  const TinyIntVal& src_base, const TinyIntVal& dst_base);
76  static BigIntVal PmodBigInt(FunctionContext*, const BigIntVal&, const BigIntVal&);
77  static DoubleVal PmodDouble(FunctionContext*, const DoubleVal&, const DoubleVal&);
78  static FloatVal FmodFloat(FunctionContext*, const FloatVal&, const FloatVal&);
79  static DoubleVal FmodDouble(FunctionContext*, const DoubleVal&, const DoubleVal&);
80 
81  template <typename T> static T Positive(FunctionContext*, const T&);
82  template <typename T> static T Negative(FunctionContext*, const T&);
83 
84  static BigIntVal QuotientDouble(FunctionContext*, const DoubleVal&, const DoubleVal&);
85  static BigIntVal QuotientBigInt(FunctionContext*, const BigIntVal&, const BigIntVal&);
86 
87  template <typename VAL_TYPE, bool ISLEAST>
88  static VAL_TYPE LeastGreatest(FunctionContext*, int num_args, const VAL_TYPE* args);
89  template <bool ISLEAST> static StringVal LeastGreatest(
90  FunctionContext*, int num_args, const StringVal* args);
91  template <bool ISLEAST> static TimestampVal LeastGreatest(
92  FunctionContext*, int num_args, const TimestampVal* args);
93  template <bool ISLEAST> static DecimalVal LeastGreatest(
94  FunctionContext*, int num_args, const DecimalVal* args);
95 
96  private:
97  static const int32_t MIN_BASE = 2;
98  static const int32_t MAX_BASE = 36;
99  static const char* ALPHANUMERIC_CHARS;
100 
102  static StringVal DecimalToBase(FunctionContext*, int64_t src_num, int8_t dest_base);
103 
109  static bool DecimalInBaseToDecimal(int64_t src_num, int8_t src_base, int64_t* result);
110 
117  static bool HandleParseResult(int8_t dest_base, int64_t* num,
118  StringParser::ParseResult parse_res);
119 };
120 
121 }
122 
123 #endif
This object has a compatible storage format with boost::ptime.
Definition: udf.h:495
unsigned int RandSeed()
static const char * ALPHANUMERIC_CHARS
double Rand()