Copilot commented on code in PR #6077: URL: https://github.com/apache/texera/pull/6077#discussion_r3518079304
########## common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/source/scan/file/FileScanUtilsSpec.scala: ########## @@ -0,0 +1,104 @@ +/* + * 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.source.scan.file + +import org.apache.texera.amber.operator.source.scan.{FileAttributeType, FileDecodingMethod} +import org.scalatest.BeforeAndAfterAll +import org.scalatest.flatspec.AnyFlatSpec + +import java.io.{BufferedOutputStream, FileOutputStream} +import java.nio.file.{Files, Path} +import java.util.zip.{ZipEntry, ZipOutputStream} + +class FileScanUtilsSpec extends AnyFlatSpec with BeforeAndAfterAll { + + private val zips = scala.collection.mutable.ArrayBuffer.empty[Path] + + private def makeZip(entries: (String, String)*): String = { + val path = Files.createTempFile("filescanutils-", ".zip") + zips += path + val zipOut = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(path.toFile))) + try { + entries.foreach { + case (name, content) => + zipOut.putNextEntry(new ZipEntry(name)) + zipOut.write(content.getBytes("UTF-8")) + zipOut.closeEntry() + } + } finally { + zipOut.close() + } + path.toFile.toURI.toString + } + + override def afterAll(): Unit = { + zips.foreach(Files.deleteIfExists) + super.afterAll() + } + + "FileScanUtils.createTuplesFromFile" should + "extract every zip entry as a single-string tuple" in { + val tuples = FileScanUtils + .createTuplesFromFile( + fileName = makeZip("a.txt" -> "Content A", "b.txt" -> "Content B"), + displayFileName = "ignored-when-extracting", + attributeType = FileAttributeType.SINGLE_STRING, + fileEncoding = FileDecodingMethod.UTF_8, + extract = true, + outputFileName = false, + fileScanOffset = None, + fileScanLimit = None + ) + .toSeq + assert(tuples.size == 2) Review Comment: This test only checks the number of extracted tuples; it can still pass even if entry contents are decoded incorrectly or mis-associated with entries. Asserting the actual extracted content makes the test much more robust while still exercising the same branch. ########## common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/SpecialPhysicalOpFactorySpec.scala: ########## @@ -0,0 +1,100 @@ +/* + * 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 + +import org.apache.texera.amber.core.storage.VFSURIFactory +import org.apache.texera.amber.core.tuple.{Attribute, AttributeType, Schema} +import org.apache.texera.amber.core.virtualidentity.{ + ExecutionIdentity, + OperatorIdentity, + PhysicalOpIdentity, + WorkflowIdentity +} +import org.apache.texera.amber.core.workflow.{GlobalPortIdentity, PortIdentity, PreferController} +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +class SpecialPhysicalOpFactorySpec extends AnyFlatSpec with Matchers { + + private val workflowId = WorkflowIdentity(42L) + private val executionId = ExecutionIdentity(7L) + private val schema = Schema().add(new Attribute("col", AttributeType.STRING)) + + private def portUri(opName: String, layer: String, portId: Int) = { + val gpid = GlobalPortIdentity( + PhysicalOpIdentity(OperatorIdentity(opName), layer), + PortIdentity(portId), + input = false + ) + VFSURIFactory.resultURI(VFSURIFactory.createPortBaseURI(workflowId, executionId, gpid)) + } + + "SpecialPhysicalOpFactory.newSourcePhysicalOp" should + "derive a source op that wires the decoded port identity, ports, and schema" in { + val uri = portUri("srcOp", "layerA", 3) + val downstream = PhysicalOpIdentity(OperatorIdentity("down-stream"), "main") + val op = SpecialPhysicalOpFactory.newSourcePhysicalOp( + workflowId, + executionId, + uri, + downstream, + PortIdentity(5), + schema + ) + op.id.logicalOpId shouldBe OperatorIdentity("srcOp") + // layerName: "${layerName}_source_${portId.id}_${downstreamLogicalId'}_${downstreamPort.id}" Review Comment: The layerName explanation comment has a stray apostrophe in the downstream logical id placeholder ("downstreamLogicalId'") which is confusing/misleading for readers trying to match the interpolated pieces. ########## common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/source/scan/file/FileScanUtilsSpec.scala: ########## @@ -0,0 +1,104 @@ +/* + * 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.source.scan.file + +import org.apache.texera.amber.operator.source.scan.{FileAttributeType, FileDecodingMethod} +import org.scalatest.BeforeAndAfterAll +import org.scalatest.flatspec.AnyFlatSpec + +import java.io.{BufferedOutputStream, FileOutputStream} +import java.nio.file.{Files, Path} +import java.util.zip.{ZipEntry, ZipOutputStream} + +class FileScanUtilsSpec extends AnyFlatSpec with BeforeAndAfterAll { + + private val zips = scala.collection.mutable.ArrayBuffer.empty[Path] + + private def makeZip(entries: (String, String)*): String = { + val path = Files.createTempFile("filescanutils-", ".zip") + zips += path + val zipOut = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(path.toFile))) + try { + entries.foreach { + case (name, content) => + zipOut.putNextEntry(new ZipEntry(name)) + zipOut.write(content.getBytes("UTF-8")) + zipOut.closeEntry() + } + } finally { + zipOut.close() + } + path.toFile.toURI.toString + } + + override def afterAll(): Unit = { + zips.foreach(Files.deleteIfExists) + super.afterAll() + } + + "FileScanUtils.createTuplesFromFile" should + "extract every zip entry as a single-string tuple" in { + val tuples = FileScanUtils + .createTuplesFromFile( + fileName = makeZip("a.txt" -> "Content A", "b.txt" -> "Content B"), + displayFileName = "ignored-when-extracting", + attributeType = FileAttributeType.SINGLE_STRING, + fileEncoding = FileDecodingMethod.UTF_8, + extract = true, + outputFileName = false, + fileScanOffset = None, + fileScanLimit = None + ) + .toSeq + assert(tuples.size == 2) + } + + it should "drop __MACOSX metadata entries when extracting" in { + val tuples = FileScanUtils + .createTuplesFromFile( + fileName = makeZip("real.txt" -> "keep me", "__MACOSX/._real.txt" -> "junk"), + displayFileName = "d", + attributeType = FileAttributeType.SINGLE_STRING, + fileEncoding = FileDecodingMethod.UTF_8, + extract = true, + outputFileName = false, + fileScanOffset = None, + fileScanLimit = None + ) + .toSeq + assert(tuples.size == 1) Review Comment: This test only asserts the tuple count. Adding a content assertion ensures the __MACOSX filtering test fails if the remaining entry's content is not actually extracted/decoded correctly. ########## common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/source/scan/file/FileScanUtilsSpec.scala: ########## @@ -0,0 +1,104 @@ +/* + * 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.source.scan.file + +import org.apache.texera.amber.operator.source.scan.{FileAttributeType, FileDecodingMethod} +import org.scalatest.BeforeAndAfterAll +import org.scalatest.flatspec.AnyFlatSpec + +import java.io.{BufferedOutputStream, FileOutputStream} +import java.nio.file.{Files, Path} +import java.util.zip.{ZipEntry, ZipOutputStream} + +class FileScanUtilsSpec extends AnyFlatSpec with BeforeAndAfterAll { + + private val zips = scala.collection.mutable.ArrayBuffer.empty[Path] + + private def makeZip(entries: (String, String)*): String = { + val path = Files.createTempFile("filescanutils-", ".zip") + zips += path + val zipOut = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(path.toFile))) + try { + entries.foreach { + case (name, content) => + zipOut.putNextEntry(new ZipEntry(name)) + zipOut.write(content.getBytes("UTF-8")) + zipOut.closeEntry() + } + } finally { + zipOut.close() + } + path.toFile.toURI.toString + } + + override def afterAll(): Unit = { + zips.foreach(Files.deleteIfExists) + super.afterAll() + } + + "FileScanUtils.createTuplesFromFile" should + "extract every zip entry as a single-string tuple" in { + val tuples = FileScanUtils + .createTuplesFromFile( + fileName = makeZip("a.txt" -> "Content A", "b.txt" -> "Content B"), + displayFileName = "ignored-when-extracting", + attributeType = FileAttributeType.SINGLE_STRING, + fileEncoding = FileDecodingMethod.UTF_8, + extract = true, + outputFileName = false, + fileScanOffset = None, + fileScanLimit = None + ) + .toSeq + assert(tuples.size == 2) + } + + it should "drop __MACOSX metadata entries when extracting" in { + val tuples = FileScanUtils + .createTuplesFromFile( + fileName = makeZip("real.txt" -> "keep me", "__MACOSX/._real.txt" -> "junk"), + displayFileName = "d", + attributeType = FileAttributeType.SINGLE_STRING, + fileEncoding = FileDecodingMethod.UTF_8, + extract = true, + outputFileName = false, + fileScanOffset = None, + fileScanLimit = None + ) + .toSeq + assert(tuples.size == 1) + } + + it should "flat-map each line of an extracted entry for a per-line attribute type" in { + val tuples = FileScanUtils + .createTuplesFromFile( + fileName = makeZip("lines.txt" -> "l1\nl2\nl3"), + displayFileName = "d", + attributeType = FileAttributeType.STRING, + fileEncoding = FileDecodingMethod.UTF_8, + extract = true, + outputFileName = false, + fileScanOffset = None, + fileScanLimit = None + ) + .toSeq + assert(tuples.size == 3) Review Comment: This test asserts only the number of produced tuples. Verifying the per-line contents (and their order) better pins the intended flat-map behavior for per-line attribute types. -- 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]
