1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

Merge branch 'develop' into MCOL-4841

# Conflicts:
#	exemgr/main.cpp
#	oam/etc/Columnstore.xml.singleserver
#	primitives/primproc/primproc.cpp
This commit is contained in:
david.hall
2022-06-09 10:07:26 -05:00
523 changed files with 32140 additions and 8380 deletions

View File

@ -354,4 +354,3 @@ int purgePrimProcFdCache(const std::vector<BRM::FileInfo> files, const int pmId)
}
} // namespace cacheutils
// vim:ts=4 sw=4:

View File

@ -72,4 +72,3 @@ int dropPrimProcFdCache();
int purgePrimProcFdCache(const std::vector<BRM::FileInfo> files, const int pmId);
} // namespace cacheutils
// vim:ts=4 sw=4:

View File

@ -11,11 +11,12 @@ set(common_LIB_SRCS
nullvaluemanip.cpp
threadnaming.cpp
utils_utf8.cpp
statistics.cpp)
statistics.cpp
string_prefixes.cpp)
add_library(common SHARED ${common_LIB_SRCS})
target_link_libraries(common boost_filesystem)
target_link_libraries(common Boost::filesystem)
add_dependencies(common loggingcpp)

View File

@ -20,13 +20,8 @@
#include "logger.h"
#include <fstream>
#include <iostream>
#include <boost/regex.hpp>
#ifdef _MSC_VER
#include "unistd.h"
#include "sysinfo.h"
#else
#include <sys/sysinfo.h>
#endif
using namespace boost;
using namespace std;

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2020 MariaDB Corporation
Copyright (C) 2020-2022 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -88,6 +88,8 @@ typedef double pfloat; /* Mixed prototypes can't take float */
typedef const struct charset_info_st CHARSET_INFO;
extern "C" MYSQL_PLUGIN_IMPORT CHARSET_INFO* default_charset_info;
#define HAVE_PSI_INTERFACE
#include "m_ctype.h"
#undef FALSE
@ -133,6 +135,8 @@ class Charset
{
protected:
const struct charset_info_st* mCharset;
private:
static constexpr uint flags_ = MY_STRXFRM_PAD_WITH_SPACE | MY_STRXFRM_PAD_TO_MAXLEN;
public:
Charset(CHARSET_INFO& cs) : mCharset(&cs)
@ -177,6 +181,34 @@ class Charset
bool res = !mCharset->wildcmp(subject.str(), subject.end(), pattern.str(), pattern.end(), '\\', '_', '%');
return neg ? !res : res;
}
size_t strnxfrm(uchar* dst, size_t dstlen, uint nweights, const uchar* src, size_t srclen, uint flags)
{
idbassert(mCharset->coll);
return mCharset->coll->strnxfrm(mCharset, dst, dstlen, nweights, src, srclen, flags);
}
// The magic check that tells that bytes are mapped to weights as 1:1
bool strnxfrmIsValid() const
{
return (mCharset->state & MY_CS_NON1TO1) == 0;
}
template<typename T>
T strnxfrm(const char* src) const
{
T ret = 0;
size_t len __attribute__((unused)) = mCharset->strnxfrm((char*)&ret, sizeof(T), sizeof(T),
src, sizeof(T), flags_);
assert(len <= sizeof(T));
return ret;
}
template<typename T>
T strnxfrm(const utils::ConstString &src) const
{
T ret = 0;
size_t len __attribute__((unused)) = mCharset->strnxfrm((char*)&ret, sizeof(T), sizeof(T),
(char*)src.str(), src.length(), flags_);
assert(len <= sizeof(T));
return ret;
}
};
class CollationAwareHasher : public Charset

View File

@ -50,4 +50,3 @@ class HashFamily
};
} // namespace utils
// vim:ts=2 sw=2:

View File

@ -21,4 +21,3 @@
using int128_t = __int128;
using uint128_t = unsigned __int128;
// vim:ts=2 sw=2:

View File

