Skip to content

Commit

Permalink
Merge pull request #83 from citusdata/develop
Browse files Browse the repository at this point in the history
version 1.4
  • Loading branch information
mtuncer committed Jan 15, 2016
2 parents 30ca458 + c8c4b2f commit 31fe102
Show file tree
Hide file tree
Showing 16 changed files with 525 additions and 116 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@ env:
matrix:
- PGVERSION=9.3
- PGVERSION=9.4
- PGVERSION=9.5
before_install:
- sudo apt-get update -qq
- sudo update-alternatives --remove-all postmaster.1.gz
- git clone --depth 1 https://gist.github.com/9963879.git tools
- tools/nuke_pg.sh
- git clone --depth 1 https://github.com/citusdata/tools.git
- tools/travis/nuke_pg.sh
install:
- sudo apt-get install protobuf-c-compiler
- sudo apt-get install libprotobuf-c0-dev
- sudo locale-gen da_DK
- sudo locale-gen da_DK.utf8
- sudo pip install cpp-coveralls
- tools/install_pg.sh
- tools/travis/install_pg.sh
before_script:
- chmod 777 .
- chmod 777 data
- chmod 666 data/*
- tools/config_and_start_cluster.sh
script: tools/pg_travis_test.sh
- tools/travis/config_and_start_cluster.sh
script: tools/travis/pg_travis_test.sh
after_success:
- sudo chmod 666 *.gcda
- coveralls --exclude cstore.pb-c.c --exclude cstore.pb-c.h
6 changes: 3 additions & 3 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"name": "cstore_fdw",
"abstract": "Columnar Store for PostgreSQL",
"description": "PostgreSQL extension which implements a Columnar Store.",
"version": "1.3.0",
"version": "1.4.0",
"maintainer": "Murat Tuncer <mtuncer@citusdata.com>",
"license": "apache_2_0",
"provides": {
"cstore_fdw": {
"abstract": "Foreign Data Wrapper for Columnar Store Tables",
"file": "cstore_fdw--1.3.sql",
"file": "cstore_fdw--1.4.sql",
"docfile": "README.md",
"version": "1.3.0"
"version": "1.4.0"
}
},
"prereqs": {
Expand Down
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# cstore_fdw/Makefile
#
# Copyright (c) 2015 Citus Data, Inc.
# Copyright (c) 2016 Citus Data, Inc.
#

MODULE_big = cstore_fdw

PG_CPPFLAGS = --std=c99
SHLIB_LINK = -lprotobuf-c
OBJS = cstore.pb-c.o cstore_fdw.o cstore_writer.o cstore_reader.o \
cstore_metadata_serialization.o
cstore_metadata_serialization.o cstore_compression.o

EXTENSION = cstore_fdw
DATA = cstore_fdw--1.3.sql cstore_fdw--1.2--1.3.sql cstore_fdw--1.1--1.2.sql \
cstore_fdw--1.0--1.1.sql
DATA = cstore_fdw--1.4.sql cstore_fdw--1.3--1.4.sql cstore_fdw--1.2--1.3.sql \
cstore_fdw--1.1--1.2.sql cstore_fdw--1.0--1.1.sql

REGRESS = create load query analyze data_types functions block_filtering drop \
insert copyto alter
insert copyto alter truncate
EXTRA_CLEAN = cstore.pb-c.h cstore.pb-c.c data/*.cstore data/*.cstore.footer \
sql/block_filtering.sql sql/create.sql sql/data_types.sql sql/load.sql \
sql/copyto.sql expected/block_filtering.out expected/create.out \
Expand All @@ -40,8 +40,8 @@ ifndef MAJORVERSION
MAJORVERSION := $(basename $(VERSION))
endif

ifeq (,$(findstring $(MAJORVERSION), 9.3 9.4))
$(error PostgreSQL 9.3 or 9.4 is required to compile this extension)
ifeq (,$(findstring $(MAJORVERSION), 9.3 9.4 9.5))
$(error PostgreSQL 9.3 or 9.4 or 9.5 is required to compile this extension)
endif

cstore.pb-c.c: cstore.proto
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ installation's bin/ directory path. For example:
PATH=/usr/local/pgsql/bin/:$PATH make
sudo PATH=/usr/local/pgsql/bin/:$PATH make install

**Note.** cstore_fdw requires PostgreSQL 9.3 or 9.4. It doesn't support earlier
**Note.** cstore_fdw requires PostgreSQL 9.3, 9.4 or 9.5. It doesn't support earlier
versions of PostgreSQL.


Expand Down Expand Up @@ -115,13 +115,13 @@ most efficient execution plan for each query.
commands. We also don't support single row inserts.


Updating from version 1.0, 1.1 or 1.2 to 1.3
--------------------------------------------
Updating from earlier versions to 1.4
--------------------------------------

To update your existing cstore_fdw installation from version 1.0, 1.1, or 1.2 to 1.3
To update your existing cstore_fdw installation from earlier versions 1.4
you can take the following steps:

* Download and install cstore_fdw version 1.3 using instructions from the "Building"
* Download and install cstore_fdw version 1.4 using instructions from the "Building"
section,
* Restart the PostgreSQL server,
* Run the ```ALTER EXTENSION cstore_fdw UPDATE;``` command.
Expand Down Expand Up @@ -283,6 +283,10 @@ the installation:

Changeset
---------
### Version 1.4

* (Feature) Added support for ```TRUNCATE TABLE```
* (Fix) Added support for PostgreSQL 9.5

### Version 1.3

Expand Down Expand Up @@ -315,7 +319,7 @@ Changeset
Copyright
---------

Copyright (c) 2015 Citus Data, Inc.
Copyright (c) 2016 Citus Data, Inc.

This module is free software; you can redistribute it and/or modify it under the
Apache v2.0 License.
Expand All @@ -325,7 +329,7 @@ engage @ citusdata.com.

[status]: https://travis-ci.org/citusdata/cstore_fdw
[mailing-list]: https://groups.google.com/forum/#!forum/cstore-users
[citus-cstore-docs]: http://citusdata.com/docs/foreign-data#cstore-wrapper
[citus-cstore-docs]: https://www.citusdata.com/documentation/citusdb-documentation/
[coverage]: https://coveralls.io/r/citusdata/cstore_fdw
[copy-command]: http://www.postgresql.org/docs/current/static/sql-copy.html
[analyze-command]: http://www.postgresql.org/docs/current/static/sql-analyze.html
164 changes: 164 additions & 0 deletions cstore_compression.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*-------------------------------------------------------------------------
*
* cstore_compression.c
*
* This file contains compression/decompression functions definitions
* used in cstore_fdw.
*
* Copyright (c) 2016, Citus Data, Inc.
*
* $Id$
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "cstore_fdw.h"

#if PG_VERSION_NUM >= 90500
#include "common/pg_lzcompress.h"
#else
#include "utils/pg_lzcompress.h"
#endif




#if PG_VERSION_NUM >= 90500
/*
* The information at the start of the compressed data. This decription is taken
* from pg_lzcompress in pre-9.5 version of PostgreSQL.
*/
typedef struct CStoreCompressHeader
{
int32 vl_len_; /* varlena header (do not touch directly!) */
int32 rawsize;
} CStoreCompressHeader;

