use of org.teiid.query.function.UDFSource in project teiid by teiid.
the class TestODataSQLVistor method setUp.
@Before
public void setUp() throws Exception {
translator = new ODataExecutionFactory();
translator.start();
String csdl = ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.xml"));
EdmDataServices eds = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new InputStreamReader(new ByteArrayInputStream(csdl.getBytes()))));
ODataMetadataProcessor processor = new ODataMetadataProcessor();
Properties props = new Properties();
props.setProperty("schemaNamespace", "ODataWeb.Northwind.Model");
props.setProperty("entityContainer", "NorthwindEntities");
MetadataFactory mf = new MetadataFactory("vdb", 1, "nw", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
processor.getMetadata(mf, eds);
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "northwind", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
// TransformationMetadata metadata = RealMetadataFactory.fromDDL(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.ddl")), "northwind", "nw");
utility = new TranslationUtility(metadata);
}
use of org.teiid.query.function.UDFSource in project teiid by teiid.
the class TestSAPODataMetadataProcessor method testSchema.
@Test
public void testSchema() throws Exception {
translator = new SAPODataExecutionFactory();
translator.start();
String csdl = ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("sap-metadata.xml"));
SAPMetadataProcessor processor = new SAPMetadataProcessor();
Properties props = new Properties();
MetadataFactory mf = new MetadataFactory("vdb", 1, "flight", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
processor.getMetadata(mf, new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new InputStreamReader(new ByteArrayInputStream(csdl.getBytes())))));
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "flight", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
// String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
// System.out.println(ddl);
//
// MetadataFactory mf2 = new MetadataFactory(null, 1, "flight", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
// QueryParser.getQueryParser().parseDDL(mf2, ddl);
TranslationUtility utility = new TranslationUtility(metadata);
RuntimeMetadata rm = utility.createRuntimeMetadata();
Table t = rm.getTable("flight", "SubscriptionCollection");
assertNotNull(t);
// check the label name
assertNotNull(t.getColumnByName("persistNotifications"));
assertTrue(!t.getColumnByName("ID").isUpdatable());
assertEquals("Persist Notification", t.getColumnByName("persistNotifications").getAnnotation());
// check filterable
assertEquals(SearchType.Unsearchable, t.getColumnByName("persistNotifications").getSearchType());
// check sortable
assertEquals(SearchType.Unsearchable, t.getColumnByName("filter").getSearchType());
// check visible
assertEquals(false, t.getColumnByName("filter").isSelectable());
// check required-in-filter
assertEquals(1, t.getAccessPatterns().size());
assertEquals(2, t.getAccessPatterns().get(0).getColumns().size());
}
use of org.teiid.query.function.UDFSource in project teiid by teiid.
the class RealMetadataFactory method createTransformationMetadata.
public static TransformationMetadata createTransformationMetadata(CompositeMetadataStore store, String vdbName, Properties vdbProperties, FunctionTree... functionModels) {
VDBMetaData vdbMetaData = new VDBMetaData();
// $NON-NLS-1$
vdbMetaData.setName(vdbName);
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;
}
use of org.teiid.query.function.UDFSource in project teiid by teiid.
the class TestExcelMetadataProcessor method getDDL.
static String getDDL(Properties props, String filename) throws TranslatorException, ResourceException {
ExcelExecutionFactory translator = new ExcelExecutionFactory();
translator.start();
String xlsName = props.getProperty("importer.excelFileName");
MetadataFactory mf = new MetadataFactory("vdb", 1, "people", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
FileConnection connection = Mockito.mock(FileConnection.class);
if (xlsName.contains("*.")) {
Mockito.stub(connection.getFile(xlsName)).toReturn(UnitTestUtil.getTestDataFile(xlsName));
File f = Mockito.mock(File.class);
Mockito.stub(f.isDirectory()).toReturn(true);
Mockito.stub(f.listFiles()).toReturn(new File[] { UnitTestUtil.getTestDataFile(filename) });
Mockito.stub(connection.getFile(xlsName)).toReturn(f);
} else {
Mockito.stub(connection.getFile(xlsName)).toReturn(UnitTestUtil.getTestDataFile(xlsName));
}
translator.getMetadata(mf, connection);
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
return ddl;
}
use of org.teiid.query.function.UDFSource in project teiid by teiid.
the class TestODataMetadataProcessor method getTransformationMetadata.
public static TransformationMetadata getTransformationMetadata(MetadataFactory mf, ODataExecutionFactory ef) throws Exception {
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "trippin", 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;
}
Aggregations