Search in sources :

Example 31 with Command

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

the class TestNativeSpreadsheet method testDirect.

@Test
public void testDirect() throws TranslatorException {
    SpreadsheetExecutionFactory sef = new SpreadsheetExecutionFactory();
    sef.setSupportsDirectQueryProcedure(true);
    String input = "call native('worksheet=x;query=$1 foo;limit=2', 'a')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    GoogleSpreadsheetConnection connection = Mockito.mock(GoogleSpreadsheetConnection.class);
    RowsResult result = Mockito.mock(RowsResult.class);
    Mockito.stub(result.iterator()).toReturn(Arrays.asList(new SheetRow()).iterator());
    Mockito.stub(connection.executeQuery("x", "'a' foo", null, 2, 0)).toReturn(result);
    ResultSetExecution execution = (ResultSetExecution) sef.createExecution(command, ec, rm, connection);
    execution.execute();
    List<?> vals = execution.next();
    assertTrue(vals.get(0) instanceof Object[]);
}
Also used : TranslationUtility(org.teiid.cdk.api.TranslationUtility) RowsResult(org.teiid.translator.google.api.result.RowsResult) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) SheetRow(org.teiid.translator.google.api.result.SheetRow) Command(org.teiid.language.Command) GoogleSpreadsheetConnection(org.teiid.translator.google.api.GoogleSpreadsheetConnection) Test(org.junit.Test)

Example 32 with Command

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

the class TestN1QLUpdateVisitor method helpTranslate.

private String helpTranslate(String sql) {
    Command command = translationUtility.parseCommand(sql);
    N1QLUpdateVisitor visitor = TRANSLATOR.getN1QLUpdateVisitor();
    visitor.append(command);
    String actual = visitor.toString();
    return actual;
}
Also used : Command(org.teiid.language.Command)

Example 33 with Command

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

the class TestN1QLVisitor method helpTranslate.

static String helpTranslate(String sql) {
    Command command = translationUtility.parseCommand(sql);
    N1QLVisitor visitor = TRANSLATOR.getN1QLVisitor();
    visitor.append(command);
    String actual = visitor.toString();
    return actual;
}
Also used : Command(org.teiid.language.Command)

Example 34 with Command

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

the class TestLDAPDirectQueryExecution method testUpdate.

@Test
public void testUpdate() throws Exception {
    String input = "exec native('update;uid=doe,ou=people,o=teiid.org;attributes=one,two,three', 'one', 2, 3.0)";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    LdapContext connection = Mockito.mock(LdapContext.class);
    LdapContext ctx = Mockito.mock(LdapContext.class);
    Mockito.stub(connection.lookup("")).toReturn(ctx);
    LDAPDirectCreateUpdateDeleteQueryExecution execution = (LDAPDirectCreateUpdateDeleteQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    ArgumentCaptor<String> nameArgument = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<ModificationItem[]> modificationItemArgument = ArgumentCaptor.forClass(ModificationItem[].class);
    Mockito.verify(ctx).modifyAttributes(nameArgument.capture(), modificationItemArgument.capture());
    assertEquals("uid=doe,ou=people,o=teiid.org", nameArgument.getValue());
    assertEquals("one", modificationItemArgument.getValue()[0].getAttribute().getID());
    assertEquals("one", modificationItemArgument.getValue()[0].getAttribute().get());
    assertEquals("two", modificationItemArgument.getValue()[1].getAttribute().getID());
    assertEquals("2", modificationItemArgument.getValue()[1].getAttribute().get());
    assertEquals("three", modificationItemArgument.getValue()[2].getAttribute().getID());
    assertEquals("3.0", modificationItemArgument.getValue()[2].getAttribute().get());
}
Also used : ModificationItem(javax.naming.directory.ModificationItem) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) LdapContext(javax.naming.ldap.LdapContext) Test(org.junit.Test)

Example 35 with Command

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

the class TestLDAPDirectQueryExecution method testSearchDefaultsAndEscaping.

@Test
public void testSearchDefaultsAndEscaping() throws Exception {
    String input = "exec native('search;context-name=corporate;filter=(;;)')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    LdapContext connection = Mockito.mock(LdapContext.class);
    LdapContext ctx = Mockito.mock(LdapContext.class);
    Mockito.stub(connection.lookup("corporate")).toReturn(ctx);
    LDAPDirectSearchQueryExecution execution = (LDAPDirectSearchQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    LDAPSearchDetails details = execution.getDelegate().getSearchDetails();
    assertEquals("corporate", details.getContextName());
    assertEquals("(;)", details.getContextFilter());
    assertEquals(-1, details.getCountLimit());
    assertEquals(0, details.getTimeLimit());
    assertEquals(1, details.getSearchScope());
    assertEquals(0, details.getElementList().size());
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) LdapContext(javax.naming.ldap.LdapContext) 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