forked from citusdata/cstore_fdw
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcstore_utils.c
59 lines (51 loc) · 1.49 KB
/
cstore_utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*-------------------------------------------------------------------------
*
* cstore_utils.c
*
* This file contains utility functions definitions for cstore
*
* Copyright (c) 2015, Citus Data, Inc.
*
* $Id$
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "cstore_fdw.h"
#include "cstore_utils.h"
/*
* This is a wrapper function on PostgreSQL's pglz_compress
* function, because PostgreSQL 9.5 changes the function signature.
*/
bool
cstore_pglz_compress(const char *source, int32 slen, PGLZ_Header *dest,
const PGLZ_Strategy *strategy)
{
#if PG_VERSION_NUM >= 90500
StringInfoData *info = (StringInfoData*)dest;
int compressedLength = 0;
char *bp = (char*)((unsigned char *) info) + sizeof(PGLZ_Header);
compressedLength = pglz_compress(source, slen, bp, strategy);
if (compressedLength <= 0)
return false;
dest->rawsize = slen;
SET_VARSIZE_COMPRESSED(dest, compressedLength + sizeof(PGLZ_Header));
#else
return pglz_compress(source, slen, dest, strategy);
#endif
return true;
}
/*
* This is a wrapper function on PostgreSQL's pglz_decompress
* function, because PostgreSQL 9.5 changes the function prototype.
*/
void
cstore_pglz_decompress(const PGLZ_Header *source, char *dest)
{
#if PG_VERSION_NUM >= 90500
char *sp = (char*)((const unsigned char *) source) + sizeof(PGLZ_Header);
pglz_decompress (sp, VARSIZE(source), dest, PGLZ_RAW_SIZE(source));
#else
pglz_decompress(source, dest);
#endif
}