/*
* Utilities for manipulation of header information for compressed data
*/

#define CSTORE_COMPRESS_HDRSZ ((int32) sizeof(CStoreCompressHeader))
#define CSTORE_COMPRESS_RAWSIZE(ptr) (((CStoreCompressHeader *) (ptr))->rawsize)
#define CSTORE_COMPRESS_RAWDATA(ptr) (((char *) (ptr)) + CSTORE_COMPRESS_HDRSZ)
#define CSTORE_COMPRESS_SET_RAWSIZE(ptr, len) (((CStoreCompressHeader *) (ptr))->rawsize = (len))

#else

#define CSTORE_COMPRESS_HDRSZ (0)
#define CSTORE_COMPRESS_RAWSIZE(ptr) (PGLZ_RAW_SIZE((PGLZ_Header *) buffer->data))
#define CSTORE_COMPRESS_RAWDATA(ptr) (((PGLZ_Header *) (ptr)))
#define CSTORE_COMPRESS_SET_RAWSIZE(ptr, len) (((CStoreCompressHeader *) (ptr))->rawsize = (len))

#endif



/*
* CompressBuffer compresses the given buffer with the given compression type
* outputBuffer enlarged to contain compressed data. The function returns true
* if compression is done, returns false if compression is not done.
* outputBuffer is valid only if the function returns true.
*/
bool
CompressBuffer(StringInfo inputBuffer, StringInfo outputBuffer,
CompressionType compressionType)
{
uint64 maximumLength = PGLZ_MAX_OUTPUT(inputBuffer->len) + CSTORE_COMPRESS_HDRSZ;
bool compressionResult = false;
#if PG_VERSION_NUM >= 90500
int32 compressedByteCount = 0;
#endif

if (compressionType != COMPRESSION_PG_LZ)
{
return false;
}

resetStringInfo(outputBuffer);
enlargeStringInfo(outputBuffer, maximumLength);

#if PG_VERSION_NUM >= 90500
compressedByteCount = pglz_compress((const char *) inputBuffer->data,
inputBuffer->len,
CSTORE_COMPRESS_RAWDATA(outputBuffer->data),
PGLZ_strategy_always);
if (compressedByteCount >= 0)
{
CSTORE_COMPRESS_SET_RAWSIZE(outputBuffer->data, inputBuffer->len);
SET_VARSIZE_COMPRESSED(outputBuffer->data,
compressedByteCount + CSTORE_COMPRESS_HDRSZ);
compressionResult = true;
}
#else

compressionResult = pglz_compress(inputBuffer->data, inputBuffer->len,
CSTORE_COMPRESS_RAWDATA(outputBuffer->data),
PGLZ_strategy_always);
#endif

if (compressionResult)
{
outputBuffer->len = VARSIZE(outputBuffer->data);
}

return compressionResult;
}


