Skip to content

[SPARK-1308] Add getNumPartitions to pyspark RDD - #995

Closed
syedhashmi wants to merge 1 commit into
apache:masterfrom
syedhashmi:master
Closed

syedhashmi wants to merge 1 commit into
apache:masterfrom
syedhashmi:master

Conversation

@syedhashmi

Copy link
Copy Markdown

Add getNumPartitions to pyspark RDD to provide an intuitive way to get number of partitions in RDD like we can do in scala today.

Add getNumPartitions to pyspark RDD to provide an intuitive
way to get numbr of partitions in RDD like we can do in
scala today.
@AmplabJenkins

Copy link
Copy Markdown

Can one of the admins verify this patch?

@rxin

rxin commented Jun 9, 2014

Copy link
Copy Markdown
Contributor

Jenkins, test this please.

@AmplabJenkins

Copy link
Copy Markdown

Merged build triggered.

@AmplabJenkins

Copy link
Copy Markdown

Merged build started.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. All automated tests passed.

@AmplabJenkins

Copy link
Copy Markdown

All automated tests passed.
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/15556/

@rxin

rxin commented Jun 9, 2014

Copy link
Copy Markdown
Contributor

Thanks. I've merged this in master.

@asfgit asfgit closed this in 6113ac1 Jun 9, 2014
pdeyhim pushed a commit to pdeyhim/spark-1 that referenced this pull request Jun 25, 2014
Add getNumPartitions to pyspark RDD to provide an intuitive way to get number of partitions in RDD like we can do in scala today.

Author: Syed Hashmi <shashmi@cloudera.com>

Closes apache#995 from syedhashmi/master and squashes the following commits:

de0ed5e [Syed Hashmi] [SPARK-1308] Add getNumPartitions to pyspark RDD
xiliu82 pushed a commit to xiliu82/spark that referenced this pull request Sep 4, 2014
Add getNumPartitions to pyspark RDD to provide an intuitive way to get number of partitions in RDD like we can do in scala today.

Author: Syed Hashmi <shashmi@cloudera.com>

Closes apache#995 from syedhashmi/master and squashes the following commits:

de0ed5e [Syed Hashmi] [SPARK-1308] Add getNumPartitions to pyspark RDD
wangyum pushed a commit that referenced this pull request May 26, 2023
…995)

Extend the `TransposeWindow` rule to transpose `Window` nodes, that have `Project` between them.

The analyzer will turn a `dataset.withColumn("colName", expressionWithWindowFunction)` method call to a `Project - Window - Project` chain in the logical plan. When this method is called multiple times in a row, then the projects can block the `Window` nodes from being transposed by the current `TransposeWindow` rule.

TPCDS q47 and q57 are also improved by this.

No

UT

Closes #31980 from tanelk/SPARK-34807_transpose_window.

Lead-authored-by: tanel.kiis@gmail.com <tanel.kiis@gmail.com>
Co-authored-by: Tanel Kiis <tanel.kiis@gmail.com>
Signed-off-by: Yuming Wang <yumwang@ebay.com>

