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

Table concatenation results in empty table #329

Open
alexbezhan opened this issue Jun 1, 2023 · 0 comments
Open

Table concatenation results in empty table #329

alexbezhan opened this issue Jun 1, 2023 · 0 comments

Comments

@alexbezhan
Copy link

If I have multiple tables that I want to concatenate, if the first table is empty, then the final concatenated table is also empty.
Code:

export async function fetchArrowFilesAndConcat(fetches: Parameters<typeof fetch>[0][]) {
    let table: ColumnTable | undefined = undefined
    for (const f of fetches) {
        const response = await fetch(f)
        const responseData = await response.arrayBuffer()
        const newTable = aq.fromArrow(responseData)
        table = table === undefined ? newTable : table.concat(newTable)
    }
    assertDefined(table, `table must be defined`)
    return table // table is empty here if the first table was empty
}

And this is a fixed version - I skip the first empty table:

export async function fetchArrowFilesAndConcat(fetches: Parameters<typeof fetch>[0][]) {
    let table: ColumnTable | undefined = undefined
    let emptyTableSkipped = false
    for (const f of fetches) {
        const response = await fetch(f)
        const responseData = await response.arrayBuffer()
        const newTable = aq.fromArrow(responseData)
        const numRows = newTable.numRows()
        if (numRows === 0 && emptyTableSkipped === false) {
            emptyTableSkipped = true
            continue // skip first empty table, because it's causing the final table to be empty as well
        }
        table = table === undefined ? newTable : table.concat(newTable)
    }
    assertDefined(table, `table must be defined`)
    return table
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant