Issue#62: Constraint suggestion extended example#394
Conversation
| val STATUSES = Array("IN_TRANSIT", "DELAYED", "UNKNOWN") | ||
| val VALUABLES = Array("true", "false", null) | ||
| val ran = new Random() | ||
|
|
There was a problem hiding this comment.
Mutable state (dataList) at the object level makes this non-thread-safe and broken if generateData is called more than once (the list accumulates across calls). Move dataList inside generateData as a local variable, or clear it at the start of the method.
| dataProfile.valuableDist <= 100) { | ||
| for (i <- 1 to dataProfile.size) | ||
| yield addData( | ||
| RawData( |
There was a problem hiding this comment.
The for/yield expression produces a Seq[Unit] because addData returns Unit, not RawData. The generated data is only accumulated in the mutable dataList as a side effect, and the yielded sequence is discarded. Either make addData return the RawData and collect the yield, or drop the yield entirely and just use a for loop (since you already rely on the side-effecting dataList).
| generateTotalNumber(50), // Generates values between 0(inclusive) & 50(exclusive) | ||
| generateStatus(dataProfile), // Generates status according to DataProfile.statusDist | ||
| generateValuable(dataProfile) // Generates valuable according to DataProfile.valuableDist | ||
| ) |
There was a problem hiding this comment.
println("Data not generated...") is inside a branch that should return an empty Seq, but because the if/else result is discarded (the method always returns dataList.toSeq at the end), invalid DataProfile values (e.g. negative size, statusDist > 100) will still return whatever was left in the shared mutable dataList. The control flow needs restructuring—either return early or use the if/else as the method body.
| * DataProfile(300, 0, 0) so it would generate 300 rows with random statuses and | ||
| * random valuables. | ||
| */ | ||
| val dataProfile = DataProfile(300, 75, 50) |
There was a problem hiding this comment.
DataProfile and GenerateDataUtils are referenced here but RawData (used inside GenerateDataUtils) is never defined in this PR. The code won't compile without a RawData case class. You need to either define it (e.g. case class RawData(name: String, totalNumber: String, status: String, valuable: String)) or import it.
|
|
||
| // Generates totalNumber from zero inclusive to maxValue exclusive. | ||
| def generateTotalNumber(maxValue: Int) : String = { | ||
| ran.nextInt(maxValue).toFloat.toString |
There was a problem hiding this comment.
Returning totalNumber as a String representation of a Float (e.g. "23.0") is unusual. If the intent is an integer count, consider returning an Int or at least a String of the integer (ran.nextInt(maxValue).toString). The .toFloat.toString adds a spurious .0 suffix.
|
This PR has been inactive for 60 days. It will be closed in 14 days if there is no further activity. If you are still working on this, please push an update or comment to keep it open. |
Issue #62, if available:
Description of changes:
::: Generates data according to DataProfile object:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.