1 /* Copyright (C) 2017 MariaDB Corporation
2 
3    This program is free software; you can redistribute it and/or
4    modify it under the terms of the GNU General Public License
5    as published by the Free Software Foundation; version 2 of
6    the License.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16    MA 02110-1301, USA. */
17 
18 /***********************************************************************
19 *   $Id$
20 *
21 *   avgx.h
22 ***********************************************************************/
23 
24 /**
25  * Columnstore interface for for the avgx function
26  *
27  *
28  *    CREATE AGGREGATE FUNCTION avgx returns REAL soname
29  *    'libudf_mysql.so';
30  *
31  */
32 #ifndef HEADER_avgx
33 #define HEADER_avgx
34 
35 #include <cstdlib>
36 #include <string>
37 #include <vector>
38 #ifdef _MSC_VER
39 #include <unordered_map>
40 #else
41 #include <tr1/unordered_map>
42 #endif
43 
44 #include "mcsv1_udaf.h"
45 #include "calpontsystemcatalog.h"
46 #include "windowfunctioncolumn.h"
47 
48 #if defined(_MSC_VER) && defined(xxxRGNODE_DLLEXPORT)
49 #define EXPORT __declspec(dllexport)
50 #else
51 #define EXPORT
52 #endif
53 
54 namespace mcsv1sdk
55 {
56 
57 // Override mcsv1_UDAF to build your User Defined Aggregate (UDAF) and/or
58 // User Defined Analytic Function (UDAnF).
59 // These will be singleton classes, so don't put any instance
60 // specific data in here. All instance data is stored in mcsv1Context
61 // passed to each user function and retrieved by the getUserData() method.
62 //
63 // Each API function returns a ReturnCode. If ERROR is returned at any time,
64 // the query is aborted, getInterrupted() will begin to return true and the
65 // message set in config->setErrorMessage() is returned to MariaDB.
66 
67 // Return the avgx value of the dataset
68 
69 class avgx : public  mcsv1_UDAF
70 {
71 public:
72     // Defaults OK
avgx()73     avgx() : mcsv1_UDAF() {};
~avgx()74     virtual ~avgx() {};
75 
76     virtual ReturnCode init(mcsv1Context* context,
77                             ColumnDatum* colTypes);
78 
79     virtual ReturnCode reset(mcsv1Context* context);
80 
81     virtual ReturnCode nextValue(mcsv1Context* context, ColumnDatum* valsIn);
82 
83     virtual ReturnCode subEvaluate(mcsv1Context* context, const UserData* valIn);
84 
85     virtual ReturnCode evaluate(mcsv1Context* context, static_any::any& valOut);
86 
87     virtual ReturnCode dropValue(mcsv1Context* context, ColumnDatum* valsDropped);
88 
89 protected:
90 };
91 
92 };  // namespace
93 
94 #undef EXPORT
95 
96 #endif // HEADER_.h
97 
98