|
4 | 4 | #include "postgres.h"
|
5 | 5 | #include "fmgr.h"
|
6 | 6 |
|
7 |
| -#include "access/compression.h" |
| 7 | +#include "access/cmapi.h" |
8 | 8 | #include "access/htup_details.h"
|
9 | 9 | #include "access/sysattr.h"
|
10 | 10 | #include "access/xact.h"
|
@@ -643,7 +643,7 @@ packJsonbValue(JsonbValue *val, int header_size, int *len)
|
643 | 643 |
|
644 | 644 | /* Compress jsonb using dictionary */
|
645 | 645 | static struct varlena *
|
646 |
| -jsonbd_compress(CompressionMethodOptions *cmoptions, const struct varlena *data) |
| 646 | +jsonbd_cmcompress(CompressionAmOptions *cmoptions, const struct varlena *data) |
647 | 647 | {
|
648 | 648 | int size;
|
649 | 649 | JsonbIteratorToken r;
|
@@ -712,7 +712,7 @@ jsonbd_compress(CompressionMethodOptions *cmoptions, const struct varlena *data)
|
712 | 712 | Assert(offset == len);
|
713 | 713 |
|
714 | 714 | /* retrieve or generate ids */
|
715 |
| - jsonbd_worker_get_key_ids(cmoptions->cmoptoid, buf, len, idsbuf, nkeys); |
| 715 | + jsonbd_worker_get_key_ids(cmoptions->acoid, buf, len, idsbuf, nkeys); |
716 | 716 |
|
717 | 717 | /* replace the old keys with encoded ids */
|
718 | 718 | for (i = 0; i < nkeys; i++)
|
@@ -740,21 +740,23 @@ jsonbd_compress(CompressionMethodOptions *cmoptions, const struct varlena *data)
|
740 | 740 | return res;
|
741 | 741 | }
|
742 | 742 |
|
743 |
| -static void |
744 |
| -jsonbd_configure(Form_pg_attribute attr, List *options) |
| 743 | +static void * |
| 744 | +jsonbd_cminitstate(Oid acoid, List *options) |
745 | 745 | {
|
746 | 746 | if (!OidIsValid(jsonbd_get_dictionary_relid()))
|
747 | 747 | elog(ERROR, "could not create jsonbd dictionary");
|
| 748 | + |
| 749 | + return NULL; |
748 | 750 | }
|
749 | 751 |
|
750 | 752 | static void
|
751 |
| -jsonbd_drop(Form_pg_attribute attr, List *options) |
| 753 | +jsonbd_cmdrop(Oid acoid) |
752 | 754 | {
|
753 | 755 | /* TODO: if there is no compression options, remove the dictionary */
|
754 | 756 | }
|
755 | 757 |
|
756 | 758 | static struct varlena *
|
757 |
| -jsonbd_decompress(CompressionMethodOptions *cmoptions, const struct varlena *data) |
| 759 | +jsonbd_cmdecompress(CompressionAmOptions *cmoptions, const struct varlena *data) |
758 | 760 | {
|
759 | 761 | JsonbIteratorToken r;
|
760 | 762 | JsonbValue v,
|
@@ -802,7 +804,7 @@ jsonbd_decompress(CompressionMethodOptions *cmoptions, const struct varlena *dat
|
802 | 804 | }
|
803 | 805 |
|
804 | 806 | /* retrieve keys */
|
805 |
| - buf = jsonbd_worker_get_keys(cmoptions->cmoptoid, compression_buffers->idsbuf, nkeys, &buflen); |
| 807 | + buf = jsonbd_worker_get_keys(cmoptions->acoid, compression_buffers->idsbuf, nkeys, &buflen); |
806 | 808 | if (buf == NULL)
|
807 | 809 | elog(ERROR, "jsonbd: decompression error");
|
808 | 810 |
|
@@ -830,21 +832,24 @@ jsonbd_decompress(CompressionMethodOptions *cmoptions, const struct varlena *dat
|
830 | 832 | return res;
|
831 | 833 | }
|
832 | 834 |
|
| 835 | +static void |
| 836 | +jsonbd_cmcheck(Form_pg_attribute att, List *options) |
| 837 | +{ |
| 838 | + if (att->atttypid != JSONBOID) |
| 839 | + elog(ERROR, "unexpected type %d for jsonbd compression handler", |
| 840 | + att->atttypid); |
| 841 | +} |
| 842 | + |
833 | 843 | Datum
|
834 | 844 | jsonbd_compression_handler(PG_FUNCTION_ARGS)
|
835 | 845 | {
|
836 |
| - CompressionMethodRoutine *cmr = makeNode(CompressionMethodRoutine); |
837 |
| - CompressionMethodOpArgs *opargs = |
838 |
| - (CompressionMethodOpArgs *) PG_GETARG_POINTER(0); |
839 |
| - Oid typeid = opargs->typeid; |
840 |
| - |
841 |
| - if (OidIsValid(typeid) && typeid != JSONBOID) |
842 |
| - elog(ERROR, "unexpected type %d for jsonbd compression handler", typeid); |
| 846 | + CompressionAmRoutine *routine = makeNode(CompressionAmRoutine); |
843 | 847 |
|
844 |
| - cmr->configure = jsonbd_configure; |
845 |
| - cmr->drop = jsonbd_drop; |
846 |
| - cmr->compress = jsonbd_compress; |
847 |
| - cmr->decompress = jsonbd_decompress; |
| 848 | + routine->cmcheck = jsonbd_cmcheck; |
| 849 | + routine->cmdrop = jsonbd_cmdrop; /* no drop behavior */ |
| 850 | + routine->cminitstate = jsonbd_cminitstate; |
| 851 | + routine->cmcompress = jsonbd_cmcompress; |
| 852 | + routine->cmdecompress = jsonbd_cmdecompress; |
848 | 853 |
|
849 |
| - PG_RETURN_POINTER(cmr); |
| 854 | + PG_RETURN_POINTER(routine); |
850 | 855 | }
|
0 commit comments