You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "adutra (via GitHub)" <gi...@apache.org> on 2025/09/19 15:44:20 UTC

[PR] Fix & enhancements to the Events API hierarchy [polaris]

adutra opened a new pull request, #2629:
URL: https://github.com/apache/polaris/pull/2629

   Summary of changes:
   
   - Turned `PolarisEventListener` into an interface to facilitate implementation / mocking
   - Added missing `implements PolarisEvent` to many event records
   - Removed unused method overrides
   - Added missing method overrides to `TestPolarisEventListener`


-- 
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@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix & enhancements to the Events API hierarchy [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2629:
URL: https://github.com/apache/polaris/pull/2629#discussion_r2367173513


##########
runtime/service/src/main/java/org/apache/polaris/service/events/listeners/PolarisEventListener.java:
##########
@@ -29,287 +29,287 @@
  * Represents an event listener that can respond to notable moments during Polaris's execution.
  * Event details are documented under the event objects themselves.
  */
-public abstract class PolarisEventListener {
+public interface PolarisEventListener {

Review Comment:
   Thank you both for reviving this discussion. I've re-read the old thread carefully, and I still do not understand what the problem is with using an interface rather than an abstract class. 
   
   Can you please summarize your concerns here for clarity?
   
   If it's about binary compatibility when adding more methods to the API, I'm afraid an interface and an ABC provide roughly the same linkage risks. From [JLS 13.4.16](https://docs.oracle.com/javase/specs/jls/se21/html/jls-13.html#jls-13.4.16) (emphasis mine):
   
   > adding a default method is a binary-compatible change because it does not introduce errors at link time, even if it introduces errors at compile time or invocation time. In practice, **the risk of accidental clashes occurring by introducing a default method are similar to those associated with adding a new method to a non-final class**.
   
   In contrast, the advantages of using interfaces rather than abstract classes in public APIs are abundantly documented. From _Effective Java, 3rd Edition_ (J. Bloch, 2017) (emphasis mine):
   
   > Item 20: Prefer interfaces to abstract classes
   > Java has two mechanisms to define a type that permits multiple implementations: interfaces and abstract classes. Since the introduction of default methods for interfaces in Java 8 [JLS 9.4.3], both mechanisms allow you to provide implementations for some instance methods. A major difference is that to implement the type defined by an abstract class, a class must be a subclass of the abstract class. **Because Java permits only single inheritance, this restriction on abstract classes severely constrains their use as type definitions**. Any class that defines all the required methods and obeys the general contract is permitted to implement an interface, regardless of where the class resides in the class hierarchy.



-- 
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@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix & enhancements to the Events API hierarchy [polaris]

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


-- 
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@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix & enhancements to the Events API hierarchy [polaris]

Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on code in PR #2629:
URL: https://github.com/apache/polaris/pull/2629#discussion_r2364897765


##########
runtime/service/src/main/java/org/apache/polaris/service/events/listeners/PolarisEventListener.java:
##########
@@ -29,287 +29,287 @@
  * Represents an event listener that can respond to notable moments during Polaris's execution.
  * Event details are documented under the event objects themselves.
  */
-public abstract class PolarisEventListener {
+public interface PolarisEventListener {

Review Comment:
   Thanks for flagging it, @eric-maynard. I still hold my point, that this should be ABC, not interface. 



-- 
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@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix & enhancements to the Events API hierarchy [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #2629:
URL: https://github.com/apache/polaris/pull/2629#discussion_r2364024565


##########
runtime/service/src/main/java/org/apache/polaris/service/events/listeners/PolarisEventListener.java:
##########
@@ -29,287 +29,287 @@
  * Represents an event listener that can respond to notable moments during Polaris's execution.
  * Event details are documented under the event objects themselves.
  */
-public abstract class PolarisEventListener {
+public interface PolarisEventListener {

Review Comment:
   This was extensively debated at the time, but see [this comment](https://github.com/apache/polaris/pull/922#discussion_r1988472892) and related ones for why this is an ABC rather than an interface.



-- 
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@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix & enhancements to the Events API hierarchy [polaris]

Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on code in PR #2629:
URL: https://github.com/apache/polaris/pull/2629#discussion_r2369771545


##########
runtime/service/src/main/java/org/apache/polaris/service/events/listeners/PolarisEventListener.java:
##########
@@ -29,287 +29,287 @@
  * Represents an event listener that can respond to notable moments during Polaris's execution.
  * Event details are documented under the event objects themselves.
  */
-public abstract class PolarisEventListener {
+public interface PolarisEventListener {

Review Comment:
   Yes, binary compatibility is the concern. The upstream changes shouldn't break downstream event listeners. However, looking over the PR, it looks like all methods are now default methods, which is fine. Let's also ensure that any new methods added in the future are default as well.
   
   Could we add a test to enforce this? It might also be helpful to include a comment on the class to explicitly state that all new methods should be default.



-- 
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@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix & enhancements to the Events API hierarchy [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2629:
URL: https://github.com/apache/polaris/pull/2629#discussion_r2372932409


##########
runtime/service/src/main/java/org/apache/polaris/service/events/listeners/PolarisEventListener.java:
##########
@@ -29,287 +29,287 @@
  * Represents an event listener that can respond to notable moments during Polaris's execution.
  * Event details are documented under the event objects themselves.
  */
-public abstract class PolarisEventListener {
+public interface PolarisEventListener {

Review Comment:
   Added a comment and tests as suggested.
   
   I also re-organized the interface methods into "sections" for clarity, I hope that's OK.
   
   The tests check that all methods are default and well-formed, and also that all events have corresponding methods in the interface. 
   
   I added a similar check to `TestPolarisEventListener` (it was lacking many methods).



-- 
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@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix & enhancements to the Events API hierarchy [polaris]

Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on code in PR #2629:
URL: https://github.com/apache/polaris/pull/2629#discussion_r2369771545


##########
runtime/service/src/main/java/org/apache/polaris/service/events/listeners/PolarisEventListener.java:
##########
@@ -29,287 +29,287 @@
  * Represents an event listener that can respond to notable moments during Polaris's execution.
  * Event details are documented under the event objects themselves.
  */
-public abstract class PolarisEventListener {
+public interface PolarisEventListener {

Review Comment:
   Looking over the PR, it looks like all methods are now default methods, which is fine. Let's also ensure that any new methods added in the future are default as well.
   
   Could we add a test to enforce this? It might also be helpful to include a comment on the class to explicitly state that all new methods should be default.



-- 
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@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix & enhancements to the Events API hierarchy [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2629:
URL: https://github.com/apache/polaris/pull/2629#discussion_r2372777090


##########
runtime/service/src/main/java/org/apache/polaris/service/events/listeners/PolarisEventListener.java:
##########
@@ -29,287 +29,287 @@
  * Represents an event listener that can respond to notable moments during Polaris's execution.
  * Event details are documented under the event objects themselves.
  */
-public abstract class PolarisEventListener {
+public interface PolarisEventListener {

Review Comment:
   Hi @flyrain thanks for your flexibility 🙂 
   
   I will add the comment and the test as suggested. 
   
   I'd note that this kind of check would be a good fit for the `revapi` plugin – the same one we use in Iceberg to track API breaking changes. But I think Polaris is still a young project, and revapi would flag too many API changes that would be otherwise permitted by our current evolution rules:
   
   https://github.com/apache/polaris/blob/b1eb9bd81da10b8cc7bb3f200ceb22b9990642bb/site/content/in-dev/unreleased/evolution.md?plain=1#L81-L82
   
   So, let's stick with a small test for now 👍 



-- 
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@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix & enhancements to the Events API hierarchy [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2629:
URL: https://github.com/apache/polaris/pull/2629#discussion_r2367173513


##########
runtime/service/src/main/java/org/apache/polaris/service/events/listeners/PolarisEventListener.java:
##########
@@ -29,287 +29,287 @@
  * Represents an event listener that can respond to notable moments during Polaris's execution.
  * Event details are documented under the event objects themselves.
  */
-public abstract class PolarisEventListener {
+public interface PolarisEventListener {

Review Comment:
   Thank you both for reviving this discussion. I've re-read the old thread carefully, and I still do not understand what the problem is with using an interface rather than an abstract class. 
   
   Can you please summarize your concerns here for clarity?
   
   If it's about binary compatibility when adding more methods to the API, I'm afraid an interface and an ABC provide roughly the same linkage risks. From [JLS 13.4.16](https://docs.oracle.com/javase/specs/jls/se21/html/jls-13.html#jls-13.4.16) (emphasis mine):
   
   > adding a default method is a binary-compatible change because it does not introduce errors at link time, even if it introduces errors at compile time or invocation time. In practice, **the risk of accidental clashes occurring by introducing a default method are similar to those associated with adding a new method to a non-final class**.
   
   In contrast, the advantages of using interfaces rather than abstract classes in public APIs is abundantly documented. From _Effective Java, 3rd Edition_ (J. Bloch, 2017) (emphasis mine):
   
   > Item 20: Prefer interfaces to abstract classes
   > Java has two mechanisms to define a type that permits multiple implementations: interfaces and abstract classes. Since the introduction of default methods for interfaces in Java 8 [JLS 9.4.3], both mechanisms allow you to provide implementations for some instance methods. A major difference is that to implement the type defined by an abstract class, a class must be a subclass of the abstract class. **Because Java permits only single inheritance, this restriction on abstract classes severely constrains their use as type definitions**. Any class that defines all the required methods and obeys the general contract is permitted to implement an interface, regardless of where the class resides in the class hierarchy.



-- 
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@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix & enhancements to the Events API hierarchy [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2629:
URL: https://github.com/apache/polaris/pull/2629#discussion_r2372935231


##########
runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisCatalogsEventServiceDelegator.java:
##########
@@ -91,9 +91,9 @@ public Response updateCatalog(
 
   @Override
   public Response listCatalogs(RealmContext realmContext, SecurityContext securityContext) {
-    polarisEventListener.onBeforeListCatalog(new CatalogsServiceEvents.BeforeListCatalogEvent());
+    polarisEventListener.onBeforeListCatalogs(new CatalogsServiceEvents.BeforeListCatalogsEvent());

Review Comment:
   When I added tests for method compliance I noticed that this event was different from other "list" events because the object type being listed wasn't in the plural.



-- 
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@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix & enhancements to the Events API hierarchy [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on PR #2629:
URL: https://github.com/apache/polaris/pull/2629#issuecomment-3312701170

   cc @adnanhemani 


-- 
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@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix & enhancements to the Events API hierarchy [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2629:
URL: https://github.com/apache/polaris/pull/2629#discussion_r2372932409


##########
runtime/service/src/main/java/org/apache/polaris/service/events/listeners/PolarisEventListener.java:
##########
@@ -29,287 +29,287 @@
  * Represents an event listener that can respond to notable moments during Polaris's execution.
  * Event details are documented under the event objects themselves.
  */
-public abstract class PolarisEventListener {
+public interface PolarisEventListener {

Review Comment:
   Added a comment and tests as suggested.
   
   I also re-organized the interface methods into "section" for clarity, I hope that's OK.
   
   The tests check that all methods are default and well-formed, and also that all events have corresponding methods in the interface. 
   
   I added a similar check to `TestPolarisEventListener` (it was lacking many methods).



-- 
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@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix & enhancements to the Events API hierarchy [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on PR #2629:
URL: https://github.com/apache/polaris/pull/2629#issuecomment-3335752487

   @flyrain @eric-maynard is the code looking better now?


-- 
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@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org