Skip to content

Commit

Permalink
Bugfix: rowgroup filtering by float and double attributes (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
zilder committed Dec 21, 2020
1 parent 09ae462 commit 666c49a
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 17 deletions.
Binary file modified data/example1.parquet
Binary file not shown.
Binary file modified data/example2.parquet
Binary file not shown.
2 changes: 1 addition & 1 deletion data/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
date(2018, 1, 5),
date(2018, 1, 6)],
'six': [False, False, False],
'seven': [0.5, None, 1.0]})
'seven': [1.5, None, 2.0]})
table2 = pa.Table.from_pandas(df2)

with pq.ParquetWriter('example1.parquet', table1.schema) as writer:
Expand Down
6 changes: 5 additions & 1 deletion input/parquet_fdw.source
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ SELECT * FROM example1 WHERE one = 2;
SELECT * FROM example1 WHERE one = 7;
SELECT * FROM example1 WHERE six = true;
SELECT * FROM example1 WHERE six = false;
SELECT * FROM example1 WHERE seven < 0.9;
SELECT * FROM example1 WHERE seven < 1.5;
SELECT * FROM example1 WHERE seven <= 1.5;
SELECT * FROM example1 WHERE seven = 1.5;
SELECT * FROM example1 WHERE seven > 1;
SELECT * FROM example1 WHERE seven >= 1;
SELECT * FROM example1 WHERE seven IS NULL;

-- prepared statements
Expand Down
4 changes: 2 additions & 2 deletions output/import.source
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ SELECT * FROM example_import ORDER BY one, three;
2 | {NULL,5,6} | bar | 2018-01-02 00:00:00 | 2018-01-02 | f |
3 | {7,8,9} | baz | 2018-01-03 00:00:00 | 2018-01-03 | t | 1
3 | {21,22} | zwei | 2018-01-03 00:00:00 | 2018-01-03 | f |
4 | {10,11,12} | uno | 2018-01-04 00:00:00 | 2018-01-04 | f | 0.5
4 | {10,11,12} | uno | 2018-01-04 00:00:00 | 2018-01-04 | f | 1.5
5 | {13,14,15} | dos | 2018-01-05 00:00:00 | 2018-01-05 | f |
5 | {23,24} | drei | 2018-01-05 00:00:00 | 2018-01-05 | t |
6 | {16,17,18} | tres | 2018-01-06 00:00:00 | 2018-01-06 | f | 1
6 | {16,17,18} | tres | 2018-01-06 00:00:00 | 2018-01-06 | f | 2
7 | {25,26} | vier | 2018-01-07 00:00:00 | 2018-01-07 | f |
9 | {27,28} | fünf | 2018-01-09 00:00:00 | 2018-01-09 | t |
(11 rows)
Expand Down
54 changes: 43 additions & 11 deletions output/parquet_fdw.source
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ SELECT * FROM example1;
1 | {1,2,3} | foo | 2018-01-01 00:00:00 | 2018-01-01 | t | 0.5
2 | {NULL,5,6} | bar | 2018-01-02 00:00:00 | 2018-01-02 | f |
3 | {7,8,9} | baz | 2018-01-03 00:00:00 | 2018-01-03 | t | 1
4 | {10,11,12} | uno | 2018-01-04 00:00:00 | 2018-01-04 | f | 0.5
4 | {10,11,12} | uno | 2018-01-04 00:00:00 | 2018-01-04 | f | 1.5
5 | {13,14,15} | dos | 2018-01-05 00:00:00 | 2018-01-05 | f |
6 | {16,17,18} | tres | 2018-01-06 00:00:00 | 2018-01-06 | f | 1
6 | {16,17,18} | tres | 2018-01-06 00:00:00 | 2018-01-06 | f | 2
(6 rows)

-- no explicit columns mentions
Expand Down Expand Up @@ -93,7 +93,7 @@ SELECT * FROM example1 WHERE one >= 6;
DEBUG: parquet_fdw: skip rowgroup 1
one | two | three | four | five | six | seven
-----+------------+-------+---------------------+------------+-----+-------
6 | {16,17,18} | tres | 2018-01-06 00:00:00 | 2018-01-06 | f | 1
6 | {16,17,18} | tres | 2018-01-06 00:00:00 | 2018-01-06 | f | 2
(1 row)

SELECT * FROM example1 WHERE one = 2;
Expand Down Expand Up @@ -122,18 +122,50 @@ SELECT * FROM example1 WHERE six = false;
one | two | three | four | five | six | seven
-----+------------+-------+---------------------+------------+-----+-------
2 | {NULL,5,6} | bar | 2018-01-02 00:00:00 | 2018-01-02 | f |
4 | {10,11,12} | uno | 2018-01-04 00:00:00 | 2018-01-04 | f | 0.5
4 | {10,11,12} | uno | 2018-01-04 00:00:00 | 2018-01-04 | f | 1.5
5 | {13,14,15} | dos | 2018-01-05 00:00:00 | 2018-01-05 | f |
6 | {16,17,18} | tres | 2018-01-06 00:00:00 | 2018-01-06 | f | 1
6 | {16,17,18} | tres | 2018-01-06 00:00:00 | 2018-01-06 | f | 2
(4 rows)

SELECT * FROM example1 WHERE seven < 0.9;
SELECT * FROM example1 WHERE seven < 1.5;
DEBUG: parquet_fdw: skip rowgroup 2
one | two | three | four | five | six | seven
-----+---------+-------+---------------------+------------+-----+-------
1 | {1,2,3} | foo | 2018-01-01 00:00:00 | 2018-01-01 | t | 0.5
3 | {7,8,9} | baz | 2018-01-03 00:00:00 | 2018-01-03 | t | 1
(2 rows)

