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

Merge pull request #2257 from tntnatbry/MCOL-4957

MCOL-4957 Fix performance slowdown for processing TIMESTAMP columns.
This commit is contained in:
Roman Nozdrin
2022-02-16 19:46:57 +02:00
committed by GitHub
120 changed files with 1022 additions and 695 deletions

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
@ -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;

View File

@ -289,6 +289,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 +304,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 +341,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 +357,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 +373,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 +511,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 +522,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 +595,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 +613,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 +1046,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 +1157,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 +1194,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 +1246,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 +1279,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 +1290,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 +1361,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 +1439,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

@ -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;

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);
}
}

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));
}
};

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);

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;

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();
}

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,

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;
}

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;

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,7 +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

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;
}

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;

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;

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;

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;

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);

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;
}

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);
}

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;

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;

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;
}

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;
}

View File

@ -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;
}

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));

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;
}

View File

@ -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;
@ -244,7 +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

View File

@ -569,7 +569,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));
@ -709,5 +709,11 @@ 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

@ -116,7 +116,7 @@ int64_t Func_second::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.second;
}

View File

@ -42,7 +42,7 @@ namespace
using namespace funcexp;
dataconvert::DateTime getDateTime(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
CalpontSystemCatalog::ColType& ct, const string& timeZone)
CalpontSystemCatalog::ColType& ct, long timeZone)
{
TimeExtractor extractor;
dataconvert::DateTime dateTime;
@ -186,7 +186,7 @@ string Func_str_to_date::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool&
CalpontSystemCatalog::ColType& ct)
{
dataconvert::DateTime dateTime;
dateTime = getDateTime(row, parm, isNull, ct, timeZone());
dateTime = getDateTime(row, parm, isNull, ct, ct.getTimeZone());
string convertedDate = dataconvert::DataConvert::datetimeToString(*((long long*)&dateTime));
return convertedDate;
}
@ -195,7 +195,7 @@ int32_t Func_str_to_date::getDateIntVal(rowgroup::Row& row, FunctionParm& parm,
CalpontSystemCatalog::ColType& ct)
{
dataconvert::DateTime dateTime;
dateTime = getDateTime(row, parm, isNull, ct, timeZone());
dateTime = getDateTime(row, parm, isNull, ct, ct.getTimeZone());
int64_t time = *(reinterpret_cast<int64_t*>(&dateTime));
return ((((int32_t)(time >> 32)) & 0xFFFFFFC0) | 0x3E);
}
@ -204,7 +204,7 @@ int64_t Func_str_to_date::getDatetimeIntVal(rowgroup::Row& row, FunctionParm& pa
CalpontSystemCatalog::ColType& ct)
{
dataconvert::DateTime dateTime;
dateTime = getDateTime(row, parm, isNull, ct, timeZone());
dateTime = getDateTime(row, parm, isNull, ct, ct.getTimeZone());
int64_t time = *(reinterpret_cast<int64_t*>(&dateTime));
return time;
}
@ -213,7 +213,7 @@ int64_t Func_str_to_date::getTimestampIntVal(rowgroup::Row& row, FunctionParm& p
CalpontSystemCatalog::ColType& ct)
{
dataconvert::DateTime dateTime;
dateTime = getDateTime(row, parm, isNull, ct, timeZone());
dateTime = getDateTime(row, parm, isNull, ct, ct.getTimeZone());
dataconvert::TimeStamp timestamp;
dataconvert::MySQLTime m_time;
m_time.year = dateTime.year;
@ -223,7 +223,7 @@ int64_t Func_str_to_date::getTimestampIntVal(rowgroup::Row& row, FunctionParm& p
m_time.minute = dateTime.minute;
m_time.second = dateTime.second;
bool isValid = true;
int64_t seconds = mySQLTimeToGmtSec(m_time, timeZone(), isValid);
int64_t seconds = mySQLTimeToGmtSec(m_time, ct.getTimeZone(), isValid);
if (!isValid)
{
timestamp = -1;
@ -243,7 +243,7 @@ int64_t Func_str_to_date::getTimeIntVal(rowgroup::Row& row, FunctionParm& parm,
{
dataconvert::DateTime dateTime;
dataconvert::Time retTime;
dateTime = getDateTime(row, parm, isNull, ct, timeZone());
dateTime = getDateTime(row, parm, isNull, ct, ct.getTimeZone());
retTime.day = 0;
retTime.is_neg = false;
retTime.hour = dateTime.hour;
@ -258,7 +258,7 @@ int64_t Func_str_to_date::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool
CalpontSystemCatalog::ColType& ct)
{
dataconvert::DateTime dateTime;
dateTime = getDateTime(row, parm, isNull, ct, timeZone());
dateTime = getDateTime(row, parm, isNull, ct, ct.getTimeZone());
int64_t time = *(reinterpret_cast<int64_t*>(&dateTime));
return time;
}

View File

@ -45,7 +45,7 @@ CalpontSystemCatalog::ColType Func_time::operationType(FunctionParm& fp,
}
string Func_time::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
CalpontSystemCatalog::ColType&)
CalpontSystemCatalog::ColType& ct)
{
int64_t val = 0;
@ -126,7 +126,7 @@ string Func_time::getStrVal(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, ct.getTimeZone());
dataconvert::Time time;
time.hour = m_time.hour;
time.minute = m_time.minute;

View File

@ -45,7 +45,7 @@ CalpontSystemCatalog::ColType Func_time_format::operationType(FunctionParm& fp,
}
string Func_time_format::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
CalpontSystemCatalog::ColType&)
CalpontSystemCatalog::ColType& ct)
{
// assume 256 is enough. assume not allowing incomplete date
char buf[256];
@ -72,7 +72,7 @@ string Func_time_format::getStrVal(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());
hour = m_time.hour;
min = m_time.minute;
sec = m_time.second;

View File

@ -70,7 +70,7 @@ int64_t Func_time_to_sec::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());
hour = time.hour;
min = time.minute;
sec = time.second;

View File

@ -142,16 +142,11 @@ string Func_timediff::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& is
case execplan::CalpontSystemCatalog::TIMESTAMP:
{
if (type1 != type2)
{
isNull = true;
break;
}
int64_t temp = parm[0]->data()->getTimestampIntVal(row, isNull);
dataconvert::TimeStamp timestamp(temp);
int64_t seconds = timestamp.second;
dataconvert::MySQLTime time;
dataconvert::gmtSecToMySQLTime(seconds, time, timeZone());
dataconvert::gmtSecToMySQLTime(seconds, time, ct.getTimeZone());
dataconvert::DateTime dt;
dt.year = time.year;
dt.month = time.month;
@ -239,7 +234,7 @@ string Func_timediff::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& is
dataconvert::TimeStamp timestamp(temp);
int64_t seconds = timestamp.second;
dataconvert::MySQLTime time;
dataconvert::gmtSecToMySQLTime(seconds, time, timeZone());
dataconvert::gmtSecToMySQLTime(seconds, time, ct.getTimeZone());
dataconvert::DateTime dt;
dt.year = time.year;
dt.month = time.month;
@ -328,7 +323,7 @@ int64_t Func_timediff::getDatetimeIntVal(rowgroup::Row& row, FunctionParm& parm,
int64_t Func_timediff::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());
}
int64_t Func_timediff::getTimeIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull,

View File

@ -55,7 +55,7 @@ int64_t Func_timestampdiff::getIntVal(rowgroup::Row& row, FunctionParm& parm, bo
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, op_ct.getTimeZone());
dt1.year = m_time.year;
dt1.month = m_time.month;
dt1.day = m_time.day;
@ -82,7 +82,7 @@ int64_t Func_timestampdiff::getIntVal(rowgroup::Row& row, FunctionParm& parm, bo
TimeStamp timestamp(parm[1]->data()->getTimestampIntVal(row, isNull));
int64_t seconds = timestamp.second;
MySQLTime m_time;
gmtSecToMySQLTime(seconds, m_time, timeZone());
gmtSecToMySQLTime(seconds, m_time, op_ct.getTimeZone());
dt2.year = m_time.year;
dt2.month = m_time.month;
dt2.day = m_time.day;

View File

@ -85,7 +85,7 @@ int64_t Func_to_days::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());
year = m_time.year;
month = m_time.month;
day = m_time.day;

View File

@ -560,7 +560,7 @@ IDB_Decimal Func_truncate::getDecimalVal(Row& row, FunctionParm& parm, bool& isN
int64_t x = 0;
string value =
DataConvert::timestampToString1(parm[0]->data()->getTimestampIntVal(row, isNull), timeZone());
DataConvert::timestampToString1(parm[0]->data()->getTimestampIntVal(row, isNull), op_ct.getTimeZone());
s = parm[1]->data()->getIntVal(row, isNull);
@ -714,5 +714,11 @@ string Func_truncate::getStrVal(Row& row, FunctionParm& parm, bool& isNull,
return x.toString(true);
}
int64_t Func_truncate::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

@ -76,7 +76,7 @@ int64_t Func_week::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());
year = m_time.year;
month = m_time.month;
day = m_time.day;

View File

@ -73,7 +73,7 @@ int64_t Func_weekday::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());
year = m_time.year;
month = m_time.month;
day = m_time.day;

