Skip to content

Commit

Permalink
arrow_fdw didn't map binary compatible data types
Browse files Browse the repository at this point in the history
e.g) text and varchar are binary compatible and pg2arrow maps them
     Arrow::Utf8, however, arrow_fdw rejected to map Utf8 as varchar.
  • Loading branch information
kaigai committed Mar 27, 2024
1 parent 417dde4 commit a43dcb4
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/arrow_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1966,8 +1966,28 @@ BuildArrowFileState(Relation frel, const char *filename, Bitmapset **p_stat_attr
{
Form_pg_attribute attr = TupleDescAttr(tupdesc, j);
RecordBatchFieldState *rb_field = &rb_state->fields[j];
bool compatible = false;

if (attr->atttypid != rb_field->atttypid)
if (attr->atttypid == rb_field->atttypid)
compatible = true;
else
{
/* check for binary compatible data types */
HeapTuple htup;

htup = SearchSysCache2(CASTSOURCETARGET,
ObjectIdGetDatum(rb_field->atttypid),
ObjectIdGetDatum(attr->atttypid));
if (HeapTupleIsValid(htup))
{
Form_pg_cast cast = (Form_pg_cast) GETSTRUCT(htup);

if (cast->castmethod == COERCION_METHOD_BINARY)
compatible = true;
ReleaseSysCache(htup);
}
}
if (!compatible)
elog(ERROR, "arrow_fdw: foreign table '%s' column '%s' (%s) is not compatible to the arrow field (%s) in the '%s'",
RelationGetRelationName(frel),
NameStr(attr->attname),
Expand Down

0 comments on commit a43dcb4

Please sign in to comment.