Skip to content

Commit

Permalink
Add support for bit column types
Browse files Browse the repository at this point in the history
  • Loading branch information
exAspArk committed Dec 9, 2024
1 parent 8c42c30 commit 924a152
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ Primitive data types are mapped as follows:
| PostgreSQL | Parquet | Iceberg |
|-------------------------------------------------------------|---------------------------------------------------|----------------------------------|
| `bool` | `BOOLEAN` | `boolean` |
| `bpchar`, `varchar`, `text` | `BYTE_ARRAY` (`UTF8`) | `string` |
| `varchar`, `text`, `bpchar`, `bit` | `BYTE_ARRAY` (`UTF8`) | `string` |
| `int2`, `int4` | `INT32` | `int` |
| `int8` | `INT64` | `long` |
| `xid` | `INT32` (`UINT_32`) | `int` |
Expand Down
2 changes: 1 addition & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

VERSION="0.19.4"
VERSION="0.20.0"

# Detect OS and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
Expand Down
4 changes: 4 additions & 0 deletions scripts/test-data-types.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CREATE TYPE address AS (

CREATE TABLE test_table (
id SERIAL PRIMARY KEY,
bit_column BIT,
bool_column BOOLEAN,
bpchar_column BPCHAR(10),
varchar_column VARCHAR(255),
Expand Down Expand Up @@ -48,6 +49,7 @@ CREATE TABLE test_table (
);

INSERT INTO test_table (
bit_column,
bool_column,
bpchar_column,
varchar_column,
Expand Down Expand Up @@ -83,6 +85,7 @@ INSERT INTO test_table (
array_ltree_column,
user_defined_column
) VALUES (
B'1', -- bit_column
TRUE, -- bool_column
'bpchar', -- bpchar_column
'varchar', -- varchar_column
Expand Down Expand Up @@ -118,6 +121,7 @@ INSERT INTO test_table (
'{"a.b", "c.d"}'::LTREE[], -- array_ltree_column
ROW('Toronto') -- user_defined_column
), (
NULL, -- bit_column
FALSE, -- bool_column
'', -- bpchar_column
NULL, -- varchar_column
Expand Down
8 changes: 8 additions & 0 deletions src/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import (
)

var TEST_PG_SCHEMA_COLUMNS = []PgSchemaColumn{
{
ColumnName: "bit_column",
DataType: "bit",
UdtName: "bit",
CharacterMaximumLength: "1",
},
{
ColumnName: "bool_column",
DataType: "boolean",
Expand Down Expand Up @@ -243,6 +249,7 @@ var TEST_PG_SCHEMA_COLUMNS = []PgSchemaColumn{

var TEST_LOADED_ROWS = [][]string{
{
"1", // bit_column
"true", // bool_column
"bpchar", // bpchar_column
"varchar", // varchar_column
Expand Down Expand Up @@ -280,6 +287,7 @@ var TEST_LOADED_ROWS = [][]string{
"(Toronto)", // user_defined_column
},
{
PG_NULL_STRING, // bit_column
"false", // bool_column
"", // bpchar_column
PG_NULL_STRING, // varchar_column
Expand Down
2 changes: 1 addition & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"
)

const VERSION = "0.19.4"
const VERSION = "0.20.0"

func main() {
config := LoadConfig()
Expand Down
6 changes: 3 additions & 3 deletions src/pg_schema_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (pgSchemaColumn *PgSchemaColumn) toParquetSchemaField() ParquetSchemaField

func (pgSchemaColumn *PgSchemaColumn) parquetPrimitiveValue(value string) interface{} {
switch strings.TrimLeft(pgSchemaColumn.UdtName, "_") {
case "varchar", "char", "text", "bytea", "jsonb", "json", "numeric", "uuid", "interval",
case "varchar", "char", "text", "bit", "bytea", "jsonb", "json", "numeric", "uuid", "interval",
"point", "line", "lseg", "box", "path", "polygon", "circle",
"cidr", "inet", "macaddr", "macaddr8",
"tsvector", "pg_snapshot":
Expand Down Expand Up @@ -301,7 +301,7 @@ func (pgSchemaColumn *PgSchemaColumn) parquetPrimitiveValue(value string) interf

func (pgSchemaColumn *PgSchemaColumn) parquetPrimitiveTypes() (primitiveType string, primitiveConvertedType string) {
switch strings.TrimLeft(pgSchemaColumn.UdtName, "_") {
case "varchar", "char", "text", "bpchar", "bytea", "interval", "jsonb", "json",
case "varchar", "char", "text", "bpchar", "bit", "bytea", "interval", "jsonb", "json",
"point", "line", "lseg", "box", "path", "polygon", "circle",
"cidr", "inet", "macaddr", "macaddr8",
"tsvector", "pg_snapshot":
Expand Down Expand Up @@ -350,7 +350,7 @@ func (pgSchemaColumn *PgSchemaColumn) parquetPrimitiveTypes() (primitiveType str

func (pgSchemaColumn *PgSchemaColumn) icebergPrimitiveType() string {
switch strings.TrimLeft(pgSchemaColumn.UdtName, "_") {
case "varchar", "char", "text", "interval", "jsonb", "json", "bpchar",
case "varchar", "char", "text", "interval", "jsonb", "json", "bpchar", "bit",
"point", "line", "lseg", "box", "path", "polygon", "circle",
"cidr", "inet", "macaddr", "macaddr8",
"tsvector", "pg_snapshot":
Expand Down
8 changes: 8 additions & 0 deletions src/query_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ func TestHandleQuery(t *testing.T) {
"description": {"count"},
"values": {"2"},
},
"SELECT bit_column FROM public.test_table WHERE bit_column IS NOT NULL": {
"description": {"bit_column"},
"values": {"1"},
},
"SELECT bit_column FROM public.test_table WHERE bit_column IS NULL": {
"description": {"bit_column"},
"values": {""},
},
"SELECT bool_column FROM public.test_table WHERE bool_column = TRUE": {
"description": {"bool_column"},
"values": {"true"},
Expand Down

0 comments on commit 924a152

Please sign in to comment.