unikdahal commented on code in PR #5515: URL: https://github.com/apache/datafusion-comet/pull/5515#discussion_r3907567401
########## spark/src/test/scala/org/apache/comet/serde/operator/CometIcebergDeleteFileSerdeSuite.scala: ########## @@ -0,0 +1,130 @@ +/* + * 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.comet.serde.operator + +import java.lang.reflect.InvocationTargetException + +import org.scalatest.funsuite.AnyFunSuite + +/** + * Locks in the fail-loud behavior of [[CometIcebergNativeScan.serializeDeleteFile]] required by + * apache/datafusion-comet#5256: on supported Iceberg versions `content()`, `specId()`, and + * `equalityFieldIds()` are always declared, so a reflective invocation failure must propagate + * rather than fall back to a guessed value. A null `equalityFieldIds()` (a position-delete file) + * stays a legitimate "no equality keys" result. + */ +class CometIcebergDeleteFileSerdeSuite extends AnyFunSuite { + + private def keyMetadataMethod(clazz: Class[_]) = clazz.getMethod("keyMetadata") + + private def serialize(file: AnyRef) = + CometIcebergNativeScan.serializeDeleteFile( + file, + file.getClass, + file.getClass, + keyMetadataMethod(file.getClass)) + + test("position-delete file: null equalityFieldIds() serializes with no equality ids") { + val proto = serialize(new PositionDeleteFile) + assert(proto.getContentType == "POSITION_DELETES") + assert(proto.getPartitionSpecId == 7) + assert(proto.getEqualityIdsCount == 0) + assert(proto.getFilePath == "s3://bucket/pos-delete.parquet") + } + + test("equality-delete file: declared equalityFieldIds() are serialized") { + val proto = serialize(new EqualityDeleteFile) + assert(proto.getContentType == "EQUALITY_DELETES") + assert(proto.getEqualityIdsCount == 2) + assert(proto.getEqualityIds(0) == 3) + assert(proto.getEqualityIds(1) == 5) + } + + test("content() invocation failure propagates instead of defaulting to POSITION_DELETES") { + val ex = intercept[InvocationTargetException](serialize(new ThrowingContentDeleteFile)) + assert(ex.getCause.getMessage == "content boom") + } + + test("specId() invocation failure propagates instead of defaulting to 0") { + val ex = intercept[InvocationTargetException](serialize(new ThrowingSpecIdDeleteFile)) + assert(ex.getCause.getMessage == "spec boom") + } + + test("equalityFieldIds() invocation failure propagates instead of dropping equality ids") { + val ex = intercept[InvocationTargetException](serialize(new ThrowingEqualityIdsDeleteFile)) + assert(ex.getCause.getMessage == "ids boom") + } + + test("missing content() accessor is fatal, not a default") { + // getMethod throws NoSuchMethodException directly (not wrapped) when the accessor is absent. + assertThrows[NoSuchMethodException](serialize(new NoContentAccessorDeleteFile)) + } Review Comment: Added both. The suite now checks `content`, `specId`, and `equalityFieldIds` against the real `DeleteFile` API, and there is a regression test verifying that a delete file with neither `location()` nor `path()` fails loudly. I also added coverage for a missing `equalityFieldIds()` accessor. -- 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]
