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/04/11 12:10:28 UTC

[GitHub] [avro] opwvhk opened a new pull request, #1637: AVRO-3486: Set namespace with protocol fullName

opwvhk opened a new pull request, #1637:
URL: https://github.com/apache/avro/pull/1637

   When parsing or creating a protocol, use both the name and namespace
   given to determine the actual name, namespace and fullName.
   
   Reason: the spec says "The name and namespace qualification rules
   defined for schema objects apply to protocols as well."
   
   Make sure you have checked _all_ steps below.
   
   ### Jira
   
   - [X] My PR addresses the following [Avro Jira](https://issues.apache.org/jira/browse/AVRO/) issues and references them in the PR title. For example, "AVRO-1234: My Avro PR"
     - https://issues.apache.org/jira/browse/AVRO-3486
     - In case you are adding a dependency, check if the license complies with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   
   ### Tests
   
   - [X] My PR ~adds~ updates the following unit tests __OR__ does not need testing for this extremely good reason:
       `org.apache.avro.compiler.idl.TestIdl#runTests()` for `import.avdl` and `nestedimport.avdl` by updating `bar.avpr`
   
   ### Commits
   
   - [X] My commits all reference Jira issues in their subject lines. In addition, my 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"
   
   ### Documentation
   
   - [ ] In case of new functionality, my PR adds documentation that describes how to use it.
     - All the public functions and the classes in the PR contain Javadoc that explain what it does
   


-- 
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] Christophe-LeSaec commented on a diff in pull request #1637: AVRO-3486: Set namespace with protocol fullName

Posted by GitBox <gi...@apache.org>.
Christophe-LeSaec commented on code in PR #1637:
URL: https://github.com/apache/avro/pull/1637#discussion_r880272632


