Avoid cycles in optimizeFuseQuantileFunctions

This commit is contained in:
vdimir 2021-09-17 14:30:45 +03:00
parent 661a54827b
commit 091ce151bf
No known key found for this signature in database
GPG Key ID: F57B3E10A21DBB31
3 changed files with 12 additions and 1 deletions

View File

@ -71,5 +71,13 @@ void GatherFunctionQuantileData::FuseQuantileAggregatesData::addFuncNode(ASTPtr
arg_map_function[arg_name].push_back(&ast);
}
bool GatherFunctionQuantileData::needChild(const ASTPtr & node, const ASTPtr &)
{
/// Skip children of quantile* functions to escape cycles in further processing
if (const auto * func = node ? node->as<ASTFunction>() : nullptr)
return !quantile_fuse_name_mapping.contains(func->name);
return true;
}
}

View File

@ -27,8 +27,9 @@ public:
static String getFusedName(const String & func_name);
static bool needChild(const ASTPtr & node, const ASTPtr &);
};
using GatherFunctionQuantileVisitor = InDepthNodeVisitor<OneTypeMatcher<GatherFunctionQuantileData>, true>;
using GatherFunctionQuantileVisitor = InDepthNodeVisitor<OneTypeMatcher<GatherFunctionQuantileData, GatherFunctionQuantileData::needChild>, true>;
}

View File

@ -62,5 +62,7 @@ SELECT quantileTiming(0.5)(NULL, NULL, quantileTiming(-inf)(NULL), NULL) FROM da
SELECT quantileTDigest(NULL)(NULL, quantileTDigest(3.14)(NULL, d + NULL), 2.), NULL FORMAT Null; -- { serverError ILLEGAL_AGGREGATION }
SELECT quantile(1, 0.3)(d), quantile(0.3)(d) FROM datetime; -- { serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH }
SELECT quantile(quantileDeterministic('', '2.47')('0.02', '0.2', NULL), 0.9)(d), quantile(0.3)(d) FROM datetime; -- { serverError ILLEGAL_AGGREGATION }
SELECT quantileTimingWeighted([[[[['-214748364.8'], NULL]], [[[quantileTimingWeighted([[[[['-214748364.8'], NULL], '-922337203.6854775808'], [[['-214748364.7']]], NULL]])([NULL], NULL), '-214748364.7']]], NULL]])([NULL], NULL); -- { serverError ILLEGAL_AGGREGATION }
SELECT quantileTimingWeighted([quantileTimingWeighted(0.5)(1, 1)])(1, 1); -- { serverError ILLEGAL_AGGREGATION }
DROP TABLE datetime;