bobbai00 commented on code in PR #9679:
URL: https://github.com/apache/texera/pull/9679#discussion_r4689860747


##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/source/scan/csv/CSVScanSourceOpDescSpec.scala:
##########
@@ -75,82 +75,66 @@ class CSVScanSourceOpDescSpec extends AnyFlatSpec with 
BeforeAndAfter {
       .validate(TextNode.valueOf(delimiter))
       .isSuccess
 
-  // Writes a CSV whose header row has an empty column (the third position),
-  // e.g. `id,name,,age`, and returns the absolute path.
-  private def writeCsvWithEmptyHeader(): String = {
-    val tmpFile = Files.createTempFile("empty-header-", ".csv")
-    tmpFile.toFile.deleteOnExit()
-    Files.write(
-      tmpFile,
-      
"id,name,,age\n1,Alice,x,30\n2,Bob,y,25\n".getBytes(StandardCharsets.UTF_8)
-    )
-    tmpFile.toString
-  }
+  // A CSV whose header row has an empty column (the third position).
+  private val emptyHeaderCsv = "id,name,,age\n1,Alice,x,30\n2,Bob,y,25\n"
 
-  // Writes a three-column `;`-separated CSV and returns the absolute path.
-  private def writeSemicolonCsv(): String = {
-    val tmpFile = Files.createTempFile("semicolon-", ".csv")
+  // A three-column `;`-separated CSV.
+  private val semicolonCsv = "id;name;age\n1;Alice;30\n2;Bob;25\n"
+
+  // Writes `body` to a temporary CSV and returns the absolute path.
+  private def writeCsv(body: String): String = {
+    val tmpFile = Files.createTempFile("csv-", ".csv")
     tmpFile.toFile.deleteOnExit()
-    Files.write(
-      tmpFile,
-      "id;name;age\n1;Alice;30\n2;Bob;25\n".getBytes(StandardCharsets.UTF_8)
-    )
+    Files.write(tmpFile, body.getBytes(StandardCharsets.UTF_8))
     tmpFile.toString
   }
 
-  private def columnNames(opDesc: ScanSourceOpDesc, path: String): 
List[String] = {
+  // Points `opDesc` at the file at `path`, resolved as a local file URI.
+  private def pointAt[T <: ScanSourceOpDesc](opDesc: T, path: String): T = {
     opDesc.fileName = Some(path)
     opDesc.setResolvedFileName(TestOperators.localFileUri(path))

Review Comment:
   **Advisory:**
   
   `setResolvedFileName` overwrites `fileName` unconditionally 
(`ScanSourceOpDesc.scala:113-115`), so the assignment on line 94 is replaced by 
the very next line. Now that every case reaches its file through this helper, 
this is the one place to drop it; `CSVScanSourceOpExecSpec.scala:153` already 
resolves without it.
   
   ```suggestion
       opDesc.setResolvedFileName(TestOperators.localFileUri(path))
   ```



##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/source/scan/text/TextInputSourceOpDescSpec.scala:
##########
@@ -470,37 +360,20 @@ class TextInputSourceOpDescSpec extends AnyFlatSpec with 
BeforeAndAfter {
     }
   }
 
-  /** The configured text read as STRING lines by the executor the engine 
runs. */
-  private def linesFromEngine(): Seq[String] = {
+  /** Every tuple the executor the engine runs produces for the configured 
text. */

Review Comment:
   **Polish:**
   
   The two nested clauses ("the executor the engine runs produces") make this 
hard to parse on a first read. Putting the agent last reads in one pass and 
matches the `linesFromEngine` comment below it.
   
   ```suggestion
     /** Every tuple produced for the configured text by the executor the 
engine runs. */
   ```



##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/source/scan/text/TextInputSourceOpDescSpec.scala:
##########
@@ -86,103 +86,29 @@ class TextInputSourceOpDescSpec extends AnyFlatSpec with 
BeforeAndAfter {
   }
 
   it should "read first 5 lines of the input text into corresponding output 
tuples" in {
-    val inputString: String = 
readFileIntoString(TestOperators.TestTextFilePath)
-    textInputSourceOpDesc.attributeType = FileAttributeType.STRING
-    textInputSourceOpDesc.textInput = inputString
-    textInputSourceOpDesc.fileScanLimit = Option(5)
-    val textScanSourceOpExec =
-      new 
TextInputSourceOpExec(objectMapper.writeValueAsString(textInputSourceOpDesc))
-    textScanSourceOpExec.open()
-    val processedTuple: Iterator[Tuple] = textScanSourceOpExec
-      .produceTuple()
-      .map(tupleLike =>
-        tupleLike
-          .asInstanceOf[SchemaEnforceable]
-          .enforceSchema(textInputSourceOpDesc.sourceSchema())
-      )
-
-    assert(processedTuple.next().getField("line").equals("line1"))
-    assert(processedTuple.next().getField("line").equals("line2"))
-    assert(processedTuple.next().getField("line").equals("line3"))
-    assert(processedTuple.next().getField("line").equals("line4"))
-    assert(processedTuple.next().getField("line").equals("line5"))
-    
assertThrows[java.util.NoSuchElementException](processedTuple.next().getField("line"))
-    textScanSourceOpExec.close()
+    assert(linesFrom(limit = Some(5)) == Seq("line1", "line2", "line3", 
"line4", "line5"))
   }
 
   it should "read first 5 lines of the input text with CRLF separators into 
corresponding output tuples" in {
-    val inputString: String = 
readFileIntoString(TestOperators.TestCRLFTextFilePath)
-    textInputSourceOpDesc.attributeType = FileAttributeType.STRING
-    textInputSourceOpDesc.textInput = inputString
-    textInputSourceOpDesc.fileScanLimit = Option(5)
-    val textScanSourceOpExec =
-      new 
TextInputSourceOpExec(objectMapper.writeValueAsString(textInputSourceOpDesc))
-    textScanSourceOpExec.open()
-    val processedTuple: Iterator[Tuple] = textScanSourceOpExec
-      .produceTuple()
-      .map(tupleLike =>
-        tupleLike
-          .asInstanceOf[SchemaEnforceable]
-          .enforceSchema(textInputSourceOpDesc.sourceSchema())
-      )
-
-    assert(processedTuple.next().getField("line").equals("line1"))
-    assert(processedTuple.next().getField("line").equals("line2"))
-    assert(processedTuple.next().getField("line").equals("line3"))
-    assert(processedTuple.next().getField("line").equals("line4"))
-    assert(processedTuple.next().getField("line").equals("line5"))
-    
assertThrows[java.util.NoSuchElementException](processedTuple.next().getField("line"))
-    textScanSourceOpExec.close()
+    assert(
+      linesFrom(limit = Some(5), path = TestOperators.TestCRLFTextFilePath) ==
+        Seq("line1", "line2", "line3", "line4", "line5")
+    )
   }
 
   it should "read first 5 lines of the input text into a single output tuple" 
in {

Review Comment:
   **Polish:**
   
   The name promises the first 5 lines, but the case sets no limit and expects 
all ten lines in one tuple (lines 100-103). The name predates this PR; since 
the body is rewritten here, a rename saves the next reader from looking for a 
limit that is not there.
   
   ```suggestion
     it should "read the whole input text into a single output tuple" in {
   ```



##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/source/scan/csv/CSVScanSourceOpDescSpec.scala:
##########
@@ -526,27 +400,23 @@ class CSVScanSourceOpDescSpec extends AnyFlatSpec with 
BeforeAndAfter {
     "space" -> " "
   )
 
-  private def writeCsv(delimiter: String, body: String): String = {
-    val tmpFile = Files.createTempFile("delimited-", ".csv")
-    tmpFile.toFile.deleteOnExit()
-    Files.write(tmpFile, body.replace(",", 
delimiter).getBytes(StandardCharsets.UTF_8))
-    tmpFile.toString
-  }
-
-  private def allReaders(delimiter: String): List[ScanSourceOpDesc] = {
+  // The three CSV scans, each reading `delimiter` and at most `limit` rows.

Review Comment:
   **Polish:**
   
   This only configures the three descriptors, and the cases that use it pin 
different readings. `;abc` is split on `;` (line 480) and an empty delimiter 
becomes a comma (line 471). With `limit = Some(0)` inference still reads every 
column (line 498), and the parallel executor ignores the limit 
(`ParallelCSVScanSourceOpExec.scala:110`).
   
   ```suggestion
     // The three CSV scans, each configured with `delimiter` and `limit`.
   ```



-- 
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]

Reply via email to