|
| 1 | +/*------------------------------------------------------------------------- |
| 2 | + * |
| 3 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 4 | + * or more contributor license agreements. See the NOTICE file |
| 5 | + * distributed with this work for additional information |
| 6 | + * regarding copyright ownership. The ASF licenses this file |
| 7 | + * to you under the Apache License, Version 2.0 (the |
| 8 | + * "License"); you may not use this file except in compliance |
| 9 | + * with the License. You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, |
| 14 | + * software distributed under the License is distributed on an |
| 15 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | + * KIND, either express or implied. See the License for the |
| 17 | + * specific language governing permissions and limitations |
| 18 | + * under the License. |
| 19 | + * |
| 20 | + * @filename: |
| 21 | + * CXformSplitWindowFunc.h |
| 22 | + * |
| 23 | + * @doc: |
| 24 | + * Split a window function into pair of local and global window function |
| 25 | + * |
| 26 | + *------------------------------------------------------------------------- |
| 27 | + */ |
| 28 | +#ifndef GPOPT_CXformSplitWindowFunc_H |
| 29 | +#define GPOPT_CXformSplitWindowFunc_H |
| 30 | + |
| 31 | +#include "gpos/base.h" |
| 32 | + |
| 33 | +#include "gpopt/xforms/CXformExploration.h" |
| 34 | + |
| 35 | +namespace gpopt |
| 36 | +{ |
| 37 | +using namespace gpos; |
| 38 | + |
| 39 | +//--------------------------------------------------------------------------- |
| 40 | +// @class: |
| 41 | +// CXformSplitWindowFunc |
| 42 | +// |
| 43 | +// @doc: |
| 44 | +// Split a window function into pair of local and global window function |
| 45 | +// |
| 46 | +//--------------------------------------------------------------------------- |
| 47 | +class CXformSplitWindowFunc : public CXformExploration |
| 48 | +{ |
| 49 | +private: |
| 50 | + // generate a project lists for the local and global window function |
| 51 | + // from the original window function |
| 52 | + static CExpression *PexprWindowFunc( |
| 53 | + CMemoryPool *mp, // memory pool |
| 54 | + CExpression * |
| 55 | + pexprProjListOrig, // project list of the original global window function |
| 56 | + CExpression * |
| 57 | + ppexprProjListLocal, // project list of the new local window function |
| 58 | + CExpression * |
| 59 | + ppexprProjListGlobal // project list of the new global window function |
| 60 | + ); |
| 61 | + |
| 62 | + static void PopulateLocalGlobalProjectList( |
| 63 | + CMemoryPool *mp, CExpression *pexprProjList, |
| 64 | + CExpression **ppexprProjListLocal, CExpression **ppexprProjListGlobal); |
| 65 | + |
| 66 | + static bool CheckFilterAndProjectList(CExpression *pexprSelect, |
| 67 | + CExpression *pexprProjList); |
| 68 | + |
| 69 | + static void PopulateSelect(CMemoryPool *mp, CExpression *pexprSelect, |
| 70 | + COperator **ppSelectCopy); |
| 71 | + |
| 72 | +public: |
| 73 | + CXformSplitWindowFunc(const CXformSplitWindowFunc &) = delete; |
| 74 | + |
| 75 | + // ctor |
| 76 | + explicit CXformSplitWindowFunc(CMemoryPool *mp); |
| 77 | + |
| 78 | + // dtor |
| 79 | + ~CXformSplitWindowFunc() override = default; |
| 80 | + |
| 81 | + // ident accessors |
| 82 | + EXformId |
| 83 | + Exfid() const override |
| 84 | + { |
| 85 | + return ExfSplitWindowFunc; |
| 86 | + } |
| 87 | + |
| 88 | + // return a string for xform name |
| 89 | + const CHAR * |
| 90 | + SzId() const override |
| 91 | + { |
| 92 | + return "CXformSplitWindowFunc"; |
| 93 | + } |
| 94 | + |
| 95 | + // Compatibility function for splitting limit |
| 96 | + BOOL |
| 97 | + FCompatible(CXform::EXformId exfid) override |
| 98 | + { |
| 99 | + return (CXform::ExfSplitWindowFunc != exfid); |
| 100 | + } |
| 101 | + |
| 102 | + // compute xform promise for a given expression handle |
| 103 | + EXformPromise Exfp(CExpressionHandle &exprhdl) const override; |
| 104 | + |
| 105 | + // actual transform |
| 106 | + void Transform(CXformContext *pxfctxt, CXformResult *pxfres, |
| 107 | + CExpression *pexpr) const override; |
| 108 | + |
| 109 | +}; // class CXformSplitWindowFunc |
| 110 | + |
| 111 | +} // namespace gpopt |
| 112 | + |
| 113 | +#endif // !GPOPT_CXformSplitWindowFunc_H |
| 114 | + |
| 115 | +// EOF |
0 commit comments