@ -198,6 +198,7 @@ int64_t getSignedNullValue(CalpontSystemCatalog::ColDataType t, uint32_t colWidt
os << "getSignedNullValue(): got bad column type (" << t << "). Width=" << colWidth << endl;
throw logic_error(os.str());
}
}
} // namespace utils

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2021 Mariadb Corporation.
/* Copyright (C) 2021-2022 Mariadb Corporation.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -17,6 +17,17 @@
#pragma once
// Column filtering is dispatched 4-way based on the column type,
// which defines implementation of comparison operations for the column values
enum ENUM_KIND
{
KIND_DEFAULT, // compared as signed integers
KIND_UNSIGNED, // compared as unsigned integers
KIND_FLOAT, // compared as floating-point numbers
KIND_TEXT
}; // whitespace-trimmed and then compared as signed integers
#if defined(__x86_64__)
#include <cstdint>
@ -36,16 +47,6 @@
#include <mcs_datatype.h>
// Column filtering is dispatched 4-way based on the column type,
// which defines implementation of comparison operations for the column values
enum ENUM_KIND
{
KIND_DEFAULT, // compared as signed integers
KIND_UNSIGNED, // compared as unsigned integers
KIND_FLOAT, // compared as floating-point numbers
KIND_TEXT
}; // whitespace-trimmed and then compared as signed integers
namespace simd
{
using vi128_t = __m128i;
@ -115,6 +116,15 @@ struct StorageToFiltering<T, KIND, typename std::enable_if<KIND != KIND_FLOAT>::
using type = T;
};
template <int i0, int i1, int i2, int i3>
static inline vi128_t constant4i() {
static const union {
int i[4];
vi128_t xmm;
} u = {{i0,i1,i2,i3}};
return u.xmm;
}
template <typename VT, typename T, typename ENABLE = void>
class SimdFilterProcessor;
@ -461,7 +471,7 @@ class SimdFilterProcessor<
template <typename VT, typename CHECK_T>
class SimdFilterProcessor<VT, CHECK_T,
typename std::enable_if<std::is_same<VT, vi128_wr>::value && sizeof(CHECK_T) == 8 &&
typename std::enable_if<std::is_same<VT, vi128_wr>::value && std::is_same<CHECK_T, int64_t>::value &&
!std::is_same<CHECK_T, double>::value>::type>
{
public:
@ -568,7 +578,117 @@ class SimdFilterProcessor<VT, CHECK_T,
template <typename VT, typename CHECK_T>
class SimdFilterProcessor<VT, CHECK_T,
typename std::enable_if<std::is_same<VT, vi128_wr>::value && sizeof(CHECK_T) == 4 &&
typename std::enable_if<std::is_same<VT, vi128_wr>::value && std::is_same<CHECK_T, uint64_t>::value &&
!std::is_same<CHECK_T, double>::value>::type>
{
public:
constexpr static const uint16_t vecByteSize = 16U;
constexpr static const uint16_t vecBitSize = 128U;
using T = typename datatypes::WidthToSIntegralType<sizeof(CHECK_T)>::type;
using SimdWrapperType = vi128_wr;
using SimdType = vi128_t;
using FilterType = T;
using StorageType = T;
// Mask calculation for int and float types differs.
// See corresponding intrinsics algos for details.
constexpr static const uint16_t FilterMaskStep = sizeof(T);
// Load value
MCS_FORCE_INLINE SimdType emptyNullLoadValue(const T fill)
{
return loadValue(fill);
}
MCS_FORCE_INLINE SimdType loadValue(const T fill)
{
return _mm_set_epi64x(fill, fill);
}
// Load from
MCS_FORCE_INLINE SimdType loadFrom(const char* from)
{
return _mm_loadu_si128(reinterpret_cast<const SimdType*>(from));
}
// Compare
MCS_FORCE_INLINE MT cmpGe(SimdType& x, SimdType& y)
{
return cmpGt(y, x) ^ 0xFFFF;
}
MCS_FORCE_INLINE MT cmpGt(SimdType& x, SimdType& y)
{
SimdType signVec = constant4i<0,(int32_t)0x80000000,0,(int32_t)0x80000000>();
SimdType xFlip = _mm_xor_si128(x, signVec);
SimdType yFlip = _mm_xor_si128(y, signVec);
return _mm_movemask_epi8(_mm_cmpgt_epi64(xFlip, yFlip));
}
MCS_FORCE_INLINE MT cmpEq(SimdType& x, SimdType& y)
{
return _mm_movemask_epi8(_mm_cmpeq_epi64(x, y));
}
MCS_FORCE_INLINE MT cmpLe(SimdType& x, SimdType& y)
{
return cmpGt(x, y) ^ 0xFFFF;
}
MCS_FORCE_INLINE MT cmpLt(SimdType& x, SimdType& y)
{
return cmpGt(y, x);
}
MCS_FORCE_INLINE MT cmpNe(SimdType& x, SimdType& y)
{
return _mm_movemask_epi8(_mm_cmpeq_epi64(x, y)) ^ 0xFFFF;
}
MCS_FORCE_INLINE MT cmpAlwaysFalse(SimdType& x, SimdType& y)
{
return 0;
}
MCS_FORCE_INLINE MT cmpAlwaysTrue(SimdType& x, SimdType& y)
{
return 0xFFFF;
}
// misc
MCS_FORCE_INLINE MT convertVectorToBitMask(SimdType& vmask)
{
return _mm_movemask_epi8(vmask);
}
MCS_FORCE_INLINE SimdType setToZero()
{
return _mm_setzero_si128();
}
MCS_FORCE_INLINE MT nullEmptyCmpNe(SimdType& x, SimdType& y)
{
return cmpNe(x, y);
}
MCS_FORCE_INLINE MT nullEmptyCmpEq(SimdType& x, SimdType& y)
{
return cmpEq(x, y);
}
// store
MCS_FORCE_INLINE void storeWMask(SimdType& x, SimdType& vmask, char* dst)
{
_mm_maskmoveu_si128(x, vmask, dst);
}
MCS_FORCE_INLINE void store(char* dst, SimdType& x)
{
_mm_storeu_si128(reinterpret_cast<SimdType*>(dst), x);
}
};
template <typename VT, typename CHECK_T>
class SimdFilterProcessor<VT, CHECK_T,
typename std::enable_if<std::is_same<VT, vi128_wr>::value && std::is_same<CHECK_T, int32_t>::value &&
!std::is_same<CHECK_T, float>::value>::type>
{
public:
@ -673,9 +793,119 @@ class SimdFilterProcessor<VT, CHECK_T,
}
};
template <typename VT, typename CHECK_T>
class SimdFilterProcessor<VT, CHECK_T,
typename std::enable_if<std::is_same<VT, vi128_wr>::value && std::is_same<CHECK_T, uint32_t>::value &&
!std::is_same<CHECK_T, float>::value>::type>
{
public:
constexpr static const uint16_t vecByteSize = 16U;
constexpr static const uint16_t vecBitSize = 128U;
using T = typename datatypes::WidthToSIntegralType<sizeof(CHECK_T)>::type;
using SimdWrapperType = vi128_wr;
using SimdType = vi128_t;
using FilterType = T;
using StorageType = T;
// Mask calculation for int and float types differs.
// See corresponding intrinsics algos for details.
constexpr static const uint16_t FilterMaskStep = sizeof(T);
// Load value
MCS_FORCE_INLINE SimdType emptyNullLoadValue(const T fill)
{
return loadValue(fill);
}
MCS_FORCE_INLINE SimdType loadValue(const T fill)
{
return _mm_set1_epi32(fill);
}
// Load from
MCS_FORCE_INLINE SimdType loadFrom(const char* from)
{
return _mm_loadu_si128(reinterpret_cast<const SimdType*>(from));
}
// Compare
MCS_FORCE_INLINE MT cmpEq(SimdType& x, SimdType& y)
{
return _mm_movemask_epi8(_mm_cmpeq_epi32(x, y));
}
MCS_FORCE_INLINE MT cmpGe(SimdType& x, SimdType& y)
{
return cmpGt(y, x) ^ 0xFFFF;
}
MCS_FORCE_INLINE MT cmpGt(SimdType& x, SimdType& y)
{
SimdType signVec = constant4i<(int32_t)0x80000000,(int32_t)0x80000000,(int32_t)0x80000000,(int32_t)0x80000000>();
SimdType xFlip = _mm_xor_si128(x, signVec);
SimdType yFlip = _mm_xor_si128(y, signVec);
return _mm_movemask_epi8(_mm_cmpgt_epi32(xFlip, yFlip));
}
MCS_FORCE_INLINE MT cmpLe(SimdType& x, SimdType& y)
{
return cmpGt(x, y) ^ 0xFFFF;
}
MCS_FORCE_INLINE MT cmpLt(SimdType& x, SimdType& y)
{
return cmpGt(y, x);
}
MCS_FORCE_INLINE MT cmpNe(SimdType& x, SimdType& y)
{
return _mm_movemask_epi8(_mm_cmpeq_epi32(x, y)) ^ 0xFFFF;
}
MCS_FORCE_INLINE MT cmpAlwaysFalse(SimdType& x, SimdType& y)
{
return 0;
}
MCS_FORCE_INLINE MT cmpAlwaysTrue(SimdType& x, SimdType& y)
{
return 0xFFFF;
}
// misc
MCS_FORCE_INLINE MT convertVectorToBitMask(SimdType& vmask)
{
return _mm_movemask_epi8(vmask);
}
MCS_FORCE_INLINE MT nullEmptyCmpNe(SimdType& x, SimdType& y)
{
return cmpNe(x, y);
}
MCS_FORCE_INLINE MT nullEmptyCmpEq(SimdType& x, SimdType& y)
{
return cmpEq(x, y);
}
MCS_FORCE_INLINE SimdType setToZero()
{
return _mm_setzero_si128();
}
// store
MCS_FORCE_INLINE void storeWMask(SimdType& x, SimdType& vmask, char* dst)
{
_mm_maskmoveu_si128(x, vmask, dst);
}
MCS_FORCE_INLINE void store(char* dst, SimdType& x)
{
_mm_storeu_si128(reinterpret_cast<SimdType*>(dst), x);
}
};
template <typename VT, typename CHECK_T>
class SimdFilterProcessor<
VT, CHECK_T, typename std::enable_if<std::is_same<VT, vi128_wr>::value && sizeof(CHECK_T) == 2>::type>
VT, CHECK_T, typename std::enable_if<std::is_same<VT, vi128_wr>::value && std::is_same<CHECK_T, int16_t>::value>::type>
{
public:
constexpr static const uint16_t vecByteSize = 16U;
@ -781,7 +1011,227 @@ class SimdFilterProcessor<
template <typename VT, typename CHECK_T>
class SimdFilterProcessor<
VT, CHECK_T, typename std::enable_if<std::is_same<VT, vi128_wr>::value && sizeof(CHECK_T) == 1>::type>
VT, CHECK_T, typename std::enable_if<std::is_same<VT, vi128_wr>::value && std::is_same<CHECK_T, uint16_t>::value>::type>
{
public:
constexpr static const uint16_t vecByteSize = 16U;
constexpr static const uint16_t vecBitSize = 128U;
using T = typename datatypes::WidthToSIntegralType<sizeof(CHECK_T)>::type;
using SimdWrapperType = simd::vi128_wr;
using SimdType = simd::vi128_t;
using FilterType = T;
using StorageType = T;
// Mask calculation for int and float types differs.
// See corresponding intrinsics algos for details.
constexpr static const uint16_t FilterMaskStep = sizeof(T);
// Load value
MCS_FORCE_INLINE SimdType emptyNullLoadValue(const T fill)
{
return loadValue(fill);
}
MCS_FORCE_INLINE SimdType loadValue(const T fill)
{
return _mm_set1_epi16(fill);
}
// Load from
MCS_FORCE_INLINE SimdType loadFrom(const char* from)
{
return _mm_loadu_si128(reinterpret_cast<const SimdType*>(from));
}
// Compare
MCS_FORCE_INLINE MT cmpEq(SimdType& x, SimdType& y)
{
return _mm_movemask_epi8(_mm_cmpeq_epi16(x, y));
}
MCS_FORCE_INLINE MT cmpGe(SimdType& x, SimdType& y)
{
SimdType maxOfTwo = _mm_max_epu16(x, y); // max(x, y), unsigned
return _mm_movemask_epi8(_mm_cmpeq_epi16(x, maxOfTwo));
}
MCS_FORCE_INLINE MT cmpGt(SimdType& x, SimdType& y)
{
return cmpGe(y, x) ^ 0xFFFF;
}
MCS_FORCE_INLINE MT cmpLe(SimdType& x, SimdType& y)
{
return cmpGe(y, x);
}
MCS_FORCE_INLINE MT cmpLt(SimdType& x, SimdType& y)
{
return cmpGe(x, y) ^ 0xFFFF;
}
MCS_FORCE_INLINE MT cmpNe(SimdType& x, SimdType& y)
{
return _mm_movemask_epi8(_mm_cmpeq_epi16(x, y)) ^ 0xFFFF;
}
MCS_FORCE_INLINE MT cmpAlwaysFalse(SimdType& x, SimdType& y)
{
return 0;
}
MCS_FORCE_INLINE MT cmpAlwaysTrue(SimdType& x, SimdType& y)
{
return 0xFFFF;
}
// misc
MCS_FORCE_INLINE MT convertVectorToBitMask(SimdType& vmask)
{
return _mm_movemask_epi8(vmask);
}
MCS_FORCE_INLINE MT nullEmptyCmpNe(SimdType& x, SimdType& y)
{
return cmpNe(x, y);
}
MCS_FORCE_INLINE MT nullEmptyCmpEq(SimdType& x, SimdType& y)
{
return cmpEq(x, y);
}
MCS_FORCE_INLINE SimdType setToZero()
{
return _mm_setzero_si128();
}
// store
MCS_FORCE_INLINE void storeWMask(SimdType& x, SimdType& vmask, char* dst)
{
_mm_maskmoveu_si128(x, vmask, dst);
}
MCS_FORCE_INLINE void store(char* dst, SimdType& x)
{
_mm_storeu_si128(reinterpret_cast<SimdType*>(dst), x);
}
};
template <typename VT, typename CHECK_T>
class SimdFilterProcessor<
VT, CHECK_T, typename std::enable_if<std::is_same<VT, vi128_wr>::value && std::is_same<CHECK_T, int8_t>::value>::type>
{
public:
constexpr static const uint16_t vecByteSize = 16U;
constexpr static const uint16_t vecBitSize = 128U;
using T = typename datatypes::WidthToSIntegralType<sizeof(CHECK_T)>::type;
using SimdWrapperType = vi128_wr;
using SimdType = vi128_t;
using FilterType = T;
using StorageType = T;
// Mask calculation for int and float types differs.
// See corresponding intrinsics algos for details.
constexpr static const uint16_t FilterMaskStep = sizeof(T);
// Load value
MCS_FORCE_INLINE SimdType emptyNullLoadValue(const T fill)
{
return loadValue(fill);
}
MCS_FORCE_INLINE SimdType loadValue(const T fill)
{
return _mm_set1_epi8(fill);
}
// Load from
MCS_FORCE_INLINE SimdType loadFrom(const char* from)
{
return _mm_loadu_si128(reinterpret_cast<const SimdType*>(from));
}
// Compare
MCS_FORCE_INLINE MT cmpEq(SimdType& x, SimdType& y)
{
return _mm_movemask_epi8(_mm_cmpeq_epi8(x, y));
}
MCS_FORCE_INLINE MT cmpGe(SimdType& x, SimdType& y)
{
return cmpLt(x, y) ^ 0xFFFF;
}
MCS_FORCE_INLINE MT cmpGt(SimdType& x, SimdType& y)
{
return _mm_movemask_epi8(_mm_cmpgt_epi8(x, y));
}
MCS_FORCE_INLINE MT cmpLe(SimdType& x, SimdType& y)
{
return cmpGt(x, y) ^ 0xFFFF;
}
MCS_FORCE_INLINE MT cmpLt(SimdType& x, SimdType& y)
{
return _mm_movemask_epi8(_mm_cmplt_epi8(x, y));
}
MCS_FORCE_INLINE MT cmpNe(SimdType& x, SimdType& y)
{
return _mm_movemask_epi8(_mm_cmpeq_epi8(x, y)) ^ 0xFFFF;
}
MCS_FORCE_INLINE MT cmpAlwaysFalse(SimdType& x, SimdType& y)
{
return 0;
}
MCS_FORCE_INLINE MT cmpAlwaysTrue(SimdType& x, SimdType& y)
{
return 0xFFFF;
}
// permute
/* TODO Available in AVX-512
MCS_FORCE_INLINE SimdType perm8Bits(SimdType& x, SimdType& idx)
{
return _mm_permutexvar_epi8(x, idx);
}
*/
// misc
MCS_FORCE_INLINE MT convertVectorToBitMask(SimdType& vmask)
{
return _mm_movemask_epi8(vmask);
}
MCS_FORCE_INLINE MT nullEmptyCmpNe(SimdType& x, SimdType& y)
{
return cmpNe(x, y);
}
MCS_FORCE_INLINE MT nullEmptyCmpEq(SimdType& x, SimdType& y)
{
return cmpEq(x, y);
}
MCS_FORCE_INLINE SimdType setToZero()
{
return _mm_setzero_si128();
}
// store
MCS_FORCE_INLINE void storeWMask(SimdType& x, SimdType& vmask, char* dst)
{
_mm_maskmoveu_si128(x, vmask, dst);
}
MCS_FORCE_INLINE void store(char* dst, SimdType& x)
{
_mm_storeu_si128(reinterpret_cast<SimdType*>(dst), x);
}
};
template <typename VT, typename CHECK_T>
class SimdFilterProcessor<
VT, CHECK_T, typename std::enable_if<std::is_same<VT, vi128_wr>::value && std::is_same<CHECK_T, uint8_t>::value>::type>
{
public:
constexpr static const uint16_t vecByteSize = 16U;
@ -895,4 +1345,3 @@ class SimdFilterProcessor<
} // namespace simd
#endif // if defined(__x86_64__ )
// vim:ts=2 sw=2:

