ClickHouse/src/Functions/extractTimeZoneFromFunctionArguments.h
Robert Schulze 72b9d75a84
Add compat setting for non-const timezones
SQL function toTimezone() converts a Date or DateTime into another
timezone. The problem is that the timezone is part of the Date /
DateTime type but not part of the internal representation (value). This
led to the fact that toTimeZone() wqith non-const timezones produced
wrong and misleading results until #48471 (shipped with v23.4) enforced
a const timezone.

Unfortunately, this PR also broke existing table definitions with
non-const timezones, e.g. in ALIAS expressions. So while #48471
addressed the issue appropriately, it is really backwards-incompatible.

This PR adds a setting to toggle the behavior and makes it also part of
the compatibility profile.
2023-06-10 16:56:42 +00:00

34 lines
1.4 KiB
C++

#pragma once
#include <string>
#include <Core/ColumnNumbers.h>
#include <Core/ColumnsWithTypeAndName.h>
class DateLUTImpl;
namespace DB
{
class Block;
std::string extractTimeZoneNameFromColumn(const IColumn * column, const String & column_name);
/// Determine working timezone either from optional argument with time zone name or from time zone in DateTime type of argument.
/// Returns empty string if default time zone should be used.
///
/// Parameter allow_nonconst_timezone_arguments toggles if non-const timezone function arguments are accepted (legacy behavior) or not. The
/// problem with the old behavior is that the timezone is part of the type, and not part of the value. This lead to confusion and unexpected
/// results.
/// - For new functions, set allow_nonconst_timezone_arguments = false.
/// - For existing functions
/// - which disallow non-const timezone arguments anyways (e.g. getArgumentsThatAreAlwaysConstant()), set allow_nonconst_timezone_arguments = false,
/// - which allow non-const timezone arguments, set allow_nonconst_timezone_arguments according to the corresponding setting.
std::string extractTimeZoneNameFromFunctionArguments(
const ColumnsWithTypeAndName & arguments, size_t time_zone_arg_num, size_t datetime_arg_num, bool allow_nonconst_timezone_arguments);
const DateLUTImpl & extractTimeZoneFromFunctionArguments(
const ColumnsWithTypeAndName & arguments, size_t time_zone_arg_num, size_t datetime_arg_num);
}