Skip to content

[File format] Make all ragged column pairs optional on load #537

Closed as not planned

Description

@jeromekelleher

#530 added some infrastructure for dealing with ragged column pairs, but there's still a lot of duplicated effort and the loading logic is quite convoluted. It would be much simpler if we have a unified way of stating a ragged column pair and they were all optional.

One way we might do this would look something like this:

static int
tsk_individual_table_load(tsk_individual_table_t *self, kastore_t *store)
{
    int ret = 0;
    tsk_flags_t *flags = NULL;
    double *location = NULL;
    tsk_size_t *location_offset = NULL;
    char *metadata = NULL;
    tsk_size_t *metadata_offset = NULL;
    tsk_size_t num_rows;

    read_table_col_t cols[] = {
        { "individuals/flags", (void **) &flags, KAS_UINT32, 0 },
    };
    read_table_ragged_col_t ragged_cols[] = {
        { "individuals/location", (void **) &location, &location_offset, KAS_FLOAT64, 0 },
        { "individuals/metadata", (void **) &metadata, &metadata_offset, KAS_UINT8, 0 },
    };

    ret = read_table_main_cols(store, &num_rows, cols, sizeof(cols) / sizeof(*cols));
    if (ret != 0) {
        goto out;
    }
    ret = read_table_ragged_cols(store, num_rows, ragged_cols,
            sizeof(ragged_cols) / sizeof(*ragged_cols));
    if (ret != 0) {
        goto out;
    }
    ret = tsk_individual_table_set_columns(
        self, num_rows, flags, location, location_offset, metadata, metadata_offset);
    if (ret != 0) {
        goto out;
    }
    ret = read_table_metadata_schema(store, "individuals", self,
        tsk_individual_table_set_metadata_schema);
out:
    return ret;
}

So, we split up the different read types into main columns (must all be the same length), and ragged columns which must have an offset column of length num_rows + 1, and have offset[num_rows] == data_length. If any ragged pair is not specified, then set_columns handles this in the obvious way.

(It's not going to be quite as simple as this, unfortunately, as the population and provenance tables have no "main" columns. So read_table_ragged_cols will need a special case for num_rows==TSK_NULL where we determine num_rows within it. Perhaps we should return num_rows from these functions instead, and check for negative values as the error condition.)

This will make our lives easier because we can use the same code for all ragged columns, and don't have to distinguish between optional and not. The test code for this is now easy to do and we can verify that we're doing the right thing easily.

Whether we write out the columns optionally or not is another question, which we can address elsewhere.

Activity

  1. added this to the C API 0.99.3 milestone on May 7, 2020
  2. jeromekelleher commented on Jul 6, 2020

    @jeromekelleher
    MemberAuthor

    pushing this out to 0.99.4 because 0.99.3 now only requires a minor file format version bump.

  3. added
    C API
    enhancement
    on Sep 29, 2020
  4. benjeffery commented on Jun 6, 2025

    @benjeffery
    Member

    #2032 did most of what was proposed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C APIenhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions