-
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.
Merge branch 'main' of github.com:Leo-XM-Zeng/pg_duckdb into support_…
…domain
- Loading branch information
Showing
14 changed files
with
228 additions
and
34 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
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
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,10 @@ | ||
#pragma once | ||
|
||
#include "pgduckdb/pg/declarations.hpp" | ||
|
||
namespace pgduckdb::pg { | ||
bool IsArrayType(Oid type_oid); | ||
bool IsDomainType(Oid type_oid); | ||
bool IsArrayDomainType(Oid type_oid); | ||
Oid GetBaseDuckColumnType(Oid attribute_typoid); | ||
} |
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,52 @@ | ||
#include "pgduckdb/pg/types.hpp" | ||
#include "pgduckdb/pgduckdb_utils.hpp" | ||
extern "C" { | ||
#include "postgres.h" | ||
#include "utils/lsyscache.h" | ||
#include "utils/syscache.h" | ||
#include "catalog/pg_type.h" | ||
#include "executor/tuptable.h" | ||
} | ||
|
||
namespace pgduckdb::pg { | ||
|
||
bool | ||
IsArrayType(Oid type_oid) { | ||
// inlined type_is_array | ||
return PostgresFunctionGuard(get_element_type, type_oid) != InvalidOid; | ||
} | ||
|
||
bool | ||
IsDomainType(Oid type_oid) { | ||
return PostgresFunctionGuard(get_typtype, type_oid) == TYPTYPE_DOMAIN; | ||
} | ||
|
||
bool | ||
IsArrayDomainType(Oid type_oid) { | ||
bool is_array_domain = false; | ||
if (IsDomainType(type_oid)) { | ||
if (PostgresFunctionGuard(get_base_element_type, type_oid) != InvalidOid) { | ||
is_array_domain = true; | ||
} | ||
} | ||
return is_array_domain; | ||
} | ||
|
||
Oid | ||
GetBaseDuckColumnType(Oid attribute_typoid) { | ||
std::lock_guard<std::recursive_mutex> lock(pgduckdb::GlobalProcessLock::GetLock()); | ||
Oid typoid = attribute_typoid; | ||
if (get_typtype(attribute_typoid) == TYPTYPE_DOMAIN) { | ||
/* It is a domain type that needs to be reduced to its base type */ | ||
typoid = getBaseType(attribute_typoid); | ||
} else if (type_is_array(attribute_typoid)) { | ||
Oid eltoid = get_base_element_type(attribute_typoid); | ||
if (OidIsValid(eltoid) && get_typtype(eltoid) == TYPTYPE_DOMAIN) { | ||
/* When the member type of an array is domain, you need to build a base array type */ | ||
typoid = get_array_type(getBaseType(eltoid)); | ||
} | ||
} | ||
return typoid; | ||
} | ||
|
||
} // 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
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
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
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; |