Skip to content

feat: Add random row generator in data generator#451

Merged
andygrove merged 5 commits into
apache:mainfrom
advancedxy:random_row_generator
May 23, 2024
Merged

feat: Add random row generator in data generator#451
andygrove merged 5 commits into
apache:mainfrom
advancedxy:random_row_generator

Conversation

@advancedxy

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #.

Rationale for this change

Follow up of #426, supports generating random rows for specified struct type.

What changes are included in this PR?

Add utility method: generateRows to generate random rows.

How are these changes tested?

N/A.

@advancedxy

Copy link
Copy Markdown
Contributor Author

@andygrove would you mind to take a look at this?

Comment thread spark/src/test/scala/org/apache/comet/DataGenerator.scala
fields += data
case _ =>
val generator = RandomDataGenerator.forType(f.dataType, f.nullable, r)
assert(generator.isDefined, "Unsupported type")

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.

I think we should also check f.nullable and return null sometimes here as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The RandomDataGenerator.forType(f.dataType, f.nullable, r) handles the nullable type, so I don't think we need to handle it here.

See: https://github.com/apache/spark/blob/master/sql/catalyst/src/test/scala/org/apache/spark/sql/RandomDataGenerator.scala#L380-L392

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.

Hmmm should we do the same (create nulls in forType) for the rest of types? Then we do not need duplicated PROBABILITY_OF_NULL

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmmm should we do the same (create nulls in forType) for the rest of types?

Let me think about that. Maybe we can remove the array type case. However I think the user specified stringGen still have to access PROBABILITY_OF_NULL to generate nullable strings. Otherwise, the stringGen method itself should handle nullable by itself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated, please let me know what you think.

Comment thread spark/src/test/scala/org/apache/comet/DataGenerator.scala Outdated
Comment thread spark/src/test/scala/org/apache/comet/DataGenerator.scala Outdated
@andygrove

Copy link
Copy Markdown
Member

LGTM overall. I think this is a good addition. I left a couple of small style suggestions.

Comment thread spark/src/test/scala/org/apache/comet/DataGenerator.scala

@andygrove andygrove left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks @advancedxy

@andygrove andygrove merged commit 9125e6a into apache:main May 23, 2024
@advancedxy

Copy link
Copy Markdown
Contributor Author

Thanks everyone for reviewing.

himadripal pushed a commit to himadripal/datafusion-comet that referenced this pull request Sep 7, 2024
* feat: Add random row generator in data gen

* fix

* remove array type match case, which should already been handled in RandomDataGenerator.forType

* fix style issue

* address comments

(cherry picked from commit 9125e6a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants