Use the dialect configuration

This commit is contained in:
ltrk2 2023-02-27 12:47:21 -08:00
parent b5cef61ef3
commit b673aa8e6b
8 changed files with 45 additions and 46 deletions

View File

@ -242,26 +242,6 @@ See also:
- [DateTime data type.](../../sql-reference/data-types/datetime.md)
- [Functions for working with dates and times.](../../sql-reference/functions/date-time-functions.md)
## interval_format {#interval_format}
Allows choosing different output formats of the text representation of interval types.
Possible values:
- `kql` - KQL-style output format.
ClickHouse outputs intervals in [KQL format](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-timespan-format-strings#the-constant-c-format-specifier). For example, `toIntervalDay(2)` would be formatted as `2.00:00:00`. Please note that for interval types of varying length (ie. `IntervalMonth` and `IntervalYear`) the average number of seconds per interval is taken into account.
- `numeric` - Numeric output format.
ClickHouse outputs intervals as their underlying numeric representation. For example, `toIntervalDay(2)` would be formatted as `2`.
Default value: `numeric`.
See also:
- [Interval](../../sql-reference/data-types/special-data-types/interval.md)
## input_format_ipv4_default_on_conversion_error {#input_format_ipv4_default_on_conversion_error}
Deserialization of IPv4 will use default values instead of throwing exception on conversion error.

View File

@ -98,6 +98,26 @@ Default value: 0.
</profiles>
```
## dialect {#dialect}
Allows choosing support for different query languages.
Possible values:
- `clickhouse` - ClickHouse SQL.
- `kusto` - Microsoft KQL.
- `kusto_auto` - Tries ClickHouse SQL first, then Microsoft KQL.
In mode `clickhouse`, ClickHouse outputs intervals as their underlying numeric representation. For example, `toIntervalDay(2)` would be formatted as `2`.
In modes `kusto` and `kusto_auto`, ClickHouse outputs intervals in [KQL format](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-timespan-format-strings#the-constant-c-format-specifier). For example, `toIntervalDay(2)` would be formatted as `2.00:00:00`. Please note that for interval types of varying length (ie. `IntervalMonth` and `IntervalYear`) the average number of seconds per interval is taken into account.
Default value: `clickhouse`.
See also:
- [Interval](../../sql-reference/data-types/special-data-types/interval.md)
## distributed_product_mode {#distributed-product-mode}
Changes the behaviour of [distributed subqueries](../../sql-reference/operators/in.md).

View File

@ -906,7 +906,6 @@ class IColumn;
\
M(DateTimeInputFormat, date_time_input_format, FormatSettings::DateTimeInputFormat::Basic, "Method to read DateTime from text input formats. Possible values: 'basic', 'best_effort' and 'best_effort_us'.", 0) \
M(DateTimeOutputFormat, date_time_output_format, FormatSettings::DateTimeOutputFormat::Simple, "Method to write DateTime to text output. Possible values: 'simple', 'iso', 'unix_timestamp'.", 0) \
M(IntervalFormat, interval_format, FormatSettings::IntervalFormat::Numeric, "Textual representation of Interval. Possible values: 'kql', 'numeric'.", 0) \
\
M(Bool, input_format_ipv4_default_on_conversion_error, false, "Deserialization of IPv4 will use default values instead of throwing exception on conversion error.", 0) \
M(Bool, input_format_ipv6_default_on_conversion_error, false, "Deserialization of IPV6 will use default values instead of throwing exception on conversion error.", 0) \

View File

@ -79,10 +79,6 @@ IMPLEMENT_SETTING_ENUM(DateTimeOutputFormat, ErrorCodes::BAD_ARGUMENTS,
{"iso", FormatSettings::DateTimeOutputFormat::ISO},
{"unix_timestamp", FormatSettings::DateTimeOutputFormat::UnixTimestamp}})
IMPLEMENT_SETTING_ENUM_WITH_RENAME(IntervalFormat, ErrorCodes::BAD_ARGUMENTS,
{{"kql", FormatSettings::IntervalFormat::KQL},
{"numeric", FormatSettings::IntervalFormat::Numeric}})
IMPLEMENT_SETTING_AUTO_ENUM(LogsLevel, ErrorCodes::BAD_ARGUMENTS)
IMPLEMENT_SETTING_AUTO_ENUM(LogQueriesType, ErrorCodes::BAD_ARGUMENTS)

View File

@ -72,8 +72,6 @@ DECLARE_SETTING_ENUM_WITH_RENAME(DateTimeInputFormat, FormatSettings::DateTimeIn
DECLARE_SETTING_ENUM_WITH_RENAME(DateTimeOutputFormat, FormatSettings::DateTimeOutputFormat)
DECLARE_SETTING_ENUM_WITH_RENAME(IntervalFormat, FormatSettings::IntervalFormat)
DECLARE_SETTING_ENUM_WITH_RENAME(ParquetVersion, FormatSettings::ParquetVersion)
enum class LogsLevel

View File

@ -19,6 +19,15 @@
#include <boost/algorithm/string/case_conv.hpp>
namespace
{
DB::FormatSettings::IntervalFormat convert(const DB::Dialect dialect)
{
return dialect == DB::Dialect::kusto || dialect == DB::Dialect::kusto_auto ? DB::FormatSettings::IntervalFormat::KQL
: DB::FormatSettings::IntervalFormat::Numeric;
}
}
namespace DB
{
@ -86,7 +95,7 @@ FormatSettings getFormatSettings(ContextPtr context, const Settings & settings)
format_settings.custom.skip_trailing_empty_lines = settings.input_format_custom_skip_trailing_empty_lines;
format_settings.date_time_input_format = settings.date_time_input_format;
format_settings.date_time_output_format = settings.date_time_output_format;
format_settings.interval.format = settings.interval_format;
format_settings.interval.format = convert(context->getSettingsRef().dialect);
format_settings.input_format_ipv4_default_on_conversion_error = settings.input_format_ipv4_default_on_conversion_error;
format_settings.input_format_ipv6_default_on_conversion_error = settings.input_format_ipv6_default_on_conversion_error;
format_settings.bool_true_representation = settings.bool_true_representation;

View File

@ -1,16 +1,4 @@
numeric
kql
00:00:00
00:00:00.0000001
00:00:00.0010000
00:00:42
01:06:00
2.18:00:00
5.00:00:00
7.00:00:00
14.00:00:00
('00:01:12','21.00:00:00','00:00:00.0000002')
numeric
clickhouse
99
100
1
@ -21,3 +9,14 @@ numeric
1
2
(72,3,200)
kusto_auto
00:00:00
00:00:00.0000001
00:00:00.0010000
00:00:42
01:06:00
2.18:00:00
5.00:00:00
7.00:00:00
14.00:00:00
('00:01:12','21.00:00:00','00:00:00.0000002')

View File

@ -1,8 +1,6 @@
select value from system.settings where name = 'interval_format';
{% for format in ['kql', 'numeric'] -%}
select '{{ format }}';
set interval_format = '{{ format }}';
{% for dialect in ['clickhouse', 'kusto_auto'] -%}
select '{{ dialect }}';
set dialect = '{{ dialect }}';
select toIntervalNanosecond(99);
select toIntervalNanosecond(100);
select toIntervalMillisecond(1);