##########
lang/java/avro/src/main/java/org/apache/avro/Protocol.java:
##########
@@ -275,15 +274,29 @@ public Protocol(Protocol p) {
 
   public Protocol(String name, String doc, String namespace) {
     super(PROTOCOL_RESERVED);
-    this.name = name;
+    setName(name, namespace);
     this.doc = doc;
-    this.namespace = namespace;
   }
 
   public Protocol(String name, String namespace) {
     this(name, null, namespace);
   }
 
+  private void setName(String name, String namespace) {
+    int lastDot = name.lastIndexOf('.');
+    if (lastDot < 0) {
+      this.name = name;
+      this.namespace = namespace;
+    } else {
+      this.name = name.substring(lastDot) + 1;
+      this.namespace = name.substring(0, lastDot);
+    }
+    if ("".equals(this.namespace)) {

Review Comment:
   So
   ```java
   if (this.namespace != null && this.namespace.isEmpty()) {
   ```



##########
lang/java/avro/src/main/java/org/apache/avro/Protocol.java:
##########
@@ -275,15 +274,29 @@ public Protocol(Protocol p) {
 
   public Protocol(String name, String doc, String namespace) {
     super(PROTOCOL_RESERVED);
-    this.name = name;
+    setName(name, namespace);
     this.doc = doc;
-    this.namespace = namespace;
   }
 
   public Protocol(String name, String namespace) {
     this(name, null, namespace);
   }
 
+  private void setName(String name, String namespace) {
+    int lastDot = name.lastIndexOf('.');
+    if (lastDot < 0) {
+      this.name = name;
+      this.namespace = namespace;
+    } else {

Review Comment:
   What if namespace is "java" and name is "lang.String" 
   Here, a suggestion :
   ```java
           StringBuilder namespaceBuilder = new StringBuilder((namespace != null) ? namespace : "");
           if (namespaceBuilder.length() > 0 && namespaceBuilder.charAt(namespaceBuilder.length() - 1) != '.') {
               namespaceBuilder.append('.');
           }
           namespaceBuilder.append(name.substring(0, lastDot));
          this.namespace = namespaceBuilder.toString();
   ```



-- 
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 merged pull request #1637: AVRO-3486: Set namespace with protocol fullName

Posted by "opwvhk (via GitHub)" <gi...@apache.org>.
opwvhk merged PR #1637:
URL: https://github.com/apache/avro/pull/1637


-- 
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] KalleOlaviNiemitalo commented on a diff in pull request #1637: AVRO-3486: Set namespace with protocol fullName

Posted by GitBox <gi...@apache.org>.
KalleOlaviNiemitalo commented on code in PR #1637:
URL: https://github.com/apache/avro/pull/1637#discussion_r916532228


##########
lang/java/avro/src/main/java/org/apache/avro/Protocol.java:
##########
@@ -275,15 +274,29 @@ public Protocol(Protocol p) {
 
   public Protocol(String name, String doc, String namespace) {
     super(PROTOCOL_RESERVED);
-    this.name = name;
+    setName(name, namespace);
     this.doc = doc;
-    this.namespace = namespace;
   }
 
   public Protocol(String name, String namespace) {
     this(name, null, namespace);
   }
 
+  private void setName(String name, String namespace) {
+    int lastDot = name.lastIndexOf('.');
+    if (lastDot < 0) {
+      this.name = name;
+      this.namespace = namespace;
+    } else {

Review Comment:
   If a protocol has namespace "java" and name "lang.String", then its fullname should be "lang.String" for sure (not "java.lang.String"). But it is not clear from the spec whether types defined in this protocol should then inherit the "java" namespace (as declared) or the "lang" namespace (based on the fullname of the protocol). I don't see any justification for making nested types inherit the "java.lang" namespace.
   
   Relevant parts of the spec:
   
   <https://github.com/apache/avro/blob/4e1fefca493029ace961b7ef8889a3722458565a/doc/src/content/xdocs/spec.xml#L296-L316>
   <https://github.com/apache/avro/blob/4e1fefca493029ace961b7ef8889a3722458565a/doc/src/content/xdocs/spec.xml#L850-L851>
   
   In particular:
   
   > For example, if `"name": "X"` is specified, and this occurs within a field of the record definition of `org.foo.Y`, then the fullname is `org.foo.X`.
   
   If that is intended to apply only when there is a `"namespace":"org.foo"` property in the record definition or in some outer definition, and not when the record definition has `"name":"org.foo.Y", "namespace":"something_else"`, then the specification should say so.



-- 
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 #1637: AVRO-3486: Set namespace with protocol fullName

Posted by GitBox <gi...@apache.org>.
opwvhk commented on code in PR #1637:
URL: https://github.com/apache/avro/pull/1637#discussion_r916875707


##########
lang/java/avro/src/main/java/org/apache/avro/Protocol.java:
##########
@@ -275,15 +274,29 @@ public Protocol(Protocol p) {
 
   public Protocol(String name, String doc, String namespace) {
     super(PROTOCOL_RESERVED);
-    this.name = name;
+    setName(name, namespace);
     this.doc = doc;
-    this.namespace = namespace;
   }
 
   public Protocol(String name, String namespace) {
     this(name, null, namespace);
   }
 
+  private void setName(String name, String namespace) {
+    int lastDot = name.lastIndexOf('.');
+    if (lastDot < 0) {
+      this.name = name;
+      this.namespace = namespace;
+    } else {

Review Comment:
   The intent is to use the same namespace the the definition itself, and any enclosed definitions that don't specify one themselves. This is a lot easier to comprehend than using different namespaces.



-- 
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 #1637: AVRO-3486: Set namespace with protocol fullName

Posted by GitBox <gi...@apache.org>.
opwvhk commented on code in PR #1637:
URL: https://github.com/apache/avro/pull/1637#discussion_r916880917


##########
lang/java/avro/src/main/java/org/apache/avro/Protocol.java:
##########
@@ -275,15 +274,29 @@ public Protocol(Protocol p) {
 
   public Protocol(String name, String doc, String namespace) {
     super(PROTOCOL_RESERVED);
-    this.name = name;
+    setName(name, namespace);
     this.doc = doc;
-    this.namespace = namespace;
   }
 
   public Protocol(String name, String namespace) {
     this(name, null, namespace);
   }
 
+  private void setName(String name, String namespace) {
+    int lastDot = name.lastIndexOf('.');
+    if (lastDot < 0) {
+      this.name = name;
+      this.namespace = namespace;
+    } else {
+      this.name = name.substring(lastDot) + 1;
+      this.namespace = name.substring(0, lastDot);
+    }
+    if ("".equals(this.namespace)) {

Review Comment:
   Changed.



-- 
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