private static String getName(GenericUDF hiveUDF) { String udfName = null; if (hiveUDF instanceof GenericUDFBridge) { udfName = ((GenericUDFBridge) hiveUDF).getUdfName(); } else { Class<? extends GenericUDF> udfClass = hiveUDF.getClass(); Annotation udfAnnotation = udfClass.getAnnotation(Description.class); if (udfAnnotation != null && udfAnnotation instanceof Description) { Description udfDescription = (Description) udfAnnotation; udfName = udfDescription.name(); if (udfName != null) { String[] aliases = udfName.split(","); if (aliases.length > 0) { udfName = aliases[0]; } } } if (udfName == null || udfName.isEmpty()) { udfName = hiveUDF.getClass().getName(); int indx = udfName.lastIndexOf("."); if (indx >= 0) { indx += 1; udfName = udfName.substring(indx); } } } return udfName; }
private <I> void register(Class<? extends I> clazz, ArrayListMultimap<String, Class<? extends I>> methods) { Description desc = clazz.getAnnotation(Description.class); Stream<String> namesStream; if (desc != null) { namesStream = Stream.of(desc.name().split(",")) .map(String::trim); } else { namesStream = Stream.of(clazz) .map(Class::getName) .map(name -> name.replace('.', '_')); } // Checks specified array of function names whether they should be replaced // using FUNCTION_REPLACE_MAP map. namesStream.map(String::toLowerCase) .map(functionName -> FUNCTION_REPLACE_MAP.getOrDefault(functionName, functionName)) .forEach(name -> methods.put(name, clazz)); UDFType type = clazz.getAnnotation(UDFType.class); if (type != null && !type.deterministic()) { nonDeterministicUDFs.add(clazz); } }
private static String getName(GenericUDF hiveUDF) { String udfName = null; if (hiveUDF instanceof GenericUDFBridge) { udfName = ((GenericUDFBridge) hiveUDF).getUdfName(); } else { Class<? extends GenericUDF> udfClass = hiveUDF.getClass(); Annotation udfAnnotation = udfClass.getAnnotation(Description.class); if (udfAnnotation != null && udfAnnotation instanceof Description) { Description udfDescription = (Description) udfAnnotation; udfName = udfDescription.name(); if (udfName != null) { String[] aliases = udfName.split(","); if (aliases.length > 0) udfName = aliases[0]; } } if (udfName == null || udfName.isEmpty()) { udfName = hiveUDF.getClass().getName(); int indx = udfName.lastIndexOf("."); if (indx >= 0) { indx += 1; udfName = udfName.substring(indx); } } } return udfName; }
@Override public Void visitCall(RexCall call) { if(AnnotationUtils.getAnnotation(GenericUDFOPNotNull.class, Description.class).name().equals(call.getOperator().getName())) { if(call.getOperands().get(0) instanceof RexInputRef && !types.get(((RexInputRef)call.getOperands().get(0)).getIndex()).getType().isNullable()) { // No need to add not null filter for a constant. throw new Util.FoundOne(call); } } return super.visitCall(call); }
@Override public Void visitCall(RexCall call) { if(AnnotationUtils.getAnnotation(GenericUDFOPNotNull.class, Description.class).name().equals(call.getOperator().getName())) { if(call.getOperands().get(0) instanceof RexInputRef && !types.get(((RexInputRef)call.getOperands().get(0)).getIndex()).getType().isNullable()) { // No need to add not null filter for a constant. throw new Util.FoundOne(call); } } return super.visitCall(call); } }
/** * Given an AST this method figures out if it is a value clause * e.g. VALUES(1,3..) */ private boolean isValueClause(ASTNode select) { if(select == null) { return false; } if(select.getChildCount() == 1) { ASTNode selectExpr = (ASTNode)select.getChild(0); if(selectExpr.getChildCount() == 1 ) { ASTNode selectChildExpr = (ASTNode)selectExpr.getChild(0); if(selectChildExpr.getType() == HiveParser.TOK_FUNCTION) { ASTNode inline = (ASTNode)selectChildExpr.getChild(0); ASTNode func = (ASTNode)selectChildExpr.getChild(1); if(inline.getText().equals(GenericUDTFInline.class.getAnnotation(Description.class).name()) && func.getType() == HiveParser.TOK_FUNCTION) { ASTNode arrayNode = (ASTNode)func.getChild(0); ASTNode funcNode= (ASTNode)func.getChild(1); if(arrayNode.getText().equals(GenericUDFArray.class.getAnnotation(Description.class).name() ) && funcNode.getType() == HiveParser.TOK_FUNCTION) { return true; } } } } } return false; }
@Override boolean isCBOSupportedLateralView(ASTNode lateralView) { // Lateral view AST has the following shape: // ^(TOK_LATERAL_VIEW // ^(TOK_SELECT ^(TOK_SELEXPR ^(TOK_FUNCTION Identifier params) identifier* tableAlias))) if (lateralView.getToken().getType() == HiveParser.TOK_LATERAL_VIEW_OUTER) { // LATERAL VIEW OUTER not supported in CBO return false; } // Only INLINE followed by ARRAY supported in CBO ASTNode lvFunc = (ASTNode) lateralView.getChild(0).getChild(0).getChild(0); String lvFuncName = lvFunc.getChild(0).getText(); if (lvFuncName.compareToIgnoreCase( GenericUDTFInline.class.getAnnotation(Description.class).name()) != 0) { return false; } if (lvFunc.getChildCount() != 2) { return false; } ASTNode innerFunc = (ASTNode) lvFunc.getChild(1); if (innerFunc.getToken().getType() != HiveParser.TOK_FUNCTION || innerFunc.getChild(0).getText().compareToIgnoreCase( GenericUDFArray.class.getAnnotation(Description.class).name()) != 0) { return false; } return true; }
final RelDataTypeFactory dtFactory = this.cluster.getTypeFactory(); final String inlineFunctionName = GenericUDTFInline.class.getAnnotation(Description.class).name(); int numChildren = lateralView.getChildCount(); assert (numChildren == 2);
Description description = KeyIntermediaryService.class .getField(KeyIntermediaryService.WORLDCHECKSERVICE.name()) .getAnnotation(Description.class); System.out.println(description.name());
public static void main(String[] args) { for (Field field : KeyIntermediaryService.class.getFields()) { Description description = field.getAnnotation(Description.class); System.out.println(description.name()); } }
private <C,I> void register(Class<? extends I> clazz, ArrayListMultimap<String,Class<? extends I>> methods) { Description desc = clazz.getAnnotation(Description.class); String[] names; if (desc != null) { names = desc.name().split(","); for (int i=0; i<names.length; i++) { names[i] = names[i].trim(); } }else{ names = new String[]{clazz.getName().replace('.', '_')}; } UDFType type = clazz.getAnnotation(UDFType.class); if (type != null && !type.deterministic()) { nonDeterministicUDFs.add(clazz); } for(int i=0; i<names.length;i++) { methods.put(names[i].toLowerCase(), clazz); } }
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); }
private static String getName(GenericUDF hiveUDF) { String udfName = null; if (hiveUDF instanceof GenericUDFBridge) { udfName = ((GenericUDFBridge) hiveUDF).getUdfName(); } else { Class<? extends GenericUDF> udfClass = hiveUDF.getClass(); Annotation udfAnnotation = udfClass.getAnnotation(Description.class); if (udfAnnotation != null && udfAnnotation instanceof Description) { Description udfDescription = (Description) udfAnnotation; udfName = udfDescription.name(); if (udfName != null) { String[] aliases = udfName.split(","); if (aliases.length > 0) udfName = aliases[0]; } } if (udfName == null || udfName.isEmpty()) { udfName = hiveUDF.getClass().getName(); int indx = udfName.lastIndexOf("."); if (indx >= 0) { indx += 1; udfName = udfName.substring(indx); } } } return udfName; }
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; }
@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; }
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; }
@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; }
@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; }
@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; }
@Override public Void visitCall(RexCall call) { if(AnnotationUtils.getAnnotation(GenericUDFOPNotNull.class, Description.class).name().equals(call.getOperator().getName())) { if(call.getOperands().get(0) instanceof RexInputRef && !types.get(((RexInputRef)call.getOperands().get(0)).getIndex()).getType().isNullable()) { // No need to add not null filter for a constant. throw new Util.FoundOne(call); } } return super.visitCall(call); } }