You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-08 14:22:09 +03:00
MCOL-392 Add DATETIME microscond support
Add initial microsecond support for DATETIME
This commit is contained in:
@@ -1114,10 +1114,11 @@ literal:
|
|||||||
;
|
;
|
||||||
|
|
||||||
datetime_type:
|
datetime_type:
|
||||||
DATETIME
|
DATETIME opt_time_precision
|
||||||
{
|
{
|
||||||
$$ = new ColumnType(DDL_DATETIME);
|
$$ = new ColumnType(DDL_DATETIME);
|
||||||
$$->fLength = DDLDatatypeLength[DDL_DATETIME];
|
$$->fLength = DDLDatatypeLength[DDL_DATETIME];
|
||||||
|
$$->fPrecision = $2;
|
||||||
}
|
}
|
||||||
|
|
|
|
||||||
DATE
|
DATE
|
||||||
|
@@ -838,11 +838,21 @@ int ha_calpont_impl_write_batch_row_(uchar* buf, TABLE* table, cal_impl_if::cal_
|
|||||||
// mariadb 10.1 compatibility -- MYSQL_TYPE_DATETIME2 introduced in mysql 5.6
|
// mariadb 10.1 compatibility -- MYSQL_TYPE_DATETIME2 introduced in mysql 5.6
|
||||||
MYSQL_TIME ltime;
|
MYSQL_TIME ltime;
|
||||||
const uchar* pos = buf;
|
const uchar* pos = buf;
|
||||||
longlong tmp = my_datetime_packed_from_binary(pos, 0);
|
longlong tmp = my_datetime_packed_from_binary(pos, table->field[colpos]->decimals());
|
||||||
TIME_from_longlong_datetime_packed(<ime, tmp);
|
TIME_from_longlong_datetime_packed(<ime, tmp);
|
||||||
fprintf(ci.filePtr, "%04d-%02d-%02d %02d:%02d:%02d%c",
|
if (!ltime.second_part)
|
||||||
ltime.year, ltime.month, ltime.day,
|
{
|
||||||
ltime.hour, ltime.minute, ltime.second, ci.delimiter);
|
fprintf(ci.filePtr, "%04d-%02d-%02d %02d:%02d:%02d%c",
|
||||||
|
ltime.year, ltime.month, ltime.day,
|
||||||
|
ltime.hour, ltime.minute, ltime.second, ci.delimiter);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(ci.filePtr, "%04d-%02d-%02d %02d:%02d:%02d.%ld%c",
|
||||||
|
ltime.year, ltime.month, ltime.day,
|
||||||
|
ltime.hour, ltime.minute, ltime.second,
|
||||||
|
ltime.second_part, ci.delimiter);
|
||||||
|
}
|
||||||
buf += table->field[colpos]->pack_length();
|
buf += table->field[colpos]->pack_length();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -486,8 +486,8 @@ int fetchNextRow(uchar* buf, cal_table_info& ti, cal_connection_info* ci)
|
|||||||
* based on the result set.
|
* based on the result set.
|
||||||
*/
|
*/
|
||||||
/* MCOL-683: UTF-8 datetime no msecs is 57, this sometimes happens! */
|
/* MCOL-683: UTF-8 datetime no msecs is 57, this sometimes happens! */
|
||||||
if (((*f)->field_length > 19) && ((*f)->field_length != 57))
|
// if (((*f)->field_length > 19) && ((*f)->field_length != 57))
|
||||||
(*f)->field_length = strlen(tmp);
|
// (*f)->field_length = strlen(tmp);
|
||||||
|
|
||||||
Field_varstring* f2 = (Field_varstring*)*f;
|
Field_varstring* f2 = (Field_varstring*)*f;
|
||||||
f2->store(tmp, strlen(tmp), f2->charset());
|
f2->store(tmp, strlen(tmp), f2->charset());
|
||||||
|
@@ -1717,14 +1717,28 @@ std::string DataConvert::dateToString( int datevalue )
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DataConvert::datetimeToString( long long datetimevalue )
|
std::string DataConvert::datetimeToString( long long datetimevalue, long decimals )
|
||||||
{
|
{
|
||||||
|
// 10 is default which means we don't need microseconds
|
||||||
|
if (decimals > 6 || decimals < 0)
|
||||||
|
{
|
||||||
|
decimals = 0;
|
||||||
|
}
|
||||||
// @bug 4703 abandon multiple ostringstream's for conversion
|
// @bug 4703 abandon multiple ostringstream's for conversion
|
||||||
DateTime dt(datetimevalue);
|
DateTime dt(datetimevalue);
|
||||||
const int DATETIMETOSTRING_LEN = 21; // YYYY-MM-DD HH:MM:SS\0
|
const int DATETIMETOSTRING_LEN = 28; // YYYY-MM-DD HH:MM:SS.mmmmmm\0
|
||||||
char buf[DATETIMETOSTRING_LEN];
|
char buf[DATETIMETOSTRING_LEN];
|
||||||
|
|
||||||
sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d", dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
|
sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d", dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
|
||||||
|
if (dt.msecond && decimals)
|
||||||
|
{
|
||||||
|
snprintf(buf + strlen(buf), 21 + decimals, ".%d", dt.msecond);
|
||||||
|
// Pad end with zeros
|
||||||
|
if (strlen(buf) < (21 + decimals))
|
||||||
|
{
|
||||||
|
sprintf(buf + strlen(buf), "%0*d", 21 + decimals - strlen(buf), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -361,7 +361,7 @@ public:
|
|||||||
* @param type the columns database type
|
* @param type the columns database type
|
||||||
* @param data the columns string representation of it's data
|
* @param data the columns string representation of it's data
|
||||||
*/
|
*/
|
||||||
EXPORT static std::string datetimeToString( long long datetimevalue );
|
EXPORT static std::string datetimeToString( long long datetimevalue, long decimals = 0 );
|
||||||
static inline void datetimeToString( long long datetimevalue, char* buf, unsigned int buflen );
|
static inline void datetimeToString( long long datetimevalue, char* buf, unsigned int buflen );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -459,14 +459,29 @@ inline void DataConvert::dateToString( int datevalue, char* buf, unsigned int bu
|
|||||||
|
|
||||||
inline void DataConvert::datetimeToString( long long datetimevalue, char* buf, unsigned int buflen )
|
inline void DataConvert::datetimeToString( long long datetimevalue, char* buf, unsigned int buflen )
|
||||||
{
|
{
|
||||||
snprintf( buf, buflen, "%04d-%02d-%02d %02d:%02d:%02d",
|
if ((datetimevalue & 0xfffff) > 0)
|
||||||
(unsigned)((datetimevalue >> 48) & 0xffff),
|
{
|
||||||
(unsigned)((datetimevalue >> 44) & 0xf),
|
snprintf( buf, buflen, "%04d-%02d-%02d %02d:%02d:%02d.%d",
|
||||||
(unsigned)((datetimevalue >> 38) & 0x3f),
|
(unsigned)((datetimevalue >> 48) & 0xffff),
|
||||||
(unsigned)((datetimevalue >> 32) & 0x3f),
|
(unsigned)((datetimevalue >> 44) & 0xf),
|
||||||
(unsigned)((datetimevalue >> 26) & 0x3f),
|
(unsigned)((datetimevalue >> 38) & 0x3f),
|
||||||
(unsigned)((datetimevalue >> 20) & 0x3f)
|
(unsigned)((datetimevalue >> 32) & 0x3f),
|
||||||
);
|
(unsigned)((datetimevalue >> 26) & 0x3f),
|
||||||
|
(unsigned)((datetimevalue >> 20) & 0x3f),
|
||||||
|
(unsigned)((datetimevalue) & 0xfffff)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf( buf, buflen, "%04d-%02d-%02d %02d:%02d:%02d",
|
||||||
|
(unsigned)((datetimevalue >> 48) & 0xffff),
|
||||||
|
(unsigned)((datetimevalue >> 44) & 0xf),
|
||||||
|
(unsigned)((datetimevalue >> 38) & 0x3f),
|
||||||
|
(unsigned)((datetimevalue >> 32) & 0x3f),
|
||||||
|
(unsigned)((datetimevalue >> 26) & 0x3f),
|
||||||
|
(unsigned)((datetimevalue >> 20) & 0x3f)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void DataConvert::dateToString1( int datevalue, char* buf, unsigned int buflen)
|
inline void DataConvert::dateToString1( int datevalue, char* buf, unsigned int buflen)
|
||||||
|
@@ -2977,7 +2977,7 @@ uint8_t WE_DMLCommandProc::processUpdate(messageqcpp::ByteStream& bs,
|
|||||||
case CalpontSystemCatalog::DATETIME:
|
case CalpontSystemCatalog::DATETIME:
|
||||||
{
|
{
|
||||||
intColVal = row.getUintField<8>(fetchColPos);
|
intColVal = row.getUintField<8>(fetchColPos);
|
||||||
value = DataConvert::datetimeToString(intColVal);
|
value = DataConvert::datetimeToString(intColVal, colType.precision);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3305,7 +3305,7 @@ uint8_t WE_DMLCommandProc::processUpdate(messageqcpp::ByteStream& bs,
|
|||||||
case CalpontSystemCatalog::DATETIME:
|
case CalpontSystemCatalog::DATETIME:
|
||||||
{
|
{
|
||||||
intColVal = row.getUintField<8>(fetchColPos);
|
intColVal = row.getUintField<8>(fetchColPos);
|
||||||
value = DataConvert::datetimeToString(intColVal);
|
value = DataConvert::datetimeToString(intColVal, colType.precision);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user