private FunctionEntry add(String name, Function function) { final FunctionEntryImpl entry = new FunctionEntryImpl(this, name, function); functionMap.put(name, entry); if (function.getParameters().isEmpty()) { nullaryFunctionMapInsensitive.put(name, entry); } return entry; }
private SqlOperator toOp(SqlIdentifier name, Function function) { List<RelDataType> argTypes = new ArrayList<RelDataType>(); List<SqlTypeFamily> typeFamilies = new ArrayList<SqlTypeFamily>(); for (FunctionParameter o : function.getParameters()) { final RelDataType type = o.getType(typeFactory); argTypes.add(type); typeFamilies.add(Util.first(type.getSqlTypeName().getFamily(), SqlTypeFamily.ANY)); } final RelDataType returnType; if (function instanceof ScalarFunction) { return new SqlUserDefinedFunction( name, ReturnTypes.explicit(Schemas.proto((ScalarFunction) function)), InferTypes.explicit(argTypes), OperandTypes.family(typeFamilies), toSql(argTypes), function); } else if (function instanceof AggregateFunction) { returnType = ((AggregateFunction) function).getReturnType(typeFactory); return new SqlUserDefinedAggFunction( name, ReturnTypes.explicit(returnType), InferTypes.explicit(argTypes), OperandTypes.family(typeFamilies), (AggregateFunction) function); } else if (function instanceof TableMacro) { return new SqlUserDefinedTableMacro( name, ReturnTypes.CURSOR, InferTypes.explicit(argTypes), OperandTypes.family(typeFamilies), (TableMacro) function); } else if (function instanceof TableFunction) { return new SqlUserDefinedTableFunction( name, ReturnTypes.CURSOR, InferTypes.explicit(argTypes), OperandTypes.family(typeFamilies), toSql(argTypes), (TableFunction) function); } else { throw new AssertionError("unknown function type " + function); } }