Search in sources :

Example 6 with FunctionTree

use of org.teiid.query.function.FunctionTree 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);
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) InputStreamReader(java.io.InputStreamReader) TranslationUtility(org.teiid.cdk.api.TranslationUtility) EdmxFormatParser(org.odata4j.format.xml.EdmxFormatParser) Properties(java.util.Properties) ValidatorReport(org.teiid.query.validator.ValidatorReport) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) EdmDataServices(org.odata4j.edm.EdmDataServices) MetadataValidator(org.teiid.query.metadata.MetadataValidator) Before(org.junit.Before)

Example 7 with FunctionTree

use of org.teiid.query.function.FunctionTree 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());
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) Table(org.teiid.metadata.Table) InputStreamReader(java.io.InputStreamReader) TranslationUtility(org.teiid.cdk.api.TranslationUtility) EdmxFormatParser(org.odata4j.format.xml.EdmxFormatParser) Properties(java.util.Properties) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ValidatorReport(org.teiid.query.validator.ValidatorReport) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) MetadataValidator(org.teiid.query.metadata.MetadataValidator) Test(org.junit.Test)

Example 8 with FunctionTree

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

the class TestAggregatePushdown method testUserDefinedAggPushdown.

@Test
public void testUserDefinedAggPushdown() throws Exception {
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = getAggregateCapabilities();
    caps.setCapabilitySupport(Capability.ELEMENTARY_OLAP, true);
    caps.setCapabilitySupport(Capability.WINDOW_FUNCTION_DISTINCT_AGGREGATES, true);
    caps.setCapabilitySupport(Capability.WINDOW_FUNCTION_ORDER_BY_AGGREGATES, true);
    caps.setFunctionSupport("FIRST_VALUE", true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(RealMetadataFactory.example1Cached().getMetadataStore(), "example1", new FunctionTree("foo", new FakeFunctionMetadataSource(), true));
    ProcessorPlan plan = // $NON-NLS-1$
    TestOptimizer.helpPlan(// $NON-NLS-1$
    "select foo.FIRST_VALUE(e1) OVER (ORDER BY e2) from pm1.g2", // $NON-NLS-1$
    metadata, // $NON-NLS-1$
    null, // $NON-NLS-1$
    capFinder, new String[] { "SELECT foo.FIRST_VALUE(ALL g_0.e1) OVER (ORDER BY g_0.e2) FROM pm1.g2 AS g_0" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) FunctionTree(org.teiid.query.function.FunctionTree) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 9 with FunctionTree

use of org.teiid.query.function.FunctionTree 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;
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ArrayList(java.util.ArrayList)

Example 10 with FunctionTree

use of org.teiid.query.function.FunctionTree 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;
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) MetadataValidator(org.teiid.query.metadata.MetadataValidator) File(java.io.File) ValidatorReport(org.teiid.query.validator.ValidatorReport) FileConnection(org.teiid.translator.FileConnection)

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