Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(types): support unsigned data types #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ to_postgres_type(int arrow_type)
case arrow::Type::BOOL:
return BOOLOID;
case arrow::Type::INT8:
case arrow::Type::UINT8:
case arrow::Type::INT16:
return INT2OID;
case arrow::Type::UINT16:
case arrow::Type::INT32:
return INT4OID;
case arrow::Type::UINT32:
case arrow::Type::UINT64:
case arrow::Type::INT64:
return INT8OID;
case arrow::Type::FLOAT:
Expand All @@ -63,6 +67,7 @@ to_postgres_type(int arrow_type)
return FLOAT8OID;
case arrow::Type::STRING:
return TEXTOID;
case arrow::Type::FIXED_SIZE_BINARY:
case arrow::Type::BINARY:
return BYTEAOID;
case arrow::Type::TIMESTAMP:
Expand All @@ -88,18 +93,27 @@ bytes_to_postgres_type(const char *bytes, Size len, const arrow::DataType *arrow
return BoolGetDatum(*(bool *) bytes);
case arrow::Type::INT8:
return Int16GetDatum(*(int8 *) bytes);
case arrow::Type::UINT8:
return UInt8GetDatum(*(uint8 *) bytes);
case arrow::Type::INT16:
return Int16GetDatum(*(int16 *) bytes);
case arrow::Type::UINT16:
return UInt16GetDatum(*(uint16 *) bytes);
case arrow::Type::INT32:
return Int32GetDatum(*(int32 *) bytes);
case arrow::Type::UINT32:
return UInt32GetDatum(*(uint32 *) bytes);
case arrow::Type::INT64:
return Int64GetDatum(*(int64 *) bytes);
case arrow::Type::UINT64:
return UInt64GetDatum(*(uint64 *) bytes);
case arrow::Type::FLOAT:
return Float4GetDatum(*(float *) bytes);
case arrow::Type::DOUBLE:
return Float8GetDatum(*(double *) bytes);
case arrow::Type::STRING:
return CStringGetTextDatum(bytes);
case arrow::Type::FIXED_SIZE_BINARY:
case arrow::Type::BINARY:
return PointerGetDatum(cstring_to_text_with_len(bytes, len));
case arrow::Type::TIMESTAMP:
Expand Down
2 changes: 2 additions & 0 deletions src/parquet_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,9 @@ create_foreign_table_query(const char *tablename,
else
is_first = false;

appendStringInfoChar(&str, '"');
appendStringInfoString(&str, paths[i]);
appendStringInfoChar(&str, '"');
}
appendStringInfoChar(&str, '\'');

Expand Down
35 changes: 34 additions & 1 deletion src/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,14 @@ Datum ParquetReader::read_primitive_type(arrow::Array *array,
res = Int8GetDatum(value);
break;
}
case arrow::Type::UINT8:
{
arrow::UInt8Array *uintarray = (arrow::UInt8Array *) array;
unsigned value = uintarray->Value(i);

res = UInt8GetDatum(value);
break;
}
case arrow::Type::INT16:
{
arrow::Int16Array *intarray = (arrow::Int16Array *) array;
Expand All @@ -393,6 +401,14 @@ Datum ParquetReader::read_primitive_type(arrow::Array *array,
res = Int16GetDatum(value);
break;
}
case arrow::Type::UINT16:
{
arrow::UInt16Array *uintarray = (arrow::UInt16Array *) array;
unsigned value = uintarray->Value(i);

res = UInt16GetDatum(value);
break;
}
case arrow::Type::INT32:
{
arrow::Int32Array *intarray = (arrow::Int32Array *) array;
Expand All @@ -401,6 +417,14 @@ Datum ParquetReader::read_primitive_type(arrow::Array *array,
res = Int32GetDatum(value);
break;
}
case arrow::Type::UINT32:
{
arrow::UInt32Array *uintarray = (arrow::UInt32Array *) array;
unsigned value = uintarray->Value(i);

res = UInt32GetDatum(value);
break;
}
case arrow::Type::INT64:
{
arrow::Int64Array *intarray = (arrow::Int64Array *) array;
Expand All @@ -409,6 +433,14 @@ Datum ParquetReader::read_primitive_type(arrow::Array *array,
res = Int64GetDatum(value);
break;
}
case arrow::Type::UINT64:
{
arrow::UInt64Array *uintarray = (arrow::UInt64Array *) array;
uint64 value = uintarray->Value(i);

res = UInt64GetDatum(value);
break;
}
case arrow::Type::FLOAT:
{
arrow::FloatArray *farray = (arrow::FloatArray *) array;
Expand All @@ -426,6 +458,7 @@ Datum ParquetReader::read_primitive_type(arrow::Array *array,
break;
}
case arrow::Type::STRING:
case arrow::Type::FIXED_SIZE_BINARY:
case arrow::Type::BINARY:
{
arrow::BinaryArray *binarray = (arrow::BinaryArray *) array;
Expand Down Expand Up @@ -505,7 +538,7 @@ Datum ParquetReader::nested_list_to_datum(arrow::ListArray *larray, int pos,

#if SIZEOF_DATUM == 8
/* Fill values and nulls arrays */
if (array->null_count() == 0 && typinfo.arrow.type_id == arrow::Type::INT64)
if (array->null_count() == 0 && (typinfo.arrow.type_id == arrow::Type::INT64 || typinfo.arrow.type_id == arrow::Type::UINT64))
{
/*
* Ok, there are no nulls, so probably we could just memcpy the
Expand Down