View File

@ -63,7 +63,7 @@ int64_t Func_year::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isNul
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, op_ct.getTimeZone());
return m_time.year;
}

View File

@ -78,7 +78,7 @@ int64_t Func_yearweek::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& i
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, op_ct.getTimeZone());
year = m_time.year;
month = m_time.month;
day = m_time.day;

View File

@ -105,9 +105,9 @@ uint64_t Func::stringToDatetime(const string str)
return ret;
}
uint64_t Func::stringToTimestamp(const string str)
uint64_t Func::stringToTimestamp(const std::string& str, long timeZone)
{
int64_t ret = DataConvert::stringToTimestamp(str, timeZone());
int64_t ret = DataConvert::stringToTimestamp(str, timeZone);
if (ret == -1)
{

View File

@ -73,17 +73,6 @@ class Func
fFuncName = funcName;
}
const std::string timeZone() const
{
std::unique_lock<std::mutex> l(tzMutex);
return fTimeZone;
}
void timeZone(const std::string timeZone)
{
std::unique_lock<std::mutex> l(tzMutex);
fTimeZone = timeZone;
}
void raiseIllegalParameterDataTypeError(const execplan::CalpontSystemCatalog::ColType& colType) const
{
std::ostringstream oss;
@ -177,7 +166,7 @@ class Func
protected:
virtual uint32_t stringToDate(std::string);
virtual uint64_t stringToDatetime(std::string);
virtual uint64_t stringToTimestamp(std::string);
virtual uint64_t stringToTimestamp(const std::string&, long);
virtual int64_t stringToTime(std::string);
virtual uint32_t intToDate(int64_t);
@ -205,9 +194,6 @@ class Func
float fFloatNullVal;
double fDoubleNullVal;
long double fLongDoubleNullVal;
std::string fTimeZone;
mutable std::mutex tzMutex;
};
class ParmTSInt64 : public datatypes::TSInt64Null
@ -216,7 +202,7 @@ class ParmTSInt64 : public datatypes::TSInt64Null
ParmTSInt64()
{
}
ParmTSInt64(rowgroup::Row& row, const execplan::SPTP& parm, const funcexp::Func& thisFunc)
ParmTSInt64(rowgroup::Row& row, const execplan::SPTP& parm, const funcexp::Func& thisFunc, long timeZone)
: TSInt64Null(parm->data()->toTSInt64Null(row))
{
}
@ -228,7 +214,7 @@ class ParmTUInt64 : public datatypes::TUInt64Null
ParmTUInt64()
{
}
ParmTUInt64(rowgroup::Row& row, const execplan::SPTP& parm, const funcexp::Func& thisFunc)
ParmTUInt64(rowgroup::Row& row, const execplan::SPTP& parm, const funcexp::Func& thisFunc, long timeZone)
: TUInt64Null(parm->data()->toTUInt64Null(row))
{
}
@ -240,8 +226,8 @@ class Arg2Lazy
public:
TA a;
TB b;
Arg2Lazy(rowgroup::Row& row, FunctionParm& parm, const Func& thisFunc)
: a(row, parm[0], thisFunc), b(a.isNull() ? TB() : TB(row, parm[1], thisFunc))
Arg2Lazy(rowgroup::Row& row, FunctionParm& parm, const Func& thisFunc, long timeZone)
: a(row, parm[0], thisFunc, timeZone), b(a.isNull() ? TB() : TB(row, parm[1], thisFunc, timeZone))
{
}
};
@ -252,8 +238,8 @@ class Arg2Eager
public:
TA a;
TB b;
Arg2Eager(rowgroup::Row& row, FunctionParm& parm, const Func& thisFunc)
: a(row, parm[0], thisFunc), b(row, parm[1], thisFunc)
Arg2Eager(rowgroup::Row& row, FunctionParm& parm, const Func& thisFunc, long timeZone)
: a(row, parm[0], thisFunc, timeZone), b(row, parm[1], thisFunc, timeZone)
{
}
};

