Skip to content
Merged
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
66 changes: 45 additions & 21 deletions src/nanoarrow/ipc/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -1139,26 +1139,30 @@ static int ArrowIpcDecoderSetTypeUnion(struct ArrowSchema* schema,

static int ArrowIpcDecoderSetType(struct ArrowSchema* schema, ns(Field_table_t) field,
int64_t n_children, struct ArrowError* error) {
int type_type = ns(Field_type_type(field));
ns(Type_union_type_t) type_type = ns(Field_type_type(field));
flatbuffers_generic_t type = ns(Field_type_get(field));
if (type == NULL) {
ArrowErrorSet(error, "Field type '%s' has no value", ns(Type_type_name(type_type)));
return EINVAL;
}

switch (type_type) {
case ns(Type_Null):
return ArrowIpcDecoderSetTypeSimple(schema, NANOARROW_TYPE_NA, error);
case ns(Type_Bool):
return ArrowIpcDecoderSetTypeSimple(schema, NANOARROW_TYPE_BOOL, error);
case ns(Type_Int):
return ArrowIpcDecoderSetTypeInt(schema, ns(Field_type_get(field)), error);
return ArrowIpcDecoderSetTypeInt(schema, type, error);
case ns(Type_FloatingPoint):
return ArrowIpcDecoderSetTypeFloatingPoint(schema, ns(Field_type_get(field)),
error);
return ArrowIpcDecoderSetTypeFloatingPoint(schema, type, error);
case ns(Type_Decimal):
return ArrowIpcDecoderSetTypeDecimal(schema, ns(Field_type_get(field)), error);
return ArrowIpcDecoderSetTypeDecimal(schema, type, error);
case ns(Type_Binary):
return ArrowIpcDecoderSetTypeSimple(schema, NANOARROW_TYPE_BINARY, error);
case ns(Type_LargeBinary):
return ArrowIpcDecoderSetTypeSimple(schema, NANOARROW_TYPE_LARGE_BINARY, error);
case ns(Type_FixedSizeBinary):
return ArrowIpcDecoderSetTypeFixedSizeBinary(schema, ns(Field_type_get(field)),
error);
return ArrowIpcDecoderSetTypeFixedSizeBinary(schema, type, error);
case ns(Type_BinaryView):
ArrowErrorSet(error, "BinaryView not yet supported in IPC reader");
return ENOTSUP;
Expand All @@ -1170,33 +1174,31 @@ static int ArrowIpcDecoderSetType(struct ArrowSchema* schema, ns(Field_table_t)
ArrowErrorSet(error, "Utf8View not yet supported in IPC reader");
return ENOTSUP;
case ns(Type_Date):
return ArrowIpcDecoderSetTypeDate(schema, ns(Field_type_get(field)), error);
return ArrowIpcDecoderSetTypeDate(schema, type, error);
case ns(Type_Time):
return ArrowIpcDecoderSetTypeTime(schema, ns(Field_type_get(field)), error);
return ArrowIpcDecoderSetTypeTime(schema, type, error);
case ns(Type_Timestamp):
return ArrowIpcDecoderSetTypeTimestamp(schema, ns(Field_type_get(field)), error);
return ArrowIpcDecoderSetTypeTimestamp(schema, type, error);
case ns(Type_Duration):
return ArrowIpcDecoderSetTypeDuration(schema, ns(Field_type_get(field)), error);
return ArrowIpcDecoderSetTypeDuration(schema, type, error);
case ns(Type_Interval):
return ArrowIpcDecoderSetTypeInterval(schema, ns(Field_type_get(field)), error);
return ArrowIpcDecoderSetTypeInterval(schema, type, error);
case ns(Type_Struct_):
return ArrowIpcDecoderSetTypeSimpleNested(schema, "+s", error);
case ns(Type_List):
return ArrowIpcDecoderSetTypeSimpleNested(schema, "+l", error);
case ns(Type_LargeList):
return ArrowIpcDecoderSetTypeSimpleNested(schema, "+L", error);
case ns(Type_FixedSizeList):
return ArrowIpcDecoderSetTypeFixedSizeList(schema, ns(Field_type_get(field)),
error);
return ArrowIpcDecoderSetTypeFixedSizeList(schema, type, error);
case ns(Type_ListView):
case ns(Type_LargeListView):
ArrowErrorSet(error, "ListView/LargeListView not yet supported in IPC reader");
return ENOTSUP;
case ns(Type_Map):
return ArrowIpcDecoderSetTypeMap(schema, ns(Field_type_get(field)), error);
return ArrowIpcDecoderSetTypeMap(schema, type, error);
case ns(Type_Union):
return ArrowIpcDecoderSetTypeUnion(schema, ns(Field_type_get(field)), n_children,
error);
return ArrowIpcDecoderSetTypeUnion(schema, type, n_children, error);
case ns(Type_RunEndEncoded):
ArrowErrorSet(error, "RunEndEncoded not yet supported in IPC reader");
return ENOTSUP;
Expand Down Expand Up @@ -1229,6 +1231,9 @@ static int ArrowIpcSetDictionaryEncoding(
return EINVAL;
}

int64_t field_flags = schema->flags;
schema->flags |= ARROW_FLAG_NULLABLE;

struct ArrowSchema tmp;
ArrowSchemaMove(schema, &tmp);

Expand Down Expand Up @@ -1259,6 +1264,10 @@ static int ArrowIpcSetDictionaryEncoding(
schema->flags |= ARROW_FLAG_DICTIONARY_ORDERED;
}

if (!(field_flags & ARROW_FLAG_NULLABLE)) {
schema->flags &= ~ARROW_FLAG_NULLABLE;
}

// Sort out field metadata between the schema and the dictionary member
NANOARROW_RETURN_NOT_OK_WITH_ERROR(ArrowIpcMoveDictionaryMetadataBackToField(schema),
error);
Expand Down Expand Up @@ -1424,6 +1433,11 @@ static int ArrowIpcDecoderDecodeDictionaryBatchHeader(
(struct ArrowIpcDecoderPrivate*)decoder->private_data;

ns(DictionaryBatch_table_t) dictionary = (ns(DictionaryBatch_table_t))message_header;
if (!ns(DictionaryBatch_data_is_present(dictionary))) {
ArrowErrorSet(error, "DictionaryBatch has no data");
return EINVAL;
}

private_data->dictionary.id = ns(DictionaryBatch_id(dictionary));
private_data->dictionary.is_delta = ns(DictionaryBatch_isDelta(dictionary));

Expand Down Expand Up @@ -1710,7 +1724,8 @@ ArrowErrorCode ArrowIpcDecoderDecodeHeader(struct ArrowIpcDecoder* decoder,

// Read some basic information from the message
decoder->metadata_version = ns(Message_version(message));
decoder->message_type = ns(Message_header_type(message));
ns(MessageHeader_union_type_t) message_type = ns(Message_header_type(message));
decoder->message_type = message_type;
decoder->body_size_bytes = ns(Message_bodyLength(message));

switch (decoder->metadata_version) {
Expand All @@ -1730,7 +1745,13 @@ ArrowErrorCode ArrowIpcDecoderDecodeHeader(struct ArrowIpcDecoder* decoder,
}

flatbuffers_generic_t message_header = ns(Message_header_get(message));
switch (decoder->message_type) {
if (message_header == NULL) {
ArrowErrorSet(error, "Message header '%s' has no value",
ns(MessageHeader_type_name(message_type)));
return EINVAL;
}

switch (message_type) {
case ns(MessageHeader_Schema):
NANOARROW_RETURN_NOT_OK(
ArrowIpcDecoderDecodeSchemaHeader(decoder, message_header, error));
Expand Down Expand Up @@ -2776,11 +2797,14 @@ static ArrowErrorCode ArrowIpcDecoderDecodeDictionaryInternal(
struct ArrowIpcDecoderPrivate* dictionary_decoder_private_data =
(struct ArrowIpcDecoderPrivate*)dictionary->decoder.private_data;
dictionary->decoder.message_type = NANOARROW_IPC_MESSAGE_TYPE_RECORD_BATCH;
dictionary_decoder_private_data->last_message = record_batch;
dictionary->decoder.metadata_version = decoder->metadata_version;
// Transfer the endianness and compression settings so that buffers are byte-swapped
// and decompressed if needed (the nested decoder uses a default decompressor)
dictionary_decoder_private_data->endianness = private_data->endianness;
dictionary->decoder.codec = decoder->codec;
// Validate the nested batch's node and buffer counts before accessing its vectors.
NANOARROW_RETURN_NOT_OK(
ArrowIpcDecoderDecodeRecordBatchHeader(&dictionary->decoder, record_batch, error));
dictionary_decoder_private_data->last_message = record_batch;

struct ArrowArrayView* array_view;
NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderDecodeArrayViewInternal(
Expand Down
Loading
Loading