use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.
the class TestAccumuloQueryExecution method setUp.
@BeforeClass
public static void setUp() throws Exception {
translator = new AccumuloExecutionFactory();
translator.start();
TransformationMetadata metadata = RealMetadataFactory.fromDDL(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("sampledb.ddl")), "sakila", "rental");
utility = new TranslationUtility(metadata);
MockInstance instance = new MockInstance("teiid");
connection = Mockito.mock(AccumuloConnection.class);
Connector connector = instance.getConnector("root", new PasswordToken(""));
Mockito.stub(connection.getInstance()).toReturn(connector);
Mockito.stub(connection.getAuthorizations()).toReturn(new Authorizations("public"));
connector.tableOperations().create("customer", true, TimeType.LOGICAL);
connector.tableOperations().create("rental", true, TimeType.LOGICAL);
}
use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.
the class TestAccumuloQueryVisitor method setUp.
@Before
public void setUp() throws Exception {
this.translator = new AccumuloExecutionFactory();
this.translator.start();
TransformationMetadata metadata = RealMetadataFactory.fromDDL(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("sampledb.ddl")), "sakila", "rental");
this.utility = new TranslationUtility(metadata);
}
use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.
the class TestNativeCassandra method testNativeQuery.
@Test
public void testNativeQuery() throws Exception {
CassandraExecutionFactory cef = new CassandraExecutionFactory();
cef.setSupportsDirectQueryProcedure(true);
String input = "call proc('a', 1)";
TransformationMetadata metadata = RealMetadataFactory.fromDDL("create foreign procedure proc (in x string, in y integer) options (\"teiid_rel:native-query\" 'delete from $1 where $2')", "x", "y");
TranslationUtility util = new TranslationUtility(metadata);
Command command = util.parseCommand(input);
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
CassandraConnection connection = Mockito.mock(CassandraConnection.class);
ResultSetFuture rsf = Mockito.mock(ResultSetFuture.class);
Mockito.stub(connection.executeQuery("delete from 'a' where 1")).toReturn(rsf);
Execution execution = cef.createExecution(command, ec, rm, connection);
execution.execute();
Mockito.verify(connection).executeQuery("delete from 'a' where 1");
}
use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.
the class TestUpdates method testBatchedUpdate.
@Test
public void testBatchedUpdate() throws TranslatorException {
CassandraExecutionFactory cef = new CassandraExecutionFactory();
String input = "insert into pm1.g1 (e1) values ('a')";
TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
Command command = util.parseCommand(input);
Command command1 = util.parseCommand("update pm1.g1 set e1 = 'b'");
command = new BatchedUpdates(Arrays.asList(command, command1));
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
CassandraConnection connection = Mockito.mock(CassandraConnection.class);
ResultSetFuture rsf = Mockito.mock(ResultSetFuture.class);
Mockito.stub(rsf.isDone()).toReturn(true);
Mockito.stub(connection.executeBatch(Arrays.asList("INSERT INTO g1 (e1) VALUES ('a')", "UPDATE g1 SET e1 = 'b'"))).toReturn(rsf);
UpdateExecution execution = (UpdateExecution) cef.createExecution(command, ec, rm, connection);
execution.execute();
assertArrayEquals(new int[] { 2 }, execution.getUpdateCounts());
Mockito.verify(connection).executeBatch(Arrays.asList("INSERT INTO g1 (e1) VALUES ('a')", "UPDATE g1 SET e1 = 'b'"));
}
use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.
the class TestSimpleDBSQLVisitor method testIntersection.
@Test
public void testIntersection() throws Exception {
SimpleDBExecutionFactory translator = new SimpleDBExecutionFactory();
translator.start();
MetadataFactory mf = TestDDLParser.helpParse("create foreign table item (\"itemName()\" integer, attribute string[]);", "y");
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
TranslationUtility tu = new TranslationUtility(metadata);
Command c = tu.parseCommand("select * from item where simpledb.intersection(attribute,'1', '2')");
SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
visitor.append(c);
assertEquals("SELECT attribute FROM item WHERE attribute = '1' INTERSECTION attribute = '2'", visitor.toString());
}
Aggregations