Skip to content

[EPIC] Faster Spark-to-Arrow conversion in CometSparkToColumnarExec #6565

Description

@andygrove

What / Why

CometSparkToColumnarExec converts Spark rows and Spark column vectors to Arrow so that native operators can consume them. The conversion goes through ArrowWriter, which CometLocalTableScanExec and the Comet cache serializer also use. I measured it one column type at a time on main at 93d1189be, with 8192-row batches. Several common cases are far slower than they need to be:

  • Decimals cost 30-160 ns per row, 30 to 100 times the cost of an int. Arrow's BigDecimal setter allocates a BigInteger and two byte arrays per value, on top of the Decimal and BigDecimal that Spark's getters build.
  • The bulk copy for fixed-width columns (perf: bulk copy fixed-width columns in ArrowWriter #5442) is skipped when a batch holds a single null, and for every dictionary-encoded column. Spark's Parquet reader leaves low-cardinality columns dictionary-encoded.
  • Strings cost 13-16 ns per row, written one value at a time through Arrow's setSafe. A dictionary-encoded string also allocates a copy of its bytes on every row, because Parquet's dictionary returns a fresh array for each decode.
  • Arrays, maps and structs are written one element at a time: about 90 ns per row for array<string> and 200 ns for map<string,string>, with five entries on average.
  • Spark's vectorized Parquet reader produces 4096-row batches, and each becomes one Arrow batch, so native operators get half of Comet's batch size. The cache produces 10000-row batches, which become alternating Arrow batches of 8192 and 1808 rows.

End to end, conversion took 549 ms of a 1088 ms TPC-H Q1-style query over Spark's Parquet reader.

Work

No activity

Activity on this issue will appear here.

Activity

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions