Search in sources :

Example 26 with CommandBuilder

use of org.teiid.cdk.CommandBuilder 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 27 with CommandBuilder

use of org.teiid.cdk.CommandBuilder 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 28 with CommandBuilder

use of org.teiid.cdk.CommandBuilder in project teiid by teiid.

the class TestWSTranslator method testHeaders.

@Test
public void testHeaders() throws Exception {
    WSExecutionFactory ef = new WSExecutionFactory();
    WSConnection mockConnection = Mockito.mock(WSConnection.class);
    MetadataFactory mf = new MetadataFactory("vdb", 1, "x", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    ef.getMetadata(mf, mockConnection);
    Procedure p = mf.getSchema().getProcedure(WSExecutionFactory.INVOKE_HTTP);
    TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb");
    RuntimeMetadataImpl rm = new RuntimeMetadataImpl(tm);
    Dispatch<Object> mockDispatch = mockDispatch();
    DataSource mock = Mockito.mock(DataSource.class);
    ByteArrayInputStream baos = new ByteArrayInputStream(new byte[100]);
    Mockito.stub(mock.getInputStream()).toReturn(baos);
    Mockito.stub(mockDispatch.invoke(Mockito.any(DataSource.class))).toReturn(mock);
    Mockito.stub(mockConnection.createDispatch(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(Class.class), Mockito.any(Service.Mode.class))).toReturn(mockDispatch);
    CommandBuilder cb = new CommandBuilder(tm);
    Call call = (Call) cb.getCommand("call invokeHttp('GET', null, null, false, '{\"ContentType\":\"application/json\"}')");
    BinaryWSProcedureExecution pe = new BinaryWSProcedureExecution(call, rm, Mockito.mock(ExecutionContext.class), ef, mockConnection);
    pe.execute();
    Map<String, List<String>> headers = (Map<String, List<String>>) mockDispatch.getRequestContext().get(MessageContext.HTTP_REQUEST_HEADERS);
    assertEquals(Arrays.asList("application/json"), headers.get("ContentType"));
}
Also used : WSConnection(org.teiid.translator.WSConnection) Call(org.teiid.language.Call) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Properties(java.util.Properties) DataSource(javax.activation.DataSource) ExecutionContext(org.teiid.translator.ExecutionContext) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) RuntimeMetadataImpl(org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl) Procedure(org.teiid.metadata.Procedure) List(java.util.List) CommandBuilder(org.teiid.cdk.CommandBuilder) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Example 29 with CommandBuilder

use of org.teiid.cdk.CommandBuilder in project teiid by teiid.

the class TestWSTranslatorMetadata method testHttpMetadata.

@Ignore
@Test
public void testHttpMetadata() throws Exception {
    WSExecutionFactory ef = new WSExecutionFactory();
    Properties props = new Properties();
    props.setProperty("importer.servicename", "XigniteQuotes");
    props.setProperty("importer.portname", "XigniteQuotesHttpGet");
    WSConnection mockConnection = Mockito.mock(WSConnection.class);
    Mockito.stub(mockConnection.getWsdl()).toReturn(new File(UnitTestUtil.getTestDataPath() + "/xquotes.wsdl").toURI().toURL());
    MetadataFactory mf = new MetadataFactory("vdb", 1, "x", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
    ef.getMetadata(mf, mockConnection);
    assertEquals(34, mf.getSchema().getProcedures().size());
    TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb");
    RuntimeMetadataImpl rm = new RuntimeMetadataImpl(tm);
    Dispatch<Object> mockDispatch = Mockito.mock(Dispatch.class);
    Mockito.stub(mockDispatch.invoke(Mockito.any(DataSource.class))).toReturn(Mockito.mock(StAXSource.class));
    Mockito.stub(mockConnection.createDispatch(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(Class.class), Mockito.any(Service.Mode.class))).toReturn(mockDispatch);
    CommandBuilder cb = new CommandBuilder(tm);
    Call call = (Call) cb.getCommand("call GetFundQuote('<foo/>')");
    WSProcedureExecution wpe = new WSProcedureExecution(call, rm, Mockito.mock(ExecutionContext.class), ef, mockConnection);
    wpe.execute();
    wpe.getOutputParameterValues();
}
Also used : WSConnection(org.teiid.translator.WSConnection) Call(org.teiid.language.Call) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) StAXSource(javax.xml.transform.stax.StAXSource) Properties(java.util.Properties) DataSource(javax.activation.DataSource) ExecutionContext(org.teiid.translator.ExecutionContext) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) RuntimeMetadataImpl(org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl) CommandBuilder(org.teiid.cdk.CommandBuilder) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 30 with CommandBuilder

use of org.teiid.cdk.CommandBuilder in project teiid by teiid.

the class TestTeiidLanguageToCQL method getTranslation.

private String getTranslation(String sql, Properties modelProperties) {
    CommandBuilder builder = new CommandBuilder(cassandraMetadata(modelProperties));
    Command c = builder.getCommand(sql);
    CassandraSQLVisitor visitor = new CassandraSQLVisitor();
    visitor.translateSQL(c);
    return visitor.getTranslatedSQL();
}
Also used : Command(org.teiid.language.Command) CommandBuilder(org.teiid.cdk.CommandBuilder)

Aggregations

CommandBuilder (org.teiid.cdk.CommandBuilder)34 Test (org.junit.Test)31 Command (org.teiid.language.Command)25 SQLConversionVisitor (org.teiid.translator.jdbc.SQLConversionVisitor)9 TranslatedCommand (org.teiid.translator.jdbc.TranslatedCommand)9 ExecutionContext (org.teiid.translator.ExecutionContext)8 RuntimeMetadataImpl (org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl)6 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)6 Properties (java.util.Properties)5 DataSource (javax.activation.DataSource)5 Call (org.teiid.language.Call)5 MetadataFactory (org.teiid.metadata.MetadataFactory)5 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)5 WSConnection (org.teiid.translator.WSConnection)5 Connection (java.sql.Connection)4 Select (org.teiid.language.Select)4 StAXSource (javax.xml.transform.stax.StAXSource)3 Procedure (org.teiid.metadata.Procedure)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2