aglinxinyuan commented on code in PR #4912: URL: https://github.com/apache/texera/pull/4912#discussion_r3179902025
########## common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sink/ProgressiveUtilsSpec.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.texera.amber.operator.sink + +import org.apache.texera.amber.core.tuple.{Attribute, AttributeType, Schema, Tuple} +import org.scalatest.flatspec.AnyFlatSpec + +class ProgressiveUtilsSpec extends AnyFlatSpec { + + // --- helpers --------------------------------------------------------------- + + private val baseSchema: Schema = new Schema( + new Attribute("id", AttributeType.INTEGER), + new Attribute("name", AttributeType.STRING) + ) + + // outputSchema = flag column prepended to baseSchema + private val outputSchema: Schema = new Schema( + ProgressiveUtils.insertRetractFlagAttr, + new Attribute("id", AttributeType.INTEGER), + new Attribute("name", AttributeType.STRING) + ) + + private def baseTuple(id: Int, name: String): Tuple = + Tuple + .builder(baseSchema) + .add(new Attribute("id", AttributeType.INTEGER), Int.box(id)) + .add(new Attribute("name", AttributeType.STRING), name) + .build() + + // --- insertRetractFlagAttr ------------------------------------------------- + + "ProgressiveUtils.insertRetractFlagAttr" should "be a BOOLEAN attribute named __internal_is_insertion" in { + val attr = ProgressiveUtils.insertRetractFlagAttr + assert(attr.getName == "__internal_is_insertion") + assert(attr.getType == AttributeType.BOOLEAN) + } + + // --- addInsertionFlag / addRetractionFlag ---------------------------------- + + "ProgressiveUtils.addInsertionFlag" should "prepend the flag column with value true" in { + val flagged = ProgressiveUtils.addInsertionFlag(baseTuple(1, "alice"), outputSchema) + assert(flagged.getSchema == outputSchema) + assert(flagged.getField[Boolean](ProgressiveUtils.insertRetractFlagAttr.getName) == true) + assert(flagged.getField[Integer]("id") == 1) + assert(flagged.getField[String]("name") == "alice") + } + + "ProgressiveUtils.addRetractionFlag" should "prepend the flag column with value false" in { + val flagged = ProgressiveUtils.addRetractionFlag(baseTuple(2, "bob"), outputSchema) + assert(flagged.getField[Boolean](ProgressiveUtils.insertRetractFlagAttr.getName) == false) + assert(flagged.getField[Integer]("id") == 2) + assert(flagged.getField[String]("name") == "bob") + } + + it should "fail an assertion if the input tuple already has the flag column" in { + val alreadyFlagged = ProgressiveUtils.addInsertionFlag(baseTuple(3, "x"), outputSchema) + val ex = intercept[AssertionError] { + ProgressiveUtils.addRetractionFlag(alreadyFlagged, outputSchema) Review Comment: Done in the latest commit — added a symmetric test that `addInsertionFlag` also throws `AssertionError` when called on an already-flagged tuple, paralleling the existing `addRetractionFlag` case. ########## common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sink/ProgressiveUtilsSpec.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.texera.amber.operator.sink + +import org.apache.texera.amber.core.tuple.{Attribute, AttributeType, Schema, Tuple} +import org.scalatest.flatspec.AnyFlatSpec + +class ProgressiveUtilsSpec extends AnyFlatSpec { + + // --- helpers --------------------------------------------------------------- + + private val baseSchema: Schema = new Schema( + new Attribute("id", AttributeType.INTEGER), + new Attribute("name", AttributeType.STRING) + ) + + // outputSchema = flag column prepended to baseSchema + private val outputSchema: Schema = new Schema( + ProgressiveUtils.insertRetractFlagAttr, + new Attribute("id", AttributeType.INTEGER), + new Attribute("name", AttributeType.STRING) + ) + + private def baseTuple(id: Int, name: String): Tuple = + Tuple + .builder(baseSchema) + .add(new Attribute("id", AttributeType.INTEGER), Int.box(id)) + .add(new Attribute("name", AttributeType.STRING), name) + .build() + + // --- insertRetractFlagAttr ------------------------------------------------- + + "ProgressiveUtils.insertRetractFlagAttr" should "be a BOOLEAN attribute named __internal_is_insertion" in { + val attr = ProgressiveUtils.insertRetractFlagAttr + assert(attr.getName == "__internal_is_insertion") + assert(attr.getType == AttributeType.BOOLEAN) + } + + // --- addInsertionFlag / addRetractionFlag ---------------------------------- + + "ProgressiveUtils.addInsertionFlag" should "prepend the flag column with value true" in { + val flagged = ProgressiveUtils.addInsertionFlag(baseTuple(1, "alice"), outputSchema) + assert(flagged.getSchema == outputSchema) + assert(flagged.getField[Boolean](ProgressiveUtils.insertRetractFlagAttr.getName) == true) + assert(flagged.getField[Integer]("id") == 1) + assert(flagged.getField[String]("name") == "alice") + } + + "ProgressiveUtils.addRetractionFlag" should "prepend the flag column with value false" in { + val flagged = ProgressiveUtils.addRetractionFlag(baseTuple(2, "bob"), outputSchema) + assert(flagged.getField[Boolean](ProgressiveUtils.insertRetractFlagAttr.getName) == false) + assert(flagged.getField[Integer]("id") == 2) + assert(flagged.getField[String]("name") == "bob") + } + + it should "fail an assertion if the input tuple already has the flag column" in { + val alreadyFlagged = ProgressiveUtils.addInsertionFlag(baseTuple(3, "x"), outputSchema) + val ex = intercept[AssertionError] { + ProgressiveUtils.addRetractionFlag(alreadyFlagged, outputSchema) + } + // Don't pin the exact message; locking in the AssertionError is enough. + assert(ex != null) Review Comment: Done in the latest commit — dropped the redundant `assert(ex != null)`. `intercept[...]` already fails the test if no exception is thrown, so the null check was dead code. -- 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]
