use of org.teiid.language.Command in project teiid by teiid.
the class TestSimpleDBExecution method testInsert.
@Test
public void testInsert() throws Exception {
String query = "insert into item (\"itemName()\", attribute, somedate, strarray) values ('one', 'value', {ts '2014-04-04 10:50:45'}, ('1', '2'))";
Command cmd = utility.parseCommand(query);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
UpdateExecution exec = translator.createUpdateExecution(cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
exec.execute();
SimpleDBInsertVisitor visitor = new SimpleDBInsertVisitor();
visitor.visitNode(cmd);
ArgumentCaptor<Iterator> argument = ArgumentCaptor.forClass(Iterator.class);
ArgumentCaptor<String> itemName = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<ArrayList> columns = ArgumentCaptor.forClass(ArrayList.class);
Mockito.verify(connection).performInsert(itemName.capture(), columns.capture(), argument.capture());
assertEquals("item", itemName.getValue());
List<?> values = (List<?>) argument.getValue().next();
assertEquals("value", values.get(1));
assertEquals("2014-04-04 10:50:45.0", values.get(2).toString());
assertEquals("1,2,", arrayToStr((String[]) values.get(3)));
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestSimpleDBExecution method testSelect.
@Test
public void testSelect() throws Exception {
SelectResult result = new SelectResult();
result.setItems(mockResult());
String query = "select * from item where attribute > 'name'";
Mockito.stub(connection.performSelect(Mockito.anyString(), Mockito.anyString())).toReturn(result);
Command cmd = utility.parseCommand(query);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
Mockito.stub(context.getBatchSize()).toReturn(10);
ResultSetExecution exec = translator.createResultSetExecution((Select) cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
exec.execute();
exec.next();
Mockito.verify(connection).performSelect("SELECT attribute, somedate, strarray FROM item WHERE attribute > 'name' LIMIT 10", null);
// cap at 2500
Mockito.stub(context.getBatchSize()).toReturn(4000);
exec = translator.createResultSetExecution((Select) cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
exec.execute();
exec.next();
Mockito.verify(connection).performSelect("SELECT attribute, somedate, strarray FROM item WHERE attribute > 'name' LIMIT 2500", null);
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestSimpleDBSQLVisitor method testIN.
@Test
public void testIN() throws Exception {
TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign table item (\"itemName()\" integer, attribute string);", "x", "y");
TranslationUtility tu = new TranslationUtility(tm);
Command c = tu.parseCommand("select * from item where \"itemName()\" in (1, 2)");
SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
visitor.append(c);
assertEquals("SELECT attribute FROM item WHERE itemName() IN ('1', '2')", visitor.toString());
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestSimpleDBSQLVisitor method testEveryNotNull.
@Test
public void testEveryNotNull() 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.every(attribute) is not null");
SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
visitor.append(c);
assertEquals("SELECT attribute FROM item WHERE SIMPLEDB.EVERY(attribute) IS NOT NULL", visitor.toString());
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestSimpleDBSQLVisitor method testOrderByAllow.
@Test
public void testOrderByAllow() throws Exception {
TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign table item (\"itemName()\" string, attribute string);", "x", "y");
TranslationUtility tu = new TranslationUtility(tm);
Command c = tu.parseCommand("select * from item where \"itemName()\" = 'name' order by \"itemName()\"");
SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
visitor.append(c);
visitor.checkExceptions();
assertEquals("SELECT attribute FROM item WHERE itemName() = 'name' ORDER BY itemName()", visitor.toString());
}
Aggregations