@Override public List<SqlFunction> listFunctions() { FunctionListBuilder builder = new FunctionListBuilder(); try { List<Class<?>> classes = getFunctionClasses(); addFunctions(builder, classes); } catch (IOException e) { System.out.println("Could not load classes from jar file: " + e); return ImmutableList.of(); } return builder.getFunctions(); }
@Override public List<SqlFunction> listFunctions() { ViterbiFunction.setConfig(viterbiConfig); return new FunctionListBuilder(typeManager) .scalar(ViterbiFunction.class) .getFunctions(); }
@Override protected RelationType visitShowFunctions(ShowFunctions node, AnalysisContext context) { ImmutableList.Builder<Expression> rows = ImmutableList.builder(); for (SqlFunction function : metadata.listFunctions()) { if (function.getSignature().getKind() == APPROXIMATE_AGGREGATE) { continue; } rows.add(row( new StringLiteral(function.getSignature().getName()), new StringLiteral(function.getSignature().getReturnType().toString()), new StringLiteral(Joiner.on(", ").join(function.getSignature().getArgumentTypes())), new StringLiteral(getFunctionType(function)), function.isDeterministic() ? TRUE_LITERAL : FALSE_LITERAL, new StringLiteral(nullToEmpty(function.getDescription())))); } Map<String, String> columns = ImmutableMap.<String, String>builder() .put("function_name", "Function") .put("return_type", "Return Type") .put("argument_types", "Argument Types") .put("function_type", "Function Type") .put("deterministic", "Deterministic") .put("description", "Description") .build(); Query query = simpleQuery( selectAll(columns.entrySet().stream() .map(entry -> aliasedName(entry.getKey(), entry.getValue())) .collect(toImmutableList())), aliased(new Values(rows.build()), "functions", ImmutableList.copyOf(columns.keySet())), ordering( ascending("function_name"), ascending("return_type"), ascending("argument_types"), ascending("function_type"))); return process(query, context); }
private static String getFunctionType(SqlFunction function) { FunctionKind kind = function.getSignature().getKind(); switch (kind) { case AGGREGATE: case APPROXIMATE_AGGREGATE: return "aggregate"; case WINDOW: return "window"; case SCALAR: return "scalar"; } throw new IllegalArgumentException("Unsupported function kind: " + kind); }
public List<SqlFunction> createFunctions(Type type) { RowType rowType = checkType(type, RowType.class, "type"); ImmutableList.Builder<SqlFunction> builder = ImmutableList.builder(); List<RowField> fields = rowType.getFields(); for (int i = 0; i < fields.size(); i++) { RowField field = fields.get(i); int index = i; field.getName() .ifPresent(name -> builder.add(new RowFieldReference(rowType, field.getType(), index, field.getName().get()))); } return builder.build(); }
protected void registerScalar(Class<?> clazz) { Metadata metadata = functionAssertions.getMetadata(); List<SqlFunction> functions = new FunctionListBuilder(metadata.getTypeManager()) .scalar(clazz) .getFunctions(); metadata.getFunctionRegistry().addFunctions(functions); }
@Override public List<SqlFunction> listFunctions() { return new FunctionListBuilder(typeManager) .aggregate(LearnClassifierAggregation.class) .aggregate(LearnVarcharClassifierAggregation.class) .aggregate(LearnRegressorAggregation.class) .aggregate(LearnLibSvmClassifierAggregation.class) .aggregate(LearnLibSvmVarcharClassifierAggregation.class) .aggregate(LearnLibSvmRegressorAggregation.class) .aggregate(EvaluateClassifierPredictionsAggregation.class) .scalar(MLFunctions.class) .getFunctions(); }
@Override public List<SqlFunction> listFunctions() { return new FunctionListBuilder(typeManager) .scalar(TeradataStringFunctions.class) .scalar(TeradataDateFunctions.class) .getFunctions(); }
private GenericAggregationFunctionFactory(List<SqlFunction> aggregations) { this.aggregations = ImmutableList.copyOf(requireNonNull(aggregations, "aggregations is null")); }
@Override public List<SqlFunction> listFunctions() { return aggregations; }
public FunctionAssertions addFunctions(List<SqlFunction> functionInfos) { metadata.addFunctions(functionInfos); return this; }