/*
* DecompressBuffer decompresses the given buffer with the given compression
* type. This function returns the buffer as-is when no compression is applied.
*/
StringInfo
DecompressBuffer(StringInfo buffer, CompressionType compressionType)
{
StringInfo decompressedBuffer = NULL;

Assert(compressionType == COMPRESSION_NONE || compressionType == COMPRESSION_PG_LZ);

if (compressionType == COMPRESSION_NONE)
{
/* in case of no compression, return buffer */
decompressedBuffer = buffer;
}
else if (compressionType == COMPRESSION_PG_LZ)
{
uint32 compressedDataSize = VARSIZE(buffer->data) - CSTORE_COMPRESS_HDRSZ;
uint32 decompressedDataSize = CSTORE_COMPRESS_RAWSIZE(buffer->data);
char *decompressedData = NULL;
#if PG_VERSION_NUM >= 90500
int32 decompressedByteCount = 0;
#endif

if (compressedDataSize + CSTORE_COMPRESS_HDRSZ != buffer->len)
{
ereport(ERROR, (errmsg("cannot decompress the buffer"),
errdetail("Expected %u bytes, but received %u bytes",
compressedDataSize, buffer->len)));
}

decompressedData = palloc0(decompressedDataSize);

#if PG_VERSION_NUM >= 90500
decompressedByteCount = pglz_decompress(CSTORE_COMPRESS_RAWDATA(buffer->data),
compressedDataSize,
decompressedData, decompressedDataSize);

if (decompressedByteCount < 0)
{
ereport(ERROR, (errmsg("cannot decompress the buffer"),
errdetail("compressed data is corrupted")));
}
#else
pglz_decompress((PGLZ_Header *) buffer->data, decompressedData);
#endif

decompressedBuffer = palloc0(sizeof(StringInfoData));
decompressedBuffer->data = decompressedData;
decompressedBuffer->len = decompressedDataSize;
decompressedBuffer->maxlen = decompressedDataSize;
}

return decompressedBuffer;
}
3 changes: 3 additions & 0 deletions cstore_fdw--1.3--1.4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* cstore_fdw/cstore_fdw--1.3--1.4.sql */

-- No new functions or definitions were added in 1.4
2 changes: 1 addition & 1 deletion cstore_fdw--1.3.sql → cstore_fdw--1.4.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* cstore_fdw/cstore_fdw--1.3.sql */
/* cstore_fdw/cstore_fdw--1.4.sql */

-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION cstore_fdw" to load this file. \quit
Expand Down
Loading

0 comments on commit 31fe102

Please sign in to comment.