SELECT * FROM example1 WHERE seven <= 1.5;
one | two | three | four | five | six | seven
-----+------------+-------+---------------------+------------+-----+-------
1 | {1,2,3} | foo | 2018-01-01 00:00:00 | 2018-01-01 | t | 0.5
4 | {10,11,12} | uno | 2018-01-04 00:00:00 | 2018-01-04 | f | 0.5
3 | {7,8,9} | baz | 2018-01-03 00:00:00 | 2018-01-03 | t | 1
4 | {10,11,12} | uno | 2018-01-04 00:00:00 | 2018-01-04 | f | 1.5
(3 rows)

SELECT * FROM example1 WHERE seven = 1.5;
DEBUG: parquet_fdw: skip rowgroup 1
one | two | three | four | five | six | seven
-----+------------+-------+---------------------+------------+-----+-------
4 | {10,11,12} | uno | 2018-01-04 00:00:00 | 2018-01-04 | f | 1.5
(1 row)

SELECT * FROM example1 WHERE seven > 1;
DEBUG: parquet_fdw: skip rowgroup 1
one | two | three | four | five | six | seven
-----+------------+-------+---------------------+------------+-----+-------
4 | {10,11,12} | uno | 2018-01-04 00:00:00 | 2018-01-04 | f | 1.5
6 | {16,17,18} | tres | 2018-01-06 00:00:00 | 2018-01-06 | f | 2
(2 rows)

SELECT * FROM example1 WHERE seven >= 1;
one | two | three | four | five | six | seven
-----+------------+-------+---------------------+------------+-----+-------
3 | {7,8,9} | baz | 2018-01-03 00:00:00 | 2018-01-03 | t | 1
4 | {10,11,12} | uno | 2018-01-04 00:00:00 | 2018-01-04 | f | 1.5
6 | {16,17,18} | tres | 2018-01-06 00:00:00 | 2018-01-06 | f | 2
(3 rows)

SELECT * FROM example1 WHERE seven IS NULL;
one | two | three | four | five | six | seven
-----+------------+-------+---------------------+------------+-----+-------
Expand Down Expand Up @@ -261,9 +293,9 @@ SELECT * FROM example_seq;
1 | {1,2,3} | foo | 2018-01-01 00:00:00 | 2018-01-01 | t | 0.5
2 | {NULL,5,6} | bar | 2018-01-02 00:00:00 | 2018-01-02 | f |
3 | {7,8,9} | baz | 2018-01-03 00:00:00 | 2018-01-03 | t | 1
4 | {10,11,12} | uno | 2018-01-04 00:00:00 | 2018-01-04 | f | 0.5
4 | {10,11,12} | uno | 2018-01-04 00:00:00 | 2018-01-04 | f | 1.5
5 | {13,14,15} | dos | 2018-01-05 00:00:00 | 2018-01-05 | f |
6 | {16,17,18} | tres | 2018-01-06 00:00:00 | 2018-01-06 | f | 1
6 | {16,17,18} | tres | 2018-01-06 00:00:00 | 2018-01-06 | f | 2
1 | {19,20} | eins | 2018-01-01 00:00:00 | 2018-01-01 | t |
3 | {21,22} | zwei | 2018-01-03 00:00:00 | 2018-01-03 | f |
5 | {23,24} | drei | 2018-01-05 00:00:00 | 2018-01-05 | t |
Expand Down Expand Up @@ -300,10 +332,10 @@ SELECT * FROM example_sorted ORDER BY one;
2 | {NULL,5,6} | bar | 2018-01-02 00:00:00 | 2018-01-02 | f |
3 | {21,22} | zwei | 2018-01-03 00:00:00 | 2018-01-03 | f |
3 | {7,8,9} | baz | 2018-01-03 00:00:00 | 2018-01-03 | t | 1
4 | {10,11,12} | uno | 2018-01-04 00:00:00 | 2018-01-04 | f | 0.5
4 | {10,11,12} | uno | 2018-01-04 00:00:00 | 2018-01-04 | f | 1.5
5 | {23,24} | drei | 2018-01-05 00:00:00 | 2018-01-05 | t |
5 | {13,14,15} | dos | 2018-01-05 00:00:00 | 2018-01-05 | f |
6 | {16,17,18} | tres | 2018-01-06 00:00:00 | 2018-01-06 | f | 1
6 | {16,17,18} | tres | 2018-01-06 00:00:00 | 2018-01-06 | f | 2
7 | {25,26} | vier | 2018-01-07 00:00:00 | 2018-01-07 | f |
9 | {27,28} | fünf | 2018-01-09 00:00:00 | 2018-01-09 | t |
(11 rows)
Expand Down
4 changes: 2 additions & 2 deletions parquet_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2798,9 +2798,9 @@ bytes_to_postgres_type(const char *bytes, arrow::DataType *arrow_type)
case arrow::Type::INT64:
return Int64GetDatum(*(int64 *) bytes);
case arrow::Type::FLOAT:
return Int32GetDatum(*(float *) bytes);
return Float4GetDatum(*(float *) bytes);
case arrow::Type::DOUBLE:
return Int64GetDatum(*(double *) bytes);
return Float8GetDatum(*(double *) bytes);
case arrow::Type::STRING:
case arrow::Type::BINARY:
return CStringGetTextDatum(bytes);
Expand Down

0 comments on commit 666c49a

Please sign in to comment.