Search in sources :

Example 1 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestNativeCassandra method testDirect.

@Test
public void testDirect() throws TranslatorException {
    CassandraExecutionFactory cef = new CassandraExecutionFactory();
    cef.setSupportsDirectQueryProcedure(true);
    String input = "call native('select $1', 'a')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    CassandraConnection connection = Mockito.mock(CassandraConnection.class);
    ResultSetFuture rsf = Mockito.mock(ResultSetFuture.class);
    Mockito.stub(rsf.isDone()).toReturn(true);
    ResultSet rs = Mockito.mock(ResultSet.class);
    Mockito.stub(rsf.getUninterruptibly()).toReturn(rs);
    Row row = Mockito.mock(Row.class);
    ColumnDefinitions cd = Mockito.mock(ColumnDefinitions.class);
    Mockito.stub(row.getColumnDefinitions()).toReturn(cd);
    Mockito.stub(rs.one()).toReturn(row).toReturn(null);
    Mockito.stub(connection.executeQuery("select 'a'")).toReturn(rsf);
    ResultSetExecution execution = (ResultSetExecution) cef.createExecution(command, ec, rm, connection);
    execution.execute();
    List<?> vals = execution.next();
    assertTrue(vals.get(0) instanceof Object[]);
}
Also used : ColumnDefinitions(com.datastax.driver.core.ColumnDefinitions) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) TranslationUtility(org.teiid.cdk.api.TranslationUtility) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row) Test(org.junit.Test)

Example 2 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestUpdates method testBulkUpdate.

@Test
public void testBulkUpdate() throws Exception {
    CassandraExecutionFactory cef = new CassandraExecutionFactory();
    String input = "insert into pm1.g1 (e1) values ('a')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    Insert insert = (Insert) command;
    Parameter p = new Parameter();
    p.setType(String.class);
    p.setValueIndex(0);
    ((ExpressionValueSource) insert.getValueSource()).getValues().set(0, p);
    insert.setParameterValues(Arrays.asList(Arrays.asList("a"), Arrays.asList("b")).iterator());
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    CassandraConnection connection = Mockito.mock(CassandraConnection.class);
    ResultSetFuture rsf = Mockito.mock(ResultSetFuture.class);
    Mockito.stub(rsf.isDone()).toReturn(true);
    Mockito.stub(connection.executeBatch(Mockito.eq("INSERT INTO g1 (e1) VALUES (?)"), (List<Object[]>) Mockito.anyObject())).toReturn(rsf);
    UpdateExecution execution = (UpdateExecution) cef.createExecution(command, ec, rm, connection);
    execution.execute();
    assertArrayEquals(new int[] { 2 }, execution.getUpdateCounts());
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Parameter(org.teiid.language.Parameter) UpdateExecution(org.teiid.translator.UpdateExecution) Insert(org.teiid.language.Insert) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Example 3 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility 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 4 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestSimpleDBSQLVisitor method testIN.

@Test
public void testIN() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign table item (\"itemName()\" integer, attribute string);", "x", "y");
    TranslationUtility tu = new TranslationUtility(tm);
    Command c = tu.parseCommand("select * from item where \"itemName()\" in (1, 2)");
    SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
    visitor.append(c);
    assertEquals("SELECT attribute FROM item WHERE itemName() IN ('1', '2')", visitor.toString());
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Command(org.teiid.language.Command) SimpleDBSQLVisitor(org.teiid.translator.simpledb.SimpleDBSQLVisitor) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Test(org.junit.Test)

Example 5 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility 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)

Aggregations

TranslationUtility (org.teiid.cdk.api.TranslationUtility)76 Command (org.teiid.language.Command)52 Test (org.junit.Test)45 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)35 ExecutionContext (org.teiid.translator.ExecutionContext)33 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)26 SimpleDBSQLVisitor (org.teiid.translator.simpledb.SimpleDBSQLVisitor)14 MetadataFactory (org.teiid.metadata.MetadataFactory)13 FunctionTree (org.teiid.query.function.FunctionTree)11 UDFSource (org.teiid.query.function.UDFSource)11 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)11 Before (org.junit.Before)10 LdapContext (javax.naming.ldap.LdapContext)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 SimpleDBExecutionFactory (org.teiid.translator.simpledb.SimpleDBExecutionFactory)8 List (java.util.List)7 ResultSetExecution (org.teiid.translator.ResultSetExecution)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DataSource (javax.activation.DataSource)6 WSConnection (org.teiid.translator.WSConnection)6