2023-06-21 02:33:11 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Parsers/IAST.h>
|
|
|
|
#include <Interpreters/InDepthNodeVisitor.h>
|
|
|
|
#include "Interpreters/TreeRewriter.h"
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class ASTFunction;
|
|
|
|
|
|
|
|
/// Simple rewrite:
|
2023-06-28 06:12:24 +00:00
|
|
|
/// 'SELECT uniq(x ...) FROM (SELECT DISTINCT x ...)' to
|
2023-06-21 02:33:11 +00:00
|
|
|
/// 'SELECT count() FROM (SELECT DISTINCT x ...)'
|
|
|
|
///
|
2023-06-28 06:12:24 +00:00
|
|
|
/// 'SELECT uniq(x ...) FROM (SELECT x ... GROUP BY x ...)' to
|
|
|
|
/// 'SELECT count() FROM (SELECT x ... GROUP BY x ...)'
|
2023-06-21 02:33:11 +00:00
|
|
|
///
|
|
|
|
/// Note we can rewrite all uniq variants except uniqUpTo.
|
2023-06-25 06:43:39 +00:00
|
|
|
class RewriteUniqToCountMatcher
|
2023-06-21 02:33:11 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct Data {};
|
|
|
|
static void visit(ASTPtr & ast, Data &);
|
|
|
|
static bool needChildVisit(const ASTPtr &, const ASTPtr &) { return true; }
|
|
|
|
};
|
|
|
|
|
2023-06-25 06:43:39 +00:00
|
|
|
using RewriteUniqToCountVisitor = InDepthNodeVisitor<RewriteUniqToCountMatcher, true>;
|
2023-06-21 02:33:11 +00:00
|
|
|
}
|