Skip to content

Commit

Permalink
Add support for Postgres pg_snapshot type
Browse files Browse the repository at this point in the history
  • Loading branch information
exAspArk committed Nov 19, 2024
1 parent 0d5566d commit 8527295
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

#### [v0.12.0](https://github.com/BemiHQ/BemiDB/compare/v0.11.0...v0.12.0) - 2024-11-19

- Add support for Postgres `pg_snapshot` type

#### [v0.11.0](https://github.com/BemiHQ/BemiDB/compare/v0.10.0...v0.11.0) - 2024-11-18

- Add support for Postgres `xid` and `xid8` types
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ Primitive data types are mapped as follows:
| `interval` | `BYTE_ARRAY` (`UTF8`) | `string` |
| `point`, `line`, `lseg`, `box`, `path`, `polygon`, `circle` | `BYTE_ARRAY` (`UTF8`) | `string` |
| `cidr`, `inet`, `macaddr`, `macaddr8` | `BYTE_ARRAY` (`UTF8`) | `string` |
| `tsvector` | `BYTE_ARRAY` (`UTF8`) | `string` |
| `tsvector`, `pg_snapshot` | `BYTE_ARRAY` (`UTF8`) | `string` |
| `json`, `jsonb` | `BYTE_ARRAY` (`UTF8`) | `string` (JSON logical type) |
| `_*` (array) | `LIST` `*` | `list` |
| `*` (user-defined type) | `BYTE_ARRAY` (`UTF8`) | `string` |
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.11.0"
VERSION="0.12.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 @@ -38,6 +38,7 @@ CREATE TABLE test_table (
json_column JSON,
jsonb_column JSONB,
tsvector_column TSVECTOR,
pg_snapshot_column PG_SNAPSHOT,
array_text_column TEXT[],
array_int_column INT[],
user_defined_column address
Expand Down Expand Up @@ -73,6 +74,7 @@ INSERT INTO test_table (
json_column,
jsonb_column,
tsvector_column,
pg_snapshot_column,
array_text_column,
array_int_column,
user_defined_column
Expand Down Expand Up @@ -106,6 +108,7 @@ INSERT INTO test_table (
'{"key": "value"}'::JSON, -- json_column
'{"key": "value"}'::JSONB, -- jsonb_column
to_tsvector('Sample text for tsvector'), -- tsvector_column
pg_current_snapshot(), -- pg_snapshot_column
'{"one", "two", "three"}', -- array_text_column
'{1, 2, 3}', -- array_int_column
ROW('Toronto') -- user_defined_column
Expand Down Expand Up @@ -139,6 +142,7 @@ INSERT INTO test_table (
NULL, -- json_column
'{}'::JSONB, -- jsonb_column
NULL, -- tsvector_column
NULL, -- pg_snapshot_column
NULL, -- array_text_column
'{}', -- array_int_column
NULL -- user_defined_column
Expand Down
7 changes: 7 additions & 0 deletions src/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ var TEST_PG_SCHEMA_COLUMNS = []PgSchemaColumn{
DataType: "tsvector",
UdtName: "tsvector",
},
{
ColumnName: "pg_snapshot_column",
DataType: "pg_snapshot",
UdtName: "pg_snapshot",
},
{
ColumnName: "point_column",
DataType: "point",
Expand Down Expand Up @@ -217,6 +222,7 @@ var TEST_LOADED_ROWS = [][]string{
"\\x1234", // bytea_column
"1 mon 2 days 01:00:01.000001", // interval_column
"'sampl':1 'text':2 'tsvector':4", // tsvector_column
"2784:2784:", // pg_snapshot_column
"(37.347301483154,45.002101898193)", // point_column
"192.168.0.1", // inet_column
"{\"key\": \"value\"}", // json_column
Expand Down Expand Up @@ -251,6 +257,7 @@ var TEST_LOADED_ROWS = [][]string{
PG_NULL_STRING, // bytea_column
PG_NULL_STRING, // interval_column
PG_NULL_STRING, // tsvector_column
PG_NULL_STRING, // pg_snapshot_column
PG_NULL_STRING, // point_column
PG_NULL_STRING, // inet_column
PG_NULL_STRING, // json_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.11.0"
const VERSION = "0.12.0"

func main() {
flag.Parse()
Expand Down
15 changes: 9 additions & 6 deletions src/pg_schema_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,10 @@ func (pgSchemaColumn *PgSchemaColumn) toParquetSchemaField() ParquetSchemaField

func (pgSchemaColumn *PgSchemaColumn) parquetPrimitiveValue(value string) interface{} {
switch strings.TrimLeft(pgSchemaColumn.UdtName, "_") {
case "varchar", "char", "text", "bytea", "jsonb", "json", "tsvector", "numeric", "uuid", "interval",
case "varchar", "char", "text", "bytea", "jsonb", "json", "numeric", "uuid", "interval",
"point", "line", "lseg", "box", "path", "polygon", "circle",
"cidr", "inet", "macaddr", "macaddr8":
"cidr", "inet", "macaddr", "macaddr8",
"tsvector", "pg_snapshot":
return value
case "bpchar":
trimmedValue := strings.TrimRight(value, " ")
Expand Down Expand Up @@ -292,9 +293,10 @@ 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", "tsvector",
case "varchar", "char", "text", "bpchar", "bytea", "interval", "jsonb", "json",
"point", "line", "lseg", "box", "path", "polygon", "circle",
"cidr", "inet", "macaddr", "macaddr8":
"cidr", "inet", "macaddr", "macaddr8",
"tsvector", "pg_snapshot":
return "BYTE_ARRAY", "UTF8"
case "date":
return "INT32", "DATE"
Expand Down Expand Up @@ -339,9 +341,10 @@ func (pgSchemaColumn *PgSchemaColumn) parquetPrimitiveTypes() (primitiveType str

func (pgSchemaColumn *PgSchemaColumn) icebergPrimitiveType() string {
switch strings.TrimLeft(pgSchemaColumn.UdtName, "_") {
case "varchar", "char", "text", "interval", "jsonb", "json", "bpchar", "tsvector",
case "varchar", "char", "text", "interval", "jsonb", "json", "bpchar",
"point", "line", "lseg", "box", "path", "polygon", "circle",
"cidr", "inet", "macaddr", "macaddr8":
"cidr", "inet", "macaddr", "macaddr8",
"tsvector", "pg_snapshot":
return "string"
case "uuid":
return "uuid"
Expand Down
8 changes: 8 additions & 0 deletions src/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ func TestHandleQuery(t *testing.T) {
"description": {"tsvector_column"},
"values": {""},
},
"SELECT pg_snapshot_column FROM public.test_table WHERE pg_snapshot_column IS NOT NULL": {
"description": {"pg_snapshot_column"},
"values": {"2784:2784:"},
},
"SELECT pg_snapshot_column FROM public.test_table WHERE pg_snapshot_column IS NULL": {
"description": {"pg_snapshot_column"},
"values": {""},
},
"SELECT point_column FROM public.test_table WHERE point_column IS NOT NULL": {
"description": {"point_column"},
"values": {"(37.347301483154,45.002101898193)"},
Expand Down

0 comments on commit 8527295

Please sign in to comment.