Skip to content

Commit

Permalink
Adjust the code style and optimize the code logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-XM-Zeng committed Feb 24, 2025
1 parent 64fb2c9 commit dad46ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion include/pgduckdb/pg/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ namespace pgduckdb::pg {
bool IsArrayType(Oid type_oid);
bool IsDomainType(Oid type_oid);
bool IsArrayDomainType(Oid type_oid);
Oid GetBaseDuckColumnType(Oid attribute_typoid);
Oid GetBaseDuckColumnType(Oid attribute_type_oid);
}
20 changes: 12 additions & 8 deletions src/pg/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ IsArrayDomainType(Oid type_oid) {
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) {
static Oid
GetBaseDuckColumnType_C(Oid attribute_type_oid) {
Oid typoid = attribute_type_oid;
if (get_typtype(attribute_type_oid) == 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);
typoid = getBaseType(attribute_type_oid);
} else if (type_is_array(attribute_type_oid)) {
Oid eltoid = get_base_element_type(attribute_type_oid);
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));
Expand All @@ -49,4 +48,9 @@ GetBaseDuckColumnType(Oid attribute_typoid) {
return typoid;
}

Oid
GetBaseDuckColumnType(Oid attribute_type_oid) {
return PostgresFunctionGuard(GetBaseDuckColumnType_C, attribute_type_oid);
}

} // namespace pgduckdb::pg

0 comments on commit dad46ae

Please sign in to comment.