use of org.teiid.cdk.CommandBuilder in project teiid by teiid.
the class TestImpalaExecutionFactory method testMultipleDistinctAggregates.
@Test
public void testMultipleDistinctAggregates() {
CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.example1Cached());
Command obj = commandBuilder.getCommand("select count(distinct pm1.g1.e1), 1, count(distinct pm1.g1.e2), avg(distinct pm1.g1.e4) from pm1.g1");
SQLConversionVisitor sqlVisitor = impalaTranslator.getSQLConversionVisitor();
sqlVisitor.append(obj);
assertEquals("SELECT v0.c0, v0.c1, v1.c2, v2.c3 FROM (SELECT COUNT(DISTINCT g1.e1) AS c0, 1 AS c1 FROM g1) v0 CROSS JOIN (SELECT COUNT(DISTINCT g1.e2) AS c2 FROM g1) v1 CROSS JOIN (SELECT AVG(DISTINCT g1.e4) AS c3 FROM g1) v2", sqlVisitor.toString());
obj = commandBuilder.getCommand("select count(distinct pm1.g1.e1), 1, count(distinct pm1.g1.e2), avg(distinct pm1.g1.e4) from pm1.g1 where pm1.g1.e3 = true");
sqlVisitor = impalaTranslator.getSQLConversionVisitor();
sqlVisitor.append(obj);
assertEquals("SELECT v0.c0, v0.c1, v1.c2, v2.c3 FROM (SELECT COUNT(DISTINCT g1.e1) AS c0, 1 AS c1 FROM g1 WHERE g1.e3 = true) v0 CROSS JOIN (SELECT COUNT(DISTINCT g1.e2) AS c2 FROM g1 WHERE g1.e3 = true) v1 CROSS JOIN (SELECT AVG(DISTINCT g1.e4) AS c3 FROM g1 WHERE g1.e3 = true) v2", sqlVisitor.toString());
}
use of org.teiid.cdk.CommandBuilder in project teiid by teiid.
the class TestOlapTranslator method testCannedProcedure.
@Test
public void testCannedProcedure() throws Exception {
String ddl = "create foreign procedure proc(arg integer, arg1 date) returns table (x string) options (\"teiid_rel:native-query\" '$2 $1 something')";
String query = "exec proc(2, {d'1970-01-01'})";
TransformationMetadata tm = RealMetadataFactory.fromDDL(ddl, "x", "phy");
CommandBuilder commandBuilder = new CommandBuilder(tm);
Command obj = commandBuilder.getCommand(query);
OlapExecutionFactory oef = new OlapExecutionFactory();
Connection mock = Mockito.mock(java.sql.Connection.class);
OlapWrapper mock2 = Mockito.mock(OlapWrapper.class);
OlapConnection mock3 = Mockito.mock(OlapConnection.class);
OlapStatement mock4 = Mockito.mock(OlapStatement.class);
Mockito.stub(mock4.executeOlapQuery(Mockito.anyString())).toThrow(new TeiidRuntimeException());
Mockito.stub(mock3.createStatement()).toReturn(mock4);
Mockito.stub(mock2.unwrap(OlapConnection.class)).toReturn(mock3);
Mockito.stub(mock.unwrap(OlapWrapper.class)).toReturn(mock2);
ProcedureExecution pe = oef.createProcedureExecution((Call) obj, Mockito.mock(ExecutionContext.class), new RuntimeMetadataImpl(tm), mock);
try {
pe.execute();
fail();
} catch (TeiidRuntimeException e) {
Mockito.verify(mock4).executeOlapQuery("'1970-01-01' 2 something");
}
}
use of org.teiid.cdk.CommandBuilder in project teiid by teiid.
the class TestWSTranslator method testStreaming.
@Test
public void testStreaming() 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);
assertEquals(7, p.getParameters().size());
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, true)");
BinaryWSProcedureExecution pe = new BinaryWSProcedureExecution(call, rm, Mockito.mock(ExecutionContext.class), ef, mockConnection);
pe.execute();
List<?> result = pe.getOutputParameterValues();
Blob b = (Blob) result.get(0);
assertEquals(100, ObjectConverterUtil.convertToByteArray(b.getBinaryStream()).length);
try {
ObjectConverterUtil.convertToByteArray(b.getBinaryStream());
fail();
} catch (SQLException e) {
// should only be able to read once
}
}
use of org.teiid.cdk.CommandBuilder in project teiid by teiid.
the class TestWSTranslator method testPre81Procedure.
@Test
public void testPre81Procedure() 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);
assertEquals(7, p.getParameters().size());
p.getParameters().remove(4);
p.getParameters().remove(5);
// designer treated the result as an out parameter
p.getParameters().get(0).setType(Type.Out);
p.getParameters().add(3, p.getParameters().remove(0));
for (int i = 0; i < p.getParameters().size(); i++) {
p.getParameters().get(i).setPosition(i + 1);
}
p = mf.getSchema().getProcedure("invoke");
assertEquals(6, p.getParameters().size());
p.getParameters().remove(5);
// designer treated the result as an out parameter
p.getParameters().get(0).setType(Type.Out);
p.getParameters().add(p.getParameters().remove(0));
for (int i = 0; i < p.getParameters().size(); i++) {
p.getParameters().get(i).setPosition(i + 1);
}
TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb");
RuntimeMetadataImpl rm = new RuntimeMetadataImpl(tm);
Dispatch<Object> mockDispatch = mockDispatch();
DataSource source = Mockito.mock(DataSource.class);
Mockito.stub(mockDispatch.invoke(Mockito.any(DataSource.class))).toReturn(source);
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)");
BinaryWSProcedureExecution pe = new BinaryWSProcedureExecution(call, rm, Mockito.mock(ExecutionContext.class), ef, mockConnection);
pe.execute();
pe.getOutputParameterValues();
mockConnection = Mockito.mock(WSConnection.class);
mockDispatch = Mockito.mock(Dispatch.class);
StAXSource ssource = Mockito.mock(StAXSource.class);
Mockito.stub(mockDispatch.invoke(Mockito.any(StAXSource.class))).toReturn(ssource);
Mockito.stub(mockConnection.createDispatch(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(Class.class), Mockito.any(Service.Mode.class))).toReturn(mockDispatch);
call = (Call) cb.getCommand("call invoke()");
WSProcedureExecution wpe = new WSProcedureExecution(call, rm, Mockito.mock(ExecutionContext.class), ef, mockConnection);
wpe.execute();
wpe.getOutputParameterValues();
}
use of org.teiid.cdk.CommandBuilder in project teiid by teiid.
the class TestWSTranslatorMetadata method testMetadata.
@Test
public void testMetadata() throws Exception {
WSExecutionFactory ef = new WSExecutionFactory();
Properties props = new Properties();
WSConnection mockConnection = Mockito.mock(WSConnection.class);
Mockito.stub(mockConnection.getWsdl()).toReturn(new File(UnitTestUtil.getTestDataPath() + "/xquotes.wsdl").toURI().toURL());
Mockito.stub(mockConnection.getServiceQName()).toReturn(new QName("http://www.xignite.com/services/", "XigniteQuotes"));
Mockito.stub(mockConnection.getPortQName()).toReturn(new QName("http://www.xignite.com/services/", "XigniteQuotesSoap"));
MetadataFactory mf = new MetadataFactory("vdb", 1, "x", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
ef.getMetadata(mf, mockConnection);
assertEquals(36, mf.getSchema().getProcedures().size());
TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb");
RuntimeMetadataImpl rm = new RuntimeMetadataImpl(tm);
Dispatch<Object> mockDispatch = Mockito.mock(Dispatch.class);
StAXSource source = Mockito.mock(StAXSource.class);
Mockito.stub(mockDispatch.invoke(Mockito.any(DataSource.class))).toReturn(source);
Mockito.stub(mockConnection.createDispatch(Mockito.any(Class.class), Mockito.any(Service.Mode.class))).toReturn(mockDispatch);
CommandBuilder cb = new CommandBuilder(tm);
Call call = (Call) cb.getCommand("call GetFundQuote('<foo/>')");
WSWSDLProcedureExecution wpe = new WSWSDLProcedureExecution(call, rm, Mockito.mock(ExecutionContext.class), ef, mockConnection);
wpe.execute();
wpe.getOutputParameterValues();
}
Aggregations