Search in sources :

Example 31 with FunctionTree

use of org.teiid.query.function.FunctionTree 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 32 with FunctionTree

use of org.teiid.query.function.FunctionTree in project teiid by teiid.

the class TranslationUtility method addUDF.

public void addUDF(String schema, Collection<FunctionMethod> methods) {
    if (methods == null || methods.isEmpty()) {
        return;
    }
    this.functions.add(new FunctionTree(schema, new UDFSource(methods)));
    SystemFunctionManager sfm = SystemMetadata.getInstance().getSystemFunctionManager();
    functionLibrary = new FunctionLibrary(sfm.getSystemFunctions(), this.functions.toArray(new FunctionTree[this.functions.size()]));
}
Also used : UDFSource(org.teiid.query.function.UDFSource) FunctionTree(org.teiid.query.function.FunctionTree) SystemFunctionManager(org.teiid.query.function.SystemFunctionManager) FunctionLibrary(org.teiid.query.function.FunctionLibrary)

Example 33 with FunctionTree

use of org.teiid.query.function.FunctionTree in project teiid by teiid.

the class CompositeVDB method buildTransformationMetaData.

private static TransformationMetadata buildTransformationMetaData(VDBMetaData vdb, LinkedHashMap<String, VDBResources.Resource> visibilityMap, MetadataStore store, UDFMetaData udf, FunctionTree systemFunctions, MetadataStore[] additionalStores, boolean allowEnv) {
    Collection<FunctionTree> udfs = new ArrayList<FunctionTree>();
    if (udf != null) {
        for (Map.Entry<String, UDFSource> entry : udf.getFunctions().entrySet()) {
            udfs.add(new FunctionTree(entry.getKey(), entry.getValue(), true));
        }
    }
    // add functions for procedures
    for (Schema schema : store.getSchemas().values()) {
        if (!schema.getProcedures().isEmpty()) {
            FunctionTree ft = FunctionTree.getFunctionProcedures(schema);
            if (ft != null) {
                udfs.add(ft);
            }
        }
    }
    CompositeMetadataStore compositeStore = new CompositeMetadataStore(store);
    for (MetadataStore s : additionalStores) {
        compositeStore.merge(s);
        for (Schema schema : s.getSchemas().values()) {
            if (!schema.getFunctions().isEmpty()) {
                UDFSource source = new UDFSource(schema.getFunctions().values());
                if (udf != null) {
                    source.setClassLoader(udf.getClassLoader());
                }
                udfs.add(new FunctionTree(schema.getName(), source, true));
            }
            if (!schema.getProcedures().isEmpty()) {
                FunctionTree ft = FunctionTree.getFunctionProcedures(schema);
                if (ft != null) {
                    udfs.add(ft);
                }
            }
        }
    }
    TransformationMetadata metadata = new TransformationMetadata(vdb, compositeStore, visibilityMap, systemFunctions, udfs);
    metadata.setAllowENV(allowEnv);
    metadata.setUseOutputNames(false);
    metadata.setWidenComparisonToString(WIDEN_COMPARISON_TO_STRING);
    return metadata;
}
Also used : UDFSource(org.teiid.query.function.UDFSource) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) MetadataStore(org.teiid.metadata.MetadataStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) Schema(org.teiid.metadata.Schema) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

FunctionTree (org.teiid.query.function.FunctionTree)33 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)22 UDFSource (org.teiid.query.function.UDFSource)21 Test (org.junit.Test)19 MetadataFactory (org.teiid.metadata.MetadataFactory)15 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)14 TranslationUtility (org.teiid.cdk.api.TranslationUtility)11 MetadataValidator (org.teiid.query.metadata.MetadataValidator)10 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)10 ValidatorReport (org.teiid.query.validator.ValidatorReport)10 FakeFunctionMetadataSource (org.teiid.query.optimizer.FakeFunctionMetadataSource)9 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)8 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)8 SimpleDBExecutionFactory (org.teiid.translator.simpledb.SimpleDBExecutionFactory)8 Command (org.teiid.language.Command)7 SimpleDBSQLVisitor (org.teiid.translator.simpledb.SimpleDBSQLVisitor)7 Properties (java.util.Properties)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStreamReader (java.io.InputStreamReader)3 ArrayList (java.util.ArrayList)3