Skip to content

Commit af42d07

Browse files
mkgrgismkgrgis
andauthored
Implement MAC address support (#101)
* Implement MAC address support --------- Co-authored-by: mkgrgis <mihail.aksenov@bk.ru>
1 parent 8c98f1e commit af42d07

File tree

134 files changed

+23258
-134
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+23258
-134
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ OBJS = connection.o option.o deparse.o sqlite_query.o sqlite_fdw.o sqlite_data_n
1515
EXTENSION = sqlite_fdw
1616
DATA = sqlite_fdw--1.0.sql sqlite_fdw--1.0--1.1.sql
1717

18-
REGRESS = extra/sqlite_fdw_post extra/bitstring extra/bool extra/float4 extra/float8 extra/int4 extra/int8 extra/numeric extra/out_of_range extra/timestamp extra/uuid extra/join extra/limit extra/aggregates extra/prepare extra/select_having extra/select extra/insert extra/update extra/encodings sqlite_fdw type aggregate selectfunc
18+
ifndef REGRESS
19+
REGRESS = extra/sqlite_fdw_post types/bitstring types/bool types/float4 types/float8 types/int4 types/int8 types/numeric types/macaddr types/macaddr8 types/out_of_range types/timestamp types/uuid extra/join extra/limit extra/aggregates extra/prepare extra/select_having extra/select extra/insert extra/update extra/encodings sqlite_fdw type aggregate selectfunc
20+
endif
21+
1922
REGRESS_OPTS = --encoding=utf8
2023

2124
SQLITE_LIB = sqlite3
@@ -56,3 +59,4 @@ endif
5659

5760
REGRESS := $(addprefix $(REGRESS_PREFIX_SUB)/,$(REGRESS))
5861
$(shell mkdir -p results/$(REGRESS_PREFIX_SUB)/extra)
62+
$(shell mkdir -p results/$(REGRESS_PREFIX_SUB)/types)

README.md

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@ Features
4040
- `timestamp`: `text` and `int`,
4141
- `uuid`: `text`(32..39) and `blob`(16),
4242
- `bool`: `text`(1..5) and `int`,
43-
- `double precision`, `float` and `numeric`: `real` values and special values with `text` affinity (`+Infinity`, `-Infinity`, `NaN`).
43+
- `double precision`, `float` and `numeric`: `real` values and special values with `text` affinity (`+Infinity`, `-Infinity`, `NaN`),
44+
- `macaddr`: `text`(12..17) or `blob`(6) or `integer`,
45+
- `macaddr8`: `text`(16..23) or `blob`(8) or `integer`.
4446
- Support mixed SQLite [data affinity](https://www.sqlite.org/datatype3.html) output (`INSERT`/`UPDATE`) for such data types as
4547
- `timestamp`: `text`(default) or `int`,
46-
- `uuid`: `text`(36) or `blob`(16)(default).
48+
- `uuid`: `text`(36) or `blob`(16)(default),
49+
- `macaddr`: `text`(17) or `blob`(6) or `integer`(default),
50+
- `macaddr8`: `text`(23) or `blob`(8) or `integer`(default).
4751
- Full support for `+Infinity` (means ∞) and `-Infinity` (means -∞) special values for IEEE 754-2008 numbers in `double precision`, `float` and `numeric` columns including such conditions as ` n < '+Infinity'` or ` m > '-Infinity'`.
4852

4953
### Pushdowning
@@ -58,6 +62,7 @@ Features
5862
- `upper`, `lower` and other character case functions are **not** pushed down because they does not work with UNICODE character in SQLite.
5963
- `WITH TIES` option is **not** pushed down.
6064
- Bit string `#` (XOR) operator is **not** pushed down because there is no equal SQLite operator.
65+
- Operations with `macaddr` or `macaddr8` data are **not** pushed down.
6166

6267
### Notes about pushdowning
6368

@@ -155,9 +160,7 @@ Usage
155160

156161
### CREATE USER MAPPING options
157162

158-
There is no user or password conceptions in SQLite, hence `sqlite_fdw` no need any `CREATE USER MAPPING` command.
159-
160-
About access model and possible data modifications problems see about [connection to SQLite database file and access control](#connection-to-sqlite-database-file-and-access-control).
163+
There is no user or password conceptions in SQLite, hence `sqlite_fdw` no need any `CREATE USER MAPPING` command. About access model and possible data modifications problems see about [connection to SQLite database file and access control](#connection-to-sqlite-database-file-and-access-control).
161164

162165
### CREATE FOREIGN TABLE options
163166

@@ -199,42 +202,46 @@ in SQLite (mixed affinity case). Updated and inserted values will have this affi
199202

200203
Indicates a column as a part of primary key or unique key of SQLite table.
201204

202-
#### Datatypes
203-
**WARNING! The table below represents roadmap**, work still in progress. Until it will be ended please refer real behaviour in non-obvious cases, where there is no ✔ or ∅ mark.
204-
205+
### Datatypes
205206
This table represents `sqlite_fdw` behaviour if in PostgreSQL foreign table column some [affinity](https://www.sqlite.org/datatype3.html) of SQLite data is detected. Some details about data values support see in [limitations](#limitations).
206207

207-
* **** - no support (runtime error)
208-
* **V** - transparent transformation
209-
* **T** - cast to text in SQLite utf-8 encoding, then to **PostgreSQL text with current encoding of database** and then transparent transformation if applicable
210-
* **** - transparent transformation where PostgreSQL datatype is equal to SQLite affinity
211-
* **V+** - transparent transformation if appliacable
208+
* **** - no support (runtime error)
209+
* **** - 1↔1, PostgreSQL datatype is equal to SQLite affinity
210+
* **✔-** - PostgreSQL datatype is equal to SQLite affinity, but possible out of range error
211+
* **V** - transparent transformation if possible
212+
* **V+** - transparent transformation if possible
213+
* **i** - ISO:SQL transformation for some special constants
212214
* **?** - not described/not tested
213-
* **-** - transparent transformation is possible for PostgreSQL (always or for some special values), but not implemented in `sqlite_fdw`.
215+
* **T** - cast to text in SQLite utf-8 encoding, then to **PostgreSQL text with current encoding of database** and then transformation for `text` affinity if applicable
214216

215217
SQLite `NULL` affinity always can be transparent converted for a nullable column in PostgreSQL.
216218

217-
| PostgreSQL | SQLite <br> INT | SQLite <br> REAL | SQLite <br> BLOB | SQLite <br> TEXT | SQLite <br> TEXT but <br>empty|SQLite<br>nearest<br>affinity|
219+
**SQLite data processing dependend on affinity**
220+
221+
| PostgreSQL | INT | REAL | BLOB | TEXT | TEXT but <br>empty|nearest<br>affinity|
218222
|-------------:|:------------:|:------------:|:------------:|:------------:|:------------:|-------------:|
219-
| bool | V || T | V+ || INT |
220-
| bit(n) | V n<=64 ||||| INT |
221-
| bytea |||| - | ? | BLOB |
223+
| bool | V || T | i || INT |
224+
| bit(n) | V<br>(n<=64) ||||| INT |
225+
| bytea |||| V | ? | BLOB |
226+
| char(n) | ? | ? | T || V | TEXT |
222227
| date | V | V | T | V+ | `NULL` | ? |
223-
| float4 | V+ || T | - | `NULL` | REAL |
224-
| float8 | V+ || T | - | `NULL` | REAL |
225-
| int2 | V+ | ? | T | - | `NULL` | INT |
226-
| int4 | V+ | ? | T | - | `NULL` | INT |
227-
| int8 || ? | T | - | `NULL` | INT |
228+
| float4 | V+ || | i | `NULL` | REAL |
229+
| float8 | V+ || | i | `NULL` | REAL |
230+
| int2 | ✔- | ? | | | `NULL` | INT |
231+
| int4 | ✔- | ? | | | `NULL` | INT |
232+
| int8 || ? | | | `NULL` | INT |
228233
| json | ? | ? | T | V+ | ? | TEXT |
229-
| name | ? | ? | T | V | `NULL` | TEXT |
230-
| numeric | V | V | T || `NULL` | REAL |
234+
| macaddr | ✔- || V<br>(Len=6b)| V+ | ? | INT |
235+
| macaddr8 ||| V<br>(Len=8b)| V+ | ? | INT |
236+
| name | ? | ? | T | i | `NULL` | TEXT |
237+
| numeric | V | V | T | i | `NULL` | REAL |
231238
| text | ? | ? | T || V | TEXT |
232239
| time | V | V | T | V+ | `NULL` | ? |
233240
| timestamp | V | V | T | V+ | `NULL` | ? |
234241
|timestamp + tz| V | V | T | V+ | `NULL` | ? |
235-
| uuid |||V+<br>(only<br>16 bytes)| V+ || TEXT, BLOB |
236-
| varchar | ? | ? | T || V | TEXT |
237-
| varbit(n) | V n<=64 || V ||| INT |
242+
| uuid |||V+<br>(Len=16b)| V+ || TEXT, BLOB |
243+
| varchar(n) | ? | ? | T || V | TEXT |
244+
| varbit(n) | V<br>(n<=64) || ||| INT |
238245

239246
### IMPORT FOREIGN SCHEMA options
240247

@@ -249,7 +256,7 @@ SQLite `NULL` affinity always can be transparent converted for a nullable column
249256

250257
Allow borrowing `NULL`/`NOT NULL` constraints from SQLite table DDL.
251258

252-
#### Datatype tranlsation rules for `IMPORT FOREIGN SCHEMA`
259+
#### Datatype translation rules for `IMPORT FOREIGN SCHEMA`
253260

254261
| SQLite | PostgreSQL |
255262
|-------------:|:----------------:|
@@ -265,6 +272,8 @@ SQLite `NULL` affinity always can be transparent converted for a nullable column
265272
| time | time |
266273
| date | date |
267274
| uuid | uuid |
275+
| macaddr | macaddr |
276+
| macaddr8 | macaddr8 |
268277

269278
### TRUNCATE support
270279

@@ -587,6 +596,10 @@ for `INSERT` and `UPDATE` commands. PostgreSQL supports both `blob` and `text` [
587596
- `sqlite_fdw` PostgreSQL `bit`/`varbit` values support based on `int` SQLite data affinity, because there is no per bit operations for SQLite `blob` affinity data. Maximum SQLite `int` affinity value is 8 bytes length, hence maximum `bit`/`varbit` values length is 64 bits.
588597
- `sqlite_fdw` doesn't pushdown `#` (XOR) operator because there is no equal SQLite operator.
589598

599+
### MAC address support
600+
- `sqlite_fdw` PostgreSQL `macaddr`/`macaddr8` values support based on `int` SQLite data affinity, because there is no per bit operations for SQLite `blob` affinity data. For `macaddr` out of range error is possible because this type is 6 bytes length, but SQLite `int` can store value up to 8 bytes.
601+
- `sqlite_fdw` doesn't pushdown any operations with MAC adresses because there is 3 possible affinities for it in SQLite: `integer`, `blob` and `text`.
602+
590603
Tests
591604
-----
592605
Test directory have structure as following:

0 commit comments

Comments
 (0)