[
https://issues.apache.org/jira/browse/BEAM-3243?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16269113#comment-16269113
]
ASF GitHub Bot commented on BEAM-3243:
--------------------------------------
rmannibucau closed pull request #4172: [BEAM-3243] support multiple anonymous
classes from the same enclosing class in a pipeline
URL: https://github.com/apache/beam/pull/4172
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/NameUtils.java
b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/NameUtils.java
index 3f3054ae733..d42e41c059e 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/NameUtils.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/NameUtils.java
@@ -52,8 +52,6 @@
private static final String ANONYMOUS_CLASS_REGEX = "\\$[0-9]+\\$";
private static String approximateSimpleName(Class<?> clazz, boolean
dropOuterClassNames) {
- checkArgument(!clazz.isAnonymousClass(),
- "Attempted to get simple name of anonymous class");
return approximateSimpleName(clazz.getName(), dropOuterClassNames);
}
@@ -92,14 +90,6 @@ private static String simplifyNameComponent(String name) {
return name;
}
- /**
- * As {@link #approximateSimpleName(Object, String)} but returning {@code
"Anonymous"} when
- * {@code object} is an instance of anonymous class.
- */
- public static String approximateSimpleName(Object object) {
- return approximateSimpleName(object, "Anonymous");
- }
-
/**
* Returns a simple name describing a class that is being used as a function
(eg., a {@link DoFn}
* or {@link CombineFn}, etc.).
@@ -123,7 +113,7 @@ public static String approximateSimpleName(Object object) {
* <li>{@code another.package.PairingFn} becomes "Pairing"
* </ul>
*/
- public static String approximateSimpleName(Object object, String
anonymousValue) {
+ public static String approximateSimpleName(Object object) {
if (object instanceof NameOverride) {
return ((NameOverride) object).getNameOverride();
}
@@ -134,9 +124,11 @@ public static String approximateSimpleName(Object object,
String anonymousValue)
} else {
clazz = object.getClass();
}
+ /* if anonymous ensure the name is unique to support multiple anonymous
DoFn per class
if (clazz.isAnonymousClass()) {
return anonymousValue;
}
+ */
return approximateSimpleName(clazz, /* dropOuterClassNames */ true);
}
diff --git
a/sdks/java/core/src/test/java/org/apache/beam/sdk/util/NameUtilsTest.java
b/sdks/java/core/src/test/java/org/apache/beam/sdk/util/NameUtilsTest.java
index 411f91317e0..fb17e149d95 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/util/NameUtilsTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/util/NameUtilsTest.java
@@ -77,6 +77,9 @@ public void testDropsOuterClassNamesFalse() {
* Inner class for simple name test.
*/
private class EmbeddedDoFn {
+ private Object anonymous() { // ensure we have a single one for the test
+ return new DeeperEmbeddedDoFn() {};
+ }
private class DeeperEmbeddedDoFn extends EmbeddedDoFn {}
@@ -114,7 +117,7 @@ public void testSimpleName() {
@Test
public void testAnonSimpleName() throws Exception {
- assertEquals("Anonymous", NameUtils.approximateSimpleName(new
EmbeddedDoFn() {}));
+ assertEquals("Embedded$1", NameUtils.approximateSimpleName(new
EmbeddedDoFn().anonymous()));
}
@Test
@@ -180,10 +183,4 @@ public String getNameOverride() {
};
assertEquals("CUSTOM_NAME",
NameUtils.approximateSimpleName(overriddenName));
}
-
- @Test
- public void testApproximateSimpleNameCustomAnonymous() {
- Object overriddenName = new Object() {};
- assertEquals("CUSTOM_NAME",
NameUtils.approximateSimpleName(overriddenName, "CUSTOM_NAME"));
- }
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> multiple anonymous DoFn lead to conflicting names
> -------------------------------------------------
>
> Key: BEAM-3243
> URL: https://issues.apache.org/jira/browse/BEAM-3243
> Project: Beam
> Issue Type: Task
> Components: sdk-java-core
> Reporter: Romain Manni-Bucau
> Assignee: Romain Manni-Bucau
> Fix For: 2.3.0
>
>
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)