Skip to content

[TPCDS] Fix large-scale data generation and partition sizing - #7877

Closed
pan3793 wants to merge 4 commits into
apache:masterfrom
pan3793:fix/tpcds-large-scale-row-count
Closed

pan3793 wants to merge 4 commits into
apache:masterfrom
pan3793:fix/tpcds-large-scale-row-count

Conversation

@pan3793

@pan3793 pan3793 commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Why are the changes needed?

  1. io.trino.tpcds (1.4) narrows startingRowNumber to int in AbstractRowGenerator.skipRowsUntilStartingRowNumber:
    randomNumberStream.skipRows((int) startingRowNumber - 1).
    When generating large-scale TPC-DS tables whose row counts exceed Int.MaxValue (store_sales/store_returns at SF10000+, catalog_sales/catalog_returns at SF30000+, web_sales/web_returns at SF100000), the cast wraps negative and RandomNumberStreamImpl.skipRows skips zero rows, corrupting generated data and row counts. Both kyuubi-spark-connector-tpcds and dev/kyuubi-tpcds now seek table, parent, and child random streams using the full Long offset (startingRowNumber - 1), and iterate in computeNext() instead of recursing on empty rows.
  2. TPCDSBatchScan previously computed (_sizeInBytes / readConf.maxPartitionBytes).ceil.toInt, performing truncating Long integer division before .ceil and risking silent Int overflow, and only skipped parallelization for table.isSmall (leaving chunks 2..N empty for tables with < 1,000,000 orders per Parallel.splitWork). It now validates maxPartitionBytes > 0 unconditionally, plans 1 partition when table.isSmall || new Scaling(scale).getRowCount(table) < 1000000, and computes partition count with Math.toIntExact(LongMath.divide(_sizeInBytes, maxPartitionBytes, RoundingMode.CEILING)).
  3. Align all 127 TPC-DS Identifier columns to BIGINT/LongType per Section 2.2.2.1 a) of the TPC-DS v4.0.0 Specification and SPARK-62327:
    • In dev/kyuubi-tpcds DataGenerator, widen all Identifier columns (including cs_order_number, cr_order_number, ss_ticket_number, ws_order_number, all *_sk columns, and c_last_review_date_sk) to .long to avoid SF10000+ INT overflow and type mismatches.
    • In kyuubi-spark-connector-tpcds (TPCDSSchemaUtils.reviseColumnType), map cc_closed_date_sk, cc_open_date_sk, cp_start_date_sk, and cp_end_date_sk to LongType (working around io.trino.tpcds 1.4 declaring those four foreign-key columns as INTEGER).

Originally authored by @cfmcgrady in cfmcgrady:incubator-kyuubi:fix/tpcds-large-scale-row-count.

How was this patch tested?

Added unit tests in TPCDSTableSuite covering:

  1. Split consistency across the Int.MaxValue row-number boundary for store_sales and store_returns at SF10000.
  2. Large-scale partition row counts and first-row (order/ticket_number, item_sk, date_sk) keys matching native dsdgen across SF10000, SF30000, and SF100000 for store_*, catalog_*, and web_* tables.
  3. Exact ceiling partition sizing with non-empty reader checks (sf10.store_sales), defaultParallelism floor, single-partition planning for sub-1M / small tables (sf1.store_sales, sf0.store_sales, sf1.call_center), and non-positive maxPartitionBytes validation across all table sizes.
  4. All 127 Identifier columns across all 24 base tables mapping to LongType.

Ran locally on Scala 2.12 and Scala 2.13 (Spark 3.5 / 4.2) and -Pcross-version-test:

build/mvn test scalastyle:check spotless:check apache-rat:check -Ptpcds \
  -pl dev/kyuubi-tpcds,extensions/spark/kyuubi-spark-connector-tpcds -am \
  -Dtest=none -DwildcardSuites=org.apache.kyuubi.spark.connector.tpcds.TPCDSTableSuite,org.apache.kyuubi.spark.connector.tpcds.TPCDSCatalogSuite,org.apache.kyuubi.spark.connector.tpcds.TPCDSSchemaUtilsSuite

Was this patch assisted by generative AI tooling?

Assisted-by: DeepSeek Harness (Gemini 4 Neon)

Seek parent and child random streams with Long offsets in both the Spark connector and dev generator to avoid row-number truncation at large scales, and iterate instead of recursing in computeNext().

Round partition counts up with exact integer division, validate positive maxPartitionBytes, widen large-scale order/ticket number columns to Long in DataGenerator, and add regression tests for split boundaries, native dsdgen samples, and partition sizing.

Co-authored-by: Fu Chen <cfmcgrady@gmail.com>
@pan3793

pan3793 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Maybe we should migrate all Identifier columns from INT to BIGINT for consistency, let me hold this for a while and wait for Spark side decision.

@pan3793
pan3793 marked this pull request as ready for review November 25, 2026 02:50
@pan3793

pan3793 commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

SPARK-62327 has been accepted by the Spark community, which maps all Identifier columns from INT to the BIGINT, this PR is updated to follow that.

