dbms: development [#CONV-2944].

This commit is contained in:
Alexey Milovidov 2011-08-19 20:35:21 +00:00
parent 0f1655f42c
commit 504f799f28
2 changed files with 77 additions and 57 deletions

View File

@ -35,13 +35,6 @@ struct PlusImpl
c[i] = a[i] + b;
}
static void constant_vector(A a, const std::vector<B> & b, std::vector<ResultType> & c)
{
size_t size = b.size();
for (size_t i = 0; i < size; ++i)
c[i] = a + b[i];
}
static void constant_constant(A a, B b, ResultType & c)
{
c = a + b;
@ -67,13 +60,6 @@ struct MultiplyImpl
c[i] = a[i] * b;
}
static void constant_vector(A a, const std::vector<B> & b, std::vector<ResultType> & c)
{
size_t size = b.size();
for (size_t i = 0; i < size; ++i)
c[i] = a * b[i];
}
static void constant_constant(A a, B b, ResultType & c)
{
c = a * b;
@ -99,13 +85,6 @@ struct MinusImpl
c[i] = a[i] - b;
}
static void constant_vector(A a, const std::vector<B> & b, std::vector<ResultType> & c)
{
size_t size = b.size();
for (size_t i = 0; i < size; ++i)
c[i] = a - b[i];
}
static void constant_constant(A a, B b, ResultType & c)
{
c = a - b;
@ -131,13 +110,6 @@ struct DivideFloatingImpl
c[i] = static_cast<ResultType>(a[i]) / b;
}
static void constant_vector(A a, const std::vector<B> & b, std::vector<ResultType> & c)
{
size_t size = b.size();
for (size_t i = 0; i < size; ++i)
c[i] = static_cast<ResultType>(a) / b[i];
}
static void constant_constant(A a, B b, ResultType & c)
{
c = static_cast<ResultType>(a) / b;
@ -163,13 +135,6 @@ struct DivideIntegralImpl
c[i] = a[i] / b;
}
static void constant_vector(A a, const std::vector<B> & b, std::vector<ResultType> & c)
{
size_t size = b.size();
for (size_t i = 0; i < size; ++i)
c[i] = a / b[i];
}
static void constant_constant(A a, B b, ResultType & c)
{
c = a / b;
@ -195,13 +160,6 @@ struct ModuloImpl
c[i] = a[i] % b;
}
static void constant_vector(A a, const std::vector<B> & b, std::vector<ResultType> & c)
{
size_t size = b.size();
for (size_t i = 0; i < size; ++i)
c[i] = a % b[i];
}
static void constant_constant(A a, B b, ResultType & c)
{
c = a % b;
@ -296,7 +254,7 @@ private:
typename ColumnVector<ResultType>::Container_t & vec_res = col_res->getData();
vec_res.resize(col_left->size());
Impl<T0, T1>::constant_vector(col_left->getData(), col_right->getData(), vec_res);
Impl<T1, T0>::vector_constant(col_right->getData(), col_left->getData(), vec_res);
return true;
}

View File

@ -26,45 +26,107 @@ namespace DB
*/
template<typename A, typename B>
struct EqualsImpl
struct EqualsNumImpl
{
typedef UInt8 ResultType;
static void num_vector_num_vector(const std::vector<A> & a, const std::vector<B> & b, std::vector<ResultType> & c)
static void vector_vector(const std::vector<A> & a, const std::vector<B> & b, std::vector<ResultType> & c)
{
size_t size = a.size();
for (size_t i = 0; i < size; ++i)
c[i] = a[i] == b[i];
}
static void num_vector_num_constant(const std::vector<A> & a, B b, std::vector<ResultType> & c)
static void vector_constant(const std::vector<A> & a, B b, std::vector<ResultType> & c)
{
size_t size = a.size();
for (size_t i = 0; i < size; ++i)
c[i] = a[i] == b;
}
static void num_constant_num_vector(A a, const std::vector<B> & b, std::vector<ResultType> & c)
{
size_t size = b.size();
for (size_t i = 0; i < size; ++i)
c[i] = a == b[i];
}
static void num_constant_num_constant(A a, B b, ResultType & c)
static void constant_constant(A a, B b, ResultType & c)
{
c = a == b;
}
};
static void str_vector_str_vector(const std::vector<A> & a, const std::vector<B> & b, std::vector<ResultType> & c)
template<typename A, typename B>
struct EqualsStringImpl
{
typedef UInt8 ResultType;
static void string_vector_string_vector(
const std::vector<UInt8> & a_data, const std::vector<size_t> & a_offsets,
const std::vector<UInt8> & b_data, const std::vector<size_t> & b_offsets,
std::vector<ResultType> & c)
{
size_t size = a.size();
size_t size = a_data.size();
for (size_t i = 0; i < size; ++i)
c[i] = a[i] == b[i];
c[i] = (i == 0)
? (a_offsets[0] == b_offsets[0] && !memcmp(&a_data[0], &b_data[0], a_offsets[0]))
: (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]));
}
static void string_vector_fixed_string_vector(
const std::vector<UInt8> & a_data, const std::vector<size_t> & a_offsets,
const std::vector<UInt8> & b_data, size_t b_n,
std::vector<ResultType> & c)
{
size_t size = a_data.size();
for (size_t i = 0; i < size; ++i)
c[i] = (i == 0)
? (a_offsets[0] == b_n && !memcmp(&a_data[0], &b_data[0], b_n))
: (a_offsets[i] - a_offsets[i - 1] == b_n
&& !memcmp(&a_data[a_offsets[i - 1]], &b_data[b_n * i], b_n));
}
static void string_vector_constant(
const std::vector<UInt8> & a_data, const std::vector<size_t> & a_offsets,
const std::string & b,
std::vector<ResultType> & c)
{
size_t size = a_data.size();
size_t b_n = b.size();
const UInt8 * b_data = reinterpret_cast<const UInt8 *>(b.data())
for (size_t i = 0; i < size; ++i)
c[i] = (i == 0)
? (a_offsets[0] == b_n && !memcmp(&a_data[0], b_data, b_n))
: (a_offsets[i] - a_offsets[i - 1] == b_n
&& !memcmp(&a_data[a_offsets[i - 1]], b_data, b_n));
}
static void fixed_string_vector_fixed_string_vector(
const std::vector<UInt8> & a_data, size_t a_n,
const std::vector<UInt8> & b_data, size_t b_n,
std::vector<ResultType> & c)
{
size_t size = a_data.size();
for (size_t i = 0; i < size; i += n)
c[i] = a_n == b_n && !memcmp(&a_data[i], &b_data[i], n);
}
static void fixed_string_vector_constant(
const std::vector<UInt8> & a_data, size_t a_n,
const std::string & b,
std::vector<ResultType> & c)
{
size_t size = a_data.size();
for (size_t i = 0; i < size; i += n)
c[i] = !memcmp(&a_data[i], &b_data[i], n);
}
static void constant_constant(
const std::string & a,
const std::string & b,
std::string & c)
{
c = a == b;
}
};
template <template <typename, typename> class Impl, typename Name>
class FunctionComparison : public IFunction
{