Java Code Examples for org.apache.hadoop.hive.ql.exec.Description#name()

The following examples show how to use org.apache.hadoop.hive.ql.exec.Description#name() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UDAFToOrderedList.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Nonnull
protected final CommandLine parseOptions(String optionValue) throws UDFArgumentException {
    String[] args = optionValue.split("\\s+");
    Options opts = getOptions();
    opts.addOption("help", false, "Show function help");
    CommandLine cl = CommandLineUtils.parseOptions(args, opts);

    if (cl.hasOption("help")) {
        Description funcDesc = getClass().getAnnotation(Description.class);
        final String cmdLineSyntax;
        if (funcDesc == null) {
            cmdLineSyntax = getClass().getSimpleName();
        } else {
            String funcName = funcDesc.name();
            cmdLineSyntax = funcName == null ? getClass().getSimpleName()
                    : funcDesc.value().replace("_FUNC_", funcDesc.name());
        }
        StringWriter sw = new StringWriter();
        sw.write('\n');
        PrintWriter pw = new PrintWriter(sw);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, cmdLineSyntax, null, opts,
            HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, true);
        pw.flush();
        String helpMsg = sw.toString();
        throw new UDFArgumentException(helpMsg);
    }

    return cl;
}
 
Example 2
Source File: PLSAPredictUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Nonnull
protected final CommandLine parseOptions(String optionValue) throws UDFArgumentException {
    String[] args = optionValue.split("\\s+");
    Options opts = getOptions();
    opts.addOption("help", false, "Show function help");
    CommandLine cl = CommandLineUtils.parseOptions(args, opts);

    if (cl.hasOption("help")) {
        Description funcDesc = getClass().getAnnotation(Description.class);
        final String cmdLineSyntax;
        if (funcDesc == null) {
            cmdLineSyntax = getClass().getSimpleName();
        } else {
            String funcName = funcDesc.name();
            cmdLineSyntax = funcName == null ? getClass().getSimpleName()
                    : funcDesc.value().replace("_FUNC_", funcDesc.name());
        }
        StringWriter sw = new StringWriter();
        sw.write('\n');
        PrintWriter pw = new PrintWriter(sw);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, cmdLineSyntax, null, opts,
            HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, true);
        pw.flush();
        String helpMsg = sw.toString();
        throw new UDFArgumentException(helpMsg);
    }

    return cl;
}
 
Example 3
Source File: LDAPredictUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Nonnull
protected final CommandLine parseOptions(String optionValue) throws UDFArgumentException {
    String[] args = optionValue.split("\\s+");
    Options opts = getOptions();
    opts.addOption("help", false, "Show function help");
    CommandLine cl = CommandLineUtils.parseOptions(args, opts);

    if (cl.hasOption("help")) {
        Description funcDesc = getClass().getAnnotation(Description.class);
        final String cmdLineSyntax;
        if (funcDesc == null) {
            cmdLineSyntax = getClass().getSimpleName();
        } else {
            String funcName = funcDesc.name();
            cmdLineSyntax = funcName == null ? getClass().getSimpleName()
                    : funcDesc.value().replace("_FUNC_", funcDesc.name());
        }
        StringWriter sw = new StringWriter();
        sw.write('\n');
        PrintWriter pw = new PrintWriter(sw);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, cmdLineSyntax, null, opts,
            HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, true);
        pw.flush();
        String helpMsg = sw.toString();
        throw new UDFArgumentException(helpMsg);
    }

    return cl;
}
 
Example 4
Source File: UDTFWithOptions.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
private void showHelp(@Nonnull Options opts, @Nullable String errMsg)
        throws UDFArgumentException {
    Description funcDesc = getClass().getAnnotation(Description.class);
    final String cmdLineSyntax;
    if (funcDesc == null) {
        cmdLineSyntax = getClass().getSimpleName();
    } else {
        String funcName = funcDesc.name();
        cmdLineSyntax = funcName == null ? getClass().getSimpleName()
                : funcDesc.value().replace("_FUNC_", funcDesc.name());
    }
    StringWriter sw = new StringWriter();
    sw.write('\n');
    if (errMsg != null) {
        if (funcDesc != null && funcDesc.name() != null) {
            errMsg = errMsg.replace("_FUNC_", funcDesc.name());
        }
        sw.write(errMsg);
        sw.write("\n\n");
    }
    PrintWriter pw = new PrintWriter(sw);
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, cmdLineSyntax, null, opts,
        HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, true);
    pw.flush();
    String helpMsg = sw.toString();
    throw new UDFArgumentException(helpMsg);
}
 
Example 5
Source File: UDFWithOptions.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
private void showHelp(@Nonnull Options opts, @Nullable String errMsg)
        throws UDFArgumentException {
    Description funcDesc = getClass().getAnnotation(Description.class);
    final String cmdLineSyntax;
    if (funcDesc == null) {
        cmdLineSyntax = getClass().getSimpleName();
    } else {
        String funcName = funcDesc.name();
        cmdLineSyntax = funcName == null ? getClass().getSimpleName()
                : funcDesc.value().replace("_FUNC_", funcDesc.name());
    }
    StringWriter sw = new StringWriter();
    sw.write('\n');
    if (errMsg != null) {
        if (funcDesc != null && funcDesc.name() != null) {
            errMsg = errMsg.replace("_FUNC_", funcDesc.name());
        }
        sw.write(errMsg);
        sw.write("\n\n");
    }
    PrintWriter pw = new PrintWriter(sw);
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, cmdLineSyntax, null, opts,
        HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, true);
    pw.flush();
    String helpMsg = sw.toString();
    throw new UDFArgumentException(helpMsg);
}
 
Example 6
Source File: UDAFEvaluatorWithOptions.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Nonnull
protected final CommandLine parseOptions(@Nonnull String optionValue)
        throws UDFArgumentException {
    String[] args = optionValue.split("\\s+");
    Options opts = getOptions();
    opts.addOption("help", false, "Show function help");

    final CommandLine cl;
    try {
        cl = CommandLineUtils.parseOptions(args, opts);
    } catch (IllegalArgumentException e) {
        throw new UDFArgumentException(e);
    }

    if (cl.hasOption("help")) {
        Description funcDesc = getClass().getAnnotation(Description.class);
        final String cmdLineSyntax;
        if (funcDesc == null) {
            cmdLineSyntax = getClass().getSimpleName();
        } else {
            String funcName = funcDesc.name();
            cmdLineSyntax = funcName == null ? getClass().getSimpleName()
                    : funcDesc.value().replace("_FUNC_", funcDesc.name());
        }
        StringWriter sw = new StringWriter();
        sw.write('\n');
        PrintWriter pw = new PrintWriter(sw);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, cmdLineSyntax, null, opts,
            HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, true);
        pw.flush();
        String helpMsg = sw.toString();
        throw new UDFArgumentException(helpMsg);
    }

    return cl;
}