/** * Get all function categories, sorted in alphabetical order * @return List of function category names, sorted in alphabetical order */ public List<String> getFunctionCategories() { // Remove category duplicates TreeSet<String> categories = new TreeSet<String>(); categories.addAll( systemFunctions.getCategories() ); if (this.userFunctions != null) { for (FunctionTree tree: this.userFunctions) { categories.addAll(tree.getCategories()); } } ArrayList<String> categoryList = new ArrayList<String>(categories); return categoryList; }
/** * Get all function in a category. * @param category Category name * @return List of {@link FunctionMethod}s in a category */ public List<FunctionMethod> getFunctionsInCategory(String category) { List<FunctionMethod> forms = new ArrayList<FunctionMethod>(); forms.addAll(systemFunctions.getFunctionsInCategory(category)); if (this.userFunctions != null) { for (FunctionTree tree: this.userFunctions) { forms.addAll(tree.getFunctionsInCategory(category)); } } return forms; }
/** * Construct a new tree with the given source of function metadata. * @param source The metadata source */ public FunctionTree(String name, FunctionMetadataSource source, boolean validateClass) { // Load data structures this.schemaName = name; this.validateClass = validateClass; boolean system = CoreConstants.SYSTEM_MODEL.equalsIgnoreCase(name) || CoreConstants.SYSTEM_ADMIN_MODEL.equalsIgnoreCase(name); Collection<FunctionMethod> functions = source.getFunctionMethods(); for (FunctionMethod method : functions) { if (!containsIndistinguishableFunction(method)){ // Add to tree addFunction(name, source, method, system); } else if (!CoreConstants.SYSTEM_MODEL.equalsIgnoreCase(name)) { LogManager.logWarning(LogConstants.CTX_FUNCTION_TREE, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30011, new Object[]{method})); } } }
@Override protected NavigableMap<String, FunctionMethod> getChildren(Schema s, TransformationMetadata metadata) { //since there is no proper schema for a UDF model, no results will show up for legacy functions if (s.getName().equals(CoreConstants.SYSTEM_MODEL)) { //currently all system functions are contributed via alternative mechanisms //system source, push down functions. FunctionLibrary library = metadata.getFunctionLibrary(); FunctionTree tree = library.getSystemFunctions(); FunctionTree[] userFuncs = library.getUserFunctions(); TreeMap<String, FunctionMethod> functions = new TreeMap<String, FunctionMethod>(String.CASE_INSENSITIVE_ORDER); for (FunctionTree userFunc : userFuncs) { if (userFunc.getSchemaName().equals(CoreConstants.SYSTEM_MODEL)) { functions.putAll(userFunc.getFunctionsByUuid()); } } functions.putAll(tree.getFunctionsByUuid()); return functions; } return s.getFunctions(); } }
public SystemFunctionManager(Map<String, Datatype> typeMap) { this.types = typeMap; // Create the system source and add it to the source list SystemSource systemSource = new SystemSource(); // Validate the system source - should never fail ValidatorReport report = new ValidatorReport("Function Validation"); //$NON-NLS-1$ Collection<FunctionMethod> functionMethods = systemSource.getFunctionMethods(); FunctionMetadataValidator.validateFunctionMethods(functionMethods,report, types); if(report.hasItems()) { // Should never happen as SystemSourcTe doesn't change System.err.println(QueryPlugin.Util.getString("ERR.015.001.0005", report)); //$NON-NLS-1$ } systemFunctionTree = new FunctionTree(CoreConstants.SYSTEM_MODEL, systemSource, true); }
/** * Walk through all functions by metadata and verify that we can look * each one up by signature */ @Test public void testWalkTree() { SystemSource source = new SystemSource(); FunctionTree ft = new FunctionTree("foo", source); Collection<String> categories = ft.getCategories(); for (String category : categories) { assertTrue(ft.getFunctionsInCategory(category).size() > 0); } }
if (udf != null) { for (Map.Entry<String, UDFSource> entry : udf.getFunctions().entrySet()) { udfs.add(new FunctionTree(entry.getKey(), entry.getValue(), true)); FunctionTree ft = FunctionTree.getFunctionProcedures(schema); if (ft != null) { udfs.add(ft); source.setClassLoader(udf.getClassLoader()); udfs.add(new FunctionTree(schema.getName(), source, true)); FunctionTree ft = FunctionTree.getFunctionProcedures(schema); if (ft != null) { udfs.add(ft);
public static FunctionTree getFunctionProcedures(Schema schema) { UDFSource dummySource = new UDFSource(Collections.EMPTY_LIST); FunctionTree ft = null; for (Procedure p : schema.getProcedures().values()) { if (p.isFunction() && p.getQueryPlan() != null) { if (ft == null) { ft = new FunctionTree(schema.getName(), dummySource, false); } FunctionMethod fm = SQLParserUtil.createFunctionMethod(p); FunctionDescriptor fd = ft.addFunction(schema.getName(), dummySource, fm, false); fd.setProcedure(p); } } return ft; }
@Test public void testNullCategory() { FunctionMethod method = new FunctionMethod( "dummy", null, null, PushDown.MUST_PUSHDOWN, "nonexistentClass", "noMethod", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ new ArrayList<FunctionParameter>(0), new FunctionParameter("output", DataTypeManager.DefaultDataTypes.STRING), //$NON-NLS-1$ false, Determinism.DETERMINISTIC); Collection<org.teiid.metadata.FunctionMethod> list = Arrays.asList(method); FunctionMetadataSource fms = Mockito.mock(FunctionMetadataSource.class); Mockito.stub(fms.getFunctionMethods()).toReturn(list); FunctionTree ft = new FunctionTree("foo", fms); assertEquals(1, ft.getFunctionsInCategory(FunctionCategoryConstants.MISCELLANEOUS).size()); }
categoryKey = FunctionCategoryConstants.MISCELLANEOUS; setUuid(method); Class<?> clazz = DataTypeManager.getDataTypeClass(typeName); types[i] = clazz; setUuid(inputParams.get(i)); setUuid(method.getOutputParameter()); FunctionDescriptor descriptor = createFunctionDescriptor(source, method, types, system); descriptor.setSchema(schema);
/** * Find a function descriptor given a name and the types of the arguments. * This method matches based on case-insensitive function name and * an exact match of the number and types of parameter arguments. * @param name Name of the function to resolve * @param types Array of classes representing the types * @return Descriptor if found, null if not found */ public FunctionDescriptor findFunction(String name, Class<?>[] types) { // First look in system functions FunctionDescriptor descriptor = systemFunctions.getFunction(name, types); // If that fails, check the user defined functions if(descriptor == null && this.userFunctions != null) { for (FunctionTree tree: this.userFunctions) { descriptor = tree.getFunction(name, types); if (descriptor != null) { break; } } } return descriptor; }
/** * Find function form based on function name and # of arguments. * @param name Function name * @param numArgs Number of arguments * @return Corresponding form or null if not found */ public boolean hasFunctionMethod(String name, int numArgs) { List<FunctionMethod> methods = systemFunctions.findFunctionMethods(name, numArgs); if (!methods.isEmpty()) { return true; } if(this.userFunctions != null) { for (FunctionTree tree: this.userFunctions) { methods = tree.findFunctionMethods(name, numArgs); if (!methods.isEmpty()) { return true; } } } return false; }
public SystemFunctionManager(Map<String, Datatype> typeMap) { this.types = typeMap; // Create the system source and add it to the source list SystemSource systemSource = new SystemSource(); // Validate the system source - should never fail ValidatorReport report = new ValidatorReport("Function Validation"); //$NON-NLS-1$ Collection<FunctionMethod> functionMethods = systemSource.getFunctionMethods(); FunctionMetadataValidator.validateFunctionMethods(functionMethods,report, types); if(report.hasItems()) { // Should never happen as SystemSourcTe doesn't change System.err.println(QueryPlugin.Util.getString("ERR.015.001.0005", report)); //$NON-NLS-1$ } systemFunctionTree = new FunctionTree(CoreConstants.SYSTEM_MODEL, systemSource, true); }
public static TransformationMetadata createTransformationMetadata(CompositeMetadataStore store, String vdbName, Properties vdbProperties, FunctionTree... functionModels) { VDBMetaData vdbMetaData = new VDBMetaData(); vdbMetaData.setName(vdbName); //$NON-NLS-1$ vdbMetaData.setVersion(1); if (vdbProperties != null) { vdbMetaData.setProperties(vdbProperties); } List<FunctionTree> udfs = new ArrayList<FunctionTree>(); udfs.addAll(Arrays.asList(functionModels)); for (Schema schema : store.getSchemas().values()) { vdbMetaData.addModel(RealMetadataFactory.createModel(schema.getName(), schema.isPhysical())); if (!schema.getFunctions().isEmpty()) { udfs.add(new FunctionTree(schema.getName(), new UDFSource(schema.getFunctions().values()), true)); } if (!schema.getProcedures().isEmpty()) { FunctionTree ft = FunctionTree.getFunctionProcedures(schema); if (ft != null) { udfs.add(ft); } } } TransformationMetadata metadata = new TransformationMetadata(vdbMetaData, store, null, SFM.getSystemFunctions(), udfs); vdbMetaData.addAttchment(TransformationMetadata.class, metadata); vdbMetaData.addAttchment(QueryMetadataInterface.class, metadata); return metadata; }
public static FunctionTree getFunctionProcedures(Schema schema) { UDFSource dummySource = new UDFSource(Collections.EMPTY_LIST); FunctionTree ft = null; for (Procedure p : schema.getProcedures().values()) { if (p.isFunction() && p.getQueryPlan() != null) { if (ft == null) { ft = new FunctionTree(schema.getName(), dummySource, false); } FunctionMethod fm = SQLParserUtil.createFunctionMethod(p); FunctionDescriptor fd = ft.addFunction(schema.getName(), dummySource, fm, false); fd.setProcedure(p); } } return ft; }
@Override protected NavigableMap<String, FunctionMethod> getChildren(Schema s, TransformationMetadata metadata) { //since there is no proper schema for a UDF model, no results will show up for legacy functions if (s.getName().equals(CoreConstants.SYSTEM_MODEL)) { //currently all system functions are contributed via alternative mechanisms //system source, push down functions. FunctionLibrary library = metadata.getFunctionLibrary(); FunctionTree tree = library.getSystemFunctions(); FunctionTree[] userFuncs = library.getUserFunctions(); TreeMap<String, FunctionMethod> functions = new TreeMap<String, FunctionMethod>(String.CASE_INSENSITIVE_ORDER); for (FunctionTree userFunc : userFuncs) { if (userFunc.getSchemaName().equals(CoreConstants.SYSTEM_MODEL)) { functions.putAll(userFunc.getFunctionsByUuid()); } } functions.putAll(tree.getFunctionsByUuid()); return functions; } return s.getFunctions(); } }
categoryKey = FunctionCategoryConstants.MISCELLANEOUS; setUuid(method); Class<?> clazz = DataTypeManager.getDataTypeClass(typeName); types[i] = clazz; setUuid(inputParams.get(i)); setUuid(method.getOutputParameter()); FunctionDescriptor descriptor = createFunctionDescriptor(source, method, types, system); descriptor.setSchema(schema);
/** * Find a function descriptor given a name and the types of the arguments. * This method matches based on case-insensitive function name and * an exact match of the number and types of parameter arguments. * @param name Name of the function to resolve * @param types Array of classes representing the types * @return Descriptor if found, null if not found */ public FunctionDescriptor findFunction(String name, Class<?>[] types) { // First look in system functions FunctionDescriptor descriptor = systemFunctions.getFunction(name, types); // If that fails, check the user defined functions if(descriptor == null && this.userFunctions != null) { for (FunctionTree tree: this.userFunctions) { descriptor = tree.getFunction(name, types); if (descriptor != null) { break; } } } return descriptor; }
/** * Find function form based on function name and # of arguments. * @param name Function name * @param numArgs Number of arguments * @return Corresponding form or null if not found */ public boolean hasFunctionMethod(String name, int numArgs) { List<FunctionMethod> methods = systemFunctions.findFunctionMethods(name, numArgs); if (!methods.isEmpty()) { return true; } if(this.userFunctions != null) { for (FunctionTree tree: this.userFunctions) { methods = tree.findFunctionMethods(name, numArgs); if (!methods.isEmpty()) { return true; } } } return false; }
public SystemFunctionManager(Map<String, Datatype> typeMap) { this.types = typeMap; // Create the system source and add it to the source list SystemSource systemSource = new SystemSource(); // Validate the system source - should never fail ValidatorReport report = new ValidatorReport("Function Validation"); //$NON-NLS-1$ Collection<FunctionMethod> functionMethods = systemSource.getFunctionMethods(); FunctionMetadataValidator.validateFunctionMethods(functionMethods,report, types); if(report.hasItems()) { // Should never happen as SystemSourcTe doesn't change System.err.println(QueryPlugin.Util.getString("ERR.015.001.0005", report)); //$NON-NLS-1$ } systemFunctionTree = new FunctionTree(CoreConstants.SYSTEM_MODEL, systemSource, true); }