Search in sources :

Example 71 with Command

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

the class TestSqlServerConversionVisitor method testLocate.

@Test
public void testLocate() throws Exception {
    // $NON-NLS-1$
    String input = "select locate('a', stringkey, 2) from bqt1.smalla";
    // $NON-NLS-1$
    String output = "SELECT CHARINDEX('a', g_0.StringKey, 2) FROM SmallA g_0";
    CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
    Command obj = commandBuilder.getCommand(input, true, true);
    TranslationHelper.helpTestVisitor(output, trans, obj);
}
Also used : Command(org.teiid.language.Command) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Example 72 with Command

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

the class TestOracleTranslator method testParseFormat.

@Test
public void testParseFormat() throws Exception {
    // $NON-NLS-1$
    String input = "select parsetimestamp(smalla.timestampvalue, 'yyyy.MM.dd'), formattimestamp(smalla.timestampvalue, 'yy.MM.dd') from bqt1.smalla";
    // $NON-NLS-1$
    String output = "SELECT TO_TIMESTAMP(to_char(cast(g_0.TimestampValue AS timestamp), 'YYYY-MM-DD HH24:MI:SS.FF'), 'YYYY.MM.DD'), TO_CHAR(g_0.TimestampValue, 'YY.MM.DD') FROM SmallA g_0";
    CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
    Command obj = commandBuilder.getCommand(input, true, true);
    TranslationHelper.helpTestVisitor(output, TRANSLATOR, obj);
}
Also used : Command(org.teiid.language.Command) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Example 73 with Command

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

the class TestOracleTranslator method testCharType.

@Test
public void testCharType() throws Exception {
    CommandBuilder commandBuilder = new CommandBuilder(getOracleSpecificMetadata());
    Command command = commandBuilder.getCommand("select id from smalla where description = 'a' and ndescription in ('b', 'c')");
    for (Literal l : CollectorVisitor.collectObjects(Literal.class, command)) {
        l.setBindEligible(true);
    }
    Connection connection = Mockito.mock(Connection.class);
    PreparedStatement ps = Mockito.mock(PreparedStatement.class);
    // $NON-NLS-1$
    Mockito.stub(connection.prepareStatement("SELECT SmallishA.ID FROM SmallishA WHERE SmallishA.description = ? AND SmallishA.ndescription IN (?, ?)")).toReturn(ps);
    OracleExecutionFactory ef = new OracleExecutionFactory();
    ef.start();
    JDBCQueryExecution e = new JDBCQueryExecution(command, connection, new FakeExecutionContextImpl(), ef);
    e.execute();
    Mockito.verify(ps, Mockito.times(1)).setObject(1, "a", OracleExecutionFactory.FIXED_CHAR_TYPE);
    Mockito.verify(ps, Mockito.times(1)).setObject(2, "b", OracleExecutionFactory.FIXED_CHAR_TYPE);
}
Also used : FakeExecutionContextImpl(org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl) Command(org.teiid.language.Command) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand) Literal(org.teiid.language.Literal) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) JDBCQueryExecution(org.teiid.translator.jdbc.JDBCQueryExecution) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Example 74 with Command

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

the class TestOracleTranslator method testProcedureExecution.

@Test
public void testProcedureExecution() throws Exception {
    // $NON-NLS-1$
    Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "call spTest8(1)");
    Connection connection = Mockito.mock(Connection.class);
    CallableStatement cs = Mockito.mock(CallableStatement.class);
    Mockito.stub(cs.getUpdateCount()).toReturn(-1);
    ResultSet rs = Mockito.mock(ResultSet.class);
    Mockito.stub(cs.getObject(1)).toReturn(rs);
    Mockito.stub(cs.getInt(3)).toReturn(4);
    // $NON-NLS-1$
    Mockito.stub(connection.prepareCall("{?= call spTest8(?,?)}")).toReturn(cs);
    OracleExecutionFactory ef = new OracleExecutionFactory();
    JDBCProcedureExecution procedureExecution = new JDBCProcedureExecution(command, connection, Mockito.mock(ExecutionContext.class), ef);
    procedureExecution.execute();
    assertEquals(Arrays.asList(4), procedureExecution.getOutputParameterValues());
    Mockito.verify(cs, Mockito.times(1)).registerOutParameter(1, OracleExecutionFactory.CURSOR_TYPE);
    Mockito.verify(cs, Mockito.times(1)).getObject(1);
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) JDBCProcedureExecution(org.teiid.translator.jdbc.JDBCProcedureExecution) Test(org.junit.Test)

Example 75 with Command

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

the class TestOracleTranslator method helpTestVisitor.

private void helpTestVisitor(String vdb, String input, ExecutionContext context, String dbmsTimeZone, String expectedOutput, boolean correctNaming) throws TranslatorException {
    // Convert from sql to objects
    TranslationUtility util = new TranslationUtility(vdb);
    Command obj = util.parseCommand(input, correctNaming, true);
    this.helpTestVisitor(obj, context, dbmsTimeZone, expectedOutput);
}
Also used : Command(org.teiid.language.Command) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand) TranslationUtility(org.teiid.cdk.api.TranslationUtility)

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