Search in sources :

Example 21 with FunctionTree

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

the class TestSwaggerMetadataProcessor method getTransformationMetadata.

public static TransformationMetadata getTransformationMetadata(MetadataFactory mf, SwaggerExecutionFactory ef) throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "swagger", 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;
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) MetadataValidator(org.teiid.query.metadata.MetadataValidator) ValidatorReport(org.teiid.query.validator.ValidatorReport)

Example 22 with FunctionTree

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

the class EvaluatorIterator method createTransformationMetadata.

public static TransformationMetadata createTransformationMetadata(String ddl) {
    MetadataStore mds = new MetadataStore();
    MetadataFactory mf = new MetadataFactory("vdb", 1, IMPLICIT_MODEL_NAME, SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    QueryParser.getQueryParser().parseDDL(mf, ddl);
    mf.mergeInto(mds);
    CompositeMetadataStore store = new CompositeMetadataStore(mds);
    VDBMetaData vdbMetaData = new VDBMetaData();
    // $NON-NLS-1$
    vdbMetaData.setName("vdb");
    vdbMetaData.setVersion(1);
    List<FunctionTree> udfs = new ArrayList<FunctionTree>();
    for (Schema schema : store.getSchemas().values()) {
        vdbMetaData.addModel(createModel(schema.getName(), schema.isPhysical()));
    }
    TransformationMetadata metadata = new TransformationMetadata(vdbMetaData, store, null, SFM.getSystemFunctions(), udfs);
    vdbMetaData.addAttchment(TransformationMetadata.class, metadata);
    vdbMetaData.addAttchment(QueryMetadataInterface.class, metadata);
    return metadata;
}
Also used : CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) MetadataStore(org.teiid.metadata.MetadataStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) FunctionTree(org.teiid.query.function.FunctionTree) MetadataFactory(org.teiid.metadata.MetadataFactory) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Schema(org.teiid.metadata.Schema) ArrayList(java.util.ArrayList) Properties(java.util.Properties)

Example 23 with FunctionTree

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

the class TestSimpleDBMetadataProcessor method getDDL.

static String getDDL(Properties props) throws TranslatorException {
    SimpleDBExecutionFactory translator = new SimpleDBExecutionFactory();
    translator.start();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "people", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
    SimpleDBConnection connection = Mockito.mock(SimpleDBConnection.class);
    Mockito.stub(connection.getDomains()).toReturn(Arrays.asList("G1", "G2"));
    HashSet<SimpleDBAttribute> cols = new HashSet<SimpleDBConnection.SimpleDBAttribute>();
    cols.add(new SimpleDBAttribute("e1", false));
    cols.add(new SimpleDBAttribute("e2", false));
    Mockito.stub(connection.getAttributeNames("G1")).toReturn(cols);
    HashSet<SimpleDBAttribute> cols2 = new HashSet<SimpleDBConnection.SimpleDBAttribute>();
    cols2.add(new SimpleDBAttribute("e1", false));
    cols2.add(new SimpleDBAttribute("e2", true));
    Mockito.stub(connection.getAttributeNames("G2")).toReturn(cols2);
    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) SimpleDBAttribute(org.teiid.translator.simpledb.api.SimpleDBConnection.SimpleDBAttribute) ValidatorReport(org.teiid.query.validator.ValidatorReport) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) SimpleDBExecutionFactory(org.teiid.translator.simpledb.SimpleDBExecutionFactory) MetadataValidator(org.teiid.query.metadata.MetadataValidator) SimpleDBConnection(org.teiid.translator.simpledb.api.SimpleDBConnection) HashSet(java.util.HashSet)

Example 24 with FunctionTree

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

the class TestSimpleDBSQLVisitor method testIntersection.

@Test
public void testIntersection() 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.intersection(attribute,'1', '2')");
    SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
    visitor.append(c);
    assertEquals("SELECT attribute FROM item WHERE attribute = '1' INTERSECTION attribute = '2'", visitor.toString());
}
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) Command(org.teiid.language.Command) SimpleDBSQLVisitor(org.teiid.translator.simpledb.SimpleDBSQLVisitor) TranslationUtility(org.teiid.cdk.api.TranslationUtility) SimpleDBExecutionFactory(org.teiid.translator.simpledb.SimpleDBExecutionFactory) Test(org.junit.Test)

Example 25 with FunctionTree

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

the class TestSimpleDBSQLVisitor method testIntersection2.

@Test
public void testIntersection2() 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.intersection(attribute,'1', '2', '3') = true");
    SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
    visitor.append(c);
    assertEquals("SELECT attribute FROM item WHERE attribute = '1' INTERSECTION attribute = '2' INTERSECTION attribute = '3'", visitor.toString());
}
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) Command(org.teiid.language.Command) SimpleDBSQLVisitor(org.teiid.translator.simpledb.SimpleDBSQLVisitor) TranslationUtility(org.teiid.cdk.api.TranslationUtility) SimpleDBExecutionFactory(org.teiid.translator.simpledb.SimpleDBExecutionFactory) Test(org.junit.Test)

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