Skip to content

Commit

Permalink
fix(c/driver/postgresql): add postgres type to cols created for numeric
Browse files Browse the repository at this point in the history
- introduce constant with key name
- introduce separate private method to add field-level method
  • Loading branch information
lupko committed Feb 5, 2024
1 parent 3828e0b commit cd5eacb
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions c/driver/postgresql/postgres_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,12 @@ class PostgresType {
break;

// ---- Numeric/Decimal-------------------
case PostgresTypeId::kNumeric:
case PostgresTypeId::kNumeric: {
NANOARROW_RETURN_NOT_OK(ArrowSchemaSetType(schema, NANOARROW_TYPE_STRING));
NANOARROW_RETURN_NOT_OK(AddPostgresTypeMetadata(schema));

break;
}

// ---- Binary/string --------------------
case PostgresTypeId::kChar:
Expand Down Expand Up @@ -284,13 +287,7 @@ class PostgresType {
// can still return the bytes postgres gives us and attach the type name as
// metadata
NANOARROW_RETURN_NOT_OK(ArrowSchemaSetType(schema, NANOARROW_TYPE_BINARY));
nanoarrow::UniqueBuffer buffer;
ArrowMetadataBuilderInit(buffer.get(), nullptr);
NANOARROW_RETURN_NOT_OK(ArrowMetadataBuilderAppend(
buffer.get(), ArrowCharView("ADBC:postgresql:typname"),
ArrowCharView(typname_.c_str())));
NANOARROW_RETURN_NOT_OK(
ArrowSchemaSetMetadata(schema, reinterpret_cast<char*>(buffer->data)));
NANOARROW_RETURN_NOT_OK(AddPostgresTypeMetadata(schema));
break;
}
}
Expand All @@ -309,6 +306,19 @@ class PostgresType {
std::string typname_;
std::string field_name_;
std::vector<PostgresType> children_;

static constexpr const char* kPostgresTypeKey = "ADBC:postgresql:typname";

ArrowErrorCode AddPostgresTypeMetadata(ArrowSchema* schema) const {
nanoarrow::UniqueBuffer buffer;
ArrowMetadataBuilderInit(buffer.get(), nullptr);
NANOARROW_RETURN_NOT_OK(ArrowMetadataBuilderAppend(
buffer.get(), ArrowCharView(kPostgresTypeKey), ArrowCharView(typname_.c_str())));
NANOARROW_RETURN_NOT_OK(
ArrowSchemaSetMetadata(schema, reinterpret_cast<char*>(buffer->data)));

return NANOARROW_OK;
}
};

// Because type information is stored in a database's pg_type table, it can't
Expand Down

0 comments on commit cd5eacb

Please sign in to comment.