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

DRILL-4456: Add Hive translate UDF #1527

Closed
wants to merge 1 commit into from

Conversation

vvysotskyi
Copy link
Member

@vvysotskyi vvysotskyi commented Nov 8, 2018

  • Added renaming of Hive TRANSLATE function to TRANSLATE3 during function registration.

For problem description DRILL-4456.

@arina-ielchiieva
Copy link
Member

@vdiravka could you please review.

@vdiravka
Copy link
Member

vdiravka commented Nov 8, 2018

@vvysotskyi The PR with two commits makes sense if that tickets are interdependent.
Looks like this case is different. So please split current PR to the two different ones.

@vvysotskyi vvysotskyi changed the title DRILL-3610 & DRILL-4456 Fix TIMESTAMPADD, TIMESTAMPDIFF and Hive TRANSLATE functions DRILL-4456: Fix Hive translate UDF Nov 8, 2018
@vvysotskyi
Copy link
Member Author

@vdiravka, done: #1528

* whether specified function names should be replaced
* with the names from the map.
*/
private String[] renameUDF(String[] namesToCheck) {
Copy link
Member

Choose a reason for hiding this comment

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

Please add @param and @return.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, added.

/**
* Map for renaming Hive UDFs whose names satisfy the predicate in the key by names from the map value.
*/
private static final Map<Predicate<String[]>, String[]> FUNCTION_REPLACE_MAP = ImmutableMap.<Predicate<String[]>, String[]> builder()
Copy link
Member

Choose a reason for hiding this comment

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

Please add better description.

Copy link
Member

Choose a reason for hiding this comment

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

@vvysotskyi Try to simplify the logic for FUNCTION_REPLACE_MAP. Possibly try to get rid from String[] (you can add all function names to this Map), so in result it can be similar to
https://github.com/apache/drill/blob/master/logical/src/main/java/org/apache/drill/common/expression/fn/FunctionReplacementUtils.java#L42

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, reworded a description and simplified the map to use target function names as keys and predicates for checking as values.

Copy link
Member Author

@vvysotskyi vvysotskyi left a comment

Choose a reason for hiding this comment

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

@arina-ielchiieva, @vdiravka, Thanks for the review, I have addressed CR comments, could you please take a look again?

/**
* Map for renaming Hive UDFs whose names satisfy the predicate in the key by names from the map value.
*/
private static final Map<Predicate<String[]>, String[]> FUNCTION_REPLACE_MAP = ImmutableMap.<Predicate<String[]>, String[]> builder()
Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, reworded a description and simplified the map to use target function names as keys and predicates for checking as values.

* whether specified function names should be replaced
* with the names from the map.
*/
private String[] renameUDF(String[] namesToCheck) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, added.

@vvysotskyi vvysotskyi force-pushed the DRILL-4456 branch 4 times, most recently from d8fab54 to 86b2656 Compare November 9, 2018 08:33
@vvysotskyi vvysotskyi changed the title DRILL-4456: Fix Hive translate UDF DRILL-4456: Add Hive translate UDF Nov 9, 2018
@vvysotskyi vvysotskyi force-pushed the DRILL-4456 branch 2 times, most recently from 1c0a2d8 to 3f366b1 Compare November 9, 2018 10:56
Copy link
Member

@vdiravka vdiravka left a comment

Choose a reason for hiding this comment

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

+1 LGTM

@@ -102,15 +116,15 @@ public void register(DrillOperatorTable operatorTable) {
}
}

private <C,I> void register(Class<? extends I> clazz, ArrayListMultimap<String,Class<? extends I>> methods) {
private <I> void register(Class<? extends I> clazz, ArrayListMultimap<String, Class<? extends I>> methods) {
Copy link
Member

Choose a reason for hiding this comment

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

If it's not required to have separate renameUDF(names) method, then it's possible to simplify body of this method:

private <C, I> void register(Class<? extends I> clazz, ArrayListMultimap<String, Class<? extends I>> methods) {
    Description desc = clazz.getAnnotation(Description.class);
    Stream<String> names;
    if (desc != null) {
      names = Stream.of(desc.name().split(",")).map(String::trim);
    } else {
      names = Stream.of(clazz).map(Class::getName)
          .map(name -> name.replace('.', '_'));
    }
    names.map(String::toLowerCase)
        .map(funName -> FUNCTION_REPLACE_MAP.getOrDefault(funName, funName))
        .forEach(udfFunName -> methods.put(udfFunName, clazz));

    UDFType type = clazz.getAnnotation(UDFType.class);
    if (type != null && !type.deterministic()) {
      nonDeterministicUDFs.add(clazz);
    }
  }

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, done

@ilooner ilooner closed this in 4124b41 Nov 10, 2018
mattpollack pushed a commit to mattpollack/drill that referenced this pull request Feb 25, 2019
lushuifeng pushed a commit to lushuifeng/drill that referenced this pull request Jun 21, 2019
xiangt920 pushed a commit to xiangt920/drill that referenced this pull request Dec 26, 2019
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