Skip to content
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

SAMZA-2354: Improve UDF discovery in samza-sql. #1192

Merged
merged 3 commits into from
Oct 17, 2019

Conversation

shanthoosh
Copy link
Contributor

This patch is comprised of following changes:

  1. Currently to plugin a udf implementation into samza-sql engine, users have to set the fully qualified class name of their UDF implementation in samza.sql.udfClasses configuration. Any user error made in defining the fully-qualified name of udf-class configuration can only be identified at run-time. This patch addresses this problem by using reflection to find all the samza-sql UDF implementations available in the class-path of the samza-sql application.
  2. Removes the ConfigBasedUdfResolver class and it's associated usages.
  3. Adds unit-tests for the newly introduced UDFResolver implementation.

Replace ConfigBasedUDFResolver with the UDF resolver based on the reflections.
@shanthoosh
Copy link
Contributor Author

@atoomula @srinipunuru
Please take a look when you get a chance.

@@ -1,119 +0,0 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't delete this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, reverted this deletion.

public ReflectionBasedUdfResolver(Config udfConfig) {
// Searching the entire classpath to discover the subtypes of SamzaSqlUdf is expensive. To reduce the search space,
// the search is limited to the set of package prefixes defined in the configuration.
// Within Linkedin this configuration will be overridden to ["com.linkedin.samza", "org.apache.samza", "com.linkedin.samza.sql.shade.prefix"].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove references to Linkedin from the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the LinkedIn comment.

* ensure that all subtypes of {@link SamzaSqlUdf} extend and implement the
* method annotated with {@link SamzaSqlUdfMethod}.
*/
public class ReflectionBasedUdfResolver implements UdfResolver {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, how much of a hit are we taking with OSS jar to load the UDFs via reflection ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By selectively searching for UDF's only in selected package-prefixes from class-path for UDF's, it's a very minimal over-head.

Copy link
Contributor Author

@shanthoosh shanthoosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review aditya!

* ensure that all subtypes of {@link SamzaSqlUdf} extend and implement the
* method annotated with {@link SamzaSqlUdfMethod}.
*/
public class ReflectionBasedUdfResolver implements UdfResolver {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By selectively searching for UDF's only in selected package-prefixes from class-path for UDF's, it's a very minimal over-head.

public ReflectionBasedUdfResolver(Config udfConfig) {
// Searching the entire classpath to discover the subtypes of SamzaSqlUdf is expensive. To reduce the search space,
// the search is limited to the set of package prefixes defined in the configuration.
// Within Linkedin this configuration will be overridden to ["com.linkedin.samza", "org.apache.samza", "com.linkedin.samza.sql.shade.prefix"].
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the LinkedIn comment.

@@ -1,119 +0,0 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, reverted this deletion.

@@ -214,7 +214,7 @@ private UdfResolver createUdfResolver(Map<String, String> config) {
Properties props = new Properties();
props.putAll(domainConfig);
HashMap<String, String> udfConfig = getDomainProperties(config, CFG_UDF_CONFIG_DOMAIN, false);
return new ConfigBasedUdfResolver(props, new MapConfig(udfConfig));
return new ReflectionBasedUdfResolver(new MapConfig(udfConfig));
Copy link
Contributor

@atoomula atoomula Oct 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't realize that this is hard-coded here. Could we make this pluggable ? I think calling initializePlugin like above (createIOResolver method) should do it with the udf resolver based arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this is a useful thing to do and discussed it offline. Created a follow-up ticket(SAMZA-2355) for making the UDFResolver pluggable in samza-sql. It will be done in an immediate follow-up patch.

Copy link
Contributor

@atoomula atoomula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shanthoosh shanthoosh merged commit e2928e1 into apache:master Oct 17, 2019
shekhars-li pushed a commit to shekhars-li/samza that referenced this pull request May 28, 2021
* Improve UDF discovery in the samza-sql.

Replace ConfigBasedUDFResolver with the UDF resolver based on the reflections.

* Address review comments.

* Add TODO for the follow-up ticket in the comments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants