Skip to content

Commit

Permalink
reflected review changes for #44
Browse files Browse the repository at this point in the history
  • Loading branch information
mtuncer committed Jan 7, 2015
1 parent 8965011 commit f037240
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 60 deletions.
3 changes: 1 addition & 2 deletions Makefile
Expand Up @@ -13,8 +13,7 @@ OBJS = cstore.pb-c.o cstore_fdw.o cstore_writer.o cstore_reader.o \
EXTENSION = cstore_fdw
DATA = cstore_fdw--1.1.sql cstore_fdw--1.0--1.1.sql

REGRESS = create load query analyze data_types functions block_filtering drop \
insert copyto variable_length
REGRESS = create load query analyze data_types functions block_filtering drop insert copyto
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 Down
9 changes: 5 additions & 4 deletions cstore_writer.c
Expand Up @@ -238,12 +238,13 @@ CStoreWriteRow(TableWriteState *writeState, Datum *columnValues, bool *columnNul
int columnTypeLength = attributeForm->attlen;
Oid columnCollation = attributeForm->attcollation;
Datum columnValue = columnValues[columnIndex];
bool variableLengthColumn = columnTypeLength == -1;

if (variableLengthColumn)
/* detoast variable length attributes if necessary */
if (columnTypeLength == -1)
{
columnValue = PointerGetDatum(
PG_DETOAST_DATUM(columnValues[columnIndex]));
struct varlena *detoastedValue = PG_DETOAST_DATUM(columnValue);

columnValue = PointerGetDatum(detoastedValue);
}

blockData->existsArray[blockRowIndex] = true;
Expand Down
37 changes: 37 additions & 0 deletions expected/insert.out
Expand Up @@ -49,3 +49,40 @@ select count(*) from test_insert_command;

drop table test_insert_command_data;
drop foreign table test_insert_command;
-- test long attribute value insertion
-- create sufficiently long text so that data is stored in toast
CREATE TABLE test_long_text AS
SELECT a as int_val, string_agg(random()::text, '') as text_val
FROM generate_series(1, 10) a, generate_series(1, 1000) b
GROUP BY a ORDER BY a;
-- store hash values of text for later comparison
CREATE TABLE test_long_text_hash AS
SELECT int_val, md5(text_val) AS hash
FROM test_long_text;
CREATE FOREIGN TABLE test_cstore_long_text(int_val int, text_val text)
SERVER cstore_server;
-- store long text in cstore table
INSERT INTO test_cstore_long_text SELECT * FROM test_long_text;
-- drop source table to remove original text from toast
DROP TABLE test_long_text;
-- check if text data is still available in cstore table
-- by comparing previously stored hash.
SELECT a.int_val
FROM test_long_text_hash a, test_cstore_long_text c
WHERE a.int_val = c.int_val AND a.hash = md5(c.text_val);
int_val
---------
1
2
3
4
5
6
7
8
9
10
(10 rows)

DROP TABLE test_long_text_hash;
DROP FOREIGN TABLE test_cstore_long_text;
38 changes: 0 additions & 38 deletions expected/variable_length.out

This file was deleted.

30 changes: 30 additions & 0 deletions sql/insert.sql
Expand Up @@ -24,3 +24,33 @@ select count(*) from test_insert_command;

drop table test_insert_command_data;
drop foreign table test_insert_command;

-- test long attribute value insertion
-- create sufficiently long text so that data is stored in toast
CREATE TABLE test_long_text AS
SELECT a as int_val, string_agg(random()::text, '') as text_val
FROM generate_series(1, 10) a, generate_series(1, 1000) b
GROUP BY a ORDER BY a;

-- store hash values of text for later comparison
CREATE TABLE test_long_text_hash AS
SELECT int_val, md5(text_val) AS hash
FROM test_long_text;

CREATE FOREIGN TABLE test_cstore_long_text(int_val int, text_val text)
SERVER cstore_server;

-- store long text in cstore table
INSERT INTO test_cstore_long_text SELECT * FROM test_long_text;

-- drop source table to remove original text from toast
DROP TABLE test_long_text;

-- check if text data is still available in cstore table
-- by comparing previously stored hash.
SELECT a.int_val
FROM test_long_text_hash a, test_cstore_long_text c
WHERE a.int_val = c.int_val AND a.hash = md5(c.text_val);

DROP TABLE test_long_text_hash;
DROP FOREIGN TABLE test_cstore_long_text;
16 changes: 0 additions & 16 deletions sql/variable_length.sql

This file was deleted.

0 comments on commit f037240

Please sign in to comment.