2017-04-01 09:19:00 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <Functions/FunctionsConversion.h>
|
2014-08-22 00:57:20 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-01-22 08:33:16 +00:00
|
|
|
const DateLUTImpl * extractTimeZoneFromFunctionArguments(Block & block, const ColumnNumbers & arguments)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
if (arguments.size() == 2)
|
|
|
|
{
|
2017-07-21 06:35:58 +00:00
|
|
|
const ColumnConst * time_zone_column = checkAndGetColumnConst<ColumnString>(block.getByPosition(arguments[1]).column.get());
|
2017-01-22 08:33:16 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (!time_zone_column)
|
2017-07-21 06:35:58 +00:00
|
|
|
throw Exception("Illegal column " + block.getByPosition(arguments[1]).column->getName()
|
2017-04-01 07:20:54 +00:00
|
|
|
+ " of second (time zone) argument of function, must be constant string",
|
|
|
|
ErrorCodes::ILLEGAL_COLUMN);
|
2017-01-22 08:33:16 +00:00
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
return &DateLUT::instance(time_zone_column->getValue<String>());
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return &DateLUT::instance();
|
2017-01-22 08:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-17 07:40:06 +00:00
|
|
|
void throwExceptionForIncompletelyParsedValue(
|
2017-04-01 07:20:54 +00:00
|
|
|
ReadBuffer & read_buffer, Block & block, const ColumnNumbers & arguments, size_t result)
|
2016-08-17 07:40:06 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string message;
|
|
|
|
{
|
2017-07-21 06:35:58 +00:00
|
|
|
const IDataType & to_type = *block.getByPosition(result).type;
|
2016-08-17 07:40:06 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
WriteBufferFromString message_buf(message);
|
|
|
|
message_buf << "Cannot parse string " << quote << String(read_buffer.buffer().begin(), read_buffer.buffer().size())
|
|
|
|
<< " as " << to_type.getName()
|
|
|
|
<< ": syntax error";
|
2016-08-17 07:40:06 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (read_buffer.offset())
|
|
|
|
message_buf << " at position " << read_buffer.offset()
|
|
|
|
<< " (parsed just " << quote << String(read_buffer.buffer().begin(), read_buffer.offset()) << ")";
|
|
|
|
else
|
|
|
|
message_buf << " at begin of string";
|
2016-08-17 07:40:06 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (to_type.behavesAsNumber())
|
|
|
|
message_buf << ". Note: there are to" << to_type.getName() << "OrZero function, which returns zero instead of throwing exception.";
|
|
|
|
}
|
2016-08-17 07:40:06 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
throw Exception(message, ErrorCodes::CANNOT_PARSE_TEXT);
|
2016-08-17 07:40:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-22 00:57:20 +00:00
|
|
|
void registerFunctionsConversion(FunctionFactory & factory)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
factory.registerFunction<FunctionToUInt8>();
|
|
|
|
factory.registerFunction<FunctionToUInt16>();
|
|
|
|
factory.registerFunction<FunctionToUInt32>();
|
|
|
|
factory.registerFunction<FunctionToUInt64>();
|
|
|
|
factory.registerFunction<FunctionToInt8>();
|
|
|
|
factory.registerFunction<FunctionToInt16>();
|
|
|
|
factory.registerFunction<FunctionToInt32>();
|
|
|
|
factory.registerFunction<FunctionToInt64>();
|
|
|
|
factory.registerFunction<FunctionToFloat32>();
|
|
|
|
factory.registerFunction<FunctionToFloat64>();
|
|
|
|
factory.registerFunction<FunctionToDate>();
|
|
|
|
factory.registerFunction<FunctionToDateTime>();
|
2017-07-04 10:42:53 +00:00
|
|
|
factory.registerFunction<FunctionToUUID>();
|
2017-04-01 07:20:54 +00:00
|
|
|
factory.registerFunction<FunctionToString>();
|
|
|
|
factory.registerFunction<FunctionToFixedString>();
|
|
|
|
factory.registerFunction<FunctionToUnixTimestamp>();
|
|
|
|
factory.registerFunction<FunctionCast>();
|
|
|
|
factory.registerFunction<FunctionToUInt8OrZero>();
|
|
|
|
factory.registerFunction<FunctionToUInt16OrZero>();
|
|
|
|
factory.registerFunction<FunctionToUInt32OrZero>();
|
|
|
|
factory.registerFunction<FunctionToUInt64OrZero>();
|
|
|
|
factory.registerFunction<FunctionToInt8OrZero>();
|
|
|
|
factory.registerFunction<FunctionToInt16OrZero>();
|
|
|
|
factory.registerFunction<FunctionToInt32OrZero>();
|
|
|
|
factory.registerFunction<FunctionToInt64OrZero>();
|
|
|
|
factory.registerFunction<FunctionToFloat32OrZero>();
|
|
|
|
factory.registerFunction<FunctionToFloat64OrZero>();
|
2014-08-22 00:57:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|