2010-02-14 20:08:22 +01:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Initial
|
|
|
|
* Developer's Public License Version 1.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed AS IS,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing rights
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Adriano dos Santos Fernandes
|
|
|
|
* for the Firebird Open Source RDBMS project.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 Adriano dos Santos Fernandes <adrianosf@gmail.com>
|
|
|
|
* and all contributors signed below.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DSQL_WIN_NODES_H
|
|
|
|
#define DSQL_WIN_NODES_H
|
|
|
|
|
|
|
|
#include "../jrd/blr.h"
|
|
|
|
#include "../dsql/Nodes.h"
|
|
|
|
|
|
|
|
namespace Jrd {
|
|
|
|
|
|
|
|
|
2010-02-15 01:43:04 +01:00
|
|
|
// DENSE_RANK function.
|
2010-02-14 20:08:22 +01:00
|
|
|
class DenseRankWinNode : public WinFuncNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit DenseRankWinNode(MemoryPool& pool);
|
|
|
|
|
2010-11-07 04:03:41 +01:00
|
|
|
virtual void make(DsqlCompilerScratch* dsqlScratch, dsc* desc);
|
2010-02-14 20:08:22 +01:00
|
|
|
virtual void getDesc(thread_db* tdbb, CompilerScratch* csb, dsc* desc);
|
2011-02-06 22:59:20 +01:00
|
|
|
virtual ValueExprNode* copy(thread_db* tdbb, NodeCopier& copier) const;
|
2010-02-14 20:08:22 +01:00
|
|
|
|
|
|
|
virtual void aggInit(thread_db* tdbb, jrd_req* request) const;
|
|
|
|
virtual void aggPass(thread_db* tdbb, jrd_req* request, dsc* desc) const;
|
|
|
|
virtual dsc* aggExecute(thread_db* tdbb, jrd_req* request) const;
|
|
|
|
|
|
|
|
protected:
|
2012-05-03 18:43:29 +02:00
|
|
|
virtual AggNode* dsqlCopy(DsqlCompilerScratch* dsqlScratch) /*const*/;
|
2010-02-14 20:08:22 +01:00
|
|
|
};
|
|
|
|
|
2010-02-15 01:43:04 +01:00
|
|
|
// RANK function.
|
2010-02-14 20:08:22 +01:00
|
|
|
class RankWinNode : public WinFuncNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit RankWinNode(MemoryPool& pool);
|
|
|
|
|
2010-11-07 04:03:41 +01:00
|
|
|
virtual void make(DsqlCompilerScratch* dsqlScratch, dsc* desc);
|
2010-02-14 20:08:22 +01:00
|
|
|
virtual void getDesc(thread_db* tdbb, CompilerScratch* csb, dsc* desc);
|
2011-02-06 22:59:20 +01:00
|
|
|
virtual ValueExprNode* copy(thread_db* tdbb, NodeCopier& copier) const;
|
2012-04-25 03:42:47 +02:00
|
|
|
virtual AggNode* pass2(thread_db* tdbb, CompilerScratch* csb);
|
2010-02-14 20:08:22 +01:00
|
|
|
|
|
|
|
virtual void aggInit(thread_db* tdbb, jrd_req* request) const;
|
|
|
|
virtual void aggPass(thread_db* tdbb, jrd_req* request, dsc* desc) const;
|
|
|
|
virtual dsc* aggExecute(thread_db* tdbb, jrd_req* request) const;
|
|
|
|
|
|
|
|
protected:
|
2012-05-03 18:43:29 +02:00
|
|
|
virtual AggNode* dsqlCopy(DsqlCompilerScratch* dsqlScratch) /*const*/;
|
2010-02-14 20:08:22 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
USHORT tempImpure;
|
|
|
|
};
|
|
|
|
|
2010-02-15 01:43:04 +01:00
|
|
|
// ROW_NUMBER function.
|
2010-02-14 20:08:22 +01:00
|
|
|
class RowNumberWinNode : public WinFuncNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit RowNumberWinNode(MemoryPool& pool);
|
|
|
|
|
2010-11-07 04:03:41 +01:00
|
|
|
virtual void make(DsqlCompilerScratch* dsqlScratch, dsc* desc);
|
2010-02-14 20:08:22 +01:00
|
|
|
virtual void getDesc(thread_db* tdbb, CompilerScratch* csb, dsc* desc);
|
2011-02-06 22:59:20 +01:00
|
|
|
virtual ValueExprNode* copy(thread_db* tdbb, NodeCopier& copier) const;
|
2010-02-14 20:08:22 +01:00
|
|
|
|
|
|
|
virtual void aggInit(thread_db* tdbb, jrd_req* request) const;
|
|
|
|
virtual void aggPass(thread_db* tdbb, jrd_req* request, dsc* desc) const;
|
|
|
|
virtual dsc* aggExecute(thread_db* tdbb, jrd_req* request) const;
|
|
|
|
|
|
|
|
virtual bool shouldCallWinPass() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-02-16 01:26:53 +01:00
|
|
|
virtual dsc* winPass(thread_db* tdbb, jrd_req* request, SlidingWindow* window) const;
|
|
|
|
|
|
|
|
protected:
|
2012-05-03 18:43:29 +02:00
|
|
|
virtual AggNode* dsqlCopy(DsqlCompilerScratch* dsqlScratch) /*const*/;
|
2010-02-16 01:26:53 +01:00
|
|
|
};
|
|
|
|
|
2011-10-23 23:27:55 +02:00
|
|
|
// FIRST_VALUE function.
|
|
|
|
class FirstValueWinNode : public WinFuncNode
|
|
|
|
{
|
|
|
|
public:
|
2012-04-25 03:42:47 +02:00
|
|
|
explicit FirstValueWinNode(MemoryPool& pool, ValueExprNode* aArg = NULL);
|
2011-10-23 23:27:55 +02:00
|
|
|
|
|
|
|
virtual void make(DsqlCompilerScratch* dsqlScratch, dsc* desc);
|
|
|
|
virtual void getDesc(thread_db* tdbb, CompilerScratch* csb, dsc* desc);
|
|
|
|
virtual ValueExprNode* copy(thread_db* tdbb, NodeCopier& copier) const;
|
|
|
|
|
|
|
|
virtual void aggInit(thread_db* tdbb, jrd_req* request) const;
|
|
|
|
virtual void aggPass(thread_db* tdbb, jrd_req* request, dsc* desc) const;
|
|
|
|
virtual dsc* aggExecute(thread_db* tdbb, jrd_req* request) const;
|
|
|
|
|
|
|
|
virtual bool shouldCallWinPass() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual dsc* winPass(thread_db* tdbb, jrd_req* request, SlidingWindow* window) const;
|
|
|
|
|
|
|
|
protected:
|
2012-05-03 18:43:29 +02:00
|
|
|
virtual AggNode* dsqlCopy(DsqlCompilerScratch* dsqlScratch) /*const*/;
|
2011-10-23 23:27:55 +02:00
|
|
|
|
|
|
|
virtual void parseArgs(thread_db* tdbb, CompilerScratch* csb, unsigned count);
|
|
|
|
};
|
|
|
|
|
2011-10-25 17:04:17 +02:00
|
|
|
// LAST_VALUE function.
|
|
|
|
class LastValueWinNode : public WinFuncNode
|
|
|
|
{
|
|
|
|
public:
|
2012-04-25 03:42:47 +02:00
|
|
|
explicit LastValueWinNode(MemoryPool& pool, ValueExprNode* aArg = NULL);
|
2011-10-25 17:04:17 +02:00
|
|
|
|
|
|
|
virtual void make(DsqlCompilerScratch* dsqlScratch, dsc* desc);
|
|
|
|
virtual void getDesc(thread_db* tdbb, CompilerScratch* csb, dsc* desc);
|
|
|
|
virtual ValueExprNode* copy(thread_db* tdbb, NodeCopier& copier) const;
|
|
|
|
|
|
|
|
virtual void aggInit(thread_db* tdbb, jrd_req* request) const;
|
|
|
|
virtual void aggPass(thread_db* tdbb, jrd_req* request, dsc* desc) const;
|
|
|
|
virtual dsc* aggExecute(thread_db* tdbb, jrd_req* request) const;
|
|
|
|
|
|
|
|
virtual bool shouldCallWinPass() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual dsc* winPass(thread_db* tdbb, jrd_req* request, SlidingWindow* window) const;
|
|
|
|
|
|
|
|
protected:
|
2012-05-03 18:43:29 +02:00
|
|
|
virtual AggNode* dsqlCopy(DsqlCompilerScratch* dsqlScratch) /*const*/;
|
2011-10-25 17:04:17 +02:00
|
|
|
|
|
|
|
virtual void parseArgs(thread_db* tdbb, CompilerScratch* csb, unsigned count);
|
|
|
|
};
|
|
|
|
|
|
|
|
// NTH_VALUE function.
|
|
|
|
class NthValueWinNode : public WinFuncNode
|
|
|
|
{
|
|
|
|
public:
|
2013-04-24 17:31:13 +02:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
FROM_FIRST = 0,
|
|
|
|
FROM_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit NthValueWinNode(MemoryPool& pool, ValueExprNode* aArg = NULL,
|
|
|
|
ValueExprNode* aRow = NULL, ValueExprNode* aFrom = NULL);
|
2011-10-25 17:04:17 +02:00
|
|
|
|
|
|
|
virtual void make(DsqlCompilerScratch* dsqlScratch, dsc* desc);
|
|
|
|
virtual void getDesc(thread_db* tdbb, CompilerScratch* csb, dsc* desc);
|
|
|
|
virtual ValueExprNode* copy(thread_db* tdbb, NodeCopier& copier) const;
|
|
|
|
|
|
|
|
virtual void aggInit(thread_db* tdbb, jrd_req* request) const;
|
|
|
|
virtual void aggPass(thread_db* tdbb, jrd_req* request, dsc* desc) const;
|
|
|
|
virtual dsc* aggExecute(thread_db* tdbb, jrd_req* request) const;
|
|
|
|
|
|
|
|
virtual bool shouldCallWinPass() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual dsc* winPass(thread_db* tdbb, jrd_req* request, SlidingWindow* window) const;
|
|
|
|
|
|
|
|
protected:
|
2012-05-03 18:43:29 +02:00
|
|
|
virtual AggNode* dsqlCopy(DsqlCompilerScratch* dsqlScratch) /*const*/;
|
2011-10-25 17:04:17 +02:00
|
|
|
|
|
|
|
virtual void parseArgs(thread_db* tdbb, CompilerScratch* csb, unsigned count);
|
|
|
|
|
|
|
|
private:
|
|
|
|
NestConst<ValueExprNode> row;
|
2013-04-24 17:31:13 +02:00
|
|
|
NestConst<ValueExprNode> from;
|
2011-10-25 17:04:17 +02:00
|
|
|
};
|
|
|
|
|
2010-02-16 01:26:53 +01:00
|
|
|
// LAG/LEAD function.
|
|
|
|
class LagLeadWinNode : public WinFuncNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit LagLeadWinNode(MemoryPool& pool, const AggInfo& aAggInfo, int aDirection,
|
2012-04-25 03:42:47 +02:00
|
|
|
ValueExprNode* aArg = NULL, ValueExprNode* aRows = NULL, ValueExprNode* aOutExpr = NULL);
|
2010-02-16 01:26:53 +01:00
|
|
|
|
2010-11-07 04:03:41 +01:00
|
|
|
virtual void make(DsqlCompilerScratch* dsqlScratch, dsc* desc);
|
2010-02-16 01:26:53 +01:00
|
|
|
virtual void getDesc(thread_db* tdbb, CompilerScratch* csb, dsc* desc);
|
|
|
|
|
|
|
|
virtual void aggInit(thread_db* tdbb, jrd_req* request) const;
|
|
|
|
virtual void aggPass(thread_db* tdbb, jrd_req* request, dsc* desc) const;
|
|
|
|
virtual dsc* aggExecute(thread_db* tdbb, jrd_req* request) const;
|
|
|
|
|
|
|
|
virtual bool shouldCallWinPass() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual dsc* winPass(thread_db* tdbb, jrd_req* request, SlidingWindow* window) const;
|
|
|
|
|
2010-11-21 04:47:29 +01:00
|
|
|
protected:
|
|
|
|
virtual void parseArgs(thread_db* tdbb, CompilerScratch* csb, unsigned count);
|
|
|
|
|
2010-02-16 01:26:53 +01:00
|
|
|
protected:
|
|
|
|
const int direction;
|
2010-11-21 04:47:29 +01:00
|
|
|
NestConst<ValueExprNode> rows;
|
|
|
|
NestConst<ValueExprNode> outExpr;
|
2010-02-16 01:26:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// LAG function.
|
|
|
|
class LagWinNode : public LagLeadWinNode
|
|
|
|
{
|
|
|
|
public:
|
2012-04-25 03:42:47 +02:00
|
|
|
explicit LagWinNode(MemoryPool& pool, ValueExprNode* aArg = NULL, ValueExprNode* aRows = NULL,
|
|
|
|
ValueExprNode* aOutExpr = NULL);
|
2010-02-16 01:26:53 +01:00
|
|
|
|
2011-02-06 22:59:20 +01:00
|
|
|
virtual ValueExprNode* copy(thread_db* tdbb, NodeCopier& copier) const;
|
2010-02-16 01:26:53 +01:00
|
|
|
|
|
|
|
protected:
|
2012-05-03 18:43:29 +02:00
|
|
|
virtual AggNode* dsqlCopy(DsqlCompilerScratch* dsqlScratch) /*const*/;
|
2010-02-16 01:26:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// LEAD function.
|
|
|
|
class LeadWinNode : public LagLeadWinNode
|
|
|
|
{
|
|
|
|
public:
|
2012-04-25 03:42:47 +02:00
|
|
|
explicit LeadWinNode(MemoryPool& pool, ValueExprNode* aArg = NULL, ValueExprNode* aRows = NULL,
|
|
|
|
ValueExprNode* aOutExpr = NULL);
|
2010-02-16 01:26:53 +01:00
|
|
|
|
2011-02-06 22:59:20 +01:00
|
|
|
virtual ValueExprNode* copy(thread_db* tdbb, NodeCopier& copier) const;
|
2010-02-14 20:08:22 +01:00
|
|
|
|
|
|
|
protected:
|
2012-05-03 18:43:29 +02:00
|
|
|
virtual AggNode* dsqlCopy(DsqlCompilerScratch* dsqlScratch) /*const*/;
|
2010-02-14 20:08:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif // DSQL_WIN_NODES_H
|