Fix empty TIME2 values

The values for TIME2 were always empty as they weren't processed.
This commit is contained in:
Markus Mäkelä 2017-12-13 11:25:47 +02:00
parent 49a5dd9390
commit bdcda0f235
2 changed files with 31 additions and 1 deletions

View File

@ -402,6 +402,32 @@ static void unpack_time(uint8_t *ptr, struct tm *dest)
dest->tm_sec = second;
}
/**
* @brief Unpack a TIME2
*
* The TIME2 is stored as a 3 byte value containing the integer parts plus
* the additional fractional parts as a trailing value. The
* integer parts of the time are extracted with the following algorithm:
*
* hours = (value >> 12) % (1 << 10)
* minutes = (value >> 6) % (1 << 6)
* seconds = value % (1 << 6)
*
* As the `struct tm` doesn't support fractional seconds, the fractional part
* is ignored.
*
* @param val Value read from the binary log
* @param dest Pointer where the unpacked value is stored
*/
static void unpack_time2(uint8_t *ptr, uint8_t decimals, struct tm *dest)
{
uint64_t val = unpack3(ptr) - DATETIME2_OFFSET;
memset(dest, 0, sizeof(struct tm));
dest->tm_hour = (val >> 12) % (1 << 10);
dest->tm_min = (val >> 6) % (1 << 6);
dest->tm_sec = val % (1 << 6);
}
/**
* @brief Unpack a DATE value
* @param ptr Pointer to packed value
@ -524,6 +550,10 @@ size_t unpack_temporal_value(uint8_t type, uint8_t *ptr, uint8_t *metadata, int
unpack_time(ptr, tm);
break;
case TABLE_COL_TYPE_TIME2:
unpack_time2(ptr, *metadata, tm);
break;
case TABLE_COL_TYPE_DATE:
unpack_date(ptr, tm);
break;

View File

@ -655,7 +655,7 @@ uint8_t* process_row_event_data(TABLE_MAP *map, TABLE_CREATE *create, avro_value
create->column_lengths[i], &tm);
format_temporal_value(buf, sizeof(buf), map->column_types[i], &tm);
avro_value_set_string(&field, buf);
MXS_INFO("[%ld] TEMPORAL: %s", i, buf);
MXS_INFO("[%ld] %s: %s", i, column_type_to_string(map->column_types[i]), buf);
ss_dassert(ptr < end);
}
/** All numeric types (INT, LONG, FLOAT etc.) */