use of org.teiid.query.function.UDFSource in project teiid by teiid.
the class TestSimpleDBSQLVisitor method testEvery2.
@Test
public void testEvery2() throws Exception {
SimpleDBExecutionFactory translator = new SimpleDBExecutionFactory();
translator.start();
MetadataFactory mf = TestDDLParser.helpParse("create foreign table item (\"itemName()\" integer, attribute string[]);", "y");
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
TranslationUtility tu = new TranslationUtility(metadata);
Command c = tu.parseCommand("select * from item where simpledb.every(attribute) = '1' or simpledb.every(attribute) = '2'");
SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
visitor.append(c);
assertEquals("SELECT attribute FROM item WHERE SIMPLEDB.EVERY(attribute) IN ('2', '1')", visitor.toString());
}
use of org.teiid.query.function.UDFSource in project teiid by teiid.
the class TestSimpleDBSQLVisitor method testEveryLike.
@Test
public void testEveryLike() throws Exception {
SimpleDBExecutionFactory translator = new SimpleDBExecutionFactory();
translator.start();
MetadataFactory mf = TestDDLParser.helpParse("create foreign table item (\"itemName()\" integer, attribute string[]);", "y");
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
TranslationUtility tu = new TranslationUtility(metadata);
Command c = tu.parseCommand("select * from item where simpledb.every(attribute) like '1%'");
SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
visitor.append(c);
assertEquals("SELECT attribute FROM item WHERE SIMPLEDB.EVERY(attribute) LIKE '1%'", visitor.toString());
}
use of org.teiid.query.function.UDFSource in project teiid by teiid.
the class TestProtobufMetadataProcessor method getTransformationMetadata.
public static TransformationMetadata getTransformationMetadata(MetadataFactory mf, InfinispanExecutionFactory ef) throws Exception {
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "proto", new FunctionTree("foo", new UDFSource(ef.getPushDownFunctions())));
ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
return metadata;
}
use of org.teiid.query.function.UDFSource 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.query.function.UDFSource 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);
}
}
Aggregations