Search in sources :

Example 56 with FunctionMethod

use of org.teiid.metadata.FunctionMethod in project teiid by teiid.

the class FileUDFMetaData method buildFunctionModelFile.

public void buildFunctionModelFile(String name, String path) throws IOException, XMLStreamException {
    for (String f : files.keySet()) {
        if (f.endsWith(path)) {
            path = f;
            break;
        }
    }
    VirtualFile file = this.files.get(path);
    if (file == null) {
        throw new IOException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40075, name));
    }
    List<FunctionMethod> udfMethods = FunctionMetadataReader.loadFunctionMethods(file.openStream());
    // $NON-NLS-1$
    ValidatorReport report = new ValidatorReport("UDF load");
    FunctionMetadataValidator.validateFunctionMethods(udfMethods, report);
    if (report.hasItems()) {
        // $NON-NLS-1$
        throw new IOException(QueryPlugin.Util.getString("ERR.015.001.0005", report));
    }
    this.methods.put(name, new UDFSource(udfMethods));
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) UDFSource(org.teiid.query.function.UDFSource) FunctionMethod(org.teiid.metadata.FunctionMethod) IOException(java.io.IOException) ValidatorReport(org.teiid.query.validator.ValidatorReport)

Example 57 with FunctionMethod

use of org.teiid.metadata.FunctionMethod in project teiid by teiid.

the class VDBMetadataFactory method getVDBMetadata.

public static TransformationMetadata getVDBMetadata(String vdbName, URL vdbURL, URL udfFile) throws IOException {
    TransformationMetadata vdbmetadata = VDB_CACHE.get(vdbURL);
    if (vdbmetadata != null) {
        return vdbmetadata;
    }
    try {
        IndexVDB imf = loadMetadata(vdbName, vdbURL);
        Resource r = imf.resources.getEntriesPlusVisibilities().get("/META-INF/vdb.xml");
        VDBMetaData vdb = null;
        if (r != null) {
            vdb = VDBMetadataParser.unmarshell(r.openStream());
        }
        Collection<FunctionMethod> methods = null;
        Collection<FunctionTree> trees = null;
        if (udfFile != null) {
            String schema = FileUtils.getFilenameWithoutExtension(udfFile.getPath());
            methods = FunctionMetadataReader.loadFunctionMethods(udfFile.openStream());
            trees = Arrays.asList(new FunctionTree(schema, new UDFSource(methods), true));
        }
        SystemFunctionManager sfm = SystemMetadata.getInstance().getSystemFunctionManager();
        vdbmetadata = new TransformationMetadata(vdb, new CompositeMetadataStore(Arrays.asList(SystemMetadata.getInstance().getSystemStore(), imf.store)), imf.resources.getEntriesPlusVisibilities(), sfm.getSystemFunctions(), trees);
        VDB_CACHE.put(vdbURL, vdbmetadata);
        return vdbmetadata;
    } catch (XMLStreamException e) {
        throw new IOException(e);
    }
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) SystemFunctionManager(org.teiid.query.function.SystemFunctionManager) Resource(org.teiid.query.metadata.VDBResources.Resource) IOException(java.io.IOException) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) XMLStreamException(javax.xml.stream.XMLStreamException) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) FunctionMethod(org.teiid.metadata.FunctionMethod)

Example 58 with FunctionMethod

use of org.teiid.metadata.FunctionMethod in project teiid by teiid.

the class TestMultipleModelIndexes method testFunctionMetadata.

@Test
public void testFunctionMetadata() throws Exception {
    TransformationMetadata tm = VDBMetadataFactory.getVDBMetadata(UnitTestUtil.getTestDataPath() + "/TEIIDDES992_VDB.vdb");
    Map<String, FunctionMethod> functions = tm.getMetadataStore().getSchema("TEIIDDES992").getFunctions();
    assertEquals(1, functions.size());
    FunctionMethod fm = functions.values().iterator().next();
    assertEquals("mmuuid:5c2cede9-0e18-4e4c-a531-34507abf0ff8", fm.getUUID());
    assertEquals("sampleFunction", fm.getName());
    assertEquals(1, fm.getInputParameters().size());
    assertEquals("mmuuid:f9ded2ae-9652-414e-b5a9-74185f8703c0", fm.getOutputParameter().getUUID());
    assertNotNull(fm.getInputParameters().get(0).getParent());
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionMethod(org.teiid.metadata.FunctionMethod) Test(org.junit.Test)

Example 59 with FunctionMethod

use of org.teiid.metadata.FunctionMethod in project teiid by teiid.

the class PgCatalogMetadataStore method addFunction.

private FunctionMethod addFunction(String javaFunction, String name) {
    Method[] methods = FunctionMethods.class.getMethods();
    for (Method method : methods) {
        if (!method.getName().equals(javaFunction)) {
            continue;
        }
        FunctionMethod func = addFunction(name, method);
        // $NON-NLS-1$
        func.setCategory("pg");
        func.setDescription(name);
        return func;
    }
    // $NON-NLS-1$
    throw new AssertionError("Could not find function");
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) Method(java.lang.reflect.Method) FunctionMethod(org.teiid.metadata.FunctionMethod)

Example 60 with FunctionMethod

use of org.teiid.metadata.FunctionMethod in project teiid by teiid.

the class UDFMetaData method addFunctions.

public void addFunctions(String name, Collection<FunctionMethod> funcs) {
    if (funcs.isEmpty()) {
        return;
    }
    UDFSource udfSource = this.methods.get(name);
    if (udfSource != null) {
        // this is ambiguous about as to what classloader to use, but we assume the first is good and that the user will have set
        // the Java method if that's not the case
        ArrayList<FunctionMethod> allMethods = new ArrayList<FunctionMethod>(udfSource.getFunctionMethods());
        allMethods.addAll(funcs);
        ClassLoader cl = udfSource.getClassLoader();
        udfSource = new UDFSource(allMethods);
        udfSource.setClassLoader(cl);
    } else {
        udfSource = new UDFSource(funcs);
        udfSource.setClassLoader(classLoader);
    }
    this.methods.put(name, udfSource);
}
Also used : UDFSource(org.teiid.query.function.UDFSource) ArrayList(java.util.ArrayList) FunctionMethod(org.teiid.metadata.FunctionMethod)

Aggregations

FunctionMethod (org.teiid.metadata.FunctionMethod)63 FunctionParameter (org.teiid.metadata.FunctionParameter)31 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)9 Schema (org.teiid.metadata.Schema)6 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)6 IOException (java.io.IOException)5 MetadataStore (org.teiid.metadata.MetadataStore)5 List (java.util.List)4 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)4 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)3 DeployVDBParameter (org.teiid.jdbc.FakeServer.DeployVDBParameter)3 AggregateAttributes (org.teiid.metadata.AggregateAttributes)3 Procedure (org.teiid.metadata.Procedure)3 UDFSource (org.teiid.query.function.UDFSource)3