mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-27 12:10:49 +00:00
Merge remote-tracking branch 'origin/master' into unfreeze-partitions
This commit is contained in:
commit
3663011f9d
@ -693,6 +693,178 @@ Same as for [parseDateTimeBestEffort](#parsedatetimebesteffort) except that it r
|
|||||||
|
|
||||||
Same as for [parseDateTimeBestEffort](#parsedatetimebesteffort) except that it returns zero date or zero date time when it encounters a date format that cannot be processed.
|
Same as for [parseDateTimeBestEffort](#parsedatetimebesteffort) except that it returns zero date or zero date time when it encounters a date format that cannot be processed.
|
||||||
|
|
||||||
|
## parseDateTimeBestEffortUSOrNull {#parsedatetimebesteffortusornull}
|
||||||
|
|
||||||
|
Same as [parseDateTimeBestEffortUS](#parsedatetimebesteffortUS) function except that it returns `NULL` when it encounters a date format that cannot be processed.
|
||||||
|
|
||||||
|
**Syntax**
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
parseDateTimeBestEffortUSOrNull(time_string[, time_zone])
|
||||||
|
```
|
||||||
|
|
||||||
|
**Parameters**
|
||||||
|
|
||||||
|
- `time_string` — String containing a date or date with time to convert. The date must be in the US date format (`MM/DD/YYYY`, etc). [String](../../sql-reference/data-types/string.md).
|
||||||
|
- `time_zone` — [Timezone](../../operations/server-configuration-parameters/settings.md#server_configuration_parameters-timezone). The function parses `time_string` according to the timezone. Optional. [String](../../sql-reference/data-types/string.md).
|
||||||
|
|
||||||
|
**Supported non-standard formats**
|
||||||
|
|
||||||
|
- A string containing 9..10 digit [unix timestamp](https://en.wikipedia.org/wiki/Unix_time).
|
||||||
|
- A string with a date and a time components: `YYYYMMDDhhmmss`, `MM/DD/YYYY hh:mm:ss`, `MM-DD-YY hh:mm`, `YYYY-MM-DD hh:mm:ss`, etc.
|
||||||
|
- A string with a date, but no time component: `YYYY`, `YYYYMM`, `YYYY*MM`, `MM/DD/YYYY`, `MM-DD-YY`, etc.
|
||||||
|
- A string with a day and time: `DD`, `DD hh`, `DD hh:mm`. In this case, `YYYY-MM` are substituted with `2000-01`.
|
||||||
|
- A string that includes date and time along with timezone offset information: `YYYY-MM-DD hh:mm:ss ±h:mm`, etc. For example, `2020-12-12 17:36:00 -5:00`.
|
||||||
|
|
||||||
|
**Returned values**
|
||||||
|
|
||||||
|
- `time_string` converted to the [DateTime](../../sql-reference/data-types/datetime.md) data type.
|
||||||
|
- `NULL` if the input string cannot be converted to the `DateTime` data type.
|
||||||
|
|
||||||
|
**Examples**
|
||||||
|
|
||||||
|
Query:
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
SELECT parseDateTimeBestEffortUSOrNull('02/10/2021 21:12:57') AS parseDateTimeBestEffortUSOrNull;
|
||||||
|
```
|
||||||
|
|
||||||
|
Result:
|
||||||
|
|
||||||
|
``` text
|
||||||
|
┌─parseDateTimeBestEffortUSOrNull─┐
|
||||||
|
│ 2021-02-10 21:12:57 │
|
||||||
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
Query:
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
SELECT parseDateTimeBestEffortUSOrNull('02-10-2021 21:12:57 GMT', 'Europe/Moscow') AS parseDateTimeBestEffortUSOrNull;
|
||||||
|
```
|
||||||
|
|
||||||
|
Result:
|
||||||
|
|
||||||
|
``` text
|
||||||
|
┌─parseDateTimeBestEffortUSOrNull─┐
|
||||||
|
│ 2021-02-11 00:12:57 │
|
||||||
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
Query:
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
SELECT parseDateTimeBestEffortUSOrNull('02.10.2021') AS parseDateTimeBestEffortUSOrNull;
|
||||||
|
```
|
||||||
|
|
||||||
|
Result:
|
||||||
|
|
||||||
|
``` text
|
||||||
|
┌─parseDateTimeBestEffortUSOrNull─┐
|
||||||
|
│ 2021-02-10 00:00:00 │
|
||||||
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
Query:
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
SELECT parseDateTimeBestEffortUSOrNull('10.2021') AS parseDateTimeBestEffortUSOrNull;
|
||||||
|
```
|
||||||
|
|
||||||
|
Result:
|
||||||
|
|
||||||
|
``` text
|
||||||
|
┌─parseDateTimeBestEffortUSOrNull─┐
|
||||||
|
│ ᴺᵁᴸᴸ │
|
||||||
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
## parseDateTimeBestEffortUSOrZero {#parsedatetimebesteffortusorzero}
|
||||||
|
|
||||||
|
Same as [parseDateTimeBestEffortUS](#parsedatetimebesteffortUS) function except that it returns zero date (`1970-01-01`) or zero date with time (`1970-01-01 00:00:00`) when it encounters a date format that cannot be processed.
|
||||||
|
|
||||||
|
**Syntax**
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
parseDateTimeBestEffortUSOrZero(time_string[, time_zone])
|
||||||
|
```
|
||||||
|
|
||||||
|
**Parameters**
|
||||||
|
|
||||||
|
- `time_string` — String containing a date or date with time to convert. The date must be in the US date format (`MM/DD/YYYY`, etc). [String](../../sql-reference/data-types/string.md).
|
||||||
|
- `time_zone` — [Timezone](../../operations/server-configuration-parameters/settings.md#server_configuration_parameters-timezone). The function parses `time_string` according to the timezone. Optional. [String](../../sql-reference/data-types/string.md).
|
||||||
|
|
||||||
|
**Supported non-standard formats**
|
||||||
|
|
||||||
|
- A string containing 9..10 digit [unix timestamp](https://en.wikipedia.org/wiki/Unix_time).
|
||||||
|
- A string with a date and a time components: `YYYYMMDDhhmmss`, `MM/DD/YYYY hh:mm:ss`, `MM-DD-YY hh:mm`, `YYYY-MM-DD hh:mm:ss`, etc.
|
||||||
|
- A string with a date, but no time component: `YYYY`, `YYYYMM`, `YYYY*MM`, `MM/DD/YYYY`, `MM-DD-YY`, etc.
|
||||||
|
- A string with a day and time: `DD`, `DD hh`, `DD hh:mm`. In this case, `YYYY-MM` are substituted with `2000-01`.
|
||||||
|
- A string that includes date and time along with timezone offset information: `YYYY-MM-DD hh:mm:ss ±h:mm`, etc. For example, `2020-12-12 17:36:00 -5:00`.
|
||||||
|
|
||||||
|
**Returned values**
|
||||||
|
|
||||||
|
- `time_string` converted to the [DateTime](../../sql-reference/data-types/datetime.md) data type.
|
||||||
|
- Zero date or zero date with time if the input string cannot be converted to the `DateTime` data type.
|
||||||
|
|
||||||
|
**Examples**
|
||||||
|
|
||||||
|
Query:
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
SELECT parseDateTimeBestEffortUSOrZero('02/10/2021 21:12:57') AS parseDateTimeBestEffortUSOrZero;
|
||||||
|
```
|
||||||
|
|
||||||
|
Result:
|
||||||
|
|
||||||
|
``` text
|
||||||
|
┌─parseDateTimeBestEffortUSOrZero─┐
|
||||||
|
│ 2021-02-10 21:12:57 │
|
||||||
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
Query:
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
SELECT parseDateTimeBestEffortUSOrZero('02-10-2021 21:12:57 GMT', 'Europe/Moscow') AS parseDateTimeBestEffortUSOrZero;
|
||||||
|
```
|
||||||
|
|
||||||
|
Result:
|
||||||
|
|
||||||
|
``` text
|
||||||
|
┌─parseDateTimeBestEffortUSOrZero─┐
|
||||||
|
│ 2021-02-11 00:12:57 │
|
||||||
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
Query:
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
SELECT parseDateTimeBestEffortUSOrZero('02.10.2021') AS parseDateTimeBestEffortUSOrZero;
|
||||||
|
```
|
||||||
|
|
||||||
|
Result:
|
||||||
|
|
||||||
|
``` text
|
||||||
|
┌─parseDateTimeBestEffortUSOrZero─┐
|
||||||
|
│ 2021-02-10 00:00:00 │
|
||||||
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
Query:
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
SELECT parseDateTimeBestEffortUSOrZero('02.2021') AS parseDateTimeBestEffortUSOrZero;
|
||||||
|
```
|
||||||
|
|
||||||
|
Result:
|
||||||
|
|
||||||
|
``` text
|
||||||
|
┌─parseDateTimeBestEffortUSOrZero─┐
|
||||||
|
│ 1970-01-01 00:00:00 │
|
||||||
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
## toLowCardinality {#tolowcardinality}
|
## toLowCardinality {#tolowcardinality}
|
||||||
|
|
||||||
Converts input parameter to the [LowCardianlity](../../sql-reference/data-types/lowcardinality.md) version of same data type.
|
Converts input parameter to the [LowCardianlity](../../sql-reference/data-types/lowcardinality.md) version of same data type.
|
||||||
|
@ -658,6 +658,178 @@ AS parseDateTimeBestEffortUS;
|
|||||||
└─────────────────────────——┘
|
└─────────────────────────——┘
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## parseDateTimeBestEffortUSOrNull {#parsedatetimebesteffortusornull}
|
||||||
|
|
||||||
|
Работает аналогично функции [parseDateTimeBestEffortUS](#parsedatetimebesteffortUS), но в отличие от нее возвращает `NULL`, если входная строка не может быть преобразована в тип данных [DateTime](../../sql-reference/data-types/datetime.md).
|
||||||
|
|
||||||
|
**Синтаксис**
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
parseDateTimeBestEffortUSOrNull(time_string[, time_zone])
|
||||||
|
```
|
||||||
|
|
||||||
|
**Параметры**
|
||||||
|
|
||||||
|
- `time_string` — строка, содержащая дату или дату со временем для преобразования. Дата должна быть в американском формате (`MM/DD/YYYY` и т.д.). [String](../../sql-reference/data-types/string.md).
|
||||||
|
- `time_zone` — [часовой пояс](../../operations/server-configuration-parameters/settings.md#server_configuration_parameters-timezone). Функция анализирует `time_string` в соответствии с заданным часовым поясом. Опциональный параметр. [String](../../sql-reference/data-types/string.md).
|
||||||
|
|
||||||
|
**Поддерживаемые нестандартные форматы**
|
||||||
|
|
||||||
|
- Строка в формате [unix timestamp](https://en.wikipedia.org/wiki/Unix_time), содержащая 9-10 цифр.
|
||||||
|
- Строка, содержащая дату и время: `YYYYMMDDhhmmss`, `MM/DD/YYYY hh:mm:ss`, `MM-DD-YY hh:mm`, `YYYY-MM-DD hh:mm:ss` и т.д.
|
||||||
|
- Строка, содержащая дату без времени: `YYYY`, `YYYYMM`, `YYYY*MM`, `MM/DD/YYYY`, `MM-DD-YY` и т.д.
|
||||||
|
- Строка, содержащая день и время: `DD`, `DD hh`, `DD hh:mm`. В этом случае `YYYY-MM` заменяется на `2000-01`.
|
||||||
|
- Строка, содержащая дату и время, а также информацию о часовом поясе: `YYYY-MM-DD hh:mm:ss ±h:mm` и т.д. Например, `2020-12-12 17:36:00 -5:00`.
|
||||||
|
|
||||||
|
**Возвращаемые значения**
|
||||||
|
|
||||||
|
- `time_string`, преобразованная в тип данных `DateTime`.
|
||||||
|
- `NULL`, если входная строка не может быть преобразована в тип данных `DateTime`.
|
||||||
|
|
||||||
|
**Примеры**
|
||||||
|
|
||||||
|
Запрос:
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
SELECT parseDateTimeBestEffortUSOrNull('02/10/2021 21:12:57') AS parseDateTimeBestEffortUSOrNull;
|
||||||
|
```
|
||||||
|
|
||||||
|
Результат:
|
||||||
|
|
||||||
|
``` text
|
||||||
|
┌─parseDateTimeBestEffortUSOrNull─┐
|
||||||
|
│ 2021-02-10 21:12:57 │
|
||||||
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
Запрос:
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
SELECT parseDateTimeBestEffortUSOrNull('02-10-2021 21:12:57 GMT', 'Europe/Moscow') AS parseDateTimeBestEffortUSOrNull;
|
||||||
|
```
|
||||||
|
|
||||||
|
Результат:
|
||||||
|
|
||||||
|
``` text
|
||||||
|
┌─parseDateTimeBestEffortUSOrNull─┐
|
||||||
|
│ 2021-02-11 00:12:57 │
|
||||||
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
Запрос:
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
SELECT parseDateTimeBestEffortUSOrNull('02.10.2021') AS parseDateTimeBestEffortUSOrNull;
|
||||||
|
```
|
||||||
|
|
||||||
|
Результат:
|
||||||
|
|
||||||
|
``` text
|
||||||
|
┌─parseDateTimeBestEffortUSOrNull─┐
|
||||||
|
│ 2021-02-10 00:00:00 │
|
||||||
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
Запрос:
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
SELECT parseDateTimeBestEffortUSOrNull('10.2021') AS parseDateTimeBestEffortUSOrNull;
|
||||||
|
```
|
||||||
|
|
||||||
|
Результат:
|
||||||
|
|
||||||
|
``` text
|
||||||
|
┌─parseDateTimeBestEffortUSOrNull─┐
|
||||||
|
│ ᴺᵁᴸᴸ │
|
||||||
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
## parseDateTimeBestEffortUSOrZero {#parsedatetimebesteffortusorzero}
|
||||||
|
|
||||||
|
Работает аналогично функции [parseDateTimeBestEffortUS](#parsedatetimebesteffortUS), но в отличие от нее возвращает нулевую дату (`1970-01-01`) или нулевую дату со временем (`1970-01-01 00:00:00`), если входная строка не может быть преобразована в тип данных [DateTime](../../sql-reference/data-types/datetime.md).
|
||||||
|
|
||||||
|
**Синтаксис**
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
parseDateTimeBestEffortUSOrZero(time_string[, time_zone])
|
||||||
|
```
|
||||||
|
|
||||||
|
**Параметры**
|
||||||
|
|
||||||
|
- `time_string` — строка, содержащая дату или дату со временем для преобразования. Дата должна быть в американском формате (`MM/DD/YYYY` и т.д.). [String](../../sql-reference/data-types/string.md).
|
||||||
|
- `time_zone` — [часовой пояс](../../operations/server-configuration-parameters/settings.md#server_configuration_parameters-timezone). Функция анализирует `time_string` в соответствии с заданным часовым поясом. Опциональный параметр. [String](../../sql-reference/data-types/string.md).
|
||||||
|
|
||||||
|
**Поддерживаемые нестандартные форматы**
|
||||||
|
|
||||||
|
- Строка в формате [unix timestamp](https://en.wikipedia.org/wiki/Unix_time), содержащая 9-10 цифр.
|
||||||
|
- Строка, содержащая дату и время: `YYYYMMDDhhmmss`, `MM/DD/YYYY hh:mm:ss`, `MM-DD-YY hh:mm`, `YYYY-MM-DD hh:mm:ss` и т.д.
|
||||||
|
- Строка, содержащая дату без времени: `YYYY`, `YYYYMM`, `YYYY*MM`, `MM/DD/YYYY`, `MM-DD-YY` и т.д.
|
||||||
|
- Строка, содержащая день и время: `DD`, `DD hh`, `DD hh:mm`. В этом случае `YYYY-MM` заменяется на `2000-01`.
|
||||||
|
- Строка, содержащая дату и время, а также информацию о часовом поясе: `YYYY-MM-DD hh:mm:ss ±h:mm` и т.д. Например, `2020-12-12 17:36:00 -5:00`.
|
||||||
|
|
||||||
|
**Возвращаемые значения**
|
||||||
|
|
||||||
|
- `time_string`, преобразованная в тип данных `DateTime`.
|
||||||
|
- Нулевая дата или нулевая дата со временем, если входная строка не может быть преобразована в тип данных `DateTime`.
|
||||||
|
|
||||||
|
**Примеры**
|
||||||
|
|
||||||
|
Запрос:
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
SELECT parseDateTimeBestEffortUSOrZero('02/10/2021 21:12:57') AS parseDateTimeBestEffortUSOrZero;
|
||||||
|
```
|
||||||
|
|
||||||
|
Результат:
|
||||||
|
|
||||||
|
``` text
|
||||||
|
┌─parseDateTimeBestEffortUSOrZero─┐
|
||||||
|
│ 2021-02-10 21:12:57 │
|
||||||
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
Запрос:
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
SELECT parseDateTimeBestEffortUSOrZero('02-10-2021 21:12:57 GMT', 'Europe/Moscow') AS parseDateTimeBestEffortUSOrZero;
|
||||||
|
```
|
||||||
|
|
||||||
|
Результат:
|
||||||
|
|
||||||
|
``` text
|
||||||
|
┌─parseDateTimeBestEffortUSOrZero─┐
|
||||||
|
│ 2021-02-11 00:12:57 │
|
||||||
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
Запрос:
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
SELECT parseDateTimeBestEffortUSOrZero('02.10.2021') AS parseDateTimeBestEffortUSOrZero;
|
||||||
|
```
|
||||||
|
|
||||||
|
Результат:
|
||||||
|
|
||||||
|
``` text
|
||||||
|
┌─parseDateTimeBestEffortUSOrZero─┐
|
||||||
|
│ 2021-02-10 00:00:00 │
|
||||||
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
Запрос:
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
SELECT parseDateTimeBestEffortUSOrZero('02.2021') AS parseDateTimeBestEffortUSOrZero;
|
||||||
|
```
|
||||||
|
|
||||||
|
Результат:
|
||||||
|
|
||||||
|
``` text
|
||||||
|
┌─parseDateTimeBestEffortUSOrZero─┐
|
||||||
|
│ 1970-01-01 00:00:00 │
|
||||||
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
## toUnixTimestamp64Milli
|
## toUnixTimestamp64Milli
|
||||||
## toUnixTimestamp64Micro
|
## toUnixTimestamp64Micro
|
||||||
## toUnixTimestamp64Nano
|
## toUnixTimestamp64Nano
|
||||||
|
@ -106,6 +106,7 @@ AggregateFunctionPtr AggregateFunctionFactory::getImpl(
|
|||||||
bool has_null_arguments) const
|
bool has_null_arguments) const
|
||||||
{
|
{
|
||||||
String name = getAliasToOrName(name_param);
|
String name = getAliasToOrName(name_param);
|
||||||
|
bool is_case_insensitive = false;
|
||||||
Value found;
|
Value found;
|
||||||
|
|
||||||
/// Find by exact match.
|
/// Find by exact match.
|
||||||
@ -115,7 +116,10 @@ AggregateFunctionPtr AggregateFunctionFactory::getImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (auto jt = case_insensitive_aggregate_functions.find(Poco::toLower(name)); jt != case_insensitive_aggregate_functions.end())
|
if (auto jt = case_insensitive_aggregate_functions.find(Poco::toLower(name)); jt != case_insensitive_aggregate_functions.end())
|
||||||
|
{
|
||||||
found = jt->second;
|
found = jt->second;
|
||||||
|
is_case_insensitive = true;
|
||||||
|
}
|
||||||
|
|
||||||
const Context * query_context = nullptr;
|
const Context * query_context = nullptr;
|
||||||
if (CurrentThread::isInitialized())
|
if (CurrentThread::isInitialized())
|
||||||
@ -126,7 +130,8 @@ AggregateFunctionPtr AggregateFunctionFactory::getImpl(
|
|||||||
out_properties = found.properties;
|
out_properties = found.properties;
|
||||||
|
|
||||||
if (query_context && query_context->getSettingsRef().log_queries)
|
if (query_context && query_context->getSettingsRef().log_queries)
|
||||||
query_context->addQueryFactoriesInfo(Context::QueryLogFactories::AggregateFunction, name);
|
query_context->addQueryFactoriesInfo(
|
||||||
|
Context::QueryLogFactories::AggregateFunction, is_case_insensitive ? Poco::toLower(name) : name);
|
||||||
|
|
||||||
/// The case when aggregate function should return NULL on NULL arguments. This case is handled in "get" method.
|
/// 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)
|
if (!out_properties.returns_default_when_only_null && has_null_arguments)
|
||||||
|
@ -56,7 +56,7 @@ class ReservoirSamplerDeterministic
|
|||||||
{
|
{
|
||||||
bool good(const UInt32 hash)
|
bool good(const UInt32 hash)
|
||||||
{
|
{
|
||||||
return hash == ((hash >> skip_degree) << skip_degree);
|
return !(hash & skip_mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -135,11 +135,8 @@ public:
|
|||||||
throw Poco::Exception("Cannot merge ReservoirSamplerDeterministic's with different max sample size");
|
throw Poco::Exception("Cannot merge ReservoirSamplerDeterministic's with different max sample size");
|
||||||
sorted = false;
|
sorted = false;
|
||||||
|
|
||||||
if (b.skip_degree > skip_degree)
|
if (skip_degree < b.skip_degree)
|
||||||
{
|
setSkipDegree(b.skip_degree);
|
||||||
skip_degree = b.skip_degree;
|
|
||||||
thinOut();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto & sample : b.samples)
|
for (const auto & sample : b.samples)
|
||||||
if (good(sample.second))
|
if (good(sample.second))
|
||||||
@ -184,22 +181,39 @@ private:
|
|||||||
size_t total_values = 0; /// How many values were inserted (regardless if they remain in sample or not).
|
size_t total_values = 0; /// How many values were inserted (regardless if they remain in sample or not).
|
||||||
bool sorted = false;
|
bool sorted = false;
|
||||||
Array samples;
|
Array samples;
|
||||||
UInt8 skip_degree = 0; /// The number N determining that we save only one per 2^N elements in average.
|
|
||||||
|
/// The number N determining that we store only one per 2^N elements in average.
|
||||||
|
UInt8 skip_degree = 0;
|
||||||
|
|
||||||
|
/// skip_mask is calculated as (2 ^ skip_degree - 1). We store an element only if (hash & skip_mask) == 0.
|
||||||
|
/// For example, if skip_degree==0 then skip_mask==0 means we store each element;
|
||||||
|
/// if skip_degree==1 then skip_mask==0b0001 means we store one per 2 elements in average;
|
||||||
|
/// if skip_degree==4 then skip_mask==0b1111 means we store one per 16 elements in average.
|
||||||
|
UInt32 skip_mask = 0;
|
||||||
|
|
||||||
void insertImpl(const T & v, const UInt32 hash)
|
void insertImpl(const T & v, const UInt32 hash)
|
||||||
{
|
{
|
||||||
/// Make a room for plus one element.
|
/// Make a room for plus one element.
|
||||||
while (samples.size() >= max_sample_size)
|
while (samples.size() >= max_sample_size)
|
||||||
{
|
setSkipDegree(skip_degree + 1);
|
||||||
++skip_degree;
|
|
||||||
if (skip_degree > detail::MAX_SKIP_DEGREE)
|
|
||||||
throw DB::Exception{"skip_degree exceeds maximum value", DB::ErrorCodes::MEMORY_LIMIT_EXCEEDED};
|
|
||||||
thinOut();
|
|
||||||
}
|
|
||||||
|
|
||||||
samples.emplace_back(v, hash);
|
samples.emplace_back(v, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setSkipDegree(UInt8 skip_degree_)
|
||||||
|
{
|
||||||
|
if (skip_degree_ == skip_degree)
|
||||||
|
return;
|
||||||
|
if (skip_degree_ > detail::MAX_SKIP_DEGREE)
|
||||||
|
throw DB::Exception{"skip_degree exceeds maximum value", DB::ErrorCodes::MEMORY_LIMIT_EXCEEDED};
|
||||||
|
skip_degree = skip_degree_;
|
||||||
|
if (skip_degree == detail::MAX_SKIP_DEGREE)
|
||||||
|
skip_mask = static_cast<UInt32>(-1);
|
||||||
|
else
|
||||||
|
skip_mask = (1 << skip_degree) - 1;
|
||||||
|
thinOut();
|
||||||
|
}
|
||||||
|
|
||||||
void thinOut()
|
void thinOut()
|
||||||
{
|
{
|
||||||
samples.resize(std::distance(samples.begin(),
|
samples.resize(std::distance(samples.begin(),
|
||||||
|
@ -37,8 +37,12 @@ public:
|
|||||||
|
|
||||||
static constexpr size_t capacity =
|
static constexpr size_t capacity =
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
/* The stacks are normally larger in debug version due to less inlining. */
|
/* The stacks are normally larger in debug version due to less inlining.
|
||||||
64
|
*
|
||||||
|
* NOTE: it cannot be larger then 56 right now, since otherwise it will
|
||||||
|
* not fit into minimal PIPE_BUF (512) in TraceCollector.
|
||||||
|
*/
|
||||||
|
56
|
||||||
#else
|
#else
|
||||||
32
|
32
|
||||||
#endif
|
#endif
|
||||||
|
@ -22,7 +22,9 @@ namespace
|
|||||||
{
|
{
|
||||||
/// Normally query_id is a UUID (string with a fixed length) but user can provide custom query_id.
|
/// Normally query_id is a UUID (string with a fixed length) but user can provide custom query_id.
|
||||||
/// Thus upper bound on query_id length should be introduced to avoid buffer overflow in signal handler.
|
/// Thus upper bound on query_id length should be introduced to avoid buffer overflow in signal handler.
|
||||||
constexpr size_t QUERY_ID_MAX_LEN = 1024;
|
///
|
||||||
|
/// And it cannot be large, since otherwise it will not fit into PIPE_BUF.
|
||||||
|
constexpr size_t QUERY_ID_MAX_LEN = sizeof("00000000-0000-0000-0000-000000000000") - 1; // 36
|
||||||
}
|
}
|
||||||
|
|
||||||
LazyPipeFDs pipe;
|
LazyPipeFDs pipe;
|
||||||
@ -60,10 +62,14 @@ void TraceCollector::collect(TraceType trace_type, const StackTrace & stack_trac
|
|||||||
8 * sizeof(char) + // maximum VarUInt length for string size
|
8 * sizeof(char) + // maximum VarUInt length for string size
|
||||||
QUERY_ID_MAX_LEN * sizeof(char) + // maximum query_id length
|
QUERY_ID_MAX_LEN * sizeof(char) + // maximum query_id length
|
||||||
sizeof(UInt8) + // number of stack frames
|
sizeof(UInt8) + // number of stack frames
|
||||||
sizeof(StackTrace::Frames) + // collected stack trace, maximum capacity
|
sizeof(StackTrace::FramePointers) + // collected stack trace, maximum capacity
|
||||||
sizeof(TraceType) + // trace type
|
sizeof(TraceType) + // trace type
|
||||||
sizeof(UInt64) + // thread_id
|
sizeof(UInt64) + // thread_id
|
||||||
sizeof(Int64); // size
|
sizeof(Int64); // size
|
||||||
|
/// Write should be atomic to avoid overlaps
|
||||||
|
/// (since recursive collect() is possible)
|
||||||
|
static_assert(buf_size < PIPE_BUF, "Only write of PIPE_BUF to pipe is atomic");
|
||||||
|
|
||||||
char buffer[buf_size];
|
char buffer[buf_size];
|
||||||
WriteBufferFromFileDescriptorDiscardOnFailure out(pipe.fds_rw[1], buf_size, buffer);
|
WriteBufferFromFileDescriptorDiscardOnFailure out(pipe.fds_rw[1], buf_size, buffer);
|
||||||
|
|
||||||
|
@ -84,16 +84,7 @@ DataTypePtr DataTypeFactory::get(const String & family_name_param, const ASTPtr
|
|||||||
return get("LowCardinality", low_cardinality_params);
|
return get("LowCardinality", low_cardinality_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
DataTypePtr res = findCreatorByName(family_name)(parameters);
|
return findCreatorByName(family_name)(parameters);
|
||||||
|
|
||||||
if (CurrentThread::isInitialized())
|
|
||||||
{
|
|
||||||
const auto * query_context = CurrentThread::get().getQueryContext();
|
|
||||||
if (query_context && query_context->getSettingsRef().log_queries)
|
|
||||||
query_context->addQueryFactoriesInfo(Context::QueryLogFactories::DataType, family_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DataTypePtr DataTypeFactory::getCustom(DataTypeCustomDescPtr customization) const
|
DataTypePtr DataTypeFactory::getCustom(DataTypeCustomDescPtr customization) const
|
||||||
@ -165,10 +156,18 @@ void DataTypeFactory::registerSimpleDataTypeCustom(const String &name, SimpleCre
|
|||||||
|
|
||||||
const DataTypeFactory::Value & DataTypeFactory::findCreatorByName(const String & family_name) const
|
const DataTypeFactory::Value & DataTypeFactory::findCreatorByName(const String & family_name) const
|
||||||
{
|
{
|
||||||
|
const Context * query_context = nullptr;
|
||||||
|
if (CurrentThread::isInitialized())
|
||||||
|
query_context = CurrentThread::get().getQueryContext();
|
||||||
|
|
||||||
{
|
{
|
||||||
DataTypesDictionary::const_iterator it = data_types.find(family_name);
|
DataTypesDictionary::const_iterator it = data_types.find(family_name);
|
||||||
if (data_types.end() != it)
|
if (data_types.end() != it)
|
||||||
|
{
|
||||||
|
if (query_context && query_context->getSettingsRef().log_queries)
|
||||||
|
query_context->addQueryFactoriesInfo(Context::QueryLogFactories::DataType, family_name);
|
||||||
return it->second;
|
return it->second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String family_name_lowercase = Poco::toLower(family_name);
|
String family_name_lowercase = Poco::toLower(family_name);
|
||||||
@ -176,7 +175,11 @@ const DataTypeFactory::Value & DataTypeFactory::findCreatorByName(const String &
|
|||||||
{
|
{
|
||||||
DataTypesDictionary::const_iterator it = case_insensitive_data_types.find(family_name_lowercase);
|
DataTypesDictionary::const_iterator it = case_insensitive_data_types.find(family_name_lowercase);
|
||||||
if (case_insensitive_data_types.end() != it)
|
if (case_insensitive_data_types.end() != it)
|
||||||
|
{
|
||||||
|
if (query_context && query_context->getSettingsRef().log_queries)
|
||||||
|
query_context->addQueryFactoriesInfo(Context::QueryLogFactories::DataType, family_name_lowercase);
|
||||||
return it->second;
|
return it->second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto hints = this->getHints(family_name);
|
auto hints = this->getHints(family_name);
|
||||||
|
@ -99,7 +99,8 @@ FunctionOverloadResolverImplPtr FunctionFactory::tryGetImpl(
|
|||||||
res = it->second(context);
|
res = it->second(context);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
it = case_insensitive_functions.find(Poco::toLower(name));
|
name = Poco::toLower(name);
|
||||||
|
it = case_insensitive_functions.find(name);
|
||||||
if (case_insensitive_functions.end() != it)
|
if (case_insensitive_functions.end() != it)
|
||||||
res = it->second(context);
|
res = it->second(context);
|
||||||
}
|
}
|
||||||
|
@ -340,9 +340,15 @@ bool ValuesBlockInputFormat::parseExpression(IColumn & column, size_t column_idx
|
|||||||
bool found_in_cache = false;
|
bool found_in_cache = false;
|
||||||
const auto & result_type = header.getByPosition(column_idx).type;
|
const auto & result_type = header.getByPosition(column_idx).type;
|
||||||
const char * delimiter = (column_idx + 1 == num_columns) ? ")" : ",";
|
const char * delimiter = (column_idx + 1 == num_columns) ? ")" : ",";
|
||||||
auto structure = templates_cache.getFromCacheOrConstruct(result_type, format_settings.null_as_default,
|
auto structure = templates_cache.getFromCacheOrConstruct(
|
||||||
TokenIterator(tokens), token_iterator,
|
result_type,
|
||||||
ast, *context, &found_in_cache, delimiter);
|
!result_type->isNullable() && format_settings.null_as_default,
|
||||||
|
TokenIterator(tokens),
|
||||||
|
token_iterator,
|
||||||
|
ast,
|
||||||
|
*context,
|
||||||
|
&found_in_cache,
|
||||||
|
delimiter);
|
||||||
templates[column_idx].emplace(structure);
|
templates[column_idx].emplace(structure);
|
||||||
if (found_in_cache)
|
if (found_in_cache)
|
||||||
++attempts_to_deduce_template_cached[column_idx];
|
++attempts_to_deduce_template_cached[column_idx];
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
2 worl [123,1,1] 49 \N 50 4950 Nullable(UInt64) 50
|
2 worl 1 1 0 4950 99 [123,1,1] 49 \N 50 4950 Nullable(UInt64) 50
|
||||||
2 worl [123,1,1] 49 \N 50 4950 Nullable(UInt64) 50
|
2 worl 1 1 0 4950 99 [123,1,1] 49 \N 50 4950 Nullable(UInt64) 50
|
||||||
|
|
||||||
arraySort(used_aggregate_functions)
|
arraySort(used_aggregate_functions)
|
||||||
['avg','count','groupBitAnd','sum','uniq']
|
['avg','count','groupBitAnd','max','sum','uniq']
|
||||||
|
|
||||||
arraySort(used_aggregate_function_combinators)
|
arraySort(used_aggregate_function_combinators)
|
||||||
['Array','If','OrDefault','OrNull']
|
['Array','If','OrDefault','OrNull']
|
||||||
@ -11,7 +11,7 @@ arraySort(used_table_functions)
|
|||||||
['numbers']
|
['numbers']
|
||||||
|
|
||||||
arraySort(used_functions)
|
arraySort(used_functions)
|
||||||
['CAST','addDays','array','arrayFlatten','modulo','plus','substring','toDate','toDayOfYear','toTypeName','toWeek']
|
['CAST','CRC32','addDays','array','arrayFlatten','modulo','plus','pow','round','substring','tanh','toDate','toDayOfYear','toTypeName','toWeek']
|
||||||
|
|
||||||
arraySort(used_data_type_families)
|
arraySort(used_data_type_families)
|
||||||
['Array','Int32','Nullable','String']
|
['Array','Int32','Nullable','String']
|
||||||
@ -20,5 +20,5 @@ used_database_engines
|
|||||||
['Atomic']
|
['Atomic']
|
||||||
|
|
||||||
arraySort(used_data_type_families) used_storages
|
arraySort(used_data_type_families) used_storages
|
||||||
['DateTime','Int64'] ['Memory']
|
['Int64','datetime'] ['Memory']
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ SET database_atomic_wait_for_drop_and_detach_synchronously=1;
|
|||||||
|
|
||||||
SELECT uniqArray([1, 1, 2]),
|
SELECT uniqArray([1, 1, 2]),
|
||||||
SUBSTRING('Hello, world', 7, 5),
|
SUBSTRING('Hello, world', 7, 5),
|
||||||
|
POW(1, 2), ROUND(TANh(1)), CrC32(''),
|
||||||
|
SUM(number), MAX(number),
|
||||||
flatten([[[BIT_AND(123)]], [[mod(3, 2)], [CAST('1' AS INTEGER)]]]),
|
flatten([[[BIT_AND(123)]], [[mod(3, 2)], [CAST('1' AS INTEGER)]]]),
|
||||||
week(toDate('2000-12-05')),
|
week(toDate('2000-12-05')),
|
||||||
CAST(arrayJoin([NULL, NULL]) AS Nullable(TEXT)),
|
CAST(arrayJoin([NULL, NULL]) AS Nullable(TEXT)),
|
||||||
@ -49,7 +51,7 @@ WHERE current_database = currentDatabase() AND type == 'QueryFinish' AND (query
|
|||||||
ORDER BY query_start_time DESC LIMIT 1 FORMAT TabSeparatedWithNames;
|
ORDER BY query_start_time DESC LIMIT 1 FORMAT TabSeparatedWithNames;
|
||||||
SELECT '';
|
SELECT '';
|
||||||
|
|
||||||
CREATE OR REPLACE TABLE test_query_log_factories_info1.memory_table (id BIGINT, date DateTime) ENGINE=Memory();
|
CREATE OR REPLACE TABLE test_query_log_factories_info1.memory_table (id BIGINT, date DATETIME) ENGINE=Memory();
|
||||||
|
|
||||||
SYSTEM FLUSH LOGS;
|
SYSTEM FLUSH LOGS;
|
||||||
SELECT arraySort(used_data_type_families), used_storages
|
SELECT arraySort(used_data_type_families), used_storages
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
A
|
||||||
|
\N
|
5
tests/queries/0_stateless/01736_null_as_default.sql
Normal file
5
tests/queries/0_stateless/01736_null_as_default.sql
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
drop table if exists test_num;
|
||||||
|
create table test_enum (c Nullable(Enum16('A' = 1, 'B' = 2))) engine Log;
|
||||||
|
insert into test_enum values (1), (NULL);
|
||||||
|
select * from test_enum;
|
||||||
|
drop table if exists test_num;
|
Loading…
Reference in New Issue
Block a user