Skip to content

Issue#62: Constraint suggestion extended example#394

Open
ramonpineda81 wants to merge 3 commits into
awslabs:masterfrom
ramonpineda81:constraint_suggestion_extended_example
Open

Issue#62: Constraint suggestion extended example#394
ramonpineda81 wants to merge 3 commits into
awslabs:masterfrom
ramonpineda81:constraint_suggestion_extended_example

Conversation

@ramonpineda81

Copy link
Copy Markdown

Issue #62, if available:

Description of changes:
::: Generates data according to DataProfile object:

  • DataProfile.size: Number of rows to generate
  • DataProfile.statusDist: Minimum percent of rows with status equal to 'IN_TRANSIT'
  • DataProfile.valuableDist: Minimum percent of rows with valuable equal to 'true'

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Generated by AI (model: us.anthropic.claude-opus-4-6-v1, prompt: 38d3f74c) — may not be fully accurate. Reply if this doesn't help.

val STATUSES = Array("IN_TRANSIT", "DELAYED", "UNKNOWN")
val VALUABLES = Array("true", "false", null)
val ran = new Random()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the stale label Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants