aglinxinyuan commented on code in PR #9679:
URL: https://github.com/apache/texera/pull/9679#discussion_r4689886085
##########
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:
Dropped it in e5c00f58f7: `pointAt` now only calls `setResolvedFileName`,
which sets `fileName` itself.
_🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
##########
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:
Reworded to your suggestion in e5c00f58f7.
_🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
##########
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:
Reworded to your suggestion in e5c00f58f7.
_🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
##########
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:
Renamed in e5c00f58f7 to "read the whole input text into a single output
tuple"; it keeps its place and still passes.
_🤖 Addressed by [Claude Code](https://claude.com/claude-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]