File: wf_udaf.h

package info (click to toggle)
mariadb 1%3A10.11.14-0%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 614,128 kB
  • sloc: ansic: 2,421,226; cpp: 1,765,048; asm: 381,336; perl: 62,256; java: 39,363; pascal: 38,841; sh: 38,242; sql: 19,830; yacc: 19,731; xml: 10,414; python: 10,125; ruby: 8,544; cs: 6,542; makefile: 6,155; ada: 1,879; lex: 1,207; javascript: 996; objc: 80; tcl: 73; awk: 46; php: 22
file content (116 lines) | stat: -rw-r--r-- 3,444 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/************************************************************************************
  Copyright (C) 2017 MariaDB Corporation AB

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Library General Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Library General Public License for more details.

  You should have received a copy of the GNU Library General Public
  License along with this library; if not see <http://www.gnu.org/licenses>
  or write to the Free Software Foundation, Inc.,
  51 Franklin St., Fifth Floor, Boston, MA 02110, USA
 *************************************************************************************/

#ifndef UTILS_WF_UDAF_H
#define UTILS_WF_UDAF_H

#ifndef _MSC_VER
#include <tr1/unordered_map>
#else
#include <unordered_map>
#endif
#include "windowfunctiontype.h"
#include "mcsv1_udaf.h"

namespace windowfunction
{
// Hash classes for the distinct hashmap
class DistinctHasher
{
 public:
  inline size_t operator()(const static_any::any& a) const
  {
    return a.getHash();
  }
};

class DistinctEqual
{
 public:
  inline bool operator()(const static_any::any lhs, static_any::any rhs) const
  {
    return lhs == rhs;
  }
};

// A class to control the execution of User Define Analytic Functions (UDAnF)
// as defined by a specialization of mcsv1sdk::mcsv1_UDAF
class WF_udaf : public WindowFunctionType
{
 public:
  WF_udaf(int id, const std::string& name, mcsv1sdk::mcsv1Context& context)
   : WindowFunctionType(id, name), fUDAFContext(context), fDistinct(false), bHasDropValue(true)
  {
  }
  WF_udaf(WF_udaf& rhs);
  // pure virtual in base
  void operator()(int64_t b, int64_t e, int64_t c);
  WindowFunctionType* clone() const;
  void resetData();
  void parseParms(const std::vector<execplan::SRCP>&);
  virtual bool dropValues(int64_t, int64_t);

  mcsv1sdk::mcsv1Context& getContext()
  {
    return fUDAFContext;
  }

  bool getInterrupted()
  {
    return bInterrupted;
  }

  bool* getInterruptedPtr()
  {
    return &bInterrupted;
  }

  bool getDistinct()
  {
    return fDistinct;
  }

  void setDistinct(bool d = true)
  {
    fDistinct = d;
  }

 protected:
  void SetUDAFValue(static_any::any& valOut, int64_t colOut, int64_t b, int64_t e, int64_t c);

  mcsv1sdk::mcsv1Context fUDAFContext;  // The UDAF context
  bool bInterrupted;                    // Shared by all the threads
  bool fDistinct;
  bool bRespectNulls;  // respect null | ignore null
  bool bHasDropValue;  // Set to false when we discover the UDAnF doesn't implement dropValue.
                       // To hold distinct values and their counts
  typedef std::tr1::unordered_map<static_any::any, uint64_t, DistinctHasher, DistinctEqual> DistinctMap;
  DistinctMap fDistinctMap;

  static_any::any fValOut;  // The return value

 public:
  static boost::shared_ptr<WindowFunctionType> makeFunction(int id, const string& name, int ct,
                                                            mcsv1sdk::mcsv1Context& context,
                                                            WindowFunctionColumn* wc);
};

}  // namespace windowfunction

#endif  // UTILS_WF_UDAF_H