View File

@ -2,6 +2,10 @@
#include <atomic>
// To be refactored. There are two issues with this implentation.
// 1. It can be replaced with a lock despite the memory_order_acquire/release mem order. Needs
// std::atomic_flag instead.
// 2. https://www.realworldtech.com/forum/?threadid=189711&curpostid=189723
namespace utils
{
inline void getSpinlock(std::atomic<bool>& lock)
@ -23,4 +27,29 @@ inline void releaseSpinlock(std::atomic<bool>& lock)
lock.store(false, std::memory_order_release);
}
// c++20 offers a combination of wait/notify methods but
// I prefer to use a simpler version of uspace spin lock.
class USpaceSpinLock
{
public:
USpaceSpinLock(std::atomic_flag& flag) : flag_(flag)
{
while (flag_.test_and_set(std::memory_order_acquire))
{
;
}
};
~USpaceSpinLock()
{
release();
};
inline void release()
{
flag_.clear(std::memory_order_release);
}
private:
std::atomic_flag& flag_;
};
} // namespace utils

View File

@ -72,7 +72,7 @@ class STLPoolAllocator
void usePoolAllocator(boost::shared_ptr<PoolAllocator> b);
boost::shared_ptr<utils::PoolAllocator> getPoolAllocator();
pointer allocate(size_type, const void* hint = 0);
pointer allocate(size_type, typename STLPoolAllocator<T>::const_pointer hint = 0);
void deallocate(pointer p, size_type n);
size_type max_size() const throw();
inline uint64_t getMemUsage() const
@ -131,7 +131,7 @@ boost::shared_ptr<utils::PoolAllocator> STLPoolAllocator<T>::getPoolAllocator()
template <class T>
typename STLPoolAllocator<T>::pointer STLPoolAllocator<T>::allocate(
typename STLPoolAllocator<T>::size_type s, typename std::allocator<void>::const_pointer hint)
typename STLPoolAllocator<T>::size_type s, typename STLPoolAllocator<T>::const_pointer hint)
{
return (pointer)pa->allocate(s * sizeof(T));
}

View File

@ -0,0 +1,51 @@
/*
Copyright (C) 2021, 2022 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of
the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
/* handling of the conversion of string prefixes to int64_t for quick range checking */
#include "collation.h"
#include "joblisttypes.h"
#include "string_prefixes.h"
// XXX: string (or, actually, a BLOB) with all NUL chars will be encoded into zero. Which corresponds to
// encoding of empty string, or NULL.
int64_t encodeStringPrefix(const uint8_t* str, size_t len, int charsetNumber)
{
datatypes::Charset cset(charsetNumber);
uint8_t fixedLenPrefix[8];
memset(fixedLenPrefix, 0, sizeof(fixedLenPrefix));
cset.strnxfrm(fixedLenPrefix, sizeof(fixedLenPrefix), 8, str, len, 0);
int64_t acc = 0;
size_t i;
for (i = 0; i < 8; i++)
{
uint8_t byte = fixedLenPrefix[i];
acc = (acc << 8) + byte;
}
return acc;
}
int64_t encodeStringPrefix_check_null(const uint8_t* str, size_t len, int charsetNumber)
{
if (len < 1)
{
return joblist::UBIGINTNULL;
}
return encodeStringPrefix(str, len, charsetNumber);
}

View File

@ -0,0 +1,32 @@
/*
Copyright (C) 2021, 2022 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of
the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
/* handling of the conversion of string prefixes to int64_t for quick range checking */
#pragma once
#include <stdlib.h>
#include <stdint.h>
// Encode string prefix into an int64_t, packing as many chars from string as possible
// into the result and respecting the collation provided by charsetNumber.
//
// For one example, for CI Czech collation, encodeStringPrefix("cz") < encodeStringPrefix("CH").
int64_t encodeStringPrefix(const uint8_t* str, size_t len, int charsetNumber);
int64_t encodeStringPrefix_check_null(const uint8_t* str, size_t len, int charsetNumber);

View File

@ -672,4 +672,3 @@ std::shared_ptr<CompressInterface> getCompressorByType(
#endif
} // namespace compress
// vim:ts=4 sw=4:

View File

@ -684,4 +684,3 @@ std::string Config::getTempFileDir(Config::TempDirPurpose what)
}
} // namespace config
// vim:ts=4 sw=4:

View File

@ -254,4 +254,3 @@ class Config
#undef EXPORT
// vim:ts=4 sw=4:

View File

@ -64,4 +64,3 @@ void ConfigStream::init(const xmlChar* xp)
}
} // namespace config
// vim:ts=4 sw=4:

View File

@ -61,4 +61,3 @@ class ConfigStream
} // namespace config
// vim:ts=4 sw=4:

View File

@ -65,7 +65,6 @@ class WOConfigFileTest : public CppUnit::TestFixture
void test1()
{
WriteOnceConfig woc(cf);
CPPUNIT_ASSERT(woc.owns("PrimitiveServers", "LBID_Shift"));
CPPUNIT_ASSERT(woc.owns("SystemConfig", "DBRootCount"));
CPPUNIT_ASSERT(woc.owns("SystemConfig", "DBRMRoot"));
@ -73,9 +72,6 @@ class WOConfigFileTest : public CppUnit::TestFixture
int vali;
vali = Config::fromText(woc.getConfig("PrimitiveServers", "LBID_Shift"));
CPPUNIT_ASSERT(vali == 13);
woc.setConfig("SystemConfig", "DBRootCount", "10");
vali = Config::fromText(woc.getConfig("SystemConfig", "DBRootCount"));
CPPUNIT_ASSERT(vali == 10);

View File

@ -285,4 +285,3 @@ const vector<string> XMLParser::enumSection(const xmlDocPtr doc, const string& s
}
} // namespace config
// vim:ts=4 sw=4:

View File

@ -63,4 +63,3 @@ class XMLParser
} // namespace config
// vim:ts=4 sw=4:

View File