cfmcgrady added a commit to cfmcgrady/incubator-kyuubi that referenced this pull request Nov 25, 2026
@cfmcgrady

Copy link
Copy Markdown
Contributor

I checked a33edc7 on Spark 4.2.1. The six sampled sales and returns chunks matched native dsdgen field by field with the default seed. I found two cases worth covering in the tests.

Partition sizing. The new ceiling test uses sf1.store_sales. With five planned partitions, Parallel.splitWork gives all 240,000 orders to the first reader and leaves four readers empty. Trino applies its one-million-order threshold here, while the scan checks table.isSmall. Could we use sf10.store_sales for the rounding case and assert that each planned reader produces a row? A separate SF1 case could cover the empty-task behavior. I also found that maxPartitionBytes=0 passes planning for sf1.call_center and throws for sf1.store_sales, because the small-table branch skips validation. Partition test

Catalog dates at a chunk boundary. At SF100000, read chunk 15213974 of 80000000, then compare it with chunks 30427947 and 30427948 of 160000000 combined. This covers the same 200 orders. Both reads produced 1,856 sales and 204 returns. For order 3042794701, the two reads returned the following date keys.

Column One chunk Two chunks
cs_sold_date_sk 2451171 2451172
cr_returned_date_sk 2451350 2451351

I reproduced the one-day shift through both Kyuubi iterators and native dsdgen. I’d track the upstream date-boundary behavior separately. For this PR, a fixed-chunk assertion on order, item and date keys in both Kyuubi paths would catch value regressions that the native row counts alone miss. Catalog count assertions · Upstream date initialization

OpenAI Codex (GPT-6.2 Astra) performed this review and ran the targeted checks described above.

@pan3793

pan3793 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Thanks for the review and thorough verification! Addressed in 7659623a0:

  1. Updated TPCDSBatchScan to validate maxPartitionBytes > 0 before the single-partition branch and to plan 1 partition when new Scaling(scale).getRowCount(table) < 1000000 (matching Parallel.splitWork), avoiding empty tasks for sub-1M tables like sf1.store_sales. Updated TPCDSTableSuite to run the ceiling-rounding cases on sf10.store_sales with non-empty reader checks, verify 1 partition on sf1.store_sales/sf0.store_sales/sf1.call_center, and verify maxPartitionBytes=0 throws for both small and large tables.
  2. Added first-row (order/ticket_number, item_sk, date_sk) assertions matching native dsdgen across all 14 SF10000/SF30000/SF100000 samples in TPCDSTableSuite. The exact day-boundary 1-day shift in catalog_sales/catalog_returns is pre-existing upstream in dsdgen and io.trino.tpcds (Parallel.skipDaysUntilFirstRowOfChunk), so leaving it aligned with upstream and tracking separately.

@cfmcgrady

Copy link
Copy Markdown
Contributor

Thanks for the update. I rechecked 7659623 on Spark 4.2.1. sf1.store_sales now plans one partition, all five readers in the SF10 rounding case produce data, and maxPartitionBytes=0 is rejected for both small and large tables. I agree with tracking the catalog date-boundary behavior upstream.

  1. Partition count can still exceed the number of orders. With sf10.store_sales and maxPartitionBytes=1024, the scan plans 4,612,659 partitions for 2,400,000 orders. Reader 2,400,000 produces data. Readers 2,400,001 through 4,612,659 receive empty ranges, leaving 2,212,659 empty tasks. Could we cap the calculated parallelism at new Scaling(scale).getRowCount(table) before converting to Int? A test of the count calculation would cover this without allocating millions of partitions.

  2. The dev generator still lacks regression coverage. I compared all 8,379 rows across the 14 samples with native dsdgen. Order or ticket number, item key, and date key matched row by row through both Kyuubi readers. The new test exercises only TPCDSPartitionReader. Could we also run one sales/returns sample starting beyond Int.MaxValue through the dev module’s TPCDSRowIterator in CI? That would catch the two implementations drifting apart.

OpenAI Codex (GPT-6.2 Astra) performed this review and ran the targeted checks above.

@pan3793

pan3793 commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

Addressed in 7f735f6c1:

  1. Capped TPCDSBatchScan.parallelism at new Scaling(scale).getRowCount(table) before Math.toIntExact so small maxPartitionBytes values do not schedule empty partitions past the order count, and added unit assertions in TPCDSTableSuite (sf10.store_sales with maxPartitionBytes = 1024 and 1 -> 2,400,000).
  2. Deferring CI test enablement for dev/kyuubi-tpcds as out of scope for this PR: dev/kyuubi-tpcds/pom.xml intentionally keeps <skipTests>true</skipTests> and the module is not wired into CI test workflows.

@pan3793 pan3793 self-assigned this Nov 27, 2026
@pan3793 pan3793 added this to the v1.13.0 milestone Nov 27, 2026
@pan3793 pan3793 closed this in 1f7a47a Nov 27, 2026
@pan3793

pan3793 commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

Merge Summary:

Posted by merge_kyuubi_pr.py

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants