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));
}
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);
}
}
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());
}
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");
}
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);
}
Aggregations