Search in sources :

Example 6 with Command

use of org.teiid.language.Command in project teiid by teiid.

the class TestAccumuloQueryVisitor method testSelectEquality.

@Test
public void testSelectEquality() throws Exception {
    Command cmd = this.utility.parseCommand("select firstname from Customer where customer_id = 1");
    AccumuloQueryVisitor visitor = buildVisitor(cmd);
    assertEquals("customer", visitor.getScanTable().getName());
    assertEquals(1, visitor.getRanges().size());
    Range range = visitor.getRanges().get(0);
    assertEquals(AccumuloQueryVisitor.singleRowRange(AccumuloQueryVisitor.buildKey(new Integer(1))), range);
}
Also used : Command(org.teiid.language.Command) Range(org.apache.accumulo.core.data.Range) Test(org.junit.Test)

Example 7 with Command

use of org.teiid.language.Command in project teiid by teiid.

the class CassandraUpdateExecution method handleBatchedUpdates.

private void handleBatchedUpdates() {
    BatchedUpdates updates = (BatchedUpdates) this.command;
    List<String> cqlUpdates = new ArrayList<String>();
    for (Command update : updates.getUpdateCommands()) {
        CassandraSQLVisitor visitor = new CassandraSQLVisitor();
        visitor.translateSQL(update);
        String cql = visitor.getTranslatedSQL();
        cqlUpdates.add(cql);
    }
    this.updateCount = cqlUpdates.size();
    resultSetFuture = connection.executeBatch(cqlUpdates);
}
Also used : Command(org.teiid.language.Command) BulkCommand(org.teiid.language.BulkCommand) ArrayList(java.util.ArrayList) BatchedUpdates(org.teiid.language.BatchedUpdates)

Example 8 with Command

use of org.teiid.language.Command 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 9 with Command

use of org.teiid.language.Command 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 10 with Command

use of org.teiid.language.Command in project teiid by teiid.

the class TestSimpleDBExecution method testDeleteAll.

@Test
public void testDeleteAll() throws Exception {
    String query = "delete from item";
    Command cmd = utility.parseCommand(query);
    ExecutionContext context = Mockito.mock(ExecutionContext.class);
    UpdateExecution exec = translator.createUpdateExecution(cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
    exec.execute();
    Mockito.verify(connection).deleteDomain("item");
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) UpdateExecution(org.teiid.translator.UpdateExecution) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Aggregations

Command (org.teiid.language.Command)136 Test (org.junit.Test)99 ExecutionContext (org.teiid.translator.ExecutionContext)62 TranslationUtility (org.teiid.cdk.api.TranslationUtility)52 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)40 CommandBuilder (org.teiid.cdk.CommandBuilder)25 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)20 ResultSetExecution (org.teiid.translator.ResultSetExecution)18 TranslatedCommand (org.teiid.translator.jdbc.TranslatedCommand)17 UpdateExecution (org.teiid.translator.UpdateExecution)16 SimpleDBSQLVisitor (org.teiid.translator.simpledb.SimpleDBSQLVisitor)14 List (java.util.List)11 Connection (java.sql.Connection)10 LdapContext (javax.naming.ldap.LdapContext)9 Range (org.apache.accumulo.core.data.Range)9 SQLConversionVisitor (org.teiid.translator.jdbc.SQLConversionVisitor)9 MetadataFactory (org.teiid.metadata.MetadataFactory)8 ArrayList (java.util.ArrayList)7 FunctionTree (org.teiid.query.function.FunctionTree)7 UDFSource (org.teiid.query.function.UDFSource)7