Search in sources :

Example 1 with SimpleDBExecutionFactory

use of org.teiid.translator.simpledb.SimpleDBExecutionFactory in project teiid by teiid.

the class TestSimpleDBExecution method setup.

@Before
public void setup() throws Exception {
    translator = new SimpleDBExecutionFactory();
    translator.start();
    TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign table item (\"itemName()\" string, attribute string, somedate timestamp, strarray string[]);", "x", "y");
    utility = new TranslationUtility(tm);
    connection = Mockito.mock(SimpleDBConnection.class);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) TranslationUtility(org.teiid.cdk.api.TranslationUtility) SimpleDBExecutionFactory(org.teiid.translator.simpledb.SimpleDBExecutionFactory) SimpleDBConnection(org.teiid.translator.simpledb.api.SimpleDBConnection) Before(org.junit.Before)

Example 2 with SimpleDBExecutionFactory

use of org.teiid.translator.simpledb.SimpleDBExecutionFactory in project teiid by teiid.

the class TestSimpleDBSQLVisitor method testEveryNotNull.

@Test
public void testEveryNotNull() 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) is not null");
    SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
    visitor.append(c);
    assertEquals("SELECT attribute FROM item WHERE SIMPLEDB.EVERY(attribute) IS NOT NULL", 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 3 with SimpleDBExecutionFactory

use of org.teiid.translator.simpledb.SimpleDBExecutionFactory in project teiid by teiid.

the class TestSimpleDBSQLVisitor method testArrayCompare.

@Test
public void testArrayCompare() 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 attribute = ('1','2')");
    SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
    visitor.append(c);
    assertEquals("SELECT attribute FROM item WHERE attribute = '1' OR 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 4 with SimpleDBExecutionFactory

use of org.teiid.translator.simpledb.SimpleDBExecutionFactory in project teiid by teiid.

the class TestSimpleDBSQLVisitor method testEvery.

@Test
public void testEvery() 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'");
    SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
    visitor.append(c);
    assertEquals("SELECT attribute FROM item WHERE SIMPLEDB.EVERY(attribute) = '1'", 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 5 with SimpleDBExecutionFactory

use of org.teiid.translator.simpledb.SimpleDBExecutionFactory 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)

Aggregations

TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)9 SimpleDBExecutionFactory (org.teiid.translator.simpledb.SimpleDBExecutionFactory)9 TranslationUtility (org.teiid.cdk.api.TranslationUtility)8 MetadataFactory (org.teiid.metadata.MetadataFactory)8 FunctionTree (org.teiid.query.function.FunctionTree)8 UDFSource (org.teiid.query.function.UDFSource)8 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)8 Test (org.junit.Test)7 Command (org.teiid.language.Command)7 SimpleDBSQLVisitor (org.teiid.translator.simpledb.SimpleDBSQLVisitor)7 SimpleDBConnection (org.teiid.translator.simpledb.api.SimpleDBConnection)2 HashSet (java.util.HashSet)1 Before (org.junit.Before)1 MetadataValidator (org.teiid.query.metadata.MetadataValidator)1 ValidatorReport (org.teiid.query.validator.ValidatorReport)1 SimpleDBAttribute (org.teiid.translator.simpledb.api.SimpleDBConnection.SimpleDBAttribute)1