Repository: incubator-hivemall Updated Branches: refs/heads/master ce70aa482 -> 62a97798b
Fixed bm25() UDF for help message Project: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/commit/b97af4fe Tree: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/tree/b97af4fe Diff: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/diff/b97af4fe Branch: refs/heads/master Commit: b97af4fe0faebcbc78875b4e88fb292eaa576b42 Parents: ce70aa4 Author: Makoto Yui <[email protected]> Authored: Sat Nov 3 16:38:13 2018 +0900 Committer: Makoto Yui <[email protected]> Committed: Sat Nov 3 16:38:13 2018 +0900 ---------------------------------------------------------------------- core/src/main/java/hivemall/UDFWithOptions.java | 53 +++++++++++++------- .../java/hivemall/ftvec/text/OkapiBM25UDF.java | 2 +- 2 files changed, 36 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/b97af4fe/core/src/main/java/hivemall/UDFWithOptions.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/UDFWithOptions.java b/core/src/main/java/hivemall/UDFWithOptions.java index 04d6fdc..89e7662 100644 --- a/core/src/main/java/hivemall/UDFWithOptions.java +++ b/core/src/main/java/hivemall/UDFWithOptions.java @@ -89,29 +89,46 @@ public abstract class UDFWithOptions extends GenericUDF { 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); + showHelp(opts); } return cl; } + protected void showHelp(@Nullable String errMsg) throws UDFArgumentException { + showHelp(getOptions(), errMsg); + } + + private void showHelp(@Nonnull Options opts) throws UDFArgumentException { + showHelp(getOptions(), null); + } + + 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) { + 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); + } + /** * Raise {@link UDFArgumentException} if the given condition is false. * http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/b97af4fe/core/src/main/java/hivemall/ftvec/text/OkapiBM25UDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/ftvec/text/OkapiBM25UDF.java b/core/src/main/java/hivemall/ftvec/text/OkapiBM25UDF.java index cd36d6f..acd80bf 100644 --- a/core/src/main/java/hivemall/ftvec/text/OkapiBM25UDF.java +++ b/core/src/main/java/hivemall/ftvec/text/OkapiBM25UDF.java @@ -108,7 +108,7 @@ public final class OkapiBM25UDF extends UDFWithOptions { throws UDFArgumentException { final int numArgOIs = argOIs.length; if (numArgOIs < 5) { - throw new UDFArgumentException("argOIs.length must be greater than or equal to 5"); + showHelp("#arguments must be greater than or equal to 5: " + numArgOIs); } else if (numArgOIs == 6) { String opts = HiveUtils.getConstString(argOIs[5]); processOptions(opts);
