Search in sources :

Example 56 with Command

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

the class TestJDBCDirectQueryExecution method testSelectExecution.

@Test
public void testSelectExecution() throws Exception {
    // $NON-NLS-1$
    Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "call native('select * from Source')");
    Connection connection = Mockito.mock(Connection.class);
    Statement stmt = Mockito.mock(Statement.class);
    ResultSet rs = Mockito.mock(ResultSet.class);
    ResultSetMetaData rsm = Mockito.mock(ResultSetMetaData.class);
    Mockito.stub(stmt.getUpdateCount()).toReturn(-1);
    Mockito.stub(stmt.getResultSet()).toReturn(rs);
    Mockito.stub(rs.getMetaData()).toReturn(rsm);
    Mockito.stub(rsm.getColumnCount()).toReturn(2);
    // $NON-NLS-1$
    Mockito.stub(connection.createStatement()).toReturn(stmt);
    Mockito.stub(stmt.execute("select * from Source")).toReturn(true);
    Mockito.stub(rs.next()).toReturn(true);
    Mockito.stub(rs.getObject(1)).toReturn(5);
    Mockito.stub(rs.getObject(2)).toReturn("five");
    DatabaseMetaData dbmd = Mockito.mock(DatabaseMetaData.class);
    Mockito.stub(connection.getMetaData()).toReturn(dbmd);
    JDBCExecutionFactory ef = new JDBCExecutionFactory();
    ef.setSupportsDirectQueryProcedure(true);
    ResultSetExecution execution = (ResultSetExecution) ef.createExecution(command, Mockito.mock(ExecutionContext.class), Mockito.mock(RuntimeMetadata.class), connection);
    execution.execute();
    assertArrayEquals(new Object[] { 5, "five" }, (Object[]) execution.next().get(0));
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) ResultSetExecution(org.teiid.translator.ResultSetExecution) Command(org.teiid.language.Command) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData) Test(org.junit.Test)

Example 57 with Command

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

the class TestJDBCProcedureExecution method testProcedureExecution1.

@Test
public void testProcedureExecution1() throws Exception {
    // $NON-NLS-1$
    Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "exec pm2.spTest8(1)");
    Connection connection = Mockito.mock(Connection.class);
    CallableStatement cs = Mockito.mock(CallableStatement.class);
    Mockito.stub(cs.getUpdateCount()).toReturn(-1);
    Mockito.stub(cs.getInt(2)).toReturn(5);
    // $NON-NLS-1$
    Mockito.stub(connection.prepareCall("{call spTest8(?,?)}")).toReturn(cs);
    JDBCExecutionFactory config = new JDBCExecutionFactory();
    JDBCProcedureExecution procedureExecution = new JDBCProcedureExecution(command, connection, Mockito.mock(ExecutionContext.class), config);
    procedureExecution.execute();
    assertEquals(Arrays.asList(5), procedureExecution.getOutputParameterValues());
    Mockito.verify(cs, Mockito.times(1)).registerOutParameter(2, Types.INTEGER);
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) Test(org.junit.Test)

Example 58 with Command

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

the class TestJDBCProcedureExecution method testProcedureExecution.

@Test
public void testProcedureExecution() throws Exception {
    // $NON-NLS-1$
    Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "exec pm2.spTest8a()");
    Connection connection = Mockito.mock(Connection.class);
    CallableStatement cs = Mockito.mock(CallableStatement.class);
    Mockito.stub(cs.getUpdateCount()).toReturn(-1);
    Mockito.stub(cs.getInt(1)).toReturn(5);
    // $NON-NLS-1$
    Mockito.stub(connection.prepareCall("{call spTest8a(?)}")).toReturn(cs);
    JDBCExecutionFactory ef = new JDBCExecutionFactory();
    JDBCProcedureExecution procedureExecution = new JDBCProcedureExecution(command, connection, Mockito.mock(ExecutionContext.class), ef);
    procedureExecution.execute();
    assertEquals(Arrays.asList(5), procedureExecution.getOutputParameterValues());
    Mockito.verify(cs, Mockito.times(1)).registerOutParameter(1, Types.INTEGER);
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) Test(org.junit.Test)

Example 59 with Command

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

the class TestSqlServerConversionVisitor method testRecursiveCTEWithTypeMatching.

@Test
public void testRecursiveCTEWithTypeMatching() throws Exception {
    String input = "with a (intkey, stringkey, bigintegervalue) as (select intkey, NULL as stringkey, bigintegervalue from bqt1.smalla where intkey = 1 " + "union all " + " select n.intkey, n.stringkey, 1 from bqt1.smalla n inner join a rcte on n.intkey = rcte.intkey + 1) " + "select * from a";
    String output = "WITH a (intkey, stringkey, bigintegervalue) AS (SELECT cast(g_2.IntKey AS int) AS c_0, cast(NULL AS char) AS c_1, cast(g_2.BigIntegerValue AS numeric(38, 0)) AS c_2 FROM SmallA g_2 WHERE g_2.IntKey = 1 UNION ALL SELECT cast(g_0.IntKey AS int) AS c_0, g_0.StringKey AS c_1, cast(1 AS numeric(38, 0)) AS c_2 FROM SmallA g_0 INNER JOIN a g_1 ON g_0.IntKey = (g_1.intkey + 1)) SELECT g_3.intkey, g_3.stringkey, g_3.bigintegervalue FROM a g_3";
    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 60 with Command

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

the class TestSqlServerConversionVisitor 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 CONVERT(DATETIME, convert(varchar, g_0.TimestampValue, 21), 102), CONVERT(VARCHAR, g_0.TimestampValue, 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)

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