MaxGekk commented on code in PR #56992: URL: https://github.com/apache/spark/pull/56992#discussion_r3573603777
########## sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/orc/types/ops/OrcTypeOps.scala: ########## @@ -0,0 +1,169 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.sql.execution.datasources.orc.types.ops + +import org.apache.hadoop.hive.ql.io.sarg.PredicateLeaf +import org.apache.hadoop.io.WritableComparable +import org.apache.orc.TypeDescription + +import org.apache.spark.sql.catalyst.expressions.SpecializedGetters +import org.apache.spark.sql.types.{DataType, TimestampLTZNanosType, TimestampNTZNanosType, TimeType} + +/** + * Optional trait for ORC storage-format integration in the Types Framework. + * + * Implement this trait to enable ORC read/write support for a framework type. Each framework + * type that supports ORC provides a concrete implementation and registers it in the companion + * object's apply() method. + * + * The trait covers the ORC concerns that are homogeneous across the row-based code paths: + * - Schema mapping: Spark DataType -> ORC schema string (OrcUtils.getOrcSchemaString) and the + * ORC TypeDescription category (OrcUtils.orcTypeDescription). ORC has no native TIME / + * nanosecond-timestamp category, so framework types map onto an existing physical ORC + * category and round-trip the true Spark type via the CATALYST_TYPE_ATTRIBUTE_NAME attribute + * (stamped uniformly by the caller, so the ops only chooses the category). + * - Value write (serialize): Catalyst value -> ORC WritableComparable + * (OrcSerializer.newConverter) + * - Row-based read (deserialize): ORC WritableComparable -> Catalyst value + * (OrcDeserializer.newWriter) + * - Predicate pushdown: PredicateLeaf.Type mapping + literal casting (OrcFilters) + * + * DELIBERATELY NOT ON THE TRAIT: + * - Vectorized read. ORC's vectorized path (OrcAtomicColumnVector, a Java class) dispatches via Review Comment: Optional: worth a one-line caveat here that the vectorized read path is a *separate* registration a new type must also handle. `OrcUtils.supportColumnarReads` returns `true` for every `AtomicType` and `OrcAtomicColumnVector` dispatches by `instanceof`, so a future framework `AtomicType` added only to the ops registry would still be routed to the vectorized reader (and read raw physical values) rather than failing loudly. The current types are wired in correctly — this is just so the "one ops class + one registry arm" framing doesn't mislead the next type author. ########## sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/orc/types/ops/OrcTypeOps.scala: ########## @@ -0,0 +1,169 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.sql.execution.datasources.orc.types.ops + +import org.apache.hadoop.hive.ql.io.sarg.PredicateLeaf +import org.apache.hadoop.io.WritableComparable +import org.apache.orc.TypeDescription + +import org.apache.spark.sql.catalyst.expressions.SpecializedGetters +import org.apache.spark.sql.types.{DataType, TimestampLTZNanosType, TimestampNTZNanosType, TimeType} + +/** + * Optional trait for ORC storage-format integration in the Types Framework. + * + * Implement this trait to enable ORC read/write support for a framework type. Each framework + * type that supports ORC provides a concrete implementation and registers it in the companion + * object's apply() method. + * + * The trait covers the ORC concerns that are homogeneous across the row-based code paths: + * - Schema mapping: Spark DataType -> ORC schema string (OrcUtils.getOrcSchemaString) and the + * ORC TypeDescription category (OrcUtils.orcTypeDescription). ORC has no native TIME / + * nanosecond-timestamp category, so framework types map onto an existing physical ORC + * category and round-trip the true Spark type via the CATALYST_TYPE_ATTRIBUTE_NAME attribute + * (stamped uniformly by the caller, so the ops only chooses the category). + * - Value write (serialize): Catalyst value -> ORC WritableComparable + * (OrcSerializer.newConverter) + * - Row-based read (deserialize): ORC WritableComparable -> Catalyst value + * (OrcDeserializer.newWriter) + * - Predicate pushdown: PredicateLeaf.Type mapping + literal casting (OrcFilters) + * + * DELIBERATELY NOT ON THE TRAIT: + * - Vectorized read. ORC's vectorized path (OrcAtomicColumnVector, a Java class) dispatches via + * boolean `instanceof` flags set in the constructor plus typed accessor methods + * (getTimestampNTZNanos/getTimestampLTZNanos), NOT via an `Ops(dt).map(_.x)` closure. It has + * no per-type extension seam, so it stays inline. This mirrors Parquet, whose vectorized read + * is likewise not routed through ParquetTypeOps (it dispatches on the Spark type inline in + * ParquetVectorUpdaterFactory.getUpdater). + * - supportDataType. OrcFileFormat.supportDataType / OrcTable.supportsDataType already admit + * every `AtomicType` via `case _: AtomicType => true`, so framework types are supported with + * no per-type arm; no gate method is needed (unlike Parquet, whose default differs). + * + * DISPATCH PATTERN: framework FIRST at each row-path integration site. Each ORC infrastructure + * method wraps itself with: + * {{{ + * OrcTypeOps(dt).map(_.method(...)).getOrElse(methodDefault(dt, ...)) + * }}} + * The original inline code is extracted to a *Default method unchanged. For a framework-managed + * type the ops handles it; for any other type OrcTypeOps(dt) is None and the *Default fallback + * executes the original path. + * + * DECOUPLING NOTE: makeDeserializer takes the Catalyst setter callbacks it needs + * ((Int, Long) => Unit and (Int, Any) => Unit) rather than OrcDeserializer's CatalystDataUpdater, + * because that updater is a sealed trait nested in OrcDeserializer and is not visible to this + * sub-package. The callbacks are the only two setter shapes the current framework types use. + * + * @see TimeTypeOrcOps for a reference implementation (primitive Long-backed type) + * @see TimestampLTZNanosOrcOps / TimestampNTZNanosOrcOps for OrcTimestamp-backed types + * @since 4.4.0 Review Comment: `@since 4.4.0` doesn't match a release line. Since this routes the ORC nanos types (SPARK-57455, master-only), the change is master-only → should be `5.0.0`. Note `4.3.0` wouldn't be right despite `ParquetTypeOps` using it (cc @uros-b): Parquet's TIME+nanos were backported to `branch-4.x`, but ORC nanos was not. ########## sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/orc/types/ops/OrcTypeOps.scala: ########## @@ -0,0 +1,169 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.sql.execution.datasources.orc.types.ops + +import org.apache.hadoop.hive.ql.io.sarg.PredicateLeaf +import org.apache.hadoop.io.WritableComparable +import org.apache.orc.TypeDescription + +import org.apache.spark.sql.catalyst.expressions.SpecializedGetters +import org.apache.spark.sql.types.{DataType, TimestampLTZNanosType, TimestampNTZNanosType, TimeType} + +/** + * Optional trait for ORC storage-format integration in the Types Framework. + * + * Implement this trait to enable ORC read/write support for a framework type. Each framework + * type that supports ORC provides a concrete implementation and registers it in the companion + * object's apply() method. + * + * The trait covers the ORC concerns that are homogeneous across the row-based code paths: + * - Schema mapping: Spark DataType -> ORC schema string (OrcUtils.getOrcSchemaString) and the + * ORC TypeDescription category (OrcUtils.orcTypeDescription). ORC has no native TIME / + * nanosecond-timestamp category, so framework types map onto an existing physical ORC + * category and round-trip the true Spark type via the CATALYST_TYPE_ATTRIBUTE_NAME attribute + * (stamped uniformly by the caller, so the ops only chooses the category). + * - Value write (serialize): Catalyst value -> ORC WritableComparable + * (OrcSerializer.newConverter) + * - Row-based read (deserialize): ORC WritableComparable -> Catalyst value + * (OrcDeserializer.newWriter) + * - Predicate pushdown: PredicateLeaf.Type mapping + literal casting (OrcFilters) + * + * DELIBERATELY NOT ON THE TRAIT: + * - Vectorized read. ORC's vectorized path (OrcAtomicColumnVector, a Java class) dispatches via + * boolean `instanceof` flags set in the constructor plus typed accessor methods + * (getTimestampNTZNanos/getTimestampLTZNanos), NOT via an `Ops(dt).map(_.x)` closure. It has + * no per-type extension seam, so it stays inline. This mirrors Parquet, whose vectorized read + * is likewise not routed through ParquetTypeOps (it dispatches on the Spark type inline in + * ParquetVectorUpdaterFactory.getUpdater). + * - supportDataType. OrcFileFormat.supportDataType / OrcTable.supportsDataType already admit + * every `AtomicType` via `case _: AtomicType => true`, so framework types are supported with + * no per-type arm; no gate method is needed (unlike Parquet, whose default differs). + * + * DISPATCH PATTERN: framework FIRST at each row-path integration site. Each ORC infrastructure + * method wraps itself with: + * {{{ + * OrcTypeOps(dt).map(_.method(...)).getOrElse(methodDefault(dt, ...)) + * }}} + * The original inline code is extracted to a *Default method unchanged. For a framework-managed Review Comment: There's no `*Default` method in any of the four modified files — the fallback is expressed inline via `.getOrElse(dt.catalogString)` / `.getOrElse(throw …)` or by leaving the other `match` arms in place. Worth rewording so the pattern description matches the code. ########## sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/orc/types/ops/OrcTypeOps.scala: ########## @@ -0,0 +1,169 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.sql.execution.datasources.orc.types.ops + +import org.apache.hadoop.hive.ql.io.sarg.PredicateLeaf +import org.apache.hadoop.io.WritableComparable +import org.apache.orc.TypeDescription + +import org.apache.spark.sql.catalyst.expressions.SpecializedGetters +import org.apache.spark.sql.types.{DataType, TimestampLTZNanosType, TimestampNTZNanosType, TimeType} + +/** + * Optional trait for ORC storage-format integration in the Types Framework. + * + * Implement this trait to enable ORC read/write support for a framework type. Each framework + * type that supports ORC provides a concrete implementation and registers it in the companion + * object's apply() method. + * + * The trait covers the ORC concerns that are homogeneous across the row-based code paths: + * - Schema mapping: Spark DataType -> ORC schema string (OrcUtils.getOrcSchemaString) and the + * ORC TypeDescription category (OrcUtils.orcTypeDescription). ORC has no native TIME / + * nanosecond-timestamp category, so framework types map onto an existing physical ORC + * category and round-trip the true Spark type via the CATALYST_TYPE_ATTRIBUTE_NAME attribute + * (stamped uniformly by the caller, so the ops only chooses the category). + * - Value write (serialize): Catalyst value -> ORC WritableComparable + * (OrcSerializer.newConverter) + * - Row-based read (deserialize): ORC WritableComparable -> Catalyst value + * (OrcDeserializer.newWriter) + * - Predicate pushdown: PredicateLeaf.Type mapping + literal casting (OrcFilters) + * + * DELIBERATELY NOT ON THE TRAIT: + * - Vectorized read. ORC's vectorized path (OrcAtomicColumnVector, a Java class) dispatches via + * boolean `instanceof` flags set in the constructor plus typed accessor methods + * (getTimestampNTZNanos/getTimestampLTZNanos), NOT via an `Ops(dt).map(_.x)` closure. It has + * no per-type extension seam, so it stays inline. This mirrors Parquet, whose vectorized read + * is likewise not routed through ParquetTypeOps (it dispatches on the Spark type inline in + * ParquetVectorUpdaterFactory.getUpdater). + * - supportDataType. OrcFileFormat.supportDataType / OrcTable.supportsDataType already admit + * every `AtomicType` via `case _: AtomicType => true`, so framework types are supported with + * no per-type arm; no gate method is needed (unlike Parquet, whose default differs). + * + * DISPATCH PATTERN: framework FIRST at each row-path integration site. Each ORC infrastructure + * method wraps itself with: + * {{{ + * OrcTypeOps(dt).map(_.method(...)).getOrElse(methodDefault(dt, ...)) + * }}} + * The original inline code is extracted to a *Default method unchanged. For a framework-managed + * type the ops handles it; for any other type OrcTypeOps(dt) is None and the *Default fallback + * executes the original path. + * + * DECOUPLING NOTE: makeDeserializer takes the Catalyst setter callbacks it needs + * ((Int, Long) => Unit and (Int, Any) => Unit) rather than OrcDeserializer's CatalystDataUpdater, + * because that updater is a sealed trait nested in OrcDeserializer and is not visible to this + * sub-package. The callbacks are the only two setter shapes the current framework types use. + * + * @see TimeTypeOrcOps for a reference implementation (primitive Long-backed type) + * @see TimestampLTZNanosOrcOps / TimestampNTZNanosOrcOps for OrcTimestamp-backed types + * @since 4.4.0 + */ +private[orc] trait OrcTypeOps extends Serializable { + + // ==================== Schema Mapping ==================== + + /** + * The ORC schema-string fragment for this type (OrcUtils.getOrcSchemaString). Examples: + * TimeType -> "bigint" (LongType.catalogString), TimestampLTZNanosType -> "timestamp with local + * time zone", TimestampNTZNanosType -> "timestamp". + */ + def orcSchemaString: String + + /** + * The ORC TypeDescription category for this type (OrcUtils.orcTypeDescription). The caller + * stamps CATALYST_TYPE_ATTRIBUTE_NAME = sparkType.typeName onto the returned descriptor, so the + * ops only chooses the physical category. + */ + def orcCategory: TypeDescription.Category + + // ==================== Value Write (serialize) ==================== + + /** + * Creates a converter that turns a Catalyst value at an ordinal into an ORC WritableComparable + * (OrcSerializer.newConverter). + * + * @param reuseObj whether the serializer may reuse a single mutable Writable across rows + * (OrcSerializer passes this through; the primitive Long-backed TimeType reuses, + * the OrcTimestamp-backed nanos types do not). + */ + def makeSerializer(reuseObj: Boolean): (SpecializedGetters, Int) => WritableComparable[_] + + // ==================== Row-Based Read (deserialize) ==================== + + /** + * Creates a writer that sets a decoded ORC value into the Catalyst row at an ordinal + * (OrcDeserializer.newWriter). The WritableComparable is the raw ORC value (LongWritable for + * LONG-category types, OrcTimestamp for the timestamp categories). + * + * @param setLong callback into the row's setLong (used by primitive Long-backed types) + * @param set callback into the row's generic set (used by object-backed types, e.g. nanos) + */ + def makeDeserializer( + setLong: (Int, Long) => Unit, + set: (Int, Any) => Unit): (Int, WritableComparable[_]) => Unit + + // ==================== Predicate Pushdown ==================== + + /** + * The ORC PredicateLeaf.Type for this type (OrcFilters.getPredicateLeafType), or None to opt out + * of pushdown (the caller then treats the column as non-convertible). TimeType returns Review Comment: This says the caller "treats the column as non-convertible" on `None`, but `getPredicateLeafType` does `.getOrElse(throw unsupportedOperationForDataTypeError(dt))`, and nanos types are `AtomicType` so `getSearchableTypeMap` admits them and they reach this path — i.e. `None` **throws**. The inline comment just below in `OrcFilters` ("falls through to the unsupported error") is accurate. Suggest rewording to match. This looks like @dongjoon-hyun's earlier point. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
