Search in sources :

Example 86 with Command

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

the class TestTeradataTranslator method testPositionalOrderByUnion.

@Test
public void testPositionalOrderByUnion() throws Exception {
    String input = "SELECT a as b, b as a from (SELECT intkey as a, stringkey as b from BQT1.smalla union SELECT intkey as a, stringkey as b from BQT1.smalla) as x order by a";
    String output = "SELECT v_0.c_0, v_0.c_1 FROM (SELECT g_1.IntKey AS c_0, g_1.StringKey AS c_1 FROM SmallA AS g_1 UNION SELECT g_0.IntKey AS c_0, g_0.StringKey AS c_1 FROM SmallA AS g_0) AS v_0 ORDER BY 2";
    TranslationUtility tu = TranslationHelper.getTranslationUtility(TranslationHelper.BQT_VDB, null);
    Command command = tu.parseCommand(input, true, true);
    TranslationHelper.helpTestVisitor(output, TRANSLATOR, command);
}
Also used : Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Test(org.junit.Test)

Example 87 with Command

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

the class TestTeradataTranslator method testPositionalOrderByUnion1.

@Test
public void testPositionalOrderByUnion1() throws Exception {
    String input = "SELECT a as b from (SELECT intkey as a, stringkey as b from BQT1.smalla union SELECT intkey as a, stringkey as b from BQT1.smalla) as x order by x.b";
    String output = "SELECT v_0.c_0 FROM (SELECT g_1.IntKey AS c_0, g_1.StringKey AS c_1 FROM SmallA AS g_1 UNION SELECT g_0.IntKey AS c_0, g_0.StringKey AS c_1 FROM SmallA AS g_0) AS v_0 ORDER BY v_0.c_1";
    TranslationUtility tu = TranslationHelper.getTranslationUtility(TranslationHelper.BQT_VDB, null);
    Command command = tu.parseCommand(input, true, true);
    TranslationHelper.helpTestVisitor(output, TRANSLATOR, command);
}
Also used : Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Test(org.junit.Test)

Example 88 with Command

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

the class TestTeradataTranslator method testPositionalOrderBy.

@Test
public void testPositionalOrderBy() throws Exception {
    String input = "SELECT INTKEY, BIGDECIMALVALUE FROM BQT1.SmallA ORDER BY intkey";
    String output = "SELECT g_0.IntKey AS c_0, g_0.BigDecimalValue AS c_1 FROM SmallA AS g_0 ORDER BY 1";
    TranslationUtility tu = TranslationHelper.getTranslationUtility(TranslationHelper.BQT_VDB, null);
    Command command = tu.parseCommand(input, true, true);
    TranslationHelper.helpTestVisitor(output, TRANSLATOR, command);
}
Also used : Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Test(org.junit.Test)

Example 89 with Command

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

the class TestJPADirectQueryExecution method testWithoutMarker.

@Test
public void testWithoutMarker() throws Exception {
    String input = "exec native('jpa query')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    EntityManager connection = Mockito.mock(EntityManager.class);
    try {
        JPQLDirectQueryExecution execution = (JPQLDirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
        execution.execute();
        fail("the above should have thrown exception");
    } catch (TranslatorException e) {
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) TranslatorException(org.teiid.translator.TranslatorException) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Example 90 with Command

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

the class TestJPADirectQueryExecution method testCreate.

@Test
public void testCreate() throws Exception {
    String input = "exec native('create;', 'one')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    EntityManager connection = Mockito.mock(EntityManager.class);
    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
    Mockito.stub(connection.merge(argument.capture())).toReturn(new String("one"));
    JPQLDirectQueryExecution execution = (JPQLDirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(connection).merge(argument.capture());
    assertEquals("one", argument.getValue());
}
Also used : EntityManager(javax.persistence.EntityManager) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) 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