@ -1193,7 +1193,7 @@ bool stringToTimeStruct(const string& data, Time& dtime, long decimals)
return true;
}
bool stringToTimestampStruct(const string& data, TimeStamp& timeStamp, const string& timeZone)
bool stringToTimestampStruct(const string& data, TimeStamp& timeStamp, long timeZone)
{
// special handling for 0000-00-00 00:00:00
// "0" is sent by the server when checking for default value
@ -1418,7 +1418,7 @@ boost::any DataConvert::StringToUDecimal(const datatypes::SystemCatalog::TypeAtt
{
int64_t val64;
number_int_value(data, typeCode, colType, pushWarning, prm.noRoundup(), val64);
char ival = (char)val64;
signed char ival = (signed char)val64;
if (ival < 0 && ival != static_cast<int8_t>(joblist::TINYINTEMPTYROW) &&
ival != static_cast<int8_t>(joblist::TINYINTNULL))
@ -1879,10 +1879,11 @@ int64_t DataConvert::convertColumnDatetime(const char* dataOrg, CalpontDateTimeF
// Most of this code is taken from DataConvert::convertColumnDatetime
//------------------------------------------------------------------------------
int64_t DataConvert::convertColumnTimestamp(const char* dataOrg, CalpontDateTimeFormat datetimeFormat,
int& status, unsigned int dataOrgLen, const std::string& timeZone)
int& status, unsigned int dataOrgLen, long timeZone)
{
char tmbuf[64];
std::string dataOrgTemp = dataOrg;
status = 0;
if (dataOrgTemp.substr(0, 19) == "0000-00-00 00:00:00")
{
return 0;
@ -1902,7 +1903,6 @@ int64_t DataConvert::convertColumnTimestamp(const char* dataOrg, CalpontDateTime
dataOrgLen = strlen(tmbuf);
}
status = 0;
const char* p;
p = dataOrg;
char fld[10];
@ -2258,8 +2258,7 @@ std::string DataConvert::datetimeToString(long long datetimevalue, long decimals
return buf;
}
std::string DataConvert::timestampToString(long long timestampvalue, const std::string& timezone,
long decimals)
std::string DataConvert::timestampToString(long long timestampvalue, long timezone, long decimals)
{
// 10 is default which means we don't need microseconds
if (decimals > 6 || decimals < 0)
@ -2343,7 +2342,7 @@ std::string DataConvert::datetimeToString1(long long datetimevalue)
return buf;
}
std::string DataConvert::timestampToString1(long long timestampvalue, const std::string& timezone)
std::string DataConvert::timestampToString1(long long timestampvalue, long timezone)
{
const int TIMESTAMPTOSTRING1_LEN = 22; // YYYYMMDDHHMMSSmmmmmm\0
char buf[TIMESTAMPTOSTRING1_LEN];
@ -2381,7 +2380,7 @@ int64_t DataConvert::datetimeToInt(const string& datetime)
return stringToDatetime(datetime);
}
int64_t DataConvert::timestampToInt(const string& timestamp, const string& timeZone)
int64_t DataConvert::timestampToInt(const string& timestamp, long timeZone)
{
return stringToTimestamp(timestamp, timeZone);
}
@ -2414,7 +2413,7 @@ int64_t DataConvert::stringToDatetime(const string& data, bool* date)
return -1;
}
int64_t DataConvert::stringToTimestamp(const string& data, const string& timeZone)
int64_t DataConvert::stringToTimestamp(const string& data, long timeZone)
{
TimeStamp aTimestamp;
@ -3389,4 +3388,3 @@ void DataConvert::joinColTypeForUnion(datatypes::SystemCatalog::TypeHolderStd& u
}
} // namespace dataconvert
// vim:ts=4 sw=4:

View File

@ -28,13 +28,8 @@
#include <string>
#include <boost/any.hpp>
#include <vector>
#ifdef _MSC_VER
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#else
#include <netinet/in.h>
#endif
#ifdef __linux__
#define POSIX_REGEX
@ -43,7 +38,7 @@
#ifdef POSIX_REGEX
#include <regex.h>
#else
#include <boost/regex.hpp>
#include <regex>
#endif
#include "mcs_datatype.h"
@ -289,6 +284,14 @@ inline void unserializeTimezoneInfo(messageqcpp::ByteStream& bs, TIME_ZONE_INFO*
bs >> (uint&)tz->revcnt;
};
inline long systemTimeZoneOffset()
{
time_t t = time(NULL);
struct tm lt;
localtime_r(&t, &lt);
return lt.tm_gmtoff;
}
/**
* This function converts the timezone represented as a string
* in the format "+HH:MM" or "-HH:MM" to a signed offset in seconds
@ -296,20 +299,32 @@ inline void unserializeTimezoneInfo(messageqcpp::ByteStream& bs, TIME_ZONE_INFO*
*/
inline bool timeZoneToOffset(const char* str, std::string::size_type length, long* offset)
{
if (strcmp(str, "SYSTEM") == 0)
{
*offset = systemTimeZoneOffset();
return 0;
}
const char* end = str + length;
bool negative;
unsigned long number_tmp;
long offset_tmp;
if (length < 4)
{
*offset = 0;
return 1;
}
if (*str == '+')
negative = 0;
else if (*str == '-')
negative = 1;
else
{
*offset = 0;
return 1;
}
str++;
number_tmp = 0;
@ -321,7 +336,10 @@ inline bool timeZoneToOffset(const char* str, std::string::size_type length, lon
}
if (str + 1 >= end || *str != ':')
{
*offset = 0;
return 1;
}
str++;
offset_tmp = number_tmp * 60L;
@ -334,7 +352,10 @@ inline bool timeZoneToOffset(const char* str, std::string::size_type length, lon
}
if (str != end)
{
*offset = 0;
return 1;
}
offset_tmp = (offset_tmp + number_tmp) * 60L;
@ -347,10 +368,12 @@ inline bool timeZoneToOffset(const char* str, std::string::size_type length, lon
*/
if (number_tmp > 59 || offset_tmp < -13 * 3600L + 1 || offset_tmp > 13 * 3600L)
{
*offset = 0;
return 1;
}
*offset = offset_tmp;
return 0;
}
@ -483,10 +506,10 @@ inline bool isTimestampValid(uint64_t second, uint64_t microsecond)
*
* @param seconds the value to be converted
* @param time the broken-down representation of the timestamp
* @param timeZone a string with the server timezone of the machine
* which initiated the query
@param offset a timeZone offset (in seconds) relative to UTC.
For example, for EST which is UTC-5:00, offset will be -18000s.
*/
inline void gmtSecToMySQLTime(int64_t seconds, MySQLTime& time, const std::string& timeZone)
inline void gmtSecToMySQLTime(int64_t seconds, MySQLTime& time, long offset)
{
if (seconds == 0)
{
@ -494,78 +517,52 @@ inline void gmtSecToMySQLTime(int64_t seconds, MySQLTime& time, const std::strin
return;
}
if (timeZone == "SYSTEM")
int64_t days;
int32_t rem;
int32_t y;
int32_t yleap;
const unsigned int* ip;
days = (int64_t)(seconds / SECS_PER_DAY);
rem = (int32_t)(seconds % SECS_PER_DAY);
rem += offset;
while (rem < 0)
{
struct tm tmp_tm;
time_t tmp_t = (time_t)seconds;
localtime_r(&tmp_t, &tmp_tm);
time.second_part = 0;
time.year = (int)((tmp_tm.tm_year + 1900) % 10000);
time.month = (int)tmp_tm.tm_mon + 1;
time.day = (int)tmp_tm.tm_mday;
time.hour = (int)tmp_tm.tm_hour;
time.minute = (int)tmp_tm.tm_min;
time.second = (int)tmp_tm.tm_sec;
time.time_type = CALPONTDATETIME_ENUM;
if (time.second == 60 || time.second == 61)
time.second = 59;
rem += SECS_PER_DAY;
days--;
}
else
while (rem >= SECS_PER_DAY)
{
long offset;
if (timeZoneToOffset(timeZone.c_str(), timeZone.size(), &offset))
{
time.reset();
return;
}
int64_t days;
int32_t rem;
int32_t y;
int32_t yleap;
const unsigned int* ip;
days = (int64_t)(seconds / SECS_PER_DAY);
rem = (int32_t)(seconds % SECS_PER_DAY);
rem += offset;
while (rem < 0)
{
rem += SECS_PER_DAY;
days--;
}
while (rem >= SECS_PER_DAY)
{
rem -= SECS_PER_DAY;
days++;
}
time.hour = (unsigned int)(rem / SECS_PER_HOUR);
rem = rem % SECS_PER_HOUR;
time.minute = (unsigned int)(rem / SECS_PER_MIN);
time.second = (unsigned int)(rem % SECS_PER_MIN);
y = EPOCH_YEAR;
while (days < 0 || days >= (int64_t)(year_lengths[yleap = isLeapYear(y)]))
{
int32_t newy;
newy = y + days / DAYS_PER_NYEAR;
if (days < 0)
newy--;
days -= (newy - y) * DAYS_PER_NYEAR + leapsThruEndOf(newy - 1) - leapsThruEndOf(y - 1);
y = newy;
}
time.year = y;
ip = mon_lengths[yleap];
for (time.month = 0; days >= (int64_t)ip[time.month]; time.month++)
days -= (int64_t)ip[time.month];
time.month++;
time.day = (unsigned int)(days + 1);
time.second_part = 0;
time.time_type = CALPONTDATETIME_ENUM;
rem -= SECS_PER_DAY;
days++;
}
time.hour = (unsigned int)(rem / SECS_PER_HOUR);
rem = rem % SECS_PER_HOUR;
time.minute = (unsigned int)(rem / SECS_PER_MIN);
time.second = (unsigned int)(rem % SECS_PER_MIN);
y = EPOCH_YEAR;
while (days < 0 || days >= (int64_t)(year_lengths[yleap = isLeapYear(y)]))
{
int32_t newy;
newy = y + days / DAYS_PER_NYEAR;
if (days < 0)
newy--;
days -= (newy - y) * DAYS_PER_NYEAR + leapsThruEndOf(newy - 1) - leapsThruEndOf(y - 1);
y = newy;
}
time.year = y;
ip = mon_lengths[yleap];
for (time.month = 0; days >= (int64_t)ip[time.month]; time.month++)
days -= (int64_t)ip[time.month];
time.month++;
time.day = (unsigned int)(days + 1);
time.second_part = 0;
time.time_type = CALPONTDATETIME_ENUM;
}
/**
@ -593,41 +590,15 @@ inline int64_t secSinceEpoch(int year, int month, int day, int hour, int min, in
return ((days * HOURS_PER_DAY + hour) * MINS_PER_HOUR + min) * SECS_PER_MIN + sec;
}
// This is duplicate of funchelpers.h:calc_mysql_daynr,
// with one additional function parameter
inline uint32_t calc_mysql_daynr(uint32_t year, uint32_t month, uint32_t day, bool& isValid)
{
int temp;
int y = year;
long delsum;
if (!isDateValid(day, month, year))
{
isValid = false;
return 0;
}
delsum = (long)(365 * y + 31 * ((int)month - 1) + (int)day);
if (month <= 2)
y--;
else
delsum -= (long)((int)month * 4 + 23) / 10;
temp = (int)((y / 100 + 1) * 3) / 4;
return delsum + (int)y / 4 - temp;
}
/**
* @brief converts a timestamp from broken-down representation
* to seconds since UTC epoch
*
* @param time the broken-down representation of the timestamp
@param timeZone a string with the server timezone of the machine
which initiated the query
@param offset a timeZone offset (in seconds) relative to UTC.
For example, for EST which is UTC-5:00, offset will be -18000s.
*/
inline int64_t mySQLTimeToGmtSec(const MySQLTime& time, const std::string& timeZone, bool& isValid)
inline int64_t mySQLTimeToGmtSec(const MySQLTime& time, long offset, bool& isValid)
{
int64_t seconds;
@ -637,88 +608,7 @@ inline int64_t mySQLTimeToGmtSec(const MySQLTime& time, const std::string& timeZ
return 0;
}
if (timeZone == "SYSTEM")
{
// This is mirror of code in func_unix_timestamp.cpp
uint32_t loop;
time_t tmp_t = 0;
int shift = 0;
struct tm *l_time, tm_tmp;
int64_t diff;
localtime_r(&tmp_t, &tm_tmp);
// Get the system timezone offset at 0 seconds since epoch
int64_t my_time_zone = tm_tmp.tm_gmtoff;
int day = time.day;
if ((time.year == MAX_TIMESTAMP_YEAR) && (time.month == 1) && (day > 4))
{
day -= 2;
shift = 2;
}
tmp_t = (time_t)(((calc_mysql_daynr(time.year, time.month, day, isValid) - 719528) * 86400L +
(int64_t)time.hour * 3600L + (int64_t)(time.minute * 60 + time.second)) -
(time_t)my_time_zone);
if (!isValid)
return 0;
localtime_r(&tmp_t, &tm_tmp);
l_time = &tm_tmp;
for (loop = 0;
loop < 2 && (time.hour != (uint32_t)l_time->tm_hour || time.minute != (uint32_t)l_time->tm_min ||
time.second != (uint32_t)l_time->tm_sec);
loop++)
{
int days = day - l_time->tm_mday;
if (days < -1)
days = 1; /* Month has wrapped */
else if (days > 1)
days = -1;
diff = (3600L * (int64_t)(days * 24 + ((int)time.hour - (int)l_time->tm_hour)) +
(int64_t)(60 * ((int)time.minute - (int)l_time->tm_min)) +
(int64_t)((int)time.second - (int)l_time->tm_sec));
tmp_t += (time_t)diff;
localtime_r(&tmp_t, &tm_tmp);
l_time = &tm_tmp;
}
if (loop == 2 && time.hour != (uint32_t)l_time->tm_hour)
{
int days = day - l_time->tm_mday;
if (days < -1)
days = 1; /* Month has wrapped */
else if (days > 1)
days = -1;
diff = (3600L * (int64_t)(days * 24 + ((int)time.hour - (int)l_time->tm_hour)) +
(int64_t)(60 * ((int)time.minute - (int)l_time->tm_min)) +
(int64_t)((int)time.second - (int)l_time->tm_sec));
if (diff == 3600)
tmp_t += 3600 - time.minute * 60 - time.second; /* Move to next hour */
else if (diff == -3600)
tmp_t -= time.minute * 60 + time.second; /* Move to previous hour */
}
/* shift back, if we were dealing with boundary dates */
tmp_t += shift * 86400L;
seconds = (int64_t)tmp_t;
}
else
{
long offset;
if (timeZoneToOffset(timeZone.c_str(), timeZone.size(), &offset))
{
isValid = false;
return -1;
}
seconds = secSinceEpoch(time.year, time.month, time.day, time.hour, time.minute, time.second) - offset;
}
seconds = secSinceEpoch(time.year, time.month, time.day, time.hour, time.minute, time.second) - offset;
/* make sure we have legit timestamps (i.e. we didn't over/underflow anywhere above) */
if (seconds >= MIN_TIMESTAMP_VALUE && seconds <= MAX_TIMESTAMP_VALUE)
return seconds;
@ -1151,11 +1041,11 @@ struct TimeStamp
{
}
int64_t convertToMySQLint(const std::string& timeZone) const;
int64_t convertToMySQLint(long timeZone) const;
void reset();
};
inline int64_t TimeStamp::convertToMySQLint(const std::string& timeZone) const
inline int64_t TimeStamp::convertToMySQLint(long timeZone) const
{
const int TIMESTAMPTOSTRING1_LEN = 22; // YYYYMMDDHHMMSSmmmmmm\0
char buf[TIMESTAMPTOSTRING1_LEN];
@ -1262,10 +1152,9 @@ class DataConvert
* @param type the columns database type
* @param data the columns string representation of it's data
*/
EXPORT static std::string timestampToString(long long timestampvalue, const std::string& timezone,
long decimals = 0);
EXPORT static std::string timestampToString(long long timestampvalue, long timezone, long decimals = 0);
static inline void timestampToString(long long timestampvalue, char* buf, unsigned int buflen,
const std::string& timezone, long decimals = 0);
long timezone, long decimals = 0);
/**
* @brief convert a columns data from native format to a string
@ -1300,9 +1189,9 @@ class DataConvert
* @param type the columns database type
* @param data the columns string representation of it's data
*/
EXPORT static std::string timestampToString1(long long timestampvalue, const std::string& timezone);
EXPORT static std::string timestampToString1(long long timestampvalue, long timezone);
static inline void timestampToString1(long long timestampvalue, char* buf, unsigned int buflen,
const std::string& timezone);
long timezone);
/**
* @brief convert a columns data from native format to a string
@ -1352,11 +1241,11 @@ class DataConvert
* @param datetimeFormat the format the date value in
* @param status 0 - success, -1 - fail
* @param dataOrgLen length specification of dataOrg
* @param timeZone the timezone used for conversion to native format
* @param timeZone an offset (in seconds) relative to UTC.
For example, for EST which is UTC-5:00, offset will be -18000s.
*/
EXPORT static int64_t convertColumnTimestamp(const char* dataOrg, CalpontDateTimeFormat datetimeFormat,
int& status, unsigned int dataOrgLen,
const std::string& timeZone);
int& status, unsigned int dataOrgLen, long timeZone);
/**
* @brief convert a time column data, represented as a string,
@ -1385,7 +1274,7 @@ class DataConvert
// convert string to datetime
EXPORT static int64_t stringToDatetime(const std::string& data, bool* isDate = NULL);
// convert string to timestamp
EXPORT static int64_t stringToTimestamp(const std::string& data, const std::string& timeZone);
EXPORT static int64_t stringToTimestamp(const std::string& data, long timeZone);
// convert integer to date
EXPORT static int64_t intToDate(int64_t data);
// convert integer to datetime
@ -1396,7 +1285,7 @@ class DataConvert
EXPORT static int64_t dateToInt(const std::string& date);
// convert string to datetime. alias to datetimeToInt
EXPORT static int64_t datetimeToInt(const std::string& datetime);
EXPORT static int64_t timestampToInt(const std::string& timestamp, const std::string& timeZone);
EXPORT static int64_t timestampToInt(const std::string& timestamp, long timeZone);
EXPORT static int64_t timeToInt(const std::string& time);
EXPORT static int64_t stringToTime(const std::string& data);
// bug4388, union type conversion
@ -1467,7 +1356,7 @@ inline void DataConvert::datetimeToString(long long datetimevalue, char* buf, un
}
inline void DataConvert::timestampToString(long long timestampvalue, char* buf, unsigned int buflen,
const std::string& timezone, long decimals)
long timezone, long decimals)
{
// 10 is default which means we don't need microseconds
if (decimals > 6 || decimals < 0)
@ -1545,7 +1434,7 @@ inline void DataConvert::datetimeToString1(long long datetimevalue, char* buf, u
}
inline void DataConvert::timestampToString1(long long timestampvalue, char* buf, unsigned int buflen,
const std::string& timezone)
long timezone)
{
TimeStamp timestamp(timestampvalue);
int64_t seconds = timestamp.second;

View File

@ -270,4 +270,3 @@ int ddl_cleanup()
}
} // namespace ddlcleanuputil
// vim:ts=4 sw=4:

View File

@ -28,4 +28,3 @@ namespace ddlcleanuputil
{
int ddl_cleanup();
}
// vim:ts=4 sw=4:

View File

@ -79,4 +79,3 @@ long double Func_abs::getLongDoubleVal(Row& row, FunctionParm& parm, bool& isNul
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -171,7 +171,7 @@ int64_t Func_add_time::getTimestampIntVal(rowgroup::Row& row, FunctionParm& parm
TimeStamp timestamp(val1);
int64_t seconds = timestamp.second;
MySQLTime m_time;
gmtSecToMySQLTime(seconds, m_time, timeZone());
gmtSecToMySQLTime(seconds, m_time, ct.getTimeZone());
dt1.year = m_time.year;
dt1.month = m_time.month;
dt1.day = m_time.day;
@ -303,4 +303,3 @@ int64_t Func_add_time::getTimeIntVal(rowgroup::Row& row, FunctionParm& parm, boo
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -56,4 +56,3 @@ int64_t Func_ascii::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isNu
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -328,7 +328,7 @@ CalpontSystemCatalog::ColType Func_between::operationType(FunctionParm& fp,
if (cc)
{
Result result = cc->result();
result.intVal = dataconvert::DataConvert::timestampToInt(result.strVal, timeZone());
result.intVal = dataconvert::DataConvert::timestampToInt(result.strVal, resultType.getTimeZone());
cc->result(result);
}
}
@ -376,4 +376,3 @@ bool Func_notbetween::getBoolVal(rowgroup::Row& row, FunctionParm& pm, bool& isN
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -105,7 +105,8 @@ static datatypes::TUInt64Null DecimalToBitOperand(Row& row, const execplan::SPTP
// and could be extracted into a utility class with its own header
// if that is the case - this is left as future exercise
datatypes::TUInt64Null GenericToBitOperand(Row& row, const execplan::SPTP& parm,
const funcexp::Func& thisFunc, bool temporalRounding)
const funcexp::Func& thisFunc, bool temporalRounding,
long timeZone)
{
switch (parm->data()->resultType().colDataType)
{
@ -186,7 +187,7 @@ datatypes::TUInt64Null GenericToBitOperand(Row& row, const execplan::SPTP& parm,
return datatypes::TUInt64Null();
TimeStamp dt(time);
int64_t value = dt.convertToMySQLint(thisFunc.timeZone());
int64_t value = dt.convertToMySQLint(timeZone);
if (temporalRounding && dt.msecond >= 500000)
value++;
return datatypes::TUInt64Null((uint64_t)value);
@ -222,8 +223,8 @@ class BitOperandGeneric : public datatypes::TUInt64Null
BitOperandGeneric()
{
}
BitOperandGeneric(Row& row, const execplan::SPTP& parm, const funcexp::Func& thisFunc)
: TUInt64Null(GenericToBitOperand(row, parm, thisFunc, true))
BitOperandGeneric(Row& row, const execplan::SPTP& parm, const funcexp::Func& thisFunc, long timeZone)
: TUInt64Null(GenericToBitOperand(row, parm, thisFunc, true, timeZone))
{
}
};
@ -236,8 +237,9 @@ class BitOperandGenericShiftAmount : public datatypes::TUInt64Null
BitOperandGenericShiftAmount()
{
}
BitOperandGenericShiftAmount(Row& row, const execplan::SPTP& parm, const funcexp::Func& thisFunc)
: TUInt64Null(GenericToBitOperand(row, parm, thisFunc, false))
BitOperandGenericShiftAmount(Row& row, const execplan::SPTP& parm, const funcexp::Func& thisFunc,
long timeZone)
: TUInt64Null(GenericToBitOperand(row, parm, thisFunc, false, timeZone))
{
}
};
@ -327,7 +329,7 @@ class Func_bitand_return_uint64 : public Func_bitand
CalpontSystemCatalog::ColType& operationColType) override
{
idbassert(parm.size() == 2);
Arg2Lazy<TA, TB> args(row, parm, *this);
Arg2Lazy<TA, TB> args(row, parm, *this, operationColType.getTimeZone());
return (int64_t)(args.a & args.b).nullSafeValue(isNull);
}
};
@ -353,7 +355,7 @@ class Func_leftshift_return_uint64 : public Func_leftshift
CalpontSystemCatalog::ColType& operationColType) override
{
idbassert(parm.size() == 2);
Arg2Eager<TA, BitOperandGenericShiftAmount> args(row, parm, *this);
Arg2Eager<TA, BitOperandGenericShiftAmount> args(row, parm, *this, operationColType.getTimeZone());
return (int64_t)args.a.MariaDBShiftLeft(args.b).nullSafeValue(isNull);
}
};
@ -378,7 +380,7 @@ class Func_rightshift_return_uint64 : public Func_rightshift
CalpontSystemCatalog::ColType& operationColType) override
{
idbassert(parm.size() == 2);
Arg2Eager<TA, BitOperandGenericShiftAmount> args(row, parm, *this);
Arg2Eager<TA, BitOperandGenericShiftAmount> args(row, parm, *this, operationColType.getTimeZone());
return (int64_t)args.a.MariaDBShiftRight(args.b).nullSafeValue(isNull);
}
};
@ -409,7 +411,7 @@ class Func_bitor_return_uint64 : public Func_bitor
CalpontSystemCatalog::ColType& operationColType) override
{
idbassert(parm.size() == 2);
Arg2Lazy<TA, TB> args(row, parm, *this);
Arg2Lazy<TA, TB> args(row, parm, *this, operationColType.getTimeZone());
return (int64_t)(args.a | args.b).nullSafeValue(isNull);
}
};
@ -435,7 +437,7 @@ class Func_bitxor_return_uint64 : public Func_bitxor
CalpontSystemCatalog::ColType& operationColType) override
{
idbassert(parm.size() == 2);
Arg2Eager<TA, TB> args(row, parm, *this);
Arg2Eager<TA, TB> args(row, parm, *this, operationColType.getTimeZone());
return (int64_t)(args.a ^ args.b).nullSafeValue(isNull);
}
};
@ -475,7 +477,7 @@ class Func_bit_count_return_uint64 : public Func_bit_count
CalpontSystemCatalog::ColType& operationColType) override
{
idbassert(parm.size() == 1);
return bitCount((uint64_t)TA(row, parm[0], *this).nullSafeValue(isNull));
return bitCount((uint64_t)TA(row, parm[0], *this, operationColType.getTimeZone()).nullSafeValue(isNull));
}
};
@ -492,4 +494,3 @@ bool Func_bit_count::fix(execplan::FunctionColumn& col) const
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -723,4 +723,3 @@ int64_t Func_searched_case::getTimeIntVal(rowgroup::Row& row, FunctionParm& parm
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -186,7 +186,7 @@ int64_t Func_cast_signed::getIntVal(Row& row, FunctionParm& parm, bool& isNull,
int64_t time = parm[0]->data()->getTimestampIntVal(row, isNull);
TimeStamp dt(time);
return dt.convertToMySQLint(timeZone());
return dt.convertToMySQLint(operationColType.getTimeZone());
}
break;
@ -304,7 +304,7 @@ uint64_t Func_cast_unsigned::getUintVal(Row& row, FunctionParm& parm, bool& isNu
int64_t time = parm[0]->data()->getTimestampIntVal(row, isNull);
TimeStamp dt(time);
return dt.convertToMySQLint(timeZone());
return dt.convertToMySQLint(operationColType.getTimeZone());
}
break;
@ -433,7 +433,7 @@ string Func_cast_char::getStrVal(Row& row, FunctionParm& parm, bool& isNull,
case execplan::CalpontSystemCatalog::TIMESTAMP:
{
return dataconvert::DataConvert::timestampToString(parm[0]->data()->getTimestampIntVal(row, isNull),
timeZone())
operationColType.getTimeZone())
.substr(0, length);
}
break;
@ -568,7 +568,7 @@ int32_t Func_cast_date::getDateIntVal(rowgroup::Row& row, FunctionParm& parm, bo
case execplan::CalpontSystemCatalog::TIMESTAMP:
{
int64_t val1 = parm[0]->data()->getTimestampIntVal(row, isNull);
string value = dataconvert::DataConvert::timestampToString(val1, timeZone());
string value = dataconvert::DataConvert::timestampToString(val1, op_ct.getTimeZone());
value = value.substr(0, 10);
return dataconvert::DataConvert::stringToDate(value);
}
@ -691,7 +691,7 @@ int64_t Func_cast_date::getDatetimeIntVal(rowgroup::Row& row, FunctionParm& parm
TimeStamp timestamp(parm[0]->data()->getTimestampIntVal(row, isNull));
int64_t seconds = timestamp.second;
MySQLTime m_time;
gmtSecToMySQLTime(seconds, m_time, timeZone());
gmtSecToMySQLTime(seconds, m_time, operationColType.getTimeZone());
DateTime dt;
dt.year = m_time.year;
dt.month = m_time.month;
@ -847,7 +847,7 @@ int64_t Func_cast_datetime::getDatetimeIntVal(rowgroup::Row& row, FunctionParm&
TimeStamp timestamp(parm[0]->data()->getTimestampIntVal(row, isNull));
int64_t seconds = timestamp.second;
MySQLTime m_time;
gmtSecToMySQLTime(seconds, m_time, timeZone());
gmtSecToMySQLTime(seconds, m_time, operationColType.getTimeZone());
DateTime dt;
dt.year = m_time.year;
dt.month = m_time.month;
@ -958,7 +958,7 @@ int64_t Func_cast_datetime::getTimeIntVal(rowgroup::Row& row, FunctionParm& parm
TimeStamp timestamp(parm[0]->data()->getTimestampIntVal(row, isNull));
int64_t seconds = timestamp.second;
MySQLTime m_time;
gmtSecToMySQLTime(seconds, m_time, timeZone());
gmtSecToMySQLTime(seconds, m_time, operationColType.getTimeZone());
Time time;
time.hour = m_time.hour;
time.minute = m_time.minute;
@ -1362,7 +1362,7 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row, FunctionParm& parm, bool&
int32_t s = 0;
string value = dataconvert::DataConvert::timestampToString1(
parm[0]->data()->getTimestampIntVal(row, isNull), timeZone());
parm[0]->data()->getTimestampIntVal(row, isNull), operationColType.getTimeZone());
// strip off micro seconds
string date = value.substr(0, 14);
@ -1475,8 +1475,8 @@ double Func_cast_double::getDoubleVal(Row& row, FunctionParm& parm, bool& isNull
case execplan::CalpontSystemCatalog::TIMESTAMP:
{
string str =
DataConvert::timestampToString1(parm[0]->data()->getTimestampIntVal(row, isNull), timeZone());
string str = DataConvert::timestampToString1(parm[0]->data()->getTimestampIntVal(row, isNull),
operationColType.getTimeZone());
// strip off micro seconds
str = str.substr(0, 14);
@ -1549,4 +1549,3 @@ double Func_cast_double::getDoubleVal(Row& row, FunctionParm& parm, bool& isNull
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -571,7 +571,7 @@ IDB_Decimal Func_ceil::getDecimalVal(Row& row, FunctionParm& parm, bool& isNull,
TimeStamp dt(parm[0]->data()->getTimestampIntVal(row, isNull));
if (!isNull)
ret.value = dt.convertToMySQLint(timeZone());
ret.value = dt.convertToMySQLint(op_ct.getTimeZone());
}
break;
@ -598,4 +598,3 @@ IDB_Decimal Func_ceil::getDecimalVal(Row& row, FunctionParm& parm, bool& isNull,
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -178,4 +178,3 @@ string Func_char::getStrVal(Row& row, FunctionParm& parm, bool& isNull, CalpontS
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -99,7 +99,7 @@ int64_t Func_char_length::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool
case execplan::CalpontSystemCatalog::TIMESTAMP:
{
string date = dataconvert::DataConvert::timestampToString(
parm[0]->data()->getTimestampIntVal(row, isNull), timeZone());
parm[0]->data()->getTimestampIntVal(row, isNull), op_ct.getTimeZone());
return (int64_t)date.size();
}
@ -121,4 +121,3 @@ int64_t Func_char_length::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -244,4 +244,3 @@ execplan::IDB_Decimal Func_coalesce::getDecimalVal(rowgroup::Row& row, FunctionP
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -65,4 +65,3 @@ string Func_concat::getStrVal(Row& row, FunctionParm& parm, bool& isNull, Calpon
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -71,4 +71,3 @@ string Func_concat_oracle::getStrVal(Row& row, FunctionParm& parm, bool& isNull,
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -121,4 +121,3 @@ string Func_concat_ws::getStrVal(Row& row, FunctionParm& parm, bool& isNull,
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -304,4 +304,3 @@ string Func_conv::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -154,7 +154,9 @@ int64_t Func_convert_tz::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool&
}
else
{
seconds = dataconvert::mySQLTimeToGmtSec(my_start_time, from_tz, valid);
long from_tz_offset;
dataconvert::timeZoneToOffset(from_tz.c_str(), from_tz.size(), &from_tz_offset);
seconds = dataconvert::mySQLTimeToGmtSec(my_start_time, from_tz_offset, valid);
if (!valid)
{
if (seconds != 0)
@ -196,7 +198,9 @@ int64_t Func_convert_tz::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool&
}
else
{
dataconvert::gmtSecToMySQLTime(seconds, my_time_tmp, to_tz);
long to_tz_offset;
dataconvert::timeZoneToOffset(to_tz.c_str(), to_tz.size(), &to_tz_offset);
dataconvert::gmtSecToMySQLTime(seconds, my_time_tmp, to_tz_offset);
}
dataconvert::DateTime result_datetime(my_time_tmp.year, my_time_tmp.month, my_time_tmp.day,
@ -216,4 +220,3 @@ string Func_convert_tz::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool&
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -64,4 +64,3 @@ int64_t Func_crc32::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isNu
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -47,7 +47,7 @@ CalpontSystemCatalog::ColType Func_date::operationType(FunctionParm& fp,
}
int64_t Func_date::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
CalpontSystemCatalog::ColType&)
CalpontSystemCatalog::ColType& ct)
{
CalpontSystemCatalog::ColDataType type = parm[0]->data()->resultType().colDataType;
@ -75,7 +75,7 @@ int64_t Func_date::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isNul
case execplan::CalpontSystemCatalog::TIMESTAMP:
{
int64_t val1 = parm[0]->data()->getTimestampIntVal(row, isNull);
value = dataconvert::DataConvert::timestampToString(val1, timeZone());
value = dataconvert::DataConvert::timestampToString(val1, ct.getTimeZone());
value = value.substr(0, 10);
break;
}
@ -149,4 +149,3 @@ string Func_date::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -759,7 +759,7 @@ int64_t Func_date_add::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& i
TimeStamp timestamp(parm[0]->data()->getTimestampIntVal(row, isNull));
int64_t seconds = timestamp.second;
MySQLTime m_time;
gmtSecToMySQLTime(seconds, m_time, timeZone());
gmtSecToMySQLTime(seconds, m_time, ct.getTimeZone());
DateTime dt;
dt.year = m_time.year;
dt.month = m_time.month;
@ -816,4 +816,3 @@ string Func_date_add::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& is
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -242,7 +242,7 @@ CalpontSystemCatalog::ColType Func_date_format::operationType(FunctionParm& fp,
}
string Func_date_format::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
CalpontSystemCatalog::ColType&)
CalpontSystemCatalog::ColType& ct)
{
int64_t val = 0;
DateTime dt = 0;
@ -273,7 +273,7 @@ string Func_date_format::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool&
TimeStamp timestamp(val);
int64_t seconds = timestamp.second;
MySQLTime time;
gmtSecToMySQLTime(seconds, time, timeZone());
gmtSecToMySQLTime(seconds, time, ct.getTimeZone());
dt.year = time.year;
dt.month = time.month;
dt.day = time.day;
@ -412,8 +412,7 @@ int64_t Func_date_format::getDatetimeIntVal(rowgroup::Row& row, FunctionParm& pa
int64_t Func_date_format::getTimestampIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
CalpontSystemCatalog::ColType& ct)
{
return dataconvert::DataConvert::timestampToInt(getStrVal(row, parm, isNull, ct), timeZone());
return dataconvert::DataConvert::timestampToInt(getStrVal(row, parm, isNull, ct), ct.getTimeZone());
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -64,7 +64,7 @@ int64_t Func_day::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull
dataconvert::TimeStamp timestamp(parm[0]->data()->getTimestampIntVal(row, isNull));
int64_t seconds = timestamp.second;
dataconvert::MySQLTime m_time;
dataconvert::gmtSecToMySQLTime(seconds, m_time, timeZone());
dataconvert::gmtSecToMySQLTime(seconds, m_time, op_ct.getTimeZone());
return m_time.day;
}
@ -143,4 +143,3 @@ int64_t Func_day::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -76,7 +76,7 @@ int64_t Func_dayname::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& is
dataconvert::TimeStamp timestamp(val);
int64_t seconds = timestamp.second;
dataconvert::MySQLTime time;
dataconvert::gmtSecToMySQLTime(seconds, time, timeZone());
dataconvert::gmtSecToMySQLTime(seconds, time, op_ct.getTimeZone());
year = time.year;
month = time.month;
day = time.day;
@ -179,4 +179,3 @@ string Func_dayname::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& isN
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -75,7 +75,7 @@ int64_t Func_dayofweek::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool&
dataconvert::TimeStamp timestamp(val);
int64_t seconds = timestamp.second;
dataconvert::MySQLTime time;
dataconvert::gmtSecToMySQLTime(seconds, time, timeZone());
dataconvert::gmtSecToMySQLTime(seconds, time, ct.getTimeZone());
year = time.year;
month = time.month;
day = time.day;
@ -166,4 +166,3 @@ int64_t Func_dayofweek::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool&
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -74,7 +74,7 @@ int64_t Func_dayofyear::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool&
dataconvert::TimeStamp timestamp(parm[0]->data()->getIntVal(row, isNull));
int64_t seconds = timestamp.second;
dataconvert::MySQLTime m_time;
dataconvert::gmtSecToMySQLTime(seconds, m_time, timeZone());
dataconvert::gmtSecToMySQLTime(seconds, m_time, ct.getTimeZone());
year = m_time.year;
month = m_time.month;
day = m_time.day;
@ -160,4 +160,3 @@ int64_t Func_dayofyear::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool&
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -108,4 +108,3 @@ string Func_div::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -96,4 +96,3 @@ string Func_elt::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -110,4 +110,3 @@ long double Func_exp::getLongDoubleVal(Row& row, FunctionParm& parm, bool& isNul
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -202,7 +202,7 @@ int64_t Func_extract::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& is
dataconvert::TimeStamp timestamp(parm[0]->data()->getTimestampIntVal(row, isNull));
int64_t seconds = timestamp.second;
dataconvert::MySQLTime m_time;
dataconvert::gmtSecToMySQLTime(seconds, m_time, timeZone());
dataconvert::gmtSecToMySQLTime(seconds, m_time, ct.getTimeZone());
dataconvert::DateTime dt;
dt.year = m_time.year;
dt.month = m_time.month;
@ -254,4 +254,3 @@ int64_t Func_extract::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& is
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -127,4 +127,3 @@ execplan::IDB_Decimal Func_find_in_set::getDecimalVal(rowgroup::Row& row, Functi
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -225,7 +225,7 @@ uint64_t Func_floor::getUintVal(Row& row, FunctionParm& parm, bool& isNull,
case execplan::CalpontSystemCatalog::TIMESTAMP:
{
string str =
DataConvert::timestampToString1(parm[0]->data()->getTimestampIntVal(row, isNull), timeZone());
DataConvert::timestampToString1(parm[0]->data()->getTimestampIntVal(row, isNull), op_ct.getTimeZone());
// strip off micro seconds
str = str.substr(0, 14);
@ -519,7 +519,7 @@ IDB_Decimal Func_floor::getDecimalVal(Row& row, FunctionParm& parm, bool& isNull
case execplan::CalpontSystemCatalog::TIMESTAMP:
{
string str =
DataConvert::timestampToString1(parm[0]->data()->getTimestampIntVal(row, isNull), timeZone());
DataConvert::timestampToString1(parm[0]->data()->getTimestampIntVal(row, isNull), op_ct.getTimeZone());
// strip off micro seconds
str = str.substr(0, 14);
@ -555,4 +555,3 @@ IDB_Decimal Func_floor::getDecimalVal(Row& row, FunctionParm& parm, bool& isNull
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -80,4 +80,3 @@ int64_t Func_from_days::getDatetimeIntVal(rowgroup::Row& row, FunctionParm& parm
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -212,4 +212,3 @@ long double Func_from_unixtime::getLongDoubleVal(rowgroup::Row& row, FunctionPar
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -107,4 +107,3 @@ string Func_get_format::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool&
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -240,4 +240,3 @@ int64_t Func_greatest::getTimeIntVal(rowgroup::Row& row, FunctionParm& fp, bool&
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -95,7 +95,7 @@ string Func_hex::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
if ((val <= (double)numeric_limits<int64_t>::min()) || (val >= (double)numeric_limits<int64_t>::max()))
dec = ~(int64_t)0;
else
dec = (uint64_t)(val + (val > 0 ? 0.5 : -0.5));
dec = static_cast<uint64_t>(static_cast<int64_t>(val + (val > 0 ? 0.5 : -0.5)));
retval = helpers::convNumToStr(dec, ans, 16);
break;
@ -140,4 +140,3 @@ string Func_hex::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -117,7 +117,7 @@ int64_t Func_hour::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isNul
dataconvert::TimeStamp timestamp(parm[0]->data()->getTimestampIntVal(row, isNull));
int64_t seconds = timestamp.second;
dataconvert::MySQLTime m_time;
dataconvert::gmtSecToMySQLTime(seconds, m_time, timeZone());
dataconvert::gmtSecToMySQLTime(seconds, m_time, op_ct.getTimeZone());
return m_time.hour;
}
@ -156,4 +156,3 @@ int64_t Func_hour::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isNul
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -63,4 +63,3 @@ string Func_idbpartition::getStrVal(Row& row, FunctionParm& parm, bool& isNull,
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -35,7 +35,7 @@ using namespace rowgroup;
namespace
{
bool boolVal(SPTP& parm, Row& row, const string& timeZone)
bool boolVal(SPTP& parm, Row& row, long timeZone)
{
bool ret = true;
bool isNull = false; // Keep it local. We don't want to mess with the global one here.
@ -122,9 +122,9 @@ CalpontSystemCatalog::ColType Func_if::operationType(FunctionParm& fp,
return ct;
}
int64_t Func_if::getIntVal(Row& row, FunctionParm& parm, bool& isNull, CalpontSystemCatalog::ColType&)
int64_t Func_if::getIntVal(Row& row, FunctionParm& parm, bool& isNull, CalpontSystemCatalog::ColType& ct)
{
if (boolVal(parm[0], row, timeZone()))
if (boolVal(parm[0], row, ct.getTimeZone()))
{
return parm[1]->data()->getIntVal(row, isNull);
}
@ -134,9 +134,9 @@ int64_t Func_if::getIntVal(Row& row, FunctionParm& parm, bool& isNull, CalpontSy
}
}
string Func_if::getStrVal(Row& row, FunctionParm& parm, bool& isNull, CalpontSystemCatalog::ColType&)
string Func_if::getStrVal(Row& row, FunctionParm& parm, bool& isNull, CalpontSystemCatalog::ColType& ct)
{
if (boolVal(parm[0], row, timeZone()))
if (boolVal(parm[0], row, ct.getTimeZone()))
{
return parm[1]->data()->getStrVal(row, isNull);
}
@ -146,9 +146,10 @@ string Func_if::getStrVal(Row& row, FunctionParm& parm, bool& isNull, CalpontSys
}
}
IDB_Decimal Func_if::getDecimalVal(Row& row, FunctionParm& parm, bool& isNull, CalpontSystemCatalog::ColType&)
IDB_Decimal Func_if::getDecimalVal(Row& row, FunctionParm& parm, bool& isNull,
CalpontSystemCatalog::ColType& ct)
{
if (boolVal(parm[0], row, timeZone()))
if (boolVal(parm[0], row, ct.getTimeZone()))
{
return parm[1]->data()->getDecimalVal(row, isNull);
}
@ -158,9 +159,9 @@ IDB_Decimal Func_if::getDecimalVal(Row& row, FunctionParm& parm, bool& isNull, C
}
}
double Func_if::getDoubleVal(Row& row, FunctionParm& parm, bool& isNull, CalpontSystemCatalog::ColType&)
double Func_if::getDoubleVal(Row& row, FunctionParm& parm, bool& isNull, CalpontSystemCatalog::ColType& ct)
{
if (boolVal(parm[0], row, timeZone()))
if (boolVal(parm[0], row, ct.getTimeZone()))
{
return parm[1]->data()->getDoubleVal(row, isNull);
}
@ -171,9 +172,9 @@ double Func_if::getDoubleVal(Row& row, FunctionParm& parm, bool& isNull, Calpont
}
long double Func_if::getLongDoubleVal(Row& row, FunctionParm& parm, bool& isNull,
CalpontSystemCatalog::ColType&)
CalpontSystemCatalog::ColType& ct)
{
if (boolVal(parm[0], row, timeZone()))
if (boolVal(parm[0], row, ct.getTimeZone()))
{
return parm[1]->data()->getLongDoubleVal(row, isNull);
}
@ -183,9 +184,9 @@ long double Func_if::getLongDoubleVal(Row& row, FunctionParm& parm, bool& isNull
}
}
int32_t Func_if::getDateIntVal(Row& row, FunctionParm& parm, bool& isNull, CalpontSystemCatalog::ColType&)
int32_t Func_if::getDateIntVal(Row& row, FunctionParm& parm, bool& isNull, CalpontSystemCatalog::ColType& ct)
{
if (boolVal(parm[0], row, timeZone()))
if (boolVal(parm[0], row, ct.getTimeZone()))
{
return parm[1]->data()->getDateIntVal(row, isNull);
}
@ -195,9 +196,10 @@ int32_t Func_if::getDateIntVal(Row& row, FunctionParm& parm, bool& isNull, Calpo
}
}
int64_t Func_if::getDatetimeIntVal(Row& row, FunctionParm& parm, bool& isNull, CalpontSystemCatalog::ColType&)
int64_t Func_if::getDatetimeIntVal(Row& row, FunctionParm& parm, bool& isNull,
CalpontSystemCatalog::ColType& ct)
{
if (boolVal(parm[0], row, timeZone()))
if (boolVal(parm[0], row, ct.getTimeZone()))
{
return parm[1]->data()->getDatetimeIntVal(row, isNull);
}
@ -208,9 +210,9 @@ int64_t Func_if::getDatetimeIntVal(Row& row, FunctionParm& parm, bool& isNull, C
}
int64_t Func_if::getTimestampIntVal(Row& row, FunctionParm& parm, bool& isNull,
CalpontSystemCatalog::ColType&)
CalpontSystemCatalog::ColType& ct)
{
if (boolVal(parm[0], row, timeZone()))
if (boolVal(parm[0], row, ct.getTimeZone()))
{
return parm[1]->data()->getTimestampIntVal(row, isNull);
}
@ -220,9 +222,9 @@ int64_t Func_if::getTimestampIntVal(Row& row, FunctionParm& parm, bool& isNull,
}
}
int64_t Func_if::getTimeIntVal(Row& row, FunctionParm& parm, bool& isNull, CalpontSystemCatalog::ColType&)
int64_t Func_if::getTimeIntVal(Row& row, FunctionParm& parm, bool& isNull, CalpontSystemCatalog::ColType& ct)
{
if (boolVal(parm[0], row, timeZone()))
if (boolVal(parm[0], row, ct.getTimeZone()))
{
return parm[1]->data()->getTimeIntVal(row, isNull);
}
@ -232,4 +234,3 @@ int64_t Func_if::getTimeIntVal(Row& row, FunctionParm& parm, bool& isNull, Calpo
}
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -205,4 +205,3 @@ bool Func_ifnull::getBoolVal(Row& row, FunctionParm& parm, bool& isNull, Calpont
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -386,4 +386,3 @@ bool Func_notin::getBoolVal(rowgroup::Row& row, FunctionParm& pm, bool& isNull,
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -102,4 +102,3 @@ std::string Func_insert::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& i
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -85,4 +85,3 @@ int64_t Func_instr::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isNu
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -79,4 +79,3 @@ bool Func_isnull::getBoolVal(Row& row, FunctionParm& parm, bool& isNull, Calpont
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -74,7 +74,7 @@ int64_t Func_last_day::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& i
TimeStamp timestamp(parm[0]->data()->getIntVal(row, isNull));
int64_t seconds = timestamp.second;
MySQLTime m_time;
gmtSecToMySQLTime(seconds, m_time, timeZone());
gmtSecToMySQLTime(seconds, m_time, op_ct.getTimeZone());
year = m_time.year;
month = m_time.month;
day = m_time.day;
@ -195,4 +195,3 @@ int64_t Func_last_day::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& i
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -64,4 +64,3 @@ std::string Func_lcase::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& is
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -218,4 +218,3 @@ int64_t Func_least::getTimeIntVal(rowgroup::Row& row, FunctionParm& fp, bool& is
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -73,4 +73,3 @@ std::string Func_left::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& isN
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -55,4 +55,3 @@ int64_t Func_length::getIntVal(rowgroup::Row& row, FunctionParm& fp, bool& isNul
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -127,4 +127,3 @@ std::string Func_lpad::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& isN
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -93,4 +93,3 @@ std::string Func_ltrim::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& is
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -97,4 +97,3 @@ std::string Func_ltrim_oracle::getStrVal(rowgroup::Row& row, FunctionParm& fp, b
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -190,4 +190,3 @@ string Func_makedate::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& is
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -171,4 +171,3 @@ string Func_maketime::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& is
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -1786,7 +1786,7 @@ string Func_format::getStrVal(Row& row, FunctionParm& parm, bool& isNull,
case execplan::CalpontSystemCatalog::TIMESTAMP:
{
value = dataconvert::DataConvert::timestampToString1(parm[0]->data()->getTimestampIntVal(row, isNull),
timeZone());
operationColType.getTimeZone());
}
break;
@ -2276,4 +2276,3 @@ double Func_degrees::getDoubleVal(Row& row, FunctionParm& parm, bool& isNull, Ca
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -512,4 +512,3 @@ string Func_md5::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -137,4 +137,3 @@ int64_t Func_microsecond::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -117,7 +117,7 @@ int64_t Func_minute::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isN
dataconvert::TimeStamp timestamp(parm[0]->data()->getTimestampIntVal(row, isNull));
int64_t seconds = timestamp.second;
dataconvert::MySQLTime m_time;
dataconvert::gmtSecToMySQLTime(seconds, m_time, timeZone());
dataconvert::gmtSecToMySQLTime(seconds, m_time, op_ct.getTimeZone());
return m_time.minute;
}
@ -137,4 +137,3 @@ int64_t Func_minute::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isN
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -531,4 +531,3 @@ std::string Func_mod::getStrVal(Row& row, FunctionParm& fp, bool& isNull,
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -63,7 +63,7 @@ int64_t Func_month::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isNu
dataconvert::TimeStamp timestamp(parm[0]->data()->getTimestampIntVal(row, isNull));
int64_t seconds = timestamp.second;
dataconvert::MySQLTime m_time;
dataconvert::gmtSecToMySQLTime(seconds, m_time, timeZone());
dataconvert::gmtSecToMySQLTime(seconds, m_time, op_ct.getTimeZone());
return m_time.month;
}
@ -142,4 +142,3 @@ int64_t Func_month::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isNu
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -45,7 +45,7 @@ CalpontSystemCatalog::ColType Func_monthname::operationType(FunctionParm& fp,
string Func_monthname::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
CalpontSystemCatalog::ColType& op_ct)
{
int32_t month = getIntVal(row, parm, isNull, op_ct);
int32_t month = getIntValInternal(row, parm, isNull, op_ct);
if (month == -1)
return "";
@ -74,8 +74,8 @@ int64_t Func_monthname::getTimestampIntVal(rowgroup::Row& row, FunctionParm& par
return val;
}
int64_t Func_monthname::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
CalpontSystemCatalog::ColType& op_ct)
int64_t Func_monthname::getIntValInternal(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
CalpontSystemCatalog::ColType& op_ct)
{
int64_t val = 0;
dataconvert::DateTime aDateTime;
@ -97,7 +97,7 @@ int64_t Func_monthname::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool&
dataconvert::TimeStamp timestamp(val);
int64_t seconds = timestamp.second;
dataconvert::MySQLTime time;
dataconvert::gmtSecToMySQLTime(seconds, time, timeZone());
dataconvert::gmtSecToMySQLTime(seconds, time, op_ct.getTimeZone());
return time.month;
}
@ -165,12 +165,20 @@ int64_t Func_monthname::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool&
break;
default: isNull = true; return -1;
default:
isNull = true;
return -1;
}
return -1;
}
int64_t Func_monthname::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
return getIntValInternal(row, parm, isNull, op_ct);
}
double Func_monthname::getDoubleVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
@ -191,4 +199,3 @@ execplan::IDB_Decimal Func_monthname::getDecimalVal(rowgroup::Row& row, Function
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -955,7 +955,8 @@ execplan::IDB_Decimal Func_nullif::getDecimalVal(rowgroup::Row& row, FunctionPar
string value;
if (parm[1]->data()->resultType().colDataType == execplan::CalpontSystemCatalog::TIMESTAMP)
value = DataConvert::timestampToString1(parm[1]->data()->getTimestampIntVal(row, isNull), timeZone());
value =
DataConvert::timestampToString1(parm[1]->data()->getTimestampIntVal(row, isNull), op_ct.getTimeZone());
else
value = DataConvert::datetimeToString1(parm[1]->data()->getDatetimeIntVal(row, isNull));
@ -963,7 +964,7 @@ execplan::IDB_Decimal Func_nullif::getDecimalVal(rowgroup::Row& row, FunctionPar
{
// strip off micro seconds
value = value.substr(0, 14);
int64_t x = atoll(value.c_str());
x = atoll(value.c_str());
if (s > 5)
s = 0;
@ -1021,4 +1022,3 @@ execplan::IDB_Decimal Func_nullif::getDecimalVal(rowgroup::Row& row, FunctionPar
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -94,4 +94,3 @@ int64_t Func_period_add::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool&
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -113,4 +113,3 @@ int64_t Func_period_diff::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -121,4 +121,3 @@ long double Func_pow::getLongDoubleVal(Row& row, FunctionParm& parm, bool& isNul
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -67,7 +67,7 @@ int64_t Func_quarter::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& is
dataconvert::TimeStamp timestamp(parm[0]->data()->getTimestampIntVal(row, isNull));
int64_t seconds = timestamp.second;
dataconvert::MySQLTime m_time;
dataconvert::gmtSecToMySQLTime(seconds, m_time, timeZone());
dataconvert::gmtSecToMySQLTime(seconds, m_time, op_ct.getTimeZone());
month = m_time.month;
break;
}
@ -139,4 +139,3 @@ int64_t Func_quarter::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& is
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -80,4 +80,3 @@ std::string Func_quote::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& is
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -98,4 +98,3 @@ double Func_rand::getDoubleVal(rowgroup::Row& row, FunctionParm& parm, bool& isN
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -28,7 +28,7 @@ using namespace std;
#ifdef __linux__
#include <regex.h>
#else
#include <boost/regex.hpp>
#include <regex>
using namespace boost;
#endif
@ -48,7 +48,7 @@ using namespace logging;
namespace
{
inline bool getBool(rowgroup::Row& row, funcexp::FunctionParm& pm, bool& isNull,
CalpontSystemCatalog::ColType& ct, const string& timeZone)
CalpontSystemCatalog::ColType& ct, long timeZone)
{
string expr;
string pattern;
@ -226,8 +226,8 @@ inline bool getBool(rowgroup::Row& row, funcexp::FunctionParm& pm, bool& isNull,
return false;
#else
regex pat(pattern.c_str());
return regex_search(expr.c_str(), pat);
std::regex pat(pattern.c_str());
return std::regex_search(expr.c_str(), pat);
#endif
}
@ -244,8 +244,7 @@ CalpontSystemCatalog::ColType Func_regexp::operationType(FunctionParm& fp,
bool Func_regexp::getBoolVal(rowgroup::Row& row, FunctionParm& pm, bool& isNull,
CalpontSystemCatalog::ColType& ct)
{
return getBool(row, pm, isNull, ct, timeZone()) && !isNull;
return getBool(row, pm, isNull, ct, ct.getTimeZone()) && !isNull;
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -90,4 +90,3 @@ std::string Func_repeat::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& i
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -173,4 +173,3 @@ std::string Func_replace::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool&
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -167,4 +167,3 @@ std::string Func_replace_oracle::getStrVal(rowgroup::Row& row, FunctionParm& fp,
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -93,4 +93,3 @@ std::string Func_reverse::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool&
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -73,4 +73,3 @@ std::string Func_right::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& is
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -41,6 +41,8 @@ using namespace logging;
#include "funchelpers.h"
#include "exceptclasses.h"
namespace
{
using namespace funcexp;
@ -136,18 +138,27 @@ int64_t Func_round::getIntVal(Row& row, FunctionParm& parm, bool& isNull,
uint64_t Func_round::getUintVal(Row& row, FunctionParm& parm, bool& isNull,
CalpontSystemCatalog::ColType& op_ct)
{
uint64_t x;
if (UNLIKELY(op_ct.colDataType == execplan::CalpontSystemCatalog::DATE))
IDB_Decimal x = getDecimalVal(row, parm, isNull, op_ct);
if (!op_ct.isWideDecimalType())
{
IDB_Decimal d = getDecimalVal(row, parm, isNull, op_ct);
x = static_cast<uint64_t>(d.value);
if (x.scale > 0)
{
while (x.scale-- > 0)
x.value /= 10;
}
else
{
while (x.scale++ < 0)
x.value *= 10;
}
return x.value;
}
else
{
x = parm[0]->data()->getUintVal(row, isNull);
return static_cast<uint64_t>(x.getIntegralPart());
}
return x;
}
double Func_round::getDoubleVal(Row& row, FunctionParm& parm, bool& isNull,
@ -434,10 +445,11 @@ IDB_Decimal Func_round::getDecimalVal(Row& row, FunctionParm& parm, bool& isNull
{
uint64_t x = parm[0]->data()->getUintVal(row, isNull);
if (x > (uint64_t)helpers::maxNumber_c[18])
{
x = helpers::maxNumber_c[18];
}
// why it is here at all???
// if (x > (uint64_t)helpers::maxNumber_c[18])
//{
// x = helpers::maxNumber_c[18];
//}
decimal.value = x;
decimal.scale = 0;
@ -569,7 +581,7 @@ IDB_Decimal Func_round::getDecimalVal(Row& row, FunctionParm& parm, bool& isNull
string value;
if (op_ct.colDataType == execplan::CalpontSystemCatalog::TIMESTAMP)
value = dataconvert::DataConvert::timestampToString1(parm[0]->data()->getTimestampIntVal(row, isNull),
timeZone());
op_ct.getTimeZone());
else
value = dataconvert::DataConvert::datetimeToString1(parm[0]->data()->getDatetimeIntVal(row, isNull));
@ -645,7 +657,7 @@ string Func_round::getStrVal(Row& row, FunctionParm& parm, bool& isNull, Calpont
{
IDB_Decimal x = getDecimalVal(row, parm, isNull, op_ct);
int64_t e = (x.scale < 0) ? (-x.scale) : x.scale;
int64_t p = 1;
[[maybe_unused]] int64_t p = 1;
while (e-- > 0)
p *= 10;
@ -709,5 +721,10 @@ int64_t Func_round::getDatetimeIntVal(Row& row, FunctionParm& parm, bool& isNull
return parm[0]->data()->getIntVal(row, isNull);
}
int64_t Func_round::getTimestampIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
return parm[0]->data()->getTimestampIntVal(row, isNull);
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -127,4 +127,3 @@ std::string Func_rpad::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& isN
}
} // namespace funcexp
// vim:ts=4 sw=4:

Some files were not shown because too many files have changed in this diff Show More