-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AVRO-2385: generate camelCase method names for UPPER_SNAKE fields #735
base: main
Are you sure you want to change the base?
Conversation
If you use mvn spotless: apply, it can solve the problem of the code format built by CI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick check, the test case is great, but I think that instead of using toString, returning to StringBuilder directly can reduce the amount of code.
lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
Show resolved
Hide resolved
lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
Show resolved
Hide resolved
// use underscores as hints where the capitals go | ||
StringBuilder builder = new StringBuilder(); | ||
for (String part : StringUtils.split(s, '_')) { | ||
builder.append(StringUtils.capitalize(StringUtils.lowerCase(part))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'StringUtils.lowerCase ()' will have better performance if placed outside the loop.
8770fc2
to
1424de1
Compare
Not all the branches of
|
Changes the implementation of Avro record name to Java method name converter. Though this breaks no existing tests, it is a breaking change for records named in UPPER_SNAKE style.
63130fd
to
316c5a4
Compare
Hi @ecopoesis - is there a reason this PR is still open? Would love to use this feature. |
I am not a committer for Avro so I can’t merge this branch. |
@zeshuai007 Looks like you're one of the contributors. Would it be possible to have this PR merged? |
Trying to get the attention back for this to be merged if the contribution looks good. |
assertEquals("SnakeUuid", SpecificCompiler.camelize("snake_UUID", true)); | ||
assertEquals("Lower", SpecificCompiler.camelize("lower", true)); | ||
assertEquals("Capitalized", SpecificCompiler.camelize("Capitalized", true)); | ||
assertEquals("CAPS", SpecificCompiler.camelize("CAPS", true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional ?
At https://github.com/apache/avro/pull/735/files#diff-bdda25ef6cc04f1ca556df625d9d4ecdd65951cfcd8b4e38da5916765bff75dbR946 UUID
has been transformed to Uuid
but here CAPS
remains as CAPS
. I'd expect Caps
instead.
assertEquals("CAPS", SpecificCompiler.camelize("CAPS", true)); | ||
assertEquals("CamelCased", SpecificCompiler.camelize("camelCased", true)); | ||
assertEquals("CamelCased", SpecificCompiler.camelize("CamelCased", true)); | ||
assertEquals("SomeUUID", SpecificCompiler.camelize("someUUID", true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as form CAPS
above.
assertEquals("CamelCased", SpecificCompiler.camelize("camelCased", true)); | ||
assertEquals("CamelCased", SpecificCompiler.camelize("CamelCased", true)); | ||
assertEquals("SomeUUID", SpecificCompiler.camelize("someUUID", true)); | ||
assertEquals("UUIDFirst", SpecificCompiler.camelize("UUIDFirst", true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
return StringUtils.uncapitalize(s); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And what about MIXED_CamelCasedTYPED ? :)
Shouldn't it be better to split at start, then ignore part that contains only '_'
StringUtils.splitByCharacterTypeCamelCase("MIXED_CamelCasedTYPED") =>
["MIXED3, "_", "Camel", "Cased", "TYPED"]
I suggest
static String camelize(String s, boolean upper) {
String[] parts = StringUtils.splitByCharacterTypeCamelCase(s);
int index = 0;
while (index < parts.length && "_".equals(parts[index])) {
index++;
}
// subsections should retain their casing if all upper
...
Changes the implementation of Avro record name to Java method name
converter. Though this breaks no existing tests, it is a breaking change
for records named in UPPER_SNAKE style.
Make sure you have checked all steps below.
Jira
Tests
Adds:
org.apache.avro.compiler.specific.TestSpecificCompiler#testCamelize
Modifies:
org.apache.avro.compiler.specific.TestSpecificCompiler#generateGetMethod
org.apache.avro.compiler.specific.TestSpecificCompiler#generateSetMethod
Commits
Documentation