Copilot commented on code in PR #6076: URL: https://github.com/apache/texera/pull/6076#discussion_r3518084379
########## common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/source/scan/json/JSONLScanSourceOpExecSpec.scala: ########## @@ -0,0 +1,83 @@ +/* + * 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.json + +import org.apache.texera.amber.operator.source.scan.FileDecodingMethod +import org.apache.texera.amber.util.JSONUtils.objectMapper +import org.scalatest.flatspec.AnyFlatSpec + +import java.net.URI +import java.nio.charset.StandardCharsets +import java.nio.file.Files + +class JSONLScanSourceOpExecSpec extends AnyFlatSpec { + + private def writeJsonl(lines: String*): URI = { + val path = Files.createTempFile("jsonl-scan-", ".jsonl") + path.toFile.deleteOnExit() + Files.write(path, lines.mkString("\n").getBytes(StandardCharsets.UTF_8)) + path.toFile.toURI + } + + private def descString( + uri: URI, + flatten: Boolean = false, + limit: Option[Int] = None, + offset: Option[Int] = None + ): String = { + val desc = new JSONLScanSourceOpDesc + desc.setResolvedFileName(uri) + desc.fileEncoding = FileDecodingMethod.UTF_8 + desc.flatten = flatten + desc.limit = limit + desc.offset = offset + objectMapper.writeValueAsString(desc) + } + + private def drain(exec: JSONLScanSourceOpExec): List[Seq[Any]] = { + exec.open() + try exec.produceTuple().map(_.getFields.toSeq).toList + finally exec.close() + } + + "JSONLScanSourceOpExec" should "read each JSON line, ordering fields by sorted attribute name" in { + val exec = new JSONLScanSourceOpExec( + descString(writeJsonl("""{"id":1,"name":"a"}""", """{"id":2,"name":"b"}""")) + ) Review Comment: This test claims to verify that output fields are ordered by sorted attribute name, but both JSON objects already list fields as `id` then `name`, so the assertions would still pass even if the executor preserved input order. Using a JSON object with reversed key order would make this test actually validate the sorting behavior. ########## common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/source/scan/csv/ParallelCSVScanSourceOpExecSpec.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.csv + +import org.apache.texera.amber.util.JSONUtils.objectMapper +import org.scalatest.flatspec.AnyFlatSpec + +import java.nio.charset.StandardCharsets +import java.nio.file.Files + +class ParallelCSVScanSourceOpExecSpec extends AnyFlatSpec { + + private def writeCsv(content: String): String = { + val file = Files.createTempFile("parallel-csv-", ".csv") + file.toFile.deleteOnExit() + Files.write(file, content.getBytes(StandardCharsets.UTF_8)) + file.toFile.toURI.toString + } + + private def descString(uri: String, delimiter: String = ",", header: Boolean = true): String = { + val desc = new ParallelCSVScanSourceOpDesc() + desc.fileName = Some(uri) + desc.customDelimiter = Some(delimiter) + desc.hasHeader = header + desc.setResolvedFileName(new java.net.URI(uri)) + objectMapper.writeValueAsString(desc) + } + + private def drain(exec: ParallelCSVScanSourceOpExec): List[Seq[Any]] = { + exec.open() + try exec.produceTuple().map(_.getFields.toSeq).toList + finally exec.close() + } + + "ParallelCSVScanSourceOpExec" should "read every data row of a headered file" in { + val exec = + new ParallelCSVScanSourceOpExec(descString(writeCsv("id,name,age\n1,Alice,30\n2,Bob,25\n"))) + val rows = drain(exec) + assert(rows.size == 2) + assert(rows.head == Seq(1, "Alice", 30)) + assert(rows(1) == Seq(2, "Bob", 25)) + } + + it should "not skip the first row when the file has no header" in { + val exec = + new ParallelCSVScanSourceOpExec( + descString(writeCsv("1,Alice,30\n2,Bob,25\n"), header = false) + ) + assert(drain(exec).size == 2) + } + + it should "pad short rows with trailing nulls to the schema width" in { + // the wide first data row fixes the schema at 3 columns; the short row is padded + val exec = new ParallelCSVScanSourceOpExec(descString(writeCsv("a,b,c\n1,2,3\n4,5\n"))) + val rows = drain(exec) + assert(rows.size == 2) + assert(rows(1).length == 3) + assert(rows(1)(2) == null) + } + + it should "discard all-null (blank) lines" in { + val exec = + new ParallelCSVScanSourceOpExec(descString(writeCsv("name,city\nAlice,NYC\n\nBob,LA\n"))) + val rows = drain(exec) + assert(rows.size == 2) + assert(rows.map(_.head) == Seq("Alice", "Bob")) + } + + it should "partition a headerless file across workers by byte range" in { + // Two workers over the same file: worker 0 (idx != workerCount-1) takes the + // first byte-range chunk; worker 1 seeks past its chunk start and drops the + // leading partial line. Exact boundary rows depend on the block reader + // reading one line past the boundary, so assert only that the union covers + // all rows without duplication. + val uri = writeCsv("1,aaaa\n2,bbbb\n3,cccc\n4,dddd\n") Review Comment: The byte-range partitioning test is intended to exercise the “drop leading partial line” behavior, but the current fixture has equal-length rows (28 bytes total), so `totalBytes / 2` lands exactly on a newline boundary. In that case worker 1 skips a full line rather than a partial line, and the test relies on `BufferedBlockReader` reading one line past the boundary. Adjusting the input so the split point falls in the middle of a row makes the test deterministic for the partial-line-skip path. -- 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]
