cloud-fan commented on code in PR #55326: URL: https://github.com/apache/spark/pull/55326#discussion_r3424377129
########## sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/types/ops/ParquetTypeOps.scala: ########## @@ -0,0 +1,220 @@ +/* + * 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.parquet.types.ops + +import java.time.ZoneId + +import org.apache.parquet.io.api.{Converter, RecordConsumer} +import org.apache.parquet.schema.Type +import org.apache.parquet.schema.Type.Repetition + +import org.apache.spark.sql.catalyst.expressions.SpecializedGetters +import org.apache.spark.sql.catalyst.util.RebaseDateTime.RebaseSpec +import org.apache.spark.sql.execution.datasources.parquet.{HasParentContainerUpdater, ParentContainerUpdater, ParquetToSparkSchemaConverter} +import org.apache.spark.sql.internal.SQLConf +import org.apache.spark.sql.types.{DataType, StructType, TimeType} + +/** + * Optional trait for Parquet storage format integration in the Types Framework. + * + * Implement this trait to enable Parquet read/write support for a framework type. Each framework + * type that supports Parquet provides a concrete implementation and registers it in the companion + * object's apply() method. + * + * The trait covers all Parquet concerns: + * - Schema conversion: Spark DataType <-> Parquet schema type + * - Value write: writing values to Parquet RecordConsumer + * - Row-based read: creating Parquet converters for reading into InternalRow + * - Vectorized read: creating batch updaters for columnar reading Review Comment: The class scaladoc says the trait "covers all Parquet concerns" and lists "Vectorized read: creating batch updaters" and "Filter pushdown: creating Parquet filter predicates", but the trait exposes neither — only the `isBatchReadSupported` capability gate. Since the PR description is explicit that those are deferred, consider rewording to mark them as not-yet-on-the-trait. Relatedly, `isBatchReadSupported` returning `true` only works for types the legacy Java vectorized path already handles (there is no framework vectorized hook yet) — worth a one-line note in its scaladoc so a future type doesn't return `true` and route into a factory that doesn't know it. `TimeType` is safe for exactly that reason. ########## sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/types/ops/ParquetTypeOps.scala: ########## @@ -0,0 +1,220 @@ +/* + * 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.parquet.types.ops + +import java.time.ZoneId + +import org.apache.parquet.io.api.{Converter, RecordConsumer} +import org.apache.parquet.schema.Type +import org.apache.parquet.schema.Type.Repetition + +import org.apache.spark.sql.catalyst.expressions.SpecializedGetters +import org.apache.spark.sql.catalyst.util.RebaseDateTime.RebaseSpec +import org.apache.spark.sql.execution.datasources.parquet.{HasParentContainerUpdater, ParentContainerUpdater, ParquetToSparkSchemaConverter} +import org.apache.spark.sql.internal.SQLConf +import org.apache.spark.sql.types.{DataType, StructType, TimeType} + +/** + * Optional trait for Parquet storage format integration in the Types Framework. + * + * Implement this trait to enable Parquet read/write support for a framework type. Each framework + * type that supports Parquet provides a concrete implementation and registers it in the companion + * object's apply() method. + * + * The trait covers all Parquet concerns: + * - Schema conversion: Spark DataType <-> Parquet schema type + * - Value write: writing values to Parquet RecordConsumer + * - Row-based read: creating Parquet converters for reading into InternalRow + * - Vectorized read: creating batch updaters for columnar reading + * - Filter pushdown: creating Parquet filter predicates for predicate pushdown + * - Type gates: declaring Parquet support/capability + * - Schema clipping: declaring internal struct schema for column pruning + * + * DISPATCH PATTERN: Framework FIRST at all integration sites. Each Parquet infrastructure + * method wraps itself with: + * {{{ + * ParquetTypeOps(dt).map(_.method(...)).getOrElse(methodDefault(dt, ...)) + * }}} + * The original code is extracted to a *Default method unchanged. When the framework flag is ON, + * the ops handles the type. When OFF, the *Default fallback executes the original code path. + * + * STRUCT-BACKED TYPES: Types stored as Parquet groups should override the + * extended newConverter overload (which provides schemaConverter/convertTz/rebase specs for + * recursive field conversion) and declare parquetStructSchema for column pruning. + * + * @see TimeTypeParquetOps for a reference implementation (primitive Long-backed type) + * @since 4.3.0 + */ +private[parquet] trait ParquetTypeOps extends Serializable { + + /** The DataType this Ops instance handles. */ + def dataType: DataType + + // ==================== Schema Conversion ==================== + + /** + * Converts this Spark DataType to a Parquet schema Type (for the write path). + * + * For primitive types: returns a PrimitiveType with the appropriate annotation. + * For struct-backed types: returns a GroupType with sub-fields and a logical type annotation. + * + * @param fieldName the column/field name in the Parquet schema + * @param repetition REQUIRED, OPTIONAL, or REPEATED + * @param inShredded whether the field is nested within a shredded Variant schema + * @return the Parquet Type for this DataType + */ + def convertToParquetType( Review Comment: The struct-backed paths pass framework-recursion context inconsistently: `makeWriter` gets a `makeFieldWriter: DataType => ValueWriter` callback and the extended `newConverter` gets `schemaConverter`, but `convertToParquetType` gets only `(fieldName, repetition, inShredded)`. The legacy struct case recurses via `convertField(f, ...)`, which carries `SparkToParquetSchemaConverter` config (timestamp output type, legacy format, field-id) — but this method is called on the ops instance, which has no converter reference, so a struct-backed type would have to hand-build its sub-schema and lose that config. Suggest a minimal `StructField => Type` callback here (matching `makeWriter`'s style) for symmetry. Relatedly, since the abstract `newConverter` is the simple 2-arg overload that the scaladoc says is wrong for struct-backed types, making the extended overload the sole abstract method (per @MaxGekk's thread above) is the same shape of fix — both worth settling alongside the struct-backed reference type in follow-up #3. ########## sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/types/ops/ParquetTypeOps.scala: ########## @@ -0,0 +1,220 @@ +/* + * 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.parquet.types.ops + +import java.time.ZoneId + +import org.apache.parquet.io.api.{Converter, RecordConsumer} +import org.apache.parquet.schema.Type +import org.apache.parquet.schema.Type.Repetition + +import org.apache.spark.sql.catalyst.expressions.SpecializedGetters +import org.apache.spark.sql.catalyst.util.RebaseDateTime.RebaseSpec +import org.apache.spark.sql.execution.datasources.parquet.{HasParentContainerUpdater, ParentContainerUpdater, ParquetToSparkSchemaConverter} +import org.apache.spark.sql.internal.SQLConf +import org.apache.spark.sql.types.{DataType, StructType, TimeType} + +/** + * Optional trait for Parquet storage format integration in the Types Framework. + * + * Implement this trait to enable Parquet read/write support for a framework type. Each framework + * type that supports Parquet provides a concrete implementation and registers it in the companion + * object's apply() method. + * + * The trait covers all Parquet concerns: + * - Schema conversion: Spark DataType <-> Parquet schema type + * - Value write: writing values to Parquet RecordConsumer + * - Row-based read: creating Parquet converters for reading into InternalRow + * - Vectorized read: creating batch updaters for columnar reading + * - Filter pushdown: creating Parquet filter predicates for predicate pushdown + * - Type gates: declaring Parquet support/capability + * - Schema clipping: declaring internal struct schema for column pruning + * + * DISPATCH PATTERN: Framework FIRST at all integration sites. Each Parquet infrastructure + * method wraps itself with: + * {{{ + * ParquetTypeOps(dt).map(_.method(...)).getOrElse(methodDefault(dt, ...)) + * }}} + * The original code is extracted to a *Default method unchanged. When the framework flag is ON, + * the ops handles the type. When OFF, the *Default fallback executes the original code path. + * + * STRUCT-BACKED TYPES: Types stored as Parquet groups should override the + * extended newConverter overload (which provides schemaConverter/convertTz/rebase specs for + * recursive field conversion) and declare parquetStructSchema for column pruning. + * + * @see TimeTypeParquetOps for a reference implementation (primitive Long-backed type) + * @since 4.3.0 + */ +private[parquet] trait ParquetTypeOps extends Serializable { + + /** The DataType this Ops instance handles. */ + def dataType: DataType Review Comment: This abstract member doesn't appear to have a consumer — dispatch keys off `ParquetTypeOps(field.dataType)`, not the ops instance's `dataType`. It's mirrored from `TypeOps`, but there the reference impl gets it from a base class; here every implementer must write `override def dataType` for no reader. Consider dropping it (or giving it a default) to keep the required surface minimal. -- 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]
