← Back to Pull requests

refactor: replace CometPlainVector boolean flags with VectorKind enum #7830

Open
unknown opened this pull request with 542 lines diff across 6 files
View on GitHub
unknown unknown commented on Dec 02, 2026 16:52 UTC
Author

<!-- copilot-assessment:v1 -->

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: f7e1b13184a1fe2f87ebdb8ca9a0bde0e4451e78

| Dimension | Assessment | Rationale |
|---|---|---|
| Change confidence | 9.5/10 | ↑ Replaces boolean flags and sentinel dispatch checks with VectorKind using direct == comparisons (VARIABLE_WIDTH first), javap -c confirms zero $SwitchMap / ordinal() overhead, Java spotless:check (104/104 Java files), TestCometPlainVector (8/8), and 5 Scala vector/Arrow suites (78/78 tests) all passed.<br>↓ Full Linux CI suite is pending workflow approval. |
<!-- /copilot-assessment -->

Which issue does this PR close?

<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example Closes #123 indicates that this PR will close issue #123.
-->

Closes #4433.

Rationale for this change

<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->

CometPlainVector previously dispatched on vector kinds using boolean flags (isBaseFixedWidthVector, isLargeVarWidth), -1 sentinel checks (offsetBufferAddress != -1, valueBufferAddress == -1), and an instanceof BaseFixedWidthVector check in getBinary. Replacing those dispatch checks with a single VectorKind enum makes vector-kind classification explicit and extensible.

What changes are included in this PR?

<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->

  • spark/src/main/java/org/apache/comet/vector/CometPlainVector.java:

  • - Introduced private enum VectorKind { NULL, FIXED_WIDTH, VARIABLE_WIDTH, LARGE_VARIABLE_WIDTH, OTHER } classified once in vectorKindOf(ValueVector), followed by single assignments to valueBufferAddress and offsetBufferAddress (which still hold -1L when a vector kind has no corresponding buffer).
    - Replaced the boolean-flag, sentinel, and instanceof dispatch checks in getUTF8String, getBinary, and isNullAt with direct VectorKind reference comparisons (==), checking the common VARIABLE_WIDTH case first to avoid javac $SwitchMap overhead.
    - Widened the fixed-width byte-offset calculation in getUTF8String and getBinary from int (rowId length) to long ((long) rowId length) to prevent 32-bit signed overflow past 2 GiB.
  • spark/src/test/java/org/apache/comet/vector/TestCometPlainVector.java:

  • - Added unit tests covering LargeVarCharVector, LargeVarBinaryVector, FixedSizeBinaryVector (plain and UUID decoding), NullVector, and IntervalMonthDayNanoVector.

    How are these changes tested?

    <!--
    We typically require tests for all PRs in order to:
    1. Prevent the code from being accidentally broken by subsequent changes
    2. Serve as another way to document the expected behavior of the code

    If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
    -->

  • .\mvnw.cmd -B spotless:check "-DspotlessFiles=.*\.java" — passed (6/6 Java files in comet-common, 98/98 Java files in comet-spark; 0 violations).

  • javap -c spark\target\classes\org\apache\comet\vector\CometPlainVector.class — verified no $SwitchMap, ordinal(), or synthetic switch class is generated; both getUTF8String and getBinary test VectorKind.VARIABLE_WIDTH with a single getfield + getstatic + if_acmpne.

  • .\mvnw.cmd -B test-compile surefire:test "-Dtest=org.apache.comet.vector.TestCometPlainVector" "-Dscalastyle.skip=true" "-Dspotless.check.skip=true" — passed (8/8 tests).

  • .\mvnw.cmd -B test "-Dtest=none" "-Dsuites=org.apache.spark.sql.comet.util.UtilsSuite,org.apache.comet.vector.CometVectorUtilsSuite,org.apache.comet.DirectColumnarToRowConverterSuite,org.apache.spark.sql.comet.execution.arrow.CometArrowStreamSuite,org.apache.spark.sql.comet.execution.arrow.CachedBatchRowIteratorSuite" "-Dscalastyle.skip=true" "-Dspotless.check.skip=true" — passed (5/5 suites, 78/78 tests).
  • Diff: 542 lines (+406 / -136) across 6 files Reviewer: comphead Review duration: 1819m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.53) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.53 · 542 lines diff across 6 files
    0.53
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.377
    Shallow Review Depth shallow_review_depth
    0.344
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #7830"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 53.0% (MEDIUM) · Higher = larger blast radius
    53.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 28.2% · Safe to merge
    28.2%