[SPARK-58711][SQL] Use StructType.getFieldIndex in Parquet and ORC aggregate push down
### What changes were proposed in this pull request?
Uses `StructType.getFieldIndex` for the column lookups in the Parquet and ORC aggregate push down paths:
```scala
index = dataSchema.getFieldIndex(colName).getOrElse(-1) // was fieldNames.toList.indexOf(colName)
if (partitionSchema.getFieldIndex(colName).isDefined) { // was fields.map(_.name).toSet.contains(colName)
```
Three sites in `ParquetUtils` and one in `OrcUtils`.
### Why are the changes needed?
`fieldNames` is a `def` that allocates a fresh `Array` on every call, and the Parquet sites then convert it to a `List`, so each lookup allocated twice and scanned linearly; the `partitionSchema` check built a whole `Set` per call. `getFieldIndex` reads the cached `nameToIndex` map.
To be accurate about the size of this: **it is a readability and allocation cleanup, not a measurable speedup.** Aggregate push down is off by default, and each surrounding loop iteration reads Parquet or ORC footer statistics, which dominates any name lookup. The `OrcUtils` site is included because the two push down implementations are deliberate mirrors that share `AggregatePushDownUtils`.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Existing aggregate push down tests (`FileSourceAggregatePushDownSuite`) cover both paths.
`getOrElse(-1)` matches `indexOf`'s not-found contract, and the exact-match `getFieldIndex` is used rather than `getFieldIndexCaseInsensitive`, preserving case sensitivity. The one case where the two forms would differ is a schema with duplicate column names, where `indexOf` returns the first match and a name-keyed map the last; `FileTable.schema` runs `checkSchemaColumnNameDuplication` on both the data and partition schemas before any scan is built, and both `ParquetTable` and `OrcTable` extend `FileTable`, so that case is unreachable.
Note: open PR #57030 touches the same two `ParquetUtils` lines. There is no logical conflict, and I am happy to rebase if that one lands first.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8)
Closes #57929 from uros-b/perf-parquetutils-fieldindex.
Authored-by: Uros <221401595+uros-b@users.noreply.github.com>
Signed-off-by: Uros Bojanic <221401595+uros-b@users.noreply.github.com>
Spark is a unified analytics engine for large-scale data processing. It provides high-level APIs in Scala, Java, Python, and R (Deprecated), and an optimized engine that supports general computation graphs for data analysis. It also supports a rich set of higher-level tools including Spark SQL for SQL and DataFrames, pandas API on Spark for pandas workloads, MLlib for machine learning, GraphX for graph processing, and Structured Streaming for stream processing.
You can find the latest Spark documentation, including a programming guide, on the project web page. This README file only contains basic setup instructions.
| Branch | Status |
|---|---|
| master | |
| branch-4.x | |
| branch-4.3 | |
| branch-4.2 | |
| branch-4.1 | |
| branch-4.0 | |
| branch-3.5 | |
Spark is built using Apache Maven. To build Spark and its example programs, run:
./build/mvn -DskipTests clean package
(You do not need to do this if you downloaded a pre-built package.)
More detailed documentation is available from the project site, at “Building Spark”.
For general development tips, including info on developing Spark using an IDE, see “Useful Developer Tools”.
The easiest way to start using Spark is through the Scala shell:
./bin/spark-shell
Try the following command, which should return 1,000,000,000:
scala> spark.range(1000 * 1000 * 1000).count()
Alternatively, if you prefer Python, you can use the Python shell:
./bin/pyspark
And run the following command, which should also return 1,000,000,000:
>>> spark.range(1000 * 1000 * 1000).count()
Spark also comes with several sample programs in the examples directory. To run one of them, use ./bin/run-example <class> [params]. For example:
./bin/run-example SparkPi
will run the Pi example locally.
You can set the MASTER environment variable when running examples to submit examples to a cluster. This can be spark:// URL, “yarn” to run on YARN, and “local” to run locally with one thread, or “local[N]” to run locally with N threads. You can also use an abbreviated class name if the class is in the examples package. For instance:
MASTER=spark://host:7077 ./bin/run-example SparkPi
Many of the example programs print usage help if no params are given.
Testing first requires building Spark. Once Spark is built, tests can be run using:
./dev/run-tests
Please see the guidance on how to run tests for a module, or individual tests.
There is also a Kubernetes integration test, see resource-managers/kubernetes/integration-tests/README.md
Spark uses the Hadoop core library to talk to HDFS and other Hadoop-supported storage systems. Because the protocols have changed in different versions of Hadoop, you must build Spark against the same version that your cluster runs.
Please refer to the build documentation at “Specifying the Hadoop Version and Enabling YARN” for detailed guidance on building for a particular distribution of Hadoop, including building for particular Hive and Hive Thriftserver distributions.
Please refer to the Configuration Guide in the online documentation for an overview on how to configure Spark.
Please review the Contribution to Spark guide for information on how to get started contributing to the project.