Fix empty TIME2 values
The values for TIME2 were always empty as they weren't processed.
This commit is contained in:
@ -402,6 +402,32 @@ static void unpack_time(uint8_t *ptr, struct tm *dest)
|
|||||||
dest->tm_sec = second;
|
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
|
* @brief Unpack a DATE value
|
||||||
* @param ptr Pointer to packed 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);
|
unpack_time(ptr, tm);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case TABLE_COL_TYPE_TIME2:
|
||||||
|
unpack_time2(ptr, *metadata, tm);
|
||||||
|
break;
|
||||||
|
|
||||||
case TABLE_COL_TYPE_DATE:
|
case TABLE_COL_TYPE_DATE:
|
||||||
unpack_date(ptr, tm);
|
unpack_date(ptr, tm);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -655,7 +655,7 @@ uint8_t* process_row_event_data(TABLE_MAP *map, TABLE_CREATE *create, avro_value
|
|||||||
create->column_lengths[i], &tm);
|
create->column_lengths[i], &tm);
|
||||||
format_temporal_value(buf, sizeof(buf), map->column_types[i], &tm);
|
format_temporal_value(buf, sizeof(buf), map->column_types[i], &tm);
|
||||||
avro_value_set_string(&field, buf);
|
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);
|
ss_dassert(ptr < end);
|
||||||
}
|
}
|
||||||
/** All numeric types (INT, LONG, FLOAT etc.) */
|
/** All numeric types (INT, LONG, FLOAT etc.) */
|
||||||
|
|||||||
Reference in New Issue
Block a user