Adding timestamp oid support
parent
f9d69b3f1f
commit
be9ef38f1d
|
@ -1,7 +1,7 @@
|
||||||
package decoderbufs;
|
package decoderbufs;
|
||||||
|
|
||||||
option java_package="dedoderbufs.proto";
|
option java_package="dedoderbufs.proto";
|
||||||
option java_outer_classname = "TxnProto";
|
option java_outer_classname = "PgldProto";
|
||||||
option optimize_for = SPEED;
|
option optimize_for = SPEED;
|
||||||
|
|
||||||
enum Op {
|
enum Op {
|
||||||
|
|
|
@ -61,7 +61,7 @@ typedef struct {
|
||||||
bool debug_mode;
|
bool debug_mode;
|
||||||
} DecoderData;
|
} DecoderData;
|
||||||
|
|
||||||
/* These must be available to pg_dlsym() */
|
/* these must be available to pg_dlsym() */
|
||||||
extern void _PG_init(void);
|
extern void _PG_init(void);
|
||||||
extern void _PG_output_plugin_init(OutputPluginCallbacks *cb);
|
extern void _PG_output_plugin_init(OutputPluginCallbacks *cb);
|
||||||
|
|
||||||
|
@ -134,7 +134,8 @@ static void pg_decode_shutdown(LogicalDecodingContext *ctx) {
|
||||||
|
|
||||||
/* BEGIN callback */
|
/* BEGIN callback */
|
||||||
static void pg_decode_begin_txn(LogicalDecodingContext *ctx,
|
static void pg_decode_begin_txn(LogicalDecodingContext *ctx,
|
||||||
ReorderBufferTXN *txn) {}
|
ReorderBufferTXN *txn) {
|
||||||
|
}
|
||||||
|
|
||||||
/* COMMIT callback */
|
/* COMMIT callback */
|
||||||
static void pg_decode_commit_txn(LogicalDecodingContext *ctx,
|
static void pg_decode_commit_txn(LogicalDecodingContext *ctx,
|
||||||
|
@ -180,6 +181,7 @@ static void free_row_msg_subs(Decoderbufs__RowMessage *msg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* only used for debug-mode (currently not all OIDs are currently supported) */
|
||||||
static void print_tuple_msg(StringInfo out, Decoderbufs__DatumMessage **tup,
|
static void print_tuple_msg(StringInfo out, Decoderbufs__DatumMessage **tup,
|
||||||
size_t n) {
|
size_t n) {
|
||||||
if (tup) {
|
if (tup) {
|
||||||
|
@ -205,6 +207,8 @@ static void print_tuple_msg(StringInfo out, Decoderbufs__DatumMessage **tup,
|
||||||
appendStringInfo(out, ", datum[%f]", dmsg->datum_double);
|
appendStringInfo(out, ", datum[%f]", dmsg->datum_double);
|
||||||
break;
|
break;
|
||||||
case TEXTOID:
|
case TEXTOID:
|
||||||
|
case TIMESTAMPOID:
|
||||||
|
case TIMESTAMPTZOID:
|
||||||
appendStringInfo(out, ", datum[%s]", dmsg->datum_string);
|
appendStringInfo(out, ", datum[%s]", dmsg->datum_string);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -239,10 +243,10 @@ static double numeric_to_double_no_overflow(Numeric num) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set a datum value based on its OID specified by typid */
|
||||||
static void set_datum_value(Decoderbufs__DatumMessage *datum_msg, Oid typid,
|
static void set_datum_value(Decoderbufs__DatumMessage *datum_msg, Oid typid,
|
||||||
Oid typoutput, Datum datum) {
|
Oid typoutput, Datum datum) {
|
||||||
Numeric num;
|
Numeric num;
|
||||||
char c;
|
|
||||||
bytea *valptr;
|
bytea *valptr;
|
||||||
char *output;
|
char *output;
|
||||||
switch (typid) {
|
switch (typid) {
|
||||||
|
@ -279,14 +283,18 @@ static void set_datum_value(Decoderbufs__DatumMessage *datum_msg, Oid typid,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CHAROID:
|
case CHAROID:
|
||||||
c = DatumGetChar(datum);
|
|
||||||
datum_msg->datum_string = &c;
|
|
||||||
break;
|
|
||||||
case VARCHAROID:
|
case VARCHAROID:
|
||||||
|
case BPCHAROID:
|
||||||
case TEXTOID:
|
case TEXTOID:
|
||||||
|
case JSONOID:
|
||||||
|
case XMLOID:
|
||||||
output = OidOutputFunctionCall(typoutput, datum);
|
output = OidOutputFunctionCall(typoutput, datum);
|
||||||
datum_msg->datum_string = pnstrdup(output, strlen(output));
|
datum_msg->datum_string = pnstrdup(output, strlen(output));
|
||||||
break;
|
break;
|
||||||
|
case TIMESTAMPOID:
|
||||||
|
case TIMESTAMPTZOID:
|
||||||
|
datum_msg->datum_string = pstrdup(timestamptz_to_str(DatumGetTimestampTz(datum)));
|
||||||
|
break;
|
||||||
case BYTEAOID:
|
case BYTEAOID:
|
||||||
valptr = DatumGetByteaPCopy(datum);
|
valptr = DatumGetByteaPCopy(datum);
|
||||||
int size = VARSIZE(valptr);
|
int size = VARSIZE(valptr);
|
||||||
|
@ -307,6 +315,7 @@ static void set_datum_value(Decoderbufs__DatumMessage *datum_msg, Oid typid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* convert a PG tuple to an array of DatumMessage(s) */
|
||||||
static void tuple_to_tuple_msg(Decoderbufs__DatumMessage **tmsg,
|
static void tuple_to_tuple_msg(Decoderbufs__DatumMessage **tmsg,
|
||||||
Relation relation, HeapTuple tuple,
|
Relation relation, HeapTuple tuple,
|
||||||
TupleDesc tupdesc) {
|
TupleDesc tupdesc) {
|
||||||
|
@ -340,7 +349,7 @@ static void tuple_to_tuple_msg(Decoderbufs__DatumMessage **tmsg,
|
||||||
|
|
||||||
Oid typoutput;
|
Oid typoutput;
|
||||||
bool typisvarlena;
|
bool typisvarlena;
|
||||||
/* Query output function */
|
/* query output function */
|
||||||
getTypeOutputInfo(attr->atttypid, &typoutput, &typisvarlena);
|
getTypeOutputInfo(attr->atttypid, &typoutput, &typisvarlena);
|
||||||
if (!isnull) {
|
if (!isnull) {
|
||||||
if (typisvarlena && VARATT_IS_EXTERNAL_ONDISK(origval)) {
|
if (typisvarlena && VARATT_IS_EXTERNAL_ONDISK(origval)) {
|
||||||
|
@ -359,9 +368,7 @@ static void tuple_to_tuple_msg(Decoderbufs__DatumMessage **tmsg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* callback for individual changed tuples */
|
||||||
* callback for individual changed tuples
|
|
||||||
*/
|
|
||||||
static void pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
|
static void pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
|
||||||
Relation relation, ReorderBufferChange *change) {
|
Relation relation, ReorderBufferChange *change) {
|
||||||
DecoderData *data;
|
DecoderData *data;
|
||||||
|
|
Loading…
Reference in New Issue