2011-08-15 21:50:08 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2011-08-21 03:41:37 +00:00
|
|
|
|
#include <DB/Columns/ColumnsNumber.h>
|
|
|
|
|
#include <DB/Columns/ColumnConst.h>
|
|
|
|
|
#include <DB/Columns/ColumnString.h>
|
|
|
|
|
#include <DB/Columns/ColumnFixedString.h>
|
2016-02-14 02:37:42 +00:00
|
|
|
|
#include <DB/Columns/ColumnTuple.h>
|
2011-08-21 03:41:37 +00:00
|
|
|
|
|
2011-08-15 21:50:08 +00:00
|
|
|
|
#include <DB/DataTypes/DataTypesNumberFixed.h>
|
|
|
|
|
#include <DB/DataTypes/DataTypeDateTime.h>
|
|
|
|
|
#include <DB/DataTypes/DataTypeDate.h>
|
|
|
|
|
#include <DB/DataTypes/DataTypeString.h>
|
|
|
|
|
#include <DB/DataTypes/DataTypeFixedString.h>
|
2015-10-12 01:42:47 +00:00
|
|
|
|
#include <DB/DataTypes/DataTypeTuple.h>
|
2011-08-21 03:41:37 +00:00
|
|
|
|
|
2015-10-12 01:42:47 +00:00
|
|
|
|
#include <DB/Functions/FunctionsLogical.h>
|
2011-08-15 21:50:08 +00:00
|
|
|
|
#include <DB/Functions/IFunction.h>
|
2015-12-22 12:03:21 +00:00
|
|
|
|
#include <DB/DataTypes/DataTypeEnum.h>
|
2011-08-15 21:50:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/** Функции сравнения: ==, !=, <, >, <=, >=.
|
|
|
|
|
* Функции сравнения возвращают всегда 0 или 1 (UInt8).
|
|
|
|
|
*
|
|
|
|
|
* Сравнивать можно следующие типы:
|
|
|
|
|
* - числа;
|
|
|
|
|
* - строки и фиксированные строки;
|
|
|
|
|
* - даты;
|
|
|
|
|
* - даты-с-временем;
|
2016-02-14 02:37:42 +00:00
|
|
|
|
* внутри каждой группы, но не из разных групп;
|
|
|
|
|
* - кортежи (сравнение лексикографическое).
|
2015-06-12 07:46:58 +00:00
|
|
|
|
*
|
|
|
|
|
* Исключение: можно сравнивать дату и дату-с-временем с константной строкой. Пример: EventDate = '2015-01-01'.
|
|
|
|
|
*
|
2016-02-14 02:37:42 +00:00
|
|
|
|
* TODO Массивы.
|
2011-08-15 21:50:08 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2011-08-21 03:41:37 +00:00
|
|
|
|
/** Игнорируем warning о сравнении signed и unsigned.
|
|
|
|
|
* (Результат может быть некорректным.)
|
2014-06-26 00:58:14 +00:00
|
|
|
|
*/
|
2011-08-21 03:41:37 +00:00
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
|
#pragma GCC diagnostic ignored "-Wsign-compare"
|
|
|
|
|
|
2014-08-17 03:29:56 +00:00
|
|
|
|
template <typename A, typename B> struct EqualsOp { static UInt8 apply(A a, B b) { return a == b; } };
|
|
|
|
|
template <typename A, typename B> struct NotEqualsOp { static UInt8 apply(A a, B b) { return a != b; } };
|
|
|
|
|
template <typename A, typename B> struct LessOp { static UInt8 apply(A a, B b) { return a < b; } };
|
|
|
|
|
template <typename A, typename B> struct GreaterOp { static UInt8 apply(A a, B b) { return a > b; } };
|
|
|
|
|
template <typename A, typename B> struct LessOrEqualsOp { static UInt8 apply(A a, B b) { return a <= b; } };
|
|
|
|
|
template <typename A, typename B> struct GreaterOrEqualsOp { static UInt8 apply(A a, B b) { return a >= b; } };
|
2011-08-21 06:52:21 +00:00
|
|
|
|
|
2014-08-17 03:29:56 +00:00
|
|
|
|
#pragma GCC diagnostic pop
|
2011-08-21 06:52:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-17 03:29:56 +00:00
|
|
|
|
template<typename A, typename B, typename Op>
|
|
|
|
|
struct NumComparisonImpl
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
2016-04-15 00:33:21 +00:00
|
|
|
|
static void vector_vector(const PaddedPODArray<A> & a, const PaddedPODArray<B> & b, PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
2014-08-17 05:41:28 +00:00
|
|
|
|
/** GCC 4.8.2 векторизует цикл только если его записать в такой форме.
|
|
|
|
|
* В данном случае, если сделать цикл по индексу массива (код будет выглядеть проще),
|
|
|
|
|
* цикл не будет векторизовываться.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-08-21 06:52:21 +00:00
|
|
|
|
size_t size = a.size();
|
2014-08-17 05:41:28 +00:00
|
|
|
|
const A * a_pos = &a[0];
|
|
|
|
|
const B * b_pos = &b[0];
|
|
|
|
|
UInt8 * c_pos = &c[0];
|
|
|
|
|
const A * a_end = a_pos + size;
|
|
|
|
|
|
|
|
|
|
while (a_pos < a_end)
|
|
|
|
|
{
|
|
|
|
|
*c_pos = Op::apply(*a_pos, *b_pos);
|
|
|
|
|
++a_pos;
|
|
|
|
|
++b_pos;
|
|
|
|
|
++c_pos;
|
|
|
|
|
}
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-15 00:33:21 +00:00
|
|
|
|
static void vector_constant(const PaddedPODArray<A> & a, B b, PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
size_t size = a.size();
|
2014-08-17 05:41:28 +00:00
|
|
|
|
const A * a_pos = &a[0];
|
|
|
|
|
UInt8 * c_pos = &c[0];
|
|
|
|
|
const A * a_end = a_pos + size;
|
|
|
|
|
|
|
|
|
|
while (a_pos < a_end)
|
|
|
|
|
{
|
|
|
|
|
*c_pos = Op::apply(*a_pos, b);
|
|
|
|
|
++a_pos;
|
|
|
|
|
++c_pos;
|
|
|
|
|
}
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-15 00:33:21 +00:00
|
|
|
|
static void constant_vector(A a, const PaddedPODArray<B> & b, PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
size_t size = b.size();
|
2014-08-17 05:41:28 +00:00
|
|
|
|
const B * b_pos = &b[0];
|
|
|
|
|
UInt8 * c_pos = &c[0];
|
|
|
|
|
const B * b_end = b_pos + size;
|
|
|
|
|
|
|
|
|
|
while (b_pos < b_end)
|
|
|
|
|
{
|
|
|
|
|
*c_pos = Op::apply(a, *b_pos);
|
|
|
|
|
++b_pos;
|
|
|
|
|
++c_pos;
|
|
|
|
|
}
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void constant_constant(A a, B b, UInt8 & c)
|
|
|
|
|
{
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c = Op::apply(a, b);
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-17 03:29:56 +00:00
|
|
|
|
|
|
|
|
|
template <typename Op>
|
|
|
|
|
struct StringComparisonImpl
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
static void string_vector_string_vector(
|
2013-09-15 05:51:43 +00:00
|
|
|
|
const ColumnString::Chars_t & a_data, const ColumnString::Offsets_t & a_offsets,
|
|
|
|
|
const ColumnString::Chars_t & b_data, const ColumnString::Offsets_t & b_offsets,
|
2016-04-15 00:33:21 +00:00
|
|
|
|
PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
size_t size = a_offsets.size();
|
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (i == 0)
|
|
|
|
|
{
|
2014-08-17 03:29:56 +00:00
|
|
|
|
/// Завершающий ноль в меньшей по длине строке входит в сравнение.
|
|
|
|
|
c[i] = Op::apply(memcmp(&a_data[0], &b_data[0], std::min(a_offsets[0], b_offsets[0])), 0);
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c[i] = Op::apply(memcmp(&a_data[a_offsets[i - 1]], &b_data[b_offsets[i - 1]],
|
|
|
|
|
std::min(a_offsets[i] - a_offsets[i - 1], b_offsets[i] - b_offsets[i - 1])), 0);
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void string_vector_fixed_string_vector(
|
2013-09-15 05:51:43 +00:00
|
|
|
|
const ColumnString::Chars_t & a_data, const ColumnString::Offsets_t & a_offsets,
|
|
|
|
|
const ColumnString::Chars_t & b_data, ColumnString::Offset_t b_n,
|
2016-04-15 00:33:21 +00:00
|
|
|
|
PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
size_t size = a_offsets.size();
|
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (i == 0)
|
|
|
|
|
{
|
|
|
|
|
int res = memcmp(&a_data[0], &b_data[0], std::min(a_offsets[0] - 1, b_n));
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c[i] = Op::apply(res, 0) || (res == 0 && Op::apply(a_offsets[0], b_n + 1));
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int res = memcmp(&a_data[a_offsets[i - 1]], &b_data[i * b_n],
|
|
|
|
|
std::min(a_offsets[i] - a_offsets[i - 1] - 1, b_n));
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c[i] = Op::apply(res, 0) || (res == 0 && Op::apply(a_offsets[i] - a_offsets[i - 1], b_n + 1));
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void string_vector_constant(
|
2013-09-15 05:51:43 +00:00
|
|
|
|
const ColumnString::Chars_t & a_data, const ColumnString::Offsets_t & a_offsets,
|
2011-08-21 06:52:21 +00:00
|
|
|
|
const std::string & b,
|
2016-04-15 00:33:21 +00:00
|
|
|
|
PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
size_t size = a_offsets.size();
|
2013-05-05 15:25:25 +00:00
|
|
|
|
ColumnString::Offset_t b_n = b.size();
|
2011-08-21 06:52:21 +00:00
|
|
|
|
const UInt8 * b_data = reinterpret_cast<const UInt8 *>(b.data());
|
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (i == 0)
|
|
|
|
|
{
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c[i] = Op::apply(memcmp(&a_data[0], b_data, std::min(a_offsets[0], b_n + 1)), 0);
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c[i] = Op::apply(memcmp(&a_data[a_offsets[i - 1]], b_data,
|
|
|
|
|
std::min(a_offsets[i] - a_offsets[i - 1], b_n + 1)), 0);
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void fixed_string_vector_string_vector(
|
2013-09-15 05:51:43 +00:00
|
|
|
|
const ColumnString::Chars_t & a_data, ColumnString::Offset_t a_n,
|
|
|
|
|
const ColumnString::Chars_t & b_data, const ColumnString::Offsets_t & b_offsets,
|
2016-04-15 00:33:21 +00:00
|
|
|
|
PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
size_t size = b_offsets.size();
|
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (i == 0)
|
|
|
|
|
{
|
|
|
|
|
int res = memcmp(&a_data[0], &b_data[0], std::min(b_offsets[0] - 1, a_n));
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c[i] = Op::apply(res, 0) || (res == 0 && Op::apply(a_n + 1, b_offsets[0]));
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int res = memcmp(&a_data[i * a_n], &b_data[b_offsets[i - 1]],
|
|
|
|
|
std::min(b_offsets[i] - b_offsets[i - 1] - 1, a_n));
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c[i] = Op::apply(res, 0) || (res == 0 && Op::apply(a_n + 1, b_offsets[i] - b_offsets[i - 1]));
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void fixed_string_vector_fixed_string_vector(
|
2013-09-15 05:51:43 +00:00
|
|
|
|
const ColumnString::Chars_t & a_data, ColumnString::Offset_t a_n,
|
|
|
|
|
const ColumnString::Chars_t & b_data, ColumnString::Offset_t b_n,
|
2016-04-15 00:33:21 +00:00
|
|
|
|
PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
size_t size = a_data.size();
|
2012-08-03 20:09:06 +00:00
|
|
|
|
for (size_t i = 0, j = 0; i < size; i += a_n, ++j)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
int res = memcmp(&a_data[i], &b_data[i], std::min(a_n, b_n));
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c[j] = Op::apply(res, 0) || (res == 0 && Op::apply(a_n, b_n));
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void fixed_string_vector_constant(
|
2013-09-15 05:51:43 +00:00
|
|
|
|
const ColumnString::Chars_t & a_data, ColumnString::Offset_t a_n,
|
2011-08-21 06:52:21 +00:00
|
|
|
|
const std::string & b,
|
2016-04-15 00:33:21 +00:00
|
|
|
|
PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
size_t size = a_data.size();
|
|
|
|
|
const UInt8 * b_data = reinterpret_cast<const UInt8 *>(b.data());
|
2013-05-05 15:25:25 +00:00
|
|
|
|
ColumnString::Offset_t b_n = b.size();
|
2012-08-03 20:09:06 +00:00
|
|
|
|
for (size_t i = 0, j = 0; i < size; i += a_n, ++j)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
int res = memcmp(&a_data[i], b_data, std::min(a_n, b_n));
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c[j] = Op::apply(res, 0) || (res == 0 && Op::apply(a_n, b_n));
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void constant_string_vector(
|
|
|
|
|
const std::string & a,
|
2013-09-15 05:51:43 +00:00
|
|
|
|
const ColumnString::Chars_t & b_data, const ColumnString::Offsets_t & b_offsets,
|
2016-04-15 00:33:21 +00:00
|
|
|
|
PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
size_t size = b_offsets.size();
|
2013-05-05 15:25:25 +00:00
|
|
|
|
ColumnString::Offset_t a_n = a.size();
|
2011-08-21 06:52:21 +00:00
|
|
|
|
const UInt8 * a_data = reinterpret_cast<const UInt8 *>(a.data());
|
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (i == 0)
|
|
|
|
|
{
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c[i] = Op::apply(memcmp(a_data, &b_data[0], std::min(b_offsets[0], a_n + 1)), 0);
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c[i] = Op::apply(memcmp(a_data, &b_data[b_offsets[i - 1]],
|
|
|
|
|
std::min(b_offsets[i] - b_offsets[i - 1], a_n + 1)), 0);
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void constant_fixed_string_vector(
|
|
|
|
|
const std::string & a,
|
2013-09-15 05:51:43 +00:00
|
|
|
|
const ColumnString::Chars_t & b_data, ColumnString::Offset_t b_n,
|
2016-04-15 00:33:21 +00:00
|
|
|
|
PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
size_t size = b_data.size();
|
|
|
|
|
const UInt8 * a_data = reinterpret_cast<const UInt8 *>(a.data());
|
2013-05-05 15:25:25 +00:00
|
|
|
|
ColumnString::Offset_t a_n = a.size();
|
2012-08-03 20:09:06 +00:00
|
|
|
|
for (size_t i = 0, j = 0; i < size; i += b_n, ++j)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
int res = memcmp(a_data, &b_data[i], std::min(a_n, b_n));
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c[j] = Op::apply(res, 0) || (res == 0 && Op::apply(b_n, a_n));
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void constant_constant(
|
|
|
|
|
const std::string & a,
|
|
|
|
|
const std::string & b,
|
|
|
|
|
UInt8 & c)
|
|
|
|
|
{
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c = Op::apply(memcmp(a.data(), b.data(), std::min(a.size(), b.size()) + 1), 0);
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2014-08-17 03:29:56 +00:00
|
|
|
|
/// Сравнения на равенство/неравенство реализованы несколько более эффективно.
|
|
|
|
|
template <bool positive>
|
|
|
|
|
struct StringEqualsImpl
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
static void string_vector_string_vector(
|
2013-09-15 05:51:43 +00:00
|
|
|
|
const ColumnString::Chars_t & a_data, const ColumnString::Offsets_t & a_offsets,
|
|
|
|
|
const ColumnString::Chars_t & b_data, const ColumnString::Offsets_t & b_offsets,
|
2016-04-15 00:33:21 +00:00
|
|
|
|
PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
size_t size = a_offsets.size();
|
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c[i] = positive == ((i == 0)
|
|
|
|
|
? (a_offsets[0] == b_offsets[0] && !memcmp(&a_data[0], &b_data[0], a_offsets[0] - 1))
|
|
|
|
|
: (a_offsets[i] - a_offsets[i - 1] == b_offsets[i] - b_offsets[i - 1]
|
|
|
|
|
&& !memcmp(&a_data[a_offsets[i - 1]], &b_data[b_offsets[i - 1]], a_offsets[i] - a_offsets[i - 1] - 1)));
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void string_vector_fixed_string_vector(
|
2013-09-15 05:51:43 +00:00
|
|
|
|
const ColumnString::Chars_t & a_data, const ColumnString::Offsets_t & a_offsets,
|
|
|
|
|
const ColumnString::Chars_t & b_data, ColumnString::Offset_t b_n,
|
2016-04-15 00:33:21 +00:00
|
|
|
|
PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
size_t size = a_offsets.size();
|
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c[i] = positive == ((i == 0)
|
|
|
|
|
? (a_offsets[0] == b_n + 1 && !memcmp(&a_data[0], &b_data[0], b_n))
|
|
|
|
|
: (a_offsets[i] - a_offsets[i - 1] == b_n + 1
|
|
|
|
|
&& !memcmp(&a_data[a_offsets[i - 1]], &b_data[b_n * i], b_n)));
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void string_vector_constant(
|
2013-09-15 05:51:43 +00:00
|
|
|
|
const ColumnString::Chars_t & a_data, const ColumnString::Offsets_t & a_offsets,
|
2011-08-21 06:52:21 +00:00
|
|
|
|
const std::string & b,
|
2016-04-15 00:33:21 +00:00
|
|
|
|
PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
size_t size = a_offsets.size();
|
2013-05-05 15:25:25 +00:00
|
|
|
|
ColumnString::Offset_t b_n = b.size();
|
2011-08-21 06:52:21 +00:00
|
|
|
|
const UInt8 * b_data = reinterpret_cast<const UInt8 *>(b.data());
|
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c[i] = positive == ((i == 0)
|
|
|
|
|
? (a_offsets[0] == b_n + 1 && !memcmp(&a_data[0], b_data, b_n))
|
|
|
|
|
: (a_offsets[i] - a_offsets[i - 1] == b_n + 1
|
|
|
|
|
&& !memcmp(&a_data[a_offsets[i - 1]], b_data, b_n)));
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void fixed_string_vector_fixed_string_vector(
|
2013-09-15 05:51:43 +00:00
|
|
|
|
const ColumnString::Chars_t & a_data, ColumnString::Offset_t a_n,
|
|
|
|
|
const ColumnString::Chars_t & b_data, ColumnString::Offset_t b_n,
|
2016-04-15 00:33:21 +00:00
|
|
|
|
PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
size_t size = a_data.size();
|
2012-08-03 20:09:06 +00:00
|
|
|
|
for (size_t i = 0, j = 0; i < size; i += a_n, ++j)
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c[j] = positive == (a_n == b_n && !memcmp(&a_data[i], &b_data[i], a_n));
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void fixed_string_vector_constant(
|
2013-09-15 05:51:43 +00:00
|
|
|
|
const ColumnString::Chars_t & a_data, ColumnString::Offset_t a_n,
|
2011-08-21 06:52:21 +00:00
|
|
|
|
const std::string & b,
|
2016-04-15 00:33:21 +00:00
|
|
|
|
PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
size_t size = a_data.size();
|
|
|
|
|
const UInt8 * b_data = reinterpret_cast<const UInt8 *>(b.data());
|
2013-05-05 15:25:25 +00:00
|
|
|
|
ColumnString::Offset_t b_n = b.size();
|
2012-08-03 20:09:06 +00:00
|
|
|
|
for (size_t i = 0, j = 0; i < size; i += a_n, ++j)
|
2014-08-17 03:29:56 +00:00
|
|
|
|
c[j] = positive == (a_n == b_n && !memcmp(&a_data[i], b_data, a_n));
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 03:29:56 +00:00
|
|
|
|
static void constant_constant(
|
2011-08-21 06:52:21 +00:00
|
|
|
|
const std::string & a,
|
2014-08-17 03:29:56 +00:00
|
|
|
|
const std::string & b,
|
|
|
|
|
UInt8 & c)
|
|
|
|
|
{
|
|
|
|
|
c = positive == (a == b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void fixed_string_vector_string_vector(
|
|
|
|
|
const ColumnString::Chars_t & a_data, ColumnString::Offset_t a_n,
|
2013-09-15 05:51:43 +00:00
|
|
|
|
const ColumnString::Chars_t & b_data, const ColumnString::Offsets_t & b_offsets,
|
2016-04-15 00:33:21 +00:00
|
|
|
|
PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
2014-08-17 03:29:56 +00:00
|
|
|
|
string_vector_fixed_string_vector(b_data, b_offsets, a_data, a_n, c);
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 03:29:56 +00:00
|
|
|
|
static void constant_string_vector(
|
2011-08-21 06:52:21 +00:00
|
|
|
|
const std::string & a,
|
2014-08-17 03:29:56 +00:00
|
|
|
|
const ColumnString::Chars_t & b_data, const ColumnString::Offsets_t & b_offsets,
|
2016-04-15 00:33:21 +00:00
|
|
|
|
PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
2014-08-17 03:29:56 +00:00
|
|
|
|
string_vector_constant(b_data, b_offsets, a, c);
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 03:29:56 +00:00
|
|
|
|
static void constant_fixed_string_vector(
|
2011-08-21 06:52:21 +00:00
|
|
|
|
const std::string & a,
|
2014-08-17 03:29:56 +00:00
|
|
|
|
const ColumnString::Chars_t & b_data, ColumnString::Offset_t b_n,
|
2016-04-15 00:33:21 +00:00
|
|
|
|
PaddedPODArray<UInt8> & c)
|
2011-08-21 06:52:21 +00:00
|
|
|
|
{
|
2014-08-17 03:29:56 +00:00
|
|
|
|
fixed_string_vector_constant(b_data, b_n, a, c);
|
2011-08-21 06:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2014-08-17 03:29:56 +00:00
|
|
|
|
template <typename A, typename B>
|
|
|
|
|
struct StringComparisonImpl<EqualsOp<A, B>> : StringEqualsImpl<true> {};
|
|
|
|
|
|
|
|
|
|
template <typename A, typename B>
|
|
|
|
|
struct StringComparisonImpl<NotEqualsOp<A, B>> : StringEqualsImpl<false> {};
|
2011-08-15 21:50:08 +00:00
|
|
|
|
|
2011-08-19 20:35:21 +00:00
|
|
|
|
|
2015-10-12 01:42:47 +00:00
|
|
|
|
struct NameEquals { static constexpr auto name = "equals"; };
|
|
|
|
|
struct NameNotEquals { static constexpr auto name = "notEquals"; };
|
|
|
|
|
struct NameLess { static constexpr auto name = "less"; };
|
|
|
|
|
struct NameGreater { static constexpr auto name = "greater"; };
|
|
|
|
|
struct NameLessOrEquals { static constexpr auto name = "lessOrEquals"; };
|
|
|
|
|
struct NameGreaterOrEquals { static constexpr auto name = "greaterOrEquals"; };
|
|
|
|
|
|
|
|
|
|
|
2011-08-21 03:41:37 +00:00
|
|
|
|
template <
|
2014-08-17 03:29:56 +00:00
|
|
|
|
template <typename, typename> class Op,
|
2011-08-21 03:41:37 +00:00
|
|
|
|
typename Name>
|
2011-08-15 21:50:08 +00:00
|
|
|
|
class FunctionComparison : public IFunction
|
|
|
|
|
{
|
2014-11-12 17:23:26 +00:00
|
|
|
|
public:
|
|
|
|
|
static constexpr auto name = Name::name;
|
2016-05-28 15:42:22 +00:00
|
|
|
|
static FunctionPtr create(const Context & context) { return std::make_shared<FunctionComparison>(); };
|
2011-08-15 21:50:08 +00:00
|
|
|
|
|
2014-11-12 17:23:26 +00:00
|
|
|
|
private:
|
2011-08-15 21:50:08 +00:00
|
|
|
|
template <typename T0, typename T1>
|
2015-06-12 07:46:58 +00:00
|
|
|
|
bool executeNumRightType(Block & block, size_t result, const ColumnVector<T0> * col_left, const IColumn * col_right_untyped)
|
2011-08-15 21:50:08 +00:00
|
|
|
|
{
|
2015-06-12 07:46:58 +00:00
|
|
|
|
if (const ColumnVector<T1> * col_right = typeid_cast<const ColumnVector<T1> *>(col_right_untyped))
|
2011-08-15 21:50:08 +00:00
|
|
|
|
{
|
2016-05-28 05:31:36 +00:00
|
|
|
|
std::shared_ptr<ColumnUInt8> col_res = std::make_shared<ColumnUInt8>();
|
2011-09-24 20:32:41 +00:00
|
|
|
|
block.getByPosition(result).column = col_res;
|
2011-08-15 21:50:08 +00:00
|
|
|
|
|
2011-08-21 03:41:37 +00:00
|
|
|
|
ColumnUInt8::Container_t & vec_res = col_res->getData();
|
2011-08-15 21:50:08 +00:00
|
|
|
|
vec_res.resize(col_left->getData().size());
|
2014-08-17 03:29:56 +00:00
|
|
|
|
NumComparisonImpl<T0, T1, Op<T0, T1>>::vector_vector(col_left->getData(), col_right->getData(), vec_res);
|
2011-08-15 21:50:08 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-06-12 07:46:58 +00:00
|
|
|
|
else if (const ColumnConst<T1> * col_right = typeid_cast<const ColumnConst<T1> *>(col_right_untyped))
|
2011-08-15 21:50:08 +00:00
|
|
|
|
{
|
2016-05-28 05:31:36 +00:00
|
|
|
|
std::shared_ptr<ColumnUInt8> col_res = std::make_shared<ColumnUInt8>();
|
2011-09-24 20:32:41 +00:00
|
|
|
|
block.getByPosition(result).column = col_res;
|
2011-08-15 21:50:08 +00:00
|
|
|
|
|
2011-08-21 03:41:37 +00:00
|
|
|
|
ColumnUInt8::Container_t & vec_res = col_res->getData();
|
2011-08-15 21:50:08 +00:00
|
|
|
|
vec_res.resize(col_left->getData().size());
|
2014-08-17 03:29:56 +00:00
|
|
|
|
NumComparisonImpl<T0, T1, Op<T0, T1>>::vector_constant(col_left->getData(), col_right->getData(), vec_res);
|
2011-08-15 21:50:08 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
|
2011-08-15 21:50:08 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T0, typename T1>
|
2015-06-12 07:46:58 +00:00
|
|
|
|
bool executeNumConstRightType(Block & block, size_t result, const ColumnConst<T0> * col_left, const IColumn * col_right_untyped)
|
2011-08-15 21:50:08 +00:00
|
|
|
|
{
|
2015-06-12 07:46:58 +00:00
|
|
|
|
if (const ColumnVector<T1> * col_right = typeid_cast<const ColumnVector<T1> *>(col_right_untyped))
|
2011-08-15 21:50:08 +00:00
|
|
|
|
{
|
2016-05-28 05:31:36 +00:00
|
|
|
|
std::shared_ptr<ColumnUInt8> col_res = std::make_shared<ColumnUInt8>();
|
2011-09-24 20:32:41 +00:00
|
|
|
|
block.getByPosition(result).column = col_res;
|
2011-08-15 21:50:08 +00:00
|
|
|
|
|
2011-08-21 03:41:37 +00:00
|
|
|
|
ColumnUInt8::Container_t & vec_res = col_res->getData();
|
2011-08-15 21:50:08 +00:00
|
|
|
|
vec_res.resize(col_left->size());
|
2014-08-17 03:29:56 +00:00
|
|
|
|
NumComparisonImpl<T0, T1, Op<T0, T1>>::constant_vector(col_left->getData(), col_right->getData(), vec_res);
|
2011-08-15 21:50:08 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-06-12 07:46:58 +00:00
|
|
|
|
else if (const ColumnConst<T1> * col_right = typeid_cast<const ColumnConst<T1> *>(col_right_untyped))
|
2011-08-15 21:50:08 +00:00
|
|
|
|
{
|
2011-08-21 03:41:37 +00:00
|
|
|
|
UInt8 res = 0;
|
2014-08-17 03:29:56 +00:00
|
|
|
|
NumComparisonImpl<T0, T1, Op<T0, T1>>::constant_constant(col_left->getData(), col_right->getData(), res);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
|
2016-05-28 05:31:36 +00:00
|
|
|
|
auto col_res = std::make_shared<ColumnConstUInt8>(col_left->size(), res);
|
2011-09-24 20:32:41 +00:00
|
|
|
|
block.getByPosition(result).column = col_res;
|
2011-08-15 21:50:08 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T0>
|
2015-06-12 07:46:58 +00:00
|
|
|
|
bool executeNumLeftType(Block & block, size_t result, const IColumn * col_left_untyped, const IColumn * col_right_untyped)
|
2011-08-15 21:50:08 +00:00
|
|
|
|
{
|
2015-06-12 07:46:58 +00:00
|
|
|
|
if (const ColumnVector<T0> * col_left = typeid_cast<const ColumnVector<T0> *>(col_left_untyped))
|
2011-08-15 21:50:08 +00:00
|
|
|
|
{
|
2015-06-12 07:46:58 +00:00
|
|
|
|
if ( executeNumRightType<T0, UInt8>(block, result, col_left, col_right_untyped)
|
|
|
|
|
|| executeNumRightType<T0, UInt16>(block, result, col_left, col_right_untyped)
|
|
|
|
|
|| executeNumRightType<T0, UInt32>(block, result, col_left, col_right_untyped)
|
|
|
|
|
|| executeNumRightType<T0, UInt64>(block, result, col_left, col_right_untyped)
|
|
|
|
|
|| executeNumRightType<T0, Int8>(block, result, col_left, col_right_untyped)
|
|
|
|
|
|| executeNumRightType<T0, Int16>(block, result, col_left, col_right_untyped)
|
|
|
|
|
|| executeNumRightType<T0, Int32>(block, result, col_left, col_right_untyped)
|
|
|
|
|
|| executeNumRightType<T0, Int64>(block, result, col_left, col_right_untyped)
|
|
|
|
|
|| executeNumRightType<T0, Float32>(block, result, col_left, col_right_untyped)
|
|
|
|
|
|| executeNumRightType<T0, Float64>(block, result, col_left, col_right_untyped))
|
2011-08-15 21:50:08 +00:00
|
|
|
|
return true;
|
|
|
|
|
else
|
2015-06-12 07:46:58 +00:00
|
|
|
|
throw Exception("Illegal column " + col_right_untyped->getName()
|
2011-08-28 00:31:30 +00:00
|
|
|
|
+ " of second argument of function " + getName(),
|
2011-08-15 21:50:08 +00:00
|
|
|
|
ErrorCodes::ILLEGAL_COLUMN);
|
|
|
|
|
}
|
2015-06-12 07:46:58 +00:00
|
|
|
|
else if (const ColumnConst<T0> * col_left = typeid_cast<const ColumnConst<T0> *>(col_left_untyped))
|
2011-08-15 21:50:08 +00:00
|
|
|
|
{
|
2015-06-12 07:46:58 +00:00
|
|
|
|
if ( executeNumConstRightType<T0, UInt8>(block, result, col_left, col_right_untyped)
|
|
|
|
|
|| executeNumConstRightType<T0, UInt16>(block, result, col_left, col_right_untyped)
|
|
|
|
|
|| executeNumConstRightType<T0, UInt32>(block, result, col_left, col_right_untyped)
|
|
|
|
|
|| executeNumConstRightType<T0, UInt64>(block, result, col_left, col_right_untyped)
|
|
|
|
|
|| executeNumConstRightType<T0, Int8>(block, result, col_left, col_right_untyped)
|
|
|
|
|
|| executeNumConstRightType<T0, Int16>(block, result, col_left, col_right_untyped)
|
|
|
|
|
|| executeNumConstRightType<T0, Int32>(block, result, col_left, col_right_untyped)
|
|
|
|
|
|| executeNumConstRightType<T0, Int64>(block, result, col_left, col_right_untyped)
|
|
|
|
|
|| executeNumConstRightType<T0, Float32>(block, result, col_left, col_right_untyped)
|
|
|
|
|
|| executeNumConstRightType<T0, Float64>(block, result, col_left, col_right_untyped))
|
2011-08-15 21:50:08 +00:00
|
|
|
|
return true;
|
|
|
|
|
else
|
2015-06-12 07:46:58 +00:00
|
|
|
|
throw Exception("Illegal column " + col_right_untyped->getName()
|
2011-08-28 00:31:30 +00:00
|
|
|
|
+ " of second argument of function " + getName(),
|
2011-08-15 21:50:08 +00:00
|
|
|
|
ErrorCodes::ILLEGAL_COLUMN);
|
|
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
|
2011-08-15 21:50:08 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-08-21 03:41:37 +00:00
|
|
|
|
|
2015-06-12 07:46:58 +00:00
|
|
|
|
void executeString(Block & block, size_t result, const IColumn * c0, const IColumn * c1)
|
2011-08-21 03:41:37 +00:00
|
|
|
|
{
|
2015-06-12 07:46:58 +00:00
|
|
|
|
const ColumnString * c0_string = typeid_cast<const ColumnString *>(c0);
|
|
|
|
|
const ColumnString * c1_string = typeid_cast<const ColumnString *>(c1);
|
|
|
|
|
const ColumnFixedString * c0_fixed_string = typeid_cast<const ColumnFixedString *>(c0);
|
|
|
|
|
const ColumnFixedString * c1_fixed_string = typeid_cast<const ColumnFixedString *>(c1);
|
|
|
|
|
const ColumnConstString * c0_const = typeid_cast<const ColumnConstString *>(c0);
|
|
|
|
|
const ColumnConstString * c1_const = typeid_cast<const ColumnConstString *>(c1);
|
2011-08-21 03:41:37 +00:00
|
|
|
|
|
2014-08-17 03:29:56 +00:00
|
|
|
|
using StringImpl = StringComparisonImpl<Op<int, int>>;
|
|
|
|
|
|
2011-08-21 03:41:37 +00:00
|
|
|
|
if (c0_const && c1_const)
|
|
|
|
|
{
|
2016-05-28 05:31:36 +00:00
|
|
|
|
auto c_res = std::make_shared<ColumnConstUInt8>(c0_const->size(), 0);
|
2011-09-24 20:32:41 +00:00
|
|
|
|
block.getByPosition(result).column = c_res;
|
2011-08-21 03:41:37 +00:00
|
|
|
|
StringImpl::constant_constant(c0_const->getData(), c1_const->getData(), c_res->getData());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-05-28 05:31:36 +00:00
|
|
|
|
auto c_res = std::make_shared<ColumnUInt8>();
|
2011-09-24 20:32:41 +00:00
|
|
|
|
block.getByPosition(result).column = c_res;
|
2011-08-21 03:41:37 +00:00
|
|
|
|
ColumnUInt8::Container_t & vec_res = c_res->getData();
|
|
|
|
|
vec_res.resize(c0->size());
|
|
|
|
|
|
|
|
|
|
if (c0_string && c1_string)
|
|
|
|
|
StringImpl::string_vector_string_vector(
|
2013-05-05 15:25:25 +00:00
|
|
|
|
c0_string->getChars(), c0_string->getOffsets(),
|
|
|
|
|
c1_string->getChars(), c1_string->getOffsets(),
|
2011-08-21 03:41:37 +00:00
|
|
|
|
c_res->getData());
|
|
|
|
|
else if (c0_string && c1_fixed_string)
|
|
|
|
|
StringImpl::string_vector_fixed_string_vector(
|
2013-05-05 15:25:25 +00:00
|
|
|
|
c0_string->getChars(), c0_string->getOffsets(),
|
|
|
|
|
c1_fixed_string->getChars(), c1_fixed_string->getN(),
|
2011-08-21 03:41:37 +00:00
|
|
|
|
c_res->getData());
|
|
|
|
|
else if (c0_string && c1_const)
|
|
|
|
|
StringImpl::string_vector_constant(
|
2013-05-05 15:25:25 +00:00
|
|
|
|
c0_string->getChars(), c0_string->getOffsets(),
|
2011-08-21 03:41:37 +00:00
|
|
|
|
c1_const->getData(),
|
|
|
|
|
c_res->getData());
|
|
|
|
|
else if (c0_fixed_string && c1_string)
|
|
|
|
|
StringImpl::fixed_string_vector_string_vector(
|
2013-05-05 15:25:25 +00:00
|
|
|
|
c0_fixed_string->getChars(), c0_fixed_string->getN(),
|
|
|
|
|
c1_string->getChars(), c1_string->getOffsets(),
|
2011-08-21 03:41:37 +00:00
|
|
|
|
c_res->getData());
|
|
|
|
|
else if (c0_fixed_string && c1_fixed_string)
|
|
|
|
|
StringImpl::fixed_string_vector_fixed_string_vector(
|
2013-05-05 15:25:25 +00:00
|
|
|
|
c0_fixed_string->getChars(), c0_fixed_string->getN(),
|
|
|
|
|
c1_fixed_string->getChars(), c1_fixed_string->getN(),
|
2011-08-21 03:41:37 +00:00
|
|
|
|
c_res->getData());
|
|
|
|
|
else if (c0_fixed_string && c1_const)
|
|
|
|
|
StringImpl::fixed_string_vector_constant(
|
2013-05-05 15:25:25 +00:00
|
|
|
|
c0_fixed_string->getChars(), c0_fixed_string->getN(),
|
2011-08-21 03:41:37 +00:00
|
|
|
|
c1_const->getData(),
|
|
|
|
|
c_res->getData());
|
|
|
|
|
else if (c0_const && c1_string)
|
|
|
|
|
StringImpl::constant_string_vector(
|
|
|
|
|
c0_const->getData(),
|
2013-05-05 15:25:25 +00:00
|
|
|
|
c1_string->getChars(), c1_string->getOffsets(),
|
2011-08-21 03:41:37 +00:00
|
|
|
|
c_res->getData());
|
|
|
|
|
else if (c0_const && c1_fixed_string)
|
|
|
|
|
StringImpl::constant_fixed_string_vector(
|
|
|
|
|
c0_const->getData(),
|
2013-05-05 15:25:25 +00:00
|
|
|
|
c1_fixed_string->getChars(), c1_fixed_string->getN(),
|
2011-08-21 03:41:37 +00:00
|
|
|
|
c_res->getData());
|
|
|
|
|
else
|
2011-08-28 00:31:30 +00:00
|
|
|
|
throw Exception("Illegal columns "
|
2015-06-12 07:46:58 +00:00
|
|
|
|
+ c0->getName() + " and " + c1->getName()
|
2011-08-28 00:31:30 +00:00
|
|
|
|
+ " of arguments of function " + getName(),
|
2011-08-21 03:41:37 +00:00
|
|
|
|
ErrorCodes::ILLEGAL_COLUMN);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
|
2015-12-22 12:03:21 +00:00
|
|
|
|
void executeDateOrDateTimeOrEnumWithConstString(
|
|
|
|
|
Block & block, size_t result, const IColumn * col_left_untyped, const IColumn * col_right_untyped,
|
|
|
|
|
const DataTypePtr & left_type, const DataTypePtr & right_type, bool left_is_num, bool right_is_num)
|
2015-06-12 07:46:58 +00:00
|
|
|
|
{
|
2015-12-22 12:03:21 +00:00
|
|
|
|
/// Уже не такой и особый случай - сравнение дат, дат-с-временем и перечислений со строковой константой.
|
2015-06-12 07:46:58 +00:00
|
|
|
|
const IColumn * column_string_untyped = !left_is_num ? col_left_untyped : col_right_untyped;
|
2015-12-22 12:03:21 +00:00
|
|
|
|
const IColumn * column_number = left_is_num ? col_left_untyped : col_right_untyped;
|
|
|
|
|
const IDataType * number_type = left_is_num ? left_type.get() : right_type.get();
|
2015-06-12 07:46:58 +00:00
|
|
|
|
|
|
|
|
|
bool is_date = false;
|
|
|
|
|
bool is_date_time = false;
|
2015-12-22 12:03:21 +00:00
|
|
|
|
bool is_enum8 = false;
|
|
|
|
|
bool is_enum16 = false;
|
|
|
|
|
|
|
|
|
|
const auto legal_types = (is_date = typeid_cast<const DataTypeDate *>(number_type))
|
|
|
|
|
|| (is_date_time = typeid_cast<const DataTypeDateTime *>(number_type))
|
|
|
|
|
|| (is_enum8 = typeid_cast<const DataTypeEnum8 *>(number_type))
|
|
|
|
|
|| (is_enum16 = typeid_cast<const DataTypeEnum16 *>(number_type));
|
|
|
|
|
|
|
|
|
|
const auto column_string = typeid_cast<const ColumnConstString *>(column_string_untyped);
|
|
|
|
|
if (!column_string || !legal_types)
|
|
|
|
|
throw Exception{
|
|
|
|
|
"Illegal columns " + col_left_untyped->getName() + " and " + col_right_untyped->getName()
|
|
|
|
|
+ " of arguments of function " + getName(),
|
|
|
|
|
ErrorCodes::ILLEGAL_COLUMN
|
|
|
|
|
};
|
2015-06-12 07:46:58 +00:00
|
|
|
|
|
|
|
|
|
if (is_date)
|
|
|
|
|
{
|
|
|
|
|
DayNum_t date;
|
|
|
|
|
ReadBufferFromString in(column_string->getData());
|
|
|
|
|
readDateText(date, in);
|
|
|
|
|
if (!in.eof())
|
|
|
|
|
throw Exception("String is too long for Date: " + column_string->getData());
|
|
|
|
|
|
|
|
|
|
ColumnConst<DataTypeDate::FieldType> parsed_const_date(block.rowsInFirstColumn(), date);
|
|
|
|
|
executeNumLeftType<DataTypeDate::FieldType>(block, result,
|
|
|
|
|
left_is_num ? col_left_untyped : &parsed_const_date,
|
|
|
|
|
left_is_num ? &parsed_const_date : col_right_untyped);
|
|
|
|
|
}
|
|
|
|
|
else if (is_date_time)
|
|
|
|
|
{
|
|
|
|
|
time_t date_time;
|
|
|
|
|
ReadBufferFromString in(column_string->getData());
|
|
|
|
|
readDateTimeText(date_time, in);
|
|
|
|
|
if (!in.eof())
|
|
|
|
|
throw Exception("String is too long for DateTime: " + column_string->getData());
|
|
|
|
|
|
|
|
|
|
ColumnConst<DataTypeDateTime::FieldType> parsed_const_date_time(block.rowsInFirstColumn(), date_time);
|
|
|
|
|
executeNumLeftType<DataTypeDateTime::FieldType>(block, result,
|
|
|
|
|
left_is_num ? col_left_untyped : &parsed_const_date_time,
|
|
|
|
|
left_is_num ? &parsed_const_date_time : col_right_untyped);
|
|
|
|
|
}
|
2015-12-22 12:03:21 +00:00
|
|
|
|
else if (is_enum8)
|
2015-12-29 15:15:58 +00:00
|
|
|
|
executeEnumWithConstString<DataTypeEnum8>(block, result, column_number, column_string,
|
2015-12-22 12:03:21 +00:00
|
|
|
|
number_type, left_is_num);
|
|
|
|
|
else if (is_enum16)
|
2015-12-29 15:15:58 +00:00
|
|
|
|
executeEnumWithConstString<DataTypeEnum16>(block, result, column_number, column_string,
|
2015-12-22 12:03:21 +00:00
|
|
|
|
number_type, left_is_num);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Comparison between DataTypeEnum<T> and string constant containing the name of an enum element
|
2015-12-29 15:15:58 +00:00
|
|
|
|
template <typename EnumType>
|
2015-12-22 12:03:21 +00:00
|
|
|
|
void executeEnumWithConstString(
|
|
|
|
|
Block & block, const size_t result, const IColumn * column_number, const ColumnConstString * column_string,
|
|
|
|
|
const IDataType * type_untyped, const bool left_is_num)
|
|
|
|
|
{
|
2015-12-29 15:15:58 +00:00
|
|
|
|
const auto type = static_cast<const EnumType *>(type_untyped);
|
2015-12-22 12:03:21 +00:00
|
|
|
|
|
|
|
|
|
const Field x = nearestFieldType(type->getValue(column_string->getData()));
|
|
|
|
|
const auto enum_col = type->createConstColumn(block.rowsInFirstColumn(), x);
|
|
|
|
|
|
2015-12-29 15:15:58 +00:00
|
|
|
|
executeNumLeftType<typename EnumType::FieldType>(block, result,
|
2015-12-22 12:03:21 +00:00
|
|
|
|
left_is_num ? column_number : enum_col.get(),
|
|
|
|
|
left_is_num ? enum_col.get() : column_number);
|
2015-06-12 07:46:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 01:42:47 +00:00
|
|
|
|
void executeTuple(Block & block, size_t result, const IColumn * c0, const IColumn * c1)
|
|
|
|
|
{
|
|
|
|
|
/** Сравнивать кортежи будем лексикографически. Это делается следующим образом:
|
|
|
|
|
* x == y : x1 == y1 && x2 == y2 ...
|
|
|
|
|
* x != y : x1 != y1 || x2 != y2 ...
|
|
|
|
|
*
|
|
|
|
|
* x < y: x1 < y1 || (x1 == y1 && (x2 < y2 || (x2 == y2 ... && xn < yn))
|
|
|
|
|
* x > y: x1 > y1 || (x1 == y1 && (x2 > y2 || (x2 == y2 ... && xn > yn))
|
|
|
|
|
* x <= y: x1 < y1 || (x1 == y1 && (x2 < y2 || (x2 == y2 ... && xn <= yn))
|
|
|
|
|
*
|
|
|
|
|
* Рекурсивная запись:
|
|
|
|
|
* x <= y: x1 < y1 || (x1 == y1 && x_tail <= y_tail)
|
|
|
|
|
*
|
|
|
|
|
* x >= y: x1 > y1 || (x1 == y1 && (x2 > y2 || (x2 == y2 ... && xn >= yn))
|
|
|
|
|
*/
|
|
|
|
|
|
2016-07-10 07:24:24 +00:00
|
|
|
|
auto x_const = typeid_cast<const ColumnConstTuple *>(c0);
|
|
|
|
|
auto y_const = typeid_cast<const ColumnConstTuple *>(c1);
|
|
|
|
|
|
|
|
|
|
ColumnPtr x_tuple_of_consts;
|
|
|
|
|
ColumnPtr y_tuple_of_consts;
|
|
|
|
|
|
2015-10-12 01:43:58 +00:00
|
|
|
|
auto x = static_cast<const ColumnTuple *>(c0);
|
|
|
|
|
auto y = static_cast<const ColumnTuple *>(c1);
|
2016-07-10 07:24:24 +00:00
|
|
|
|
|
|
|
|
|
if (x_const)
|
|
|
|
|
{
|
|
|
|
|
x_tuple_of_consts = x_const->convertToTupleOfConstants();
|
|
|
|
|
x = static_cast<const ColumnTuple *>(x_tuple_of_consts.get());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (y_const)
|
|
|
|
|
{
|
|
|
|
|
y_tuple_of_consts = y_const->convertToTupleOfConstants();
|
|
|
|
|
y = static_cast<const ColumnTuple *>(y_tuple_of_consts.get());
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 01:42:47 +00:00
|
|
|
|
const size_t tuple_size = x->getData().columns();
|
|
|
|
|
|
|
|
|
|
if (0 == tuple_size)
|
|
|
|
|
throw Exception("Comparison of zero-sized tuples is not implemented.", ErrorCodes::NOT_IMPLEMENTED);
|
|
|
|
|
|
|
|
|
|
executeTupleImpl(block, result, x, y, tuple_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void executeTupleImpl(Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size);
|
|
|
|
|
|
|
|
|
|
template <typename ComparisonFunction, typename ConvolutionFunction>
|
|
|
|
|
void executeTupleEqualityImpl(Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
|
|
|
|
{
|
|
|
|
|
ComparisonFunction func_compare;
|
|
|
|
|
ConvolutionFunction func_convolution;
|
|
|
|
|
|
|
|
|
|
Block tmp_block;
|
|
|
|
|
for (size_t i = 0; i < tuple_size; ++i)
|
|
|
|
|
{
|
|
|
|
|
tmp_block.insert(x->getData().getByPosition(i));
|
|
|
|
|
tmp_block.insert(y->getData().getByPosition(i));
|
|
|
|
|
|
|
|
|
|
/// Сравнение элементов.
|
2016-05-28 07:48:40 +00:00
|
|
|
|
tmp_block.insert({ nullptr, std::make_shared<DataTypeUInt8>(), "" });
|
2015-10-12 01:42:47 +00:00
|
|
|
|
func_compare.execute(tmp_block, {i * 3, i * 3 + 1}, i * 3 + 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Логическая свёртка.
|
2016-05-28 07:48:40 +00:00
|
|
|
|
tmp_block.insert({ nullptr, std::make_shared<DataTypeUInt8>(), "" });
|
2015-10-12 01:42:47 +00:00
|
|
|
|
|
|
|
|
|
ColumnNumbers convolution_args(tuple_size);
|
|
|
|
|
for (size_t i = 0; i < tuple_size; ++i)
|
|
|
|
|
convolution_args[i] = i * 3 + 2;
|
|
|
|
|
|
|
|
|
|
func_convolution.execute(tmp_block, convolution_args, tuple_size * 3);
|
|
|
|
|
block.getByPosition(result).column = tmp_block.getByPosition(tuple_size * 3).column;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename HeadComparisonFunction, typename TailComparisonFunction>
|
|
|
|
|
void executeTupleLessGreaterImpl(Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
|
|
|
|
{
|
|
|
|
|
HeadComparisonFunction func_compare_head;
|
|
|
|
|
TailComparisonFunction func_compare_tail;
|
|
|
|
|
FunctionAnd func_and;
|
|
|
|
|
FunctionOr func_or;
|
|
|
|
|
FunctionComparison<EqualsOp, NameEquals> func_equals;
|
|
|
|
|
|
|
|
|
|
Block tmp_block;
|
|
|
|
|
|
|
|
|
|
/// Попарное сравнение на неравенство всех элементов; на равенство всех элементов кроме последнего.
|
|
|
|
|
for (size_t i = 0; i < tuple_size; ++i)
|
|
|
|
|
{
|
|
|
|
|
tmp_block.insert(x->getData().getByPosition(i));
|
|
|
|
|
tmp_block.insert(y->getData().getByPosition(i));
|
|
|
|
|
|
2016-05-28 07:48:40 +00:00
|
|
|
|
tmp_block.insert({ nullptr, std::make_shared<DataTypeUInt8>(), "" });
|
2015-10-12 01:42:47 +00:00
|
|
|
|
|
|
|
|
|
if (i + 1 != tuple_size)
|
|
|
|
|
{
|
|
|
|
|
func_compare_head.execute(tmp_block, {i * 4, i * 4 + 1}, i * 4 + 2);
|
|
|
|
|
|
2016-05-28 07:48:40 +00:00
|
|
|
|
tmp_block.insert({ nullptr, std::make_shared<DataTypeUInt8>(), "" });
|
2015-10-12 01:42:47 +00:00
|
|
|
|
func_equals.execute(tmp_block, {i * 4, i * 4 + 1}, i * 4 + 3);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
func_compare_tail.execute(tmp_block, {i * 4, i * 4 + 1}, i * 4 + 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Комбинирование. Сложный код - сделайте рисунок. Можно заменить на рекурсивное сравнение кортежей.
|
|
|
|
|
size_t i = tuple_size - 1;
|
|
|
|
|
while (i > 0)
|
|
|
|
|
{
|
2016-05-28 07:48:40 +00:00
|
|
|
|
tmp_block.insert({ nullptr, std::make_shared<DataTypeUInt8>(), "" });
|
2015-10-12 01:42:47 +00:00
|
|
|
|
func_and.execute(tmp_block, { tmp_block.columns() - 2, (i - 1) * 4 + 3 }, tmp_block.columns() - 1);
|
2016-05-28 07:48:40 +00:00
|
|
|
|
tmp_block.insert({ nullptr, std::make_shared<DataTypeUInt8>(), "" });
|
2015-10-12 01:42:47 +00:00
|
|
|
|
func_or.execute(tmp_block, { tmp_block.columns() - 2, (i - 1) * 4 + 2 }, tmp_block.columns() - 1);
|
|
|
|
|
--i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
block.getByPosition(result).column = tmp_block.getByPosition(tmp_block.columns() - 1).column;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-08-15 21:50:08 +00:00
|
|
|
|
public:
|
2011-08-21 03:41:37 +00:00
|
|
|
|
/// Получить имя функции.
|
2015-10-11 23:36:45 +00:00
|
|
|
|
String getName() const override
|
2011-08-15 21:50:08 +00:00
|
|
|
|
{
|
2014-11-12 17:23:26 +00:00
|
|
|
|
return name;
|
2011-08-15 21:50:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Получить типы результата по типам аргументов. Если функция неприменима для данных аргументов - кинуть исключение.
|
2015-10-11 23:36:45 +00:00
|
|
|
|
DataTypePtr getReturnType(const DataTypes & arguments) const override
|
2011-08-15 21:50:08 +00:00
|
|
|
|
{
|
|
|
|
|
if (arguments.size() != 2)
|
|
|
|
|
throw Exception("Number of arguments for function " + getName() + " doesn't match: passed "
|
2013-06-21 20:34:19 +00:00
|
|
|
|
+ toString(arguments.size()) + ", should be 2.",
|
2011-08-15 21:50:08 +00:00
|
|
|
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
|
|
|
|
|
2015-06-12 07:46:58 +00:00
|
|
|
|
bool left_is_date = false;
|
|
|
|
|
bool left_is_date_time = false;
|
2015-12-22 12:03:21 +00:00
|
|
|
|
bool left_is_enum8 = false;
|
|
|
|
|
bool left_is_enum16 = false;
|
2015-06-12 07:46:58 +00:00
|
|
|
|
bool left_is_string = false;
|
|
|
|
|
bool left_is_fixed_string = false;
|
2015-10-12 01:42:47 +00:00
|
|
|
|
const DataTypeTuple * left_tuple = nullptr;
|
2015-06-12 07:46:58 +00:00
|
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|| (left_is_date = typeid_cast<const DataTypeDate *>(arguments[0].get()))
|
|
|
|
|
|| (left_is_date_time = typeid_cast<const DataTypeDateTime *>(arguments[0].get()))
|
2015-12-22 12:03:21 +00:00
|
|
|
|
|| (left_is_enum8 = typeid_cast<const DataTypeEnum8 *>(arguments[0].get()))
|
|
|
|
|
|| (left_is_enum16 = typeid_cast<const DataTypeEnum16 *>(arguments[0].get()))
|
2015-06-12 07:46:58 +00:00
|
|
|
|
|| (left_is_string = typeid_cast<const DataTypeString *>(arguments[0].get()))
|
2015-10-12 01:42:47 +00:00
|
|
|
|
|| (left_is_fixed_string = typeid_cast<const DataTypeFixedString *>(arguments[0].get()))
|
|
|
|
|
|| (left_tuple = typeid_cast<const DataTypeTuple *>(arguments[0].get()));
|
2015-06-12 07:46:58 +00:00
|
|
|
|
|
2015-12-22 12:03:21 +00:00
|
|
|
|
const bool left_is_enum = left_is_enum8 || left_is_enum16;
|
|
|
|
|
|
2015-06-12 07:46:58 +00:00
|
|
|
|
bool right_is_date = false;
|
|
|
|
|
bool right_is_date_time = false;
|
2015-12-22 12:03:21 +00:00
|
|
|
|
bool right_is_enum8 = false;
|
|
|
|
|
bool right_is_enum16 = false;
|
2015-06-12 07:46:58 +00:00
|
|
|
|
bool right_is_string = false;
|
|
|
|
|
bool right_is_fixed_string = false;
|
2015-10-12 01:42:47 +00:00
|
|
|
|
const DataTypeTuple * right_tuple = nullptr;
|
2015-06-12 07:46:58 +00:00
|
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|| (right_is_date = typeid_cast<const DataTypeDate *>(arguments[1].get()))
|
|
|
|
|
|| (right_is_date_time = typeid_cast<const DataTypeDateTime *>(arguments[1].get()))
|
2015-12-22 12:03:21 +00:00
|
|
|
|
|| (right_is_enum8 = typeid_cast<const DataTypeEnum8 *>(arguments[1].get()))
|
|
|
|
|
|| (right_is_enum16 = typeid_cast<const DataTypeEnum16 *>(arguments[1].get()))
|
2015-06-12 07:46:58 +00:00
|
|
|
|
|| (right_is_string = typeid_cast<const DataTypeString *>(arguments[1].get()))
|
2015-10-12 01:42:47 +00:00
|
|
|
|
|| (right_is_fixed_string = typeid_cast<const DataTypeFixedString *>(arguments[1].get()))
|
|
|
|
|
|| (right_tuple = typeid_cast<const DataTypeTuple *>(arguments[1].get()));
|
2015-06-12 07:46:58 +00:00
|
|
|
|
|
2015-12-22 12:03:21 +00:00
|
|
|
|
const bool right_is_enum = right_is_enum8 || right_is_enum16;
|
|
|
|
|
|
2015-12-29 15:15:58 +00:00
|
|
|
|
if (!( (arguments[0]->behavesAsNumber() && arguments[1]->behavesAsNumber() && !(left_is_enum ^ right_is_enum))
|
2015-06-12 07:46:58 +00:00
|
|
|
|
|| ((left_is_string || left_is_fixed_string) && (right_is_string || right_is_fixed_string))
|
|
|
|
|
|| (left_is_date && right_is_date)
|
2015-12-22 12:03:21 +00:00
|
|
|
|
|| (left_is_date && right_is_string) /// Можно сравнивать дату, дату-с-временем и перечисление с константной строкой.
|
2015-06-12 07:46:58 +00:00
|
|
|
|
|| (left_is_string && right_is_date)
|
|
|
|
|
|| (left_is_date_time && right_is_date_time)
|
|
|
|
|
|| (left_is_date_time && right_is_string)
|
2015-10-12 01:42:47 +00:00
|
|
|
|
|| (left_is_string && right_is_date_time)
|
2015-12-22 12:03:21 +00:00
|
|
|
|
|| (left_is_date_time && right_is_date_time)
|
|
|
|
|
|| (left_is_date_time && right_is_string)
|
|
|
|
|
|| (left_is_string && right_is_date_time)
|
|
|
|
|
|| (left_is_enum && right_is_enum && arguments[0]->getName() == arguments[1]->getName()) /// only equivalent enum type values can be compared against
|
|
|
|
|
|| (left_is_enum && right_is_string)
|
|
|
|
|
|| (left_is_string && right_is_enum)
|
2015-10-12 01:42:47 +00:00
|
|
|
|
|| (left_tuple && right_tuple && left_tuple->getElements().size() == right_tuple->getElements().size())))
|
2011-08-21 03:41:37 +00:00
|
|
|
|
throw Exception("Illegal types of arguments (" + arguments[0]->getName() + ", " + arguments[1]->getName() + ")"
|
|
|
|
|
" of function " + getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
|
2015-10-12 01:42:47 +00:00
|
|
|
|
if (left_tuple && right_tuple)
|
|
|
|
|
{
|
|
|
|
|
size_t size = left_tuple->getElements().size();
|
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
|
getReturnType({ left_tuple->getElements()[i], right_tuple->getElements()[i] });
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-28 07:48:40 +00:00
|
|
|
|
return std::make_shared<DataTypeUInt8>();
|
2011-08-15 21:50:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Выполнить функцию над блоком.
|
2015-10-11 23:36:45 +00:00
|
|
|
|
void execute(Block & block, const ColumnNumbers & arguments, size_t result) override
|
2011-08-15 21:50:08 +00:00
|
|
|
|
{
|
2016-07-30 04:39:51 +00:00
|
|
|
|
const auto & col_with_type_and_name_left = block.getByPosition(arguments[0]);
|
|
|
|
|
const auto & col_with_type_and_name_right = block.getByPosition(arguments[1]);
|
|
|
|
|
const IColumn * col_left_untyped = col_with_type_and_name_left.column.get();
|
|
|
|
|
const IColumn * col_right_untyped = col_with_type_and_name_right.column.get();
|
2015-06-12 07:46:58 +00:00
|
|
|
|
|
2015-12-22 12:03:21 +00:00
|
|
|
|
const bool left_is_num = col_left_untyped->isNumeric();
|
|
|
|
|
const bool right_is_num = col_right_untyped->isNumeric();
|
2015-06-12 07:46:58 +00:00
|
|
|
|
|
|
|
|
|
if (left_is_num && right_is_num)
|
2011-08-21 03:41:37 +00:00
|
|
|
|
{
|
2015-06-12 07:46:58 +00:00
|
|
|
|
if (!( executeNumLeftType<UInt8>(block, result, col_left_untyped, col_right_untyped)
|
|
|
|
|
|| executeNumLeftType<UInt16>(block, result, col_left_untyped, col_right_untyped)
|
|
|
|
|
|| executeNumLeftType<UInt32>(block, result, col_left_untyped, col_right_untyped)
|
|
|
|
|
|| executeNumLeftType<UInt64>(block, result, col_left_untyped, col_right_untyped)
|
|
|
|
|
|| executeNumLeftType<Int8>(block, result, col_left_untyped, col_right_untyped)
|
|
|
|
|
|| executeNumLeftType<Int16>(block, result, col_left_untyped, col_right_untyped)
|
|
|
|
|
|| executeNumLeftType<Int32>(block, result, col_left_untyped, col_right_untyped)
|
|
|
|
|
|| executeNumLeftType<Int64>(block, result, col_left_untyped, col_right_untyped)
|
|
|
|
|
|| executeNumLeftType<Float32>(block, result, col_left_untyped, col_right_untyped)
|
|
|
|
|
|| executeNumLeftType<Float64>(block, result, col_left_untyped, col_right_untyped)))
|
|
|
|
|
throw Exception("Illegal column " + col_left_untyped->getName()
|
2011-08-28 00:31:30 +00:00
|
|
|
|
+ " of first argument of function " + getName(),
|
2011-08-21 03:41:37 +00:00
|
|
|
|
ErrorCodes::ILLEGAL_COLUMN);
|
|
|
|
|
}
|
2016-07-30 04:39:51 +00:00
|
|
|
|
else if (typeid_cast<const DataTypeTuple *>(col_with_type_and_name_left.type.get()))
|
2015-12-22 12:03:21 +00:00
|
|
|
|
executeTuple(block, result, col_left_untyped, col_right_untyped);
|
|
|
|
|
else if (!left_is_num && !right_is_num)
|
|
|
|
|
executeString(block, result, col_left_untyped, col_right_untyped);
|
2011-08-21 03:41:37 +00:00
|
|
|
|
else
|
2015-12-22 12:03:21 +00:00
|
|
|
|
executeDateOrDateTimeOrEnumWithConstString(
|
|
|
|
|
block, result, col_left_untyped, col_right_untyped,
|
2016-07-30 04:39:51 +00:00
|
|
|
|
col_with_type_and_name_left.type, col_with_type_and_name_right.type,
|
2015-12-22 12:03:21 +00:00
|
|
|
|
left_is_num, right_is_num);
|
|
|
|
|
}
|
2011-08-15 21:50:08 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2016-05-28 10:35:44 +00:00
|
|
|
|
using FunctionEquals = FunctionComparison<EqualsOp, NameEquals> ;
|
|
|
|
|
using FunctionNotEquals = FunctionComparison<NotEqualsOp, NameNotEquals> ;
|
|
|
|
|
using FunctionLess = FunctionComparison<LessOp, NameLess> ;
|
|
|
|
|
using FunctionGreater = FunctionComparison<GreaterOp, NameGreater> ;
|
|
|
|
|
using FunctionLessOrEquals = FunctionComparison<LessOrEqualsOp, NameLessOrEquals> ;
|
|
|
|
|
using FunctionGreaterOrEquals = FunctionComparison<GreaterOrEqualsOp, NameGreaterOrEquals>;
|
2011-08-15 21:50:08 +00:00
|
|
|
|
|
2015-10-12 01:42:47 +00:00
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
void FunctionComparison<EqualsOp, NameEquals>::executeTupleImpl(
|
|
|
|
|
Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
|
|
|
|
{
|
|
|
|
|
return executeTupleEqualityImpl<FunctionComparison<EqualsOp, NameEquals>, FunctionAnd>(block, result, x, y, tuple_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
void FunctionComparison<NotEqualsOp, NameNotEquals>::executeTupleImpl(
|
|
|
|
|
Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
|
|
|
|
{
|
|
|
|
|
return executeTupleEqualityImpl<FunctionComparison<NotEqualsOp, NameNotEquals>, FunctionOr>(block, result, x, y, tuple_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
void FunctionComparison<LessOp, NameLess>::executeTupleImpl(
|
|
|
|
|
Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
|
|
|
|
{
|
|
|
|
|
return executeTupleLessGreaterImpl<
|
|
|
|
|
FunctionComparison<LessOp, NameLess>,
|
|
|
|
|
FunctionComparison<LessOp, NameLess>>(block, result, x, y, tuple_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
void FunctionComparison<GreaterOp, NameGreater>::executeTupleImpl(
|
|
|
|
|
Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
|
|
|
|
{
|
|
|
|
|
return executeTupleLessGreaterImpl<
|
|
|
|
|
FunctionComparison<GreaterOp, NameGreater>,
|
|
|
|
|
FunctionComparison<GreaterOp, NameGreater>>(block, result, x, y, tuple_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
void FunctionComparison<LessOrEqualsOp, NameLessOrEquals>::executeTupleImpl(
|
|
|
|
|
Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
|
|
|
|
{
|
|
|
|
|
return executeTupleLessGreaterImpl<
|
|
|
|
|
FunctionComparison<LessOp, NameLess>,
|
|
|
|
|
FunctionComparison<LessOrEqualsOp, NameLessOrEquals>>(block, result, x, y, tuple_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
void FunctionComparison<GreaterOrEqualsOp, NameGreaterOrEquals>::executeTupleImpl(
|
|
|
|
|
Block & block, size_t result, const ColumnTuple * x, const ColumnTuple * y, size_t tuple_size)
|
|
|
|
|
{
|
|
|
|
|
return executeTupleLessGreaterImpl<
|
|
|
|
|
FunctionComparison<GreaterOp, NameGreater>,
|
|
|
|
|
FunctionComparison<GreaterOrEqualsOp, NameGreaterOrEquals>>(block, result, x, y, tuple_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-08-15 21:50:08 +00:00
|
|
|
|
}
|