-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly handle tables with attndims=0
- Loading branch information
Showing
6 changed files
with
145 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
#include "pgduckdb/pg/declarations.hpp" | ||
|
||
namespace pgduckdb::pg { | ||
bool IsArrayType(Oid type_oid); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "pgduckdb/pg/types.hpp" | ||
#include "pgduckdb/pgduckdb_utils.hpp" | ||
extern "C" { | ||
#include "postgres.h" | ||
#include "utils/lsyscache.h" | ||
} | ||
|
||
namespace pgduckdb::pg { | ||
|
||
bool | ||
IsArrayType(Oid type_oid) { | ||
// inlined type_is_array | ||
return PostgresFunctionGuard(get_element_type, type_oid) != InvalidOid; | ||
} | ||
|
||
} // namespace pgduckdb::pg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
set duckdb.force_execution TO FALSE; | ||
CREATE TABLE s (a text[]); | ||
INSERT INTO s VALUES (ARRAY['abc', 'def', 'ghi']); | ||
-- Because the next table is created using a CTAS, attndims is set to 0. That | ||
-- confused us in the past. See #556 for details. We assume it's single | ||
-- dimensional now. | ||
CREATE TABLE t AS TABLE s; | ||
SELECT * FROM s; | ||
a | ||
--------------- | ||
{abc,def,ghi} | ||
(1 row) | ||
|
||
SELECT * FROM t; | ||
a | ||
--------------- | ||
{abc,def,ghi} | ||
(1 row) | ||
|
||
SET duckdb.force_execution TO true; | ||
SELECT * FROM s; | ||
a | ||
--------------- | ||
{abc,def,ghi} | ||
(1 row) | ||
|
||
SELECT * FROM t; | ||
a | ||
--------------- | ||
{abc,def,ghi} | ||
(1 row) | ||
|
||
-- Processing arryas of different dimensions in the same column is not something | ||
-- that DuckDB can handle. | ||
INSERT INTO s VALUES(ARRAY[['a', 'b'],['c','d']]); | ||
SELECT * FROM s; | ||
ERROR: (PGDuckDB/Duckdb_ExecCustomScan_Cpp) Invalid Input Error: Dimensionality of the schema and the data does not match, data contains more dimensions than the amount of dimensions specified by the schema | ||
TRUNCATE s; | ||
-- And we assume that the table metadata is correct about the dimensionality. | ||
-- So even if the stored dimensionality is consistently wrong we will throw an | ||
-- error. | ||
INSERT INTO s VALUES(ARRAY[['a', 'b'],['c','d']]); | ||
SELECT * FROM s; | ||
ERROR: (PGDuckDB/Duckdb_ExecCustomScan_Cpp) Invalid Input Error: Dimensionality of the schema and the data does not match, data contains more dimensions than the amount of dimensions specified by the schema | ||
-- But if you change the defintion of the table, we will be able to handle it. | ||
ALTER TABLE s ALTER COLUMN a SET DATA TYPE text[][]; | ||
SELECT * FROM s; | ||
a | ||
--------------- | ||
{{a,b},{c,d}} | ||
(1 row) | ||
|
||
-- Similarly Posgres cannot support nested lists where different sub-lists at | ||
-- the same level have a different length. | ||
SELECT * FROM duckdb.query($$ SELECT ARRAY[ARRAY[1,2], ARRAY[3,4,5]] arr $$); | ||
ERROR: (PGDuckDB/Duckdb_ExecCustomScan_Cpp) Invalid Input Error: Expected 2 values in list at dimension 1, found 3 instead | ||
DROP TABLE s, t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
set duckdb.force_execution TO FALSE; | ||
CREATE TABLE s (a text[]); | ||
INSERT INTO s VALUES (ARRAY['abc', 'def', 'ghi']); | ||
-- Because the next table is created using a CTAS, attndims is set to 0. That | ||
-- confused us in the past. See #556 for details. We assume it's single | ||
-- dimensional now. | ||
CREATE TABLE t AS TABLE s; | ||
SELECT * FROM s; | ||
SELECT * FROM t; | ||
SET duckdb.force_execution TO true; | ||
SELECT * FROM s; | ||
SELECT * FROM t; | ||
|
||
-- Processing arryas of different dimensions in the same column is not something | ||
-- that DuckDB can handle. | ||
INSERT INTO s VALUES(ARRAY[['a', 'b'],['c','d']]); | ||
SELECT * FROM s; | ||
TRUNCATE s; | ||
|
||
-- And we assume that the table metadata is correct about the dimensionality. | ||
-- So even if the stored dimensionality is consistently wrong we will throw an | ||
-- error. | ||
INSERT INTO s VALUES(ARRAY[['a', 'b'],['c','d']]); | ||
SELECT * FROM s; | ||
-- But if you change the defintion of the table, we will be able to handle it. | ||
ALTER TABLE s ALTER COLUMN a SET DATA TYPE text[][]; | ||
SELECT * FROM s; | ||
|
||
-- Similarly Posgres cannot support nested lists where different sub-lists at | ||
-- the same level have a different length. | ||
SELECT * FROM duckdb.query($$ SELECT ARRAY[ARRAY[1,2], ARRAY[3,4,5]] arr $$); | ||
|
||
DROP TABLE s, t; |