More correct for functions and aggr. functions

This commit is contained in:
kssenii 2021-01-22 11:58:29 +00:00
parent bb91005356
commit 6dc32ae4cb
5 changed files with 67 additions and 32 deletions

View File

@ -60,13 +60,6 @@ static DataTypes convertLowCardinalityTypesToNested(const DataTypes & types)
AggregateFunctionPtr AggregateFunctionFactory::get(
const String & name, const DataTypes & argument_types, const Array & parameters, AggregateFunctionProperties & out_properties) const
{
if (CurrentThread::isInitialized())
{
auto query_context = CurrentThread::get().getQueryContext();
if (query_context && query_context->getSettingsRef().log_queries)
query_context->addQueryFactoriesInfo(Context::QueryLogFactories::AggregateFunction, name);
}
auto type_without_low_cardinality = convertLowCardinalityTypesToNested(argument_types);
/// If one of the types is Nullable, we apply aggregate function combinator "Null".
@ -116,10 +109,17 @@ AggregateFunctionPtr AggregateFunctionFactory::getImpl(
if (auto jt = case_insensitive_aggregate_functions.find(Poco::toLower(name)); jt != case_insensitive_aggregate_functions.end())
found = jt->second;
const Context * query_context = nullptr;
if (CurrentThread::isInitialized())
query_context = CurrentThread::get().getQueryContext();
if (found.creator)
{
out_properties = found.properties;
if (query_context && query_context->getSettingsRef().log_queries)
query_context->addQueryFactoriesInfo(Context::QueryLogFactories::AggregateFunction, name);
/// The case when aggregate function should return NULL on NULL arguments. This case is handled in "get" method.
if (!out_properties.returns_default_when_only_null && has_null_arguments)
return nullptr;
@ -136,6 +136,9 @@ AggregateFunctionPtr AggregateFunctionFactory::getImpl(
if (combinator->isForInternalUsageOnly())
throw Exception("Aggregate function combinator '" + combinator->getName() + "' is only for internal usage", ErrorCodes::UNKNOWN_AGGREGATE_FUNCTION);
if (query_context && query_context->getSettingsRef().log_queries)
query_context->addQueryFactoriesInfo(Context::QueryLogFactories::AggregateFunction, combinator->getName());
String nested_name = name.substr(0, name.size() - combinator->getName().size());
DataTypes nested_types = combinator->transformArguments(argument_types);
Array nested_parameters = combinator->transformParameters(parameters);

View File

@ -80,7 +80,7 @@ DataTypePtr DataTypeFactory::get(const String & family_name_param, const ASTPtr
if (CurrentThread::isInitialized())
{
auto query_context = CurrentThread::get().getQueryContext();
const auto * query_context = CurrentThread::get().getQueryContext();
if (query_context && query_context->getSettingsRef().log_queries)
query_context->addQueryFactoriesInfo(Context::QueryLogFactories::DataType, family_name);
}

View File

@ -77,13 +77,6 @@ FunctionOverloadResolverPtr FunctionFactory::get(
const std::string & name,
const Context & context) const
{
if (CurrentThread::isInitialized())
{
auto query_context = CurrentThread::get().getQueryContext();
if (query_context && query_context->getSettingsRef().log_queries)
query_context->addQueryFactoriesInfo(Context::QueryLogFactories::Function, name);
}
return std::make_shared<FunctionOverloadResolverAdaptor>(getImpl(name, context));
}
@ -93,6 +86,13 @@ FunctionOverloadResolverImplPtr FunctionFactory::tryGetImpl(
{
String name = getAliasToOrName(name_param);
if (CurrentThread::isInitialized())
{
const auto * query_context = CurrentThread::get().getQueryContext();
if (query_context && query_context->getSettingsRef().log_queries)
query_context->addQueryFactoriesInfo(Context::QueryLogFactories::Function, name);
}
auto it = functions.find(name);
if (functions.end() != it)
return it->second(context);

View File

@ -1,13 +1,21 @@
1 100
used_aggregate_functions used_table_functions used_functions
['uniq','count'] ['numbers'] ['plus','toDate','addDays']
2 worl \N 50 4950 Nullable(UInt64) 50
2 worl \N 50 4950 Nullable(UInt64) 50
\N
\N
used_functions used_data_types
['cast'] ['Nullable','UInt8']
arraySort(used_aggregate_functions)
['Array','If','OrDefault','OrNull','avg','count','sum','uniq']
arraySort(used_table_functions)
['numbers']
arraySort(used_functions)
['addDays','cast','modulo','plus','substring','toDate','toDayOfYear','toTypeName']
arraySort(used_data_types)
['Nullable','UInt8']
used_databases
['Atomic']
used_data_types used_storages
['DateTime','String'] ['Memory']
arraySort(used_data_types) used_storages
['DateTime','UInt64'] ['Memory']

View File

@ -1,27 +1,51 @@
SELECT uniq(1, 1, 2, 2), count(toDate('2000-12-05') + number as d) FROM numbers(100);
SELECT uniqArray([1, 1, 2]),
SUBSTRING('Hello, world', 7, 5),
CAST(arrayJoin([NULL, NULL]) AS Nullable(UInt8)),
avgOrDefaultIf(number, number % 2),
sumOrNull(number),
toTypeName(sumOrNull(number)),
countIf(toDate('2000-12-05') + number as d,
toDayOfYear(d) % 2)
FROM numbers(100);
SELECT '';
SYSTEM FLUSH LOGS;
SELECT used_aggregate_functions, used_table_functions, used_functions
SELECT arraySort(used_aggregate_functions)
FROM system.query_log WHERE type = 'QueryFinish' AND (query LIKE '%toDate(\'2000-12-05\')%')
ORDER BY query_start_time DESC LIMIT 1 FORMAT TabSeparatedWithNames;
SELECT '';
SELECT CAST(arrayJoin([NULL, NULL]) AS Nullable(UInt8)) AS x;
SYSTEM FLUSH LOGS;
SELECT used_functions, used_data_types
FROM system.query_log WHERE type = 'QueryFinish' AND query LIKE 'SELECT CAST(arrayJ%'
SELECT arraySort(used_table_functions)
FROM system.query_log WHERE type = 'QueryFinish' AND (query LIKE '%toDate(\'2000-12-05\')%')
ORDER BY query_start_time DESC LIMIT 1 FORMAT TabSeparatedWithNames;
SELECT '';
SELECT arraySort(used_functions)
FROM system.query_log WHERE type = 'QueryFinish' AND (query LIKE '%toDate(\'2000-12-05\')%')
ORDER BY query_start_time DESC LIMIT 1 FORMAT TabSeparatedWithNames;
SELECT '';
SELECT arraySort(used_data_types)
FROM system.query_log WHERE type = 'QueryFinish' AND (query LIKE '%toDate(\'2000-12-05\')%')
ORDER BY query_start_time DESC LIMIT 1 FORMAT TabSeparatedWithNames;
SELECT '';
DROP database IF EXISTS test_query_log_factories_info1;
CREATE database test_query_log_factories_info1 ENGINE=Atomic;
CREATE OR REPLACE TABLE test_query_log_factories_info1.memory_table (event String, date DateTime) ENGINE=Memory();
SYSTEM FLUSH LOGS;
SELECT used_databases
FROM system.query_log
WHERE type == 'QueryFinish' AND (query LIKE '%database test_query_log_factories_info%')
ORDER BY query_start_time DESC LIMIT 1 FORMAT TabSeparatedWithNames;
SELECT used_data_types, used_storages
SELECT '';
CREATE OR REPLACE TABLE test_query_log_factories_info1.memory_table (id UInt64, date DateTime) ENGINE=Memory();
SYSTEM FLUSH LOGS;
SELECT arraySort(used_data_types), used_storages
FROM system.query_log
WHERE type == 'QueryFinish' AND (query LIKE '%TABLE test%')
ORDER BY query_start_time DESC LIMIT 1 FORMAT TabSeparatedWithNames;
SELECT '';