View File

@ -180,6 +180,9 @@ class Func_round : public Func_Real
int64_t getDatetimeIntVal(rowgroup::Row& row, FunctionParm& fp, bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
int64_t getTimestampIntVal(rowgroup::Row& row, FunctionParm& fp, bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
};
/** @brief Func_truncate class
@ -214,6 +217,9 @@ class Func_truncate : public Func_Real
execplan::IDB_Decimal getDecimalVal(rowgroup::Row& row, FunctionParm& fp, bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
int64_t getTimestampIntVal(rowgroup::Row& row, FunctionParm& fp, bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
};
/** @brief Func_ceil class

View File

@ -94,7 +94,7 @@ class Func_Str : public Func
execplan::CalpontSystemCatalog::ColType& op_ct)
{
std::string str = getStrVal(row, fp, isNull, op_ct);
return (isNull ? 0 : stringToTimestamp(str));
return (isNull ? 0 : stringToTimestamp(str, op_ct.getTimeZone()));
}
int64_t getTimeIntVal(rowgroup::Row& row, FunctionParm& fp, bool& isNull,

View File

@ -1,6 +1,6 @@
/*
Copyright (C) 2014 InfiniDB, Inc.
Copyright (c) 2019-2020 MariaDB Corporation
Copyright (c) 2019-2021 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -1567,7 +1567,8 @@ void RowAggregation::serialize(messageqcpp::ByteStream& bs) const
for (uint64_t i = 0; i < functionCount; i++)
fFunctionCols[i]->serialize(bs);
bs << fTimeZone;
messageqcpp::ByteStream::octbyte timeZone = fTimeZone;
bs << timeZone;
}
//------------------------------------------------------------------------------
@ -1612,7 +1613,9 @@ void RowAggregation::deserialize(messageqcpp::ByteStream& bs)
fFunctionCols.push_back(funct);
}
bs >> fTimeZone;
messageqcpp::ByteStream::octbyte timeZone;
bs >> timeZone;
fTimeZone = timeZone;
}
//------------------------------------------------------------------------------

View File

@ -338,7 +338,7 @@ struct GroupConcat
std::vector<std::pair<int, bool>> fOrderCond; // position to order by [asc/desc]
joblist::ResourceManager* fRm; // resource manager
boost::shared_ptr<int64_t> fSessionMemLimit;
std::string fTimeZone;
long fTimeZone;
GroupConcat() : fRm(nullptr)
{
@ -505,11 +505,11 @@ class RowAggregation : public messageqcpp::Serializeable
return fAggMapKeyCount;
}
inline void timeZone(const std::string& timeZone)
inline void timeZone(long timeZone)
{
fTimeZone = timeZone;
}
inline const std::string& timeZone() const
inline long timeZone() const
{
return fTimeZone;
}
@ -598,7 +598,7 @@ class RowAggregation : public messageqcpp::Serializeable
bool fKeyOnHeap = false;
std::string fTimeZone;
long fTimeZone;
// We need a separate copy for each thread.
mcsv1sdk::mcsv1Context fRGContext;