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

Add generator classes to generate platform-specific wrappers #15

Merged
merged 3 commits into from
Apr 2, 2019

Conversation

shardulm94
Copy link
Contributor

  • Added platform-specific wrapper generators for Hive, Presto and Spark.
    • Hive and Presto wrapper generators use JavaPoet for Java code gen
    • Spark wrapper uses String templates and substitution for Scala code gen. Treehugger, the library for Scala code gen, was too complicated to use, its DSL did not have full support of complex Scala syntax and the resultant generation code did not have good readability. For our simple use case, string substitution should work as well, we can also consider if we should use string template for other wrappers.
  • Moved UDFProperties to transportable-udfs-compile-utils to share the class without having to put the annotation processor as compile dependency. (Gradle considers annotation processors in the compile classpath as being applied to the module, will be removed in future versions in favor of annotationProcessor classpath)
  • Added some helper methods to UDFProperties and changed to use LinkedHashMultimap internally to preserve ordering of UDFs (just looks prettier, no impact on functionality). Fixed a test case.

@shardulm94 shardulm94 self-assigned this Mar 23, 2019
private void generateWrapper(String topLevelStdUDFClass, Collection<String> implementationClasses, File outputDir) {
final String wrapperTemplate;
try {
wrapperTemplate = IOUtils.toString(

Choose a reason for hiding this comment

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

is this deprecated method?
Need to close stream

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method is not marked as deprecated. Updated to use try-with-resources.

import javax.lang.model.element.Modifier;


public class HiveWrapperGenerator implements WrapperGenerator {

Choose a reason for hiding this comment

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

javadoc all classes and non-private methods. (even package private ones to help contributors)

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 think a Javadoc here would be pretty redundant, it would convey that this class generates Hive wrappers which is already conveyed by the class name. The WrapperGenerator class contains the javadocs for interface as well as the public method.

try {
CodegenUtils.writeServiceFile(context.getResourcesOutputDir().toPath(), SERVICE_FILE, services);
} catch (IOException e) {
throw new RuntimeException("Error creating service file", e);

Choose a reason for hiding this comment

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

why do you convert IOException to RuntimeException (multiple places)? Better to make caller explicitly handle it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The caller in the case of these wrapper generators will be a Gradle task. The gradle task will not have a complete picture of what exactly the wrapper generator is doing. So I feel it is probably better to handle it here rather than pass to caller.


@Override
public void generateWrappers(ProjectContext context) {
Multimap<String, String> udfs = context.getUdfProperties().getUdfs();

Choose a reason for hiding this comment

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

didn't fully follow how this works - does the developer have to list all the functions in a json file? If yes, can they simply annotate the code and we scan the package for annotations instead of separate json 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.

The JSON file is generated as an output of the annotation processor. The Gradle task will then pass this JSON file to the wrapper generators to generate the wrappers. This reasoning behind adopted this approach is mentioned in the design doc.

/**
* Asserts that the contents of both directories (and their subdirectories) are equal
*/
static void assertDirectoriesAreEqual(Path actualDir, Path expectedDir) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sort listings of both directories. Go over sorted lists in parallel. Both names and contents should correspond.
See if you can stick to File all the way in this case.
Check if the chain of calling can be simplified after this approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lets discuss this tomorrow. I feel the current 2-step behaviour leads to a better error message in case of a failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added comments. Removed Path<-->File conversions. Kept the 2-step behaviour

Copy link
Contributor

@wmoustafa wmoustafa 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 PR. Looks great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants