You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by GitBox <gi...@apache.org> on 2022/09/14 14:09:21 UTC
[GitHub] [avro] clesaec opened a new pull request, #1867: AVRO-3611: fix generator
clesaec opened a new pull request, #1867:
URL: https://github.com/apache/avro/pull/1867
<!--
*Thank you very much for contributing to Apache Avro - we are happy that you want to help us improve Avro. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
*Please understand that we do not do this to make contributions to Avro a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
## Contribution Checklist
- Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/AVRO/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
- Name the pull request in the form "AVRO-XXXX: [component] Title of the pull request", where *AVRO-XXXX* should be replaced by the actual issue number.
The *component* is optional, but can help identify the correct reviewers faster: either the language ("java", "python") or subsystem such as "build" or "doc" are good candidates.
- Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
- Make sure that the change passes the automated tests. You can [build the entire project](https://github.com/apache/avro/blob/master/BUILD.md) or just the [language-specific SDK](https://avro.apache.org/project/how-to-contribute/#unit-tests).
- Each pull request should address only one issue, not mix up code from multiple issues.
- Each commit in the pull request has a meaningful commit message (including the JIRA id)
- Every commit message references Jira issues in their subject lines. In addition, commits follow the guidelines from [How to write a good git commit message](https://chris.beams.io/posts/git-commit/)
1. Subject is separated from body by a blank line
1. Subject is limited to 50 characters (not including Jira issue reference)
1. Subject does not end with a period
1. Subject uses the imperative mood ("add", not "adding")
1. Body wraps at 72 characters
1. Body explains "what" and "why", not "how"
-->
## What is the purpose of the change
* [AVRO-3611](https://issues.apache.org/jira/browse/AVRO-3611) about record generator in Java and LogicalType. Some logical type should constrain value generation to keep it valid.
## Verifying this change
This change is already covered by existing tests, as it is used by unit test to generates record to test.
## Documentation
- Does this pull request introduce a new feature? no
--
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: dev-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] clesaec commented on a diff in pull request #1867: AVRO-3611: fix generator
Posted by GitBox <gi...@apache.org>.
clesaec commented on code in PR #1867:
URL: https://github.com/apache/avro/pull/1867#discussion_r975369045
##########
lang/java/avro/src/main/java/org/apache/avro/util/RandomData.java:
##########
@@ -146,6 +150,23 @@ private Object generate(Schema schema, Random random, int d) {
private static final Charset UTF8 = StandardCharsets.UTF_8;
+ private int randomInt(Random random, LogicalType type) {
+ if (type instanceof LogicalTypes.TimeMillis) {
+ return random.nextInt((int) Duration.ofDays(1).toMillis() - 1);
Review Comment:
constant added & use
##########
lang/java/avro/src/main/java/org/apache/avro/util/RandomData.java:
##########
@@ -146,6 +150,23 @@ private Object generate(Schema schema, Random random, int d) {
private static final Charset UTF8 = StandardCharsets.UTF_8;
+ private int randomInt(Random random, LogicalType type) {
+ if (type instanceof LogicalTypes.TimeMillis) {
+ return random.nextInt((int) Duration.ofDays(1).toMillis() - 1);
+ }
+ // LogicalTypes.Date LocalDate.MAX.toEpochDay() > Integer.MAX;
+ return random.nextInt();
+ }
+
+ private long randomLong(Random random, LogicalType type) {
+ if (type instanceof LogicalTypes.TimeMicros) {
+ return ThreadLocalRandom.current().nextLong(Duration.ofDays(1).toMillis() * 1000L);
Review Comment:
constant reused
--
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: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] opwvhk commented on a diff in pull request #1867: AVRO-3611: fix generator
Posted by GitBox <gi...@apache.org>.
opwvhk commented on code in PR #1867:
URL: https://github.com/apache/avro/pull/1867#discussion_r1017480640
##########
lang/java/avro/src/main/java/org/apache/avro/util/RandomData.java:
##########
@@ -146,6 +152,23 @@ private Object generate(Schema schema, Random random, int d) {
private static final Charset UTF8 = StandardCharsets.UTF_8;
+ private int randomInt(Random random, LogicalType type) {
+ if (type instanceof LogicalTypes.TimeMillis) {
+ return random.nextInt(RandomData.MILLIS_IN_DAY - 1);
Review Comment:
The upper bound of nextInt is already exclusive. Why subtract one more?
--
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: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] dkulp merged pull request #1867: AVRO-3611: fix generator
Posted by GitBox <gi...@apache.org>.
dkulp merged PR #1867:
URL: https://github.com/apache/avro/pull/1867
--
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: dev-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] opwvhk commented on a diff in pull request #1867: AVRO-3611: fix generator
Posted by GitBox <gi...@apache.org>.
opwvhk commented on code in PR #1867:
URL: https://github.com/apache/avro/pull/1867#discussion_r1017481217
##########
lang/java/avro/src/main/java/org/apache/avro/util/RandomData.java:
##########
@@ -146,6 +152,23 @@ private Object generate(Schema schema, Random random, int d) {
private static final Charset UTF8 = StandardCharsets.UTF_8;
+ private int randomInt(Random random, LogicalType type) {
+ if (type instanceof LogicalTypes.TimeMillis) {
+ return random.nextInt(RandomData.MILLIS_IN_DAY - 1);
+ }
+ // LogicalTypes.Date LocalDate.MAX.toEpochDay() > Integer.MAX;
Review Comment:
👍
--
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: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] martin-g commented on a diff in pull request #1867: AVRO-3611: fix generator
Posted by GitBox <gi...@apache.org>.
martin-g commented on code in PR #1867:
URL: https://github.com/apache/avro/pull/1867#discussion_r974662031
##########
lang/java/avro/src/main/java/org/apache/avro/util/RandomData.java:
##########
@@ -146,6 +150,23 @@ private Object generate(Schema schema, Random random, int d) {
private static final Charset UTF8 = StandardCharsets.UTF_8;
+ private int randomInt(Random random, LogicalType type) {
+ if (type instanceof LogicalTypes.TimeMillis) {
+ return random.nextInt((int) Duration.ofDays(1).toMillis() - 1);
+ }
+ // LogicalTypes.Date LocalDate.MAX.toEpochDay() > Integer.MAX;
+ return random.nextInt();
+ }
+
+ private long randomLong(Random random, LogicalType type) {
+ if (type instanceof LogicalTypes.TimeMicros) {
+ return ThreadLocalRandom.current().nextLong(Duration.ofDays(1).toMillis() * 1000L);
Review Comment:
`Duration.ofDays(1).toMillis() * 1000L` is `86400000000`. IMO it would be good to make it a proper Java constant (`private static final int`).
##########
lang/java/avro/src/main/java/org/apache/avro/util/RandomData.java:
##########
@@ -146,6 +150,23 @@ private Object generate(Schema schema, Random random, int d) {
private static final Charset UTF8 = StandardCharsets.UTF_8;
+ private int randomInt(Random random, LogicalType type) {
+ if (type instanceof LogicalTypes.TimeMillis) {
+ return random.nextInt((int) Duration.ofDays(1).toMillis() - 1);
+ }
+ // LogicalTypes.Date LocalDate.MAX.toEpochDay() > Integer.MAX;
+ return random.nextInt();
+ }
+
+ private long randomLong(Random random, LogicalType type) {
+ if (type instanceof LogicalTypes.TimeMicros) {
+ return ThreadLocalRandom.current().nextLong(Duration.ofDays(1).toMillis() * 1000L);
Review Comment:
You could still use `Random#nextInt(86400000000)` and cast it to `long`.
##########
lang/java/avro/src/main/java/org/apache/avro/util/RandomData.java:
##########
@@ -146,6 +150,23 @@ private Object generate(Schema schema, Random random, int d) {
private static final Charset UTF8 = StandardCharsets.UTF_8;
+ private int randomInt(Random random, LogicalType type) {
+ if (type instanceof LogicalTypes.TimeMillis) {
+ return random.nextInt((int) Duration.ofDays(1).toMillis() - 1);
Review Comment:
Make `Duration.ofDays(1).toMillis() - 1` a constant.
--
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: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] viksri commented on pull request #1867: AVRO-3611: fix generator
Posted by GitBox <gi...@apache.org>.
viksri commented on PR #1867:
URL: https://github.com/apache/avro/pull/1867#issuecomment-1366612713
👍
--
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: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org