in c/driver/postgresql/postgres_type.h [566:635]
inline ArrowErrorCode PostgresType::FromSchema(const PostgresTypeResolver& resolver,
ArrowSchema* schema, PostgresType* out,
ArrowError* error) {
ArrowSchemaView schema_view;
NANOARROW_RETURN_NOT_OK(ArrowSchemaViewInit(&schema_view, schema, error));
switch (schema_view.type) {
case NANOARROW_TYPE_BOOL:
return resolver.Find(resolver.GetOID(PostgresTypeId::kBool), out, error);
case NANOARROW_TYPE_INT8:
case NANOARROW_TYPE_UINT8:
case NANOARROW_TYPE_INT16:
return resolver.Find(resolver.GetOID(PostgresTypeId::kInt2), out, error);
case NANOARROW_TYPE_UINT16:
case NANOARROW_TYPE_INT32:
return resolver.Find(resolver.GetOID(PostgresTypeId::kInt4), out, error);
case NANOARROW_TYPE_UINT32:
case NANOARROW_TYPE_INT64:
case NANOARROW_TYPE_UINT64:
return resolver.Find(resolver.GetOID(PostgresTypeId::kInt8), out, error);
case NANOARROW_TYPE_HALF_FLOAT:
case NANOARROW_TYPE_FLOAT:
return resolver.Find(resolver.GetOID(PostgresTypeId::kFloat4), out, error);
case NANOARROW_TYPE_DOUBLE:
return resolver.Find(resolver.GetOID(PostgresTypeId::kFloat8), out, error);
case NANOARROW_TYPE_STRING:
case NANOARROW_TYPE_LARGE_STRING:
case NANOARROW_TYPE_STRING_VIEW:
return resolver.Find(resolver.GetOID(PostgresTypeId::kText), out, error);
case NANOARROW_TYPE_BINARY:
case NANOARROW_TYPE_LARGE_BINARY:
case NANOARROW_TYPE_FIXED_SIZE_BINARY:
case NANOARROW_TYPE_BINARY_VIEW:
return resolver.Find(resolver.GetOID(PostgresTypeId::kBytea), out, error);
case NANOARROW_TYPE_DATE32:
case NANOARROW_TYPE_DATE64:
return resolver.Find(resolver.GetOID(PostgresTypeId::kDate), out, error);
case NANOARROW_TYPE_TIME32:
case NANOARROW_TYPE_TIME64:
return resolver.Find(resolver.GetOID(PostgresTypeId::kTime), out, error);
case NANOARROW_TYPE_DURATION:
case NANOARROW_TYPE_INTERVAL_MONTH_DAY_NANO:
return resolver.Find(resolver.GetOID(PostgresTypeId::kInterval), out, error);
case NANOARROW_TYPE_TIMESTAMP:
if (strcmp("", schema_view.timezone) == 0) {
return resolver.Find(resolver.GetOID(PostgresTypeId::kTimestamptz), out, error);
} else {
return resolver.Find(resolver.GetOID(PostgresTypeId::kTimestamp), out, error);
}
case NANOARROW_TYPE_DECIMAL128:
case NANOARROW_TYPE_DECIMAL256:
return resolver.Find(resolver.GetOID(PostgresTypeId::kNumeric), out, error);
case NANOARROW_TYPE_LIST:
case NANOARROW_TYPE_LARGE_LIST:
case NANOARROW_TYPE_FIXED_SIZE_LIST: {
PostgresType child;
NANOARROW_RETURN_NOT_OK(
PostgresType::FromSchema(resolver, schema->children[0], &child, error));
return resolver.FindArray(child.oid(), out, error);
}
case NANOARROW_TYPE_DICTIONARY:
// Dictionary arrays always resolve to the dictionary type when binding or ingesting
return PostgresType::FromSchema(resolver, schema->dictionary, out, error);
default:
ArrowErrorSet(error, "Can't map Arrow type '%s' to Postgres type",
ArrowTypeString(schema_view.type));
return ENOTSUP;
}
}