Co-authored-by: Tanel Kiis <tanel.kiis@gmail.com>
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Oct 23, 2026
…on and abs as one op (apache#995)

apache#992 and apache#993, which this was stacked on, have merged; master is merged in, and the diff against master is exactly the change (`03862a58f27`, plus the record of the owner's decision to keep the SMALLINT slices always on).

### What changes were proposed in this pull request?

`TINYINT` and `SMALLINT` kernels can be emitted two ways. The widened arm loads a narrow column into the int lane and computes in ints; the native arm computes in `ByteVector`/`ShortVector` directly. The native arm was faster on every measured all-narrow shape, 2x to 16x depending on vector width, but the widened arm was the default. This pull request makes the native arm the default, and fixes the emission findings of the reviews of apache#987 and apache#989 that change emitted bytes, so the generated files move once.

- **The lane is decided once per kernel.** The compiler, the budget check, the emitter and the compiled projection each read a kernel's lane from its first output. Under the native default that would have split `SELECT y1 + y2, i + 1`: the first entry native at the byte lane, the second at the int lane, so the second went back to Spark's row engine. `VarkaVectorIR.kernelLane` now gives one lane for all the roots: their own where they agree, the int lane where they differ and none is bigint (every narrow tree also has the widened lowering), and none where a bigint root meets another. All four consumers read it. If joining an entry would move a native kernel to the int lane at a width that cannot widen, that entry is demoted with a reason that says so.
- **The native arm is the default.** `narrowLanes` ships true. The widened arm stays as an option the option matrix runs, as `narrowLanes=false`.
- **Narrow negation is one `NEG`.** It was a multiply by -1, and x86 has no byte multiply, so it became an eight-instruction sequence. The int and long lanes keep the multiply until it is measured (row 482).
- **Narrow `abs` is one `ABS`.** It was compiled as `IfElse(x < 0, -x, x)`: a compare, a negation and a blend, and the root lost the all-null shortcut. It is now the negation node with an `abs` flag, since the two have the same single overflowing input and the same check. At the int lane a wrapping `abs` reduces its own result, because `abs` does not commute with the narrow wrap (`abs(-128)` and `abs(128)` differ).
- **A narrow `CASE` reduces once.** On the int lane, a wrapping narrow chain is reduced to its width only where a reader needs the exact value. A blend only picks lanes, so a narrow pick now passes its arms' unreduced values through and reduces once, instead of once in each arm.
- **One truncation helper.** Narrowing an int value to `TINYINT`/`SMALLINT` away from a store now uses the same shift pair as the wrap, not a round trip through the narrow species.
- **Grouping weights** count the shift pair a wrapping narrow node may emit.

### Why are the changes needed?

The native arm is the faster one on every measured all-narrow shape, but nothing used it unless a test asked for it. Making it the default without the per-kernel lane would have sent mixed projections back to the row engine. The negation and `abs` changes remove an emulated byte multiply and a three-op composition from every narrow negation and `abs`. The narrow `CASE` and truncation changes remove duplicate reductions and a second lowering of one operation.

### Does this PR introduce _any_ user-facing change?

Faster queries over `TINYINT` and `SMALLINT` columns where every value is narrow. Answers are unchanged.

### How was this patch tested?

- **Emitted bytes:** `emitted_bytes.json` moved only for the 34 narrow coverage rows at each width and the aggregate option-arm digests that include them. No non-narrow row moved.
- **New tests:**
  - A kernel of a byte sum, a short `abs` and an int sum runs on both arms against the reference.
  - The `kernelLane` answers are pinned.
  - The LEGACY chain test gains two pick shapes, a chain picked by a `CASE` and the same under `abs`. They are LEGACY only, since Spark evaluates a `CASE` branch only on the rows the condition picks.
- **Tests pinned to the widened arm:** `VarkaEmitterNarrowArithSuite`'s width-rule test took the defaults to mean the widened arm, and now pins it.
- **Suites:** all `Varka*` suites in `catalyst` and `sql` pass (`sql`: 1281 ok, 0 failed).
- **Option matrix,** ok / cancelled, nothing failed or unfused:

  | configuration | catalyst (narrow, arithmetic, family, coverage, width audit, bytes) | `VarkaCoverageDifferentialSuite` |
  | :-- | --: | --: |
  | defaults (now native) | 63 / 20 | 799 / 0 |
  | `narrowLanes=false` | 63 / 20 | 799 / 0 |
  | `lanesOverride=4` | 63 / 20 | 799 / 0 |
  | `validityByWidth=false` | 32 / 51 | 772 / 27 |

  Under `validityByWidth=false` the native arm needs no baked lane count, so 52 skip lines went stale and are removed. The rows still declining there are the checked multiplies, which always run at the int lane, and rows that read a narrow column beside an int value.
- **Benchmark** (`results/VARKA-329-negabs.txt`, laptop, before and after, with two new shapes in `VarkaNarrowEmitBenchmark`):
  - On the native arm, a byte negation and `abs` run 3.0x to 3.4x faster in L1 at 512 and 256 bits, 2.1x to 2.4x at 512 KB, and 1.15x to 1.26x at 2 MB, where the store is memory bound.
  - On the widened arm, `abs` gains 1.43x to 1.48x and negation 1.06x to 1.13x.
  - The control shape is unchanged, and no cell is slower.
- **Warm-up:** the reach gate passes with `NEG` and `ABS` warmed at the native and widened species.
- **Linters:** Error Prone, `lint-java`, `lint-scala`, the plan linter and the pre-commit hook pass.
- **Review:** an independent reviewer found no correctness bug. It noted three things that are by design or belong to rows:
  - an entry demoted for joining is not retried in a kernel of its own (row 480);
  - an int entry moves the kernel's native narrow entries to the widened lowering, the mixed shape the two arms tie on;
  - the IR fuzzers draw no narrow arithmetic, narrow `CASE` or `abs` (row 352).

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 5.5)
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

Successfully merging this pull request may close these issues.

3 participants