|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.comet.shims |
| 21 | + |
| 22 | +import org.apache.spark.sql.execution.datasources.VariantMetadata |
| 23 | +import org.apache.spark.sql.types.{DataType, StringType, StructType} |
| 24 | + |
| 25 | +trait CometTypeShim { |
| 26 | + // A `StringType` carries collation metadata in Spark 4.0. Only non-default (non-UTF8_BINARY) |
| 27 | + // collations have semantics Comet's byte-level hashing/sorting/equality cannot honor. The |
| 28 | + // default `StringType` object is `StringType(UTF8_BINARY_COLLATION_ID)`, so comparing |
| 29 | + // `collationId` against that instance's id picks out non-default collations without needing |
| 30 | + // `private[sql]` helpers on `StringType`. |
| 31 | + def isStringCollationType(dt: DataType): Boolean = dt match { |
| 32 | + case st: StringType => st.collationId != StringType.collationId |
| 33 | + case _ => false |
| 34 | + } |
| 35 | + |
| 36 | + // Spark 4.0's `PushVariantIntoScan` rewrites `VariantType` columns into a `StructType` whose |
| 37 | + // fields each carry `__VARIANT_METADATA_KEY` metadata, then pushes `variant_get` paths down as |
| 38 | + // ordinary struct field accesses. Comet's native scans don't understand the on-disk Parquet |
| 39 | + // variant shredding layout, so reading such a struct natively returns nulls. Detect the marker |
| 40 | + // and force scan fallback. |
| 41 | + def isVariantStruct(s: StructType): Boolean = VariantMetadata.isVariantStruct(s) |
| 42 | +} |
0 commit comments