Search in sources :

Example 1 with SheetRow

use of org.teiid.translator.google.api.result.SheetRow in project teiid by teiid.

the class SpreadsheetDataRetrievalTest method vGroupBy.

@Test
public void vGroupBy() {
    List<SheetRow> result = query("s1", "SELECT E,max(D) GROUP BY E", 0, 12);
    Assert.assertEquals(3, result.size());
    // TODO commas!? WTF!
    Assert.assertEquals(new SheetRow(new String[] { "Brno", "50,000" }), result.get(1));
    Assert.assertEquals(new SheetRow(new String[] { "Praha", "66,000" }), result.get(2));
    Assert.assertEquals(new SheetRow(new String[] { "Bratislava", "60,000" }), result.get(0));
}
Also used : SheetRow(org.teiid.translator.google.api.result.SheetRow) Test(org.junit.Test)

Example 2 with SheetRow

use of org.teiid.translator.google.api.result.SheetRow in project teiid by teiid.

the class SpreadsheetDataRetrievalTest method assertSimpleResultDataProtorol.

private void assertSimpleResultDataProtorol(PartialResultExecutor partialExecutor) {
    List<SheetRow> result = partialExecutor.getResultsBatch(0, 4);
    Assert.assertEquals(new SheetRow(new String[] { "0", "Michal", "Abaffy", "$26,000", "Brno", "01-17-1987" }), result.get(0));
    Assert.assertEquals(new SheetRow(new String[] { "2", "Filip", "Eliáš", "$50,000", "Brno", "02-18-1974" }), result.get(1));
    Assert.assertEquals(4, result.size());
    result = partialExecutor.getResultsBatch(1, 13);
    Assert.assertEquals(11, result.size());
    result = partialExecutor.getResultsBatch(10, 3);
    Assert.assertEquals(new SheetRow(new String[] { "11", "Pavel", "Macik", "$28,000", "Bratislava", "04-08-1954" }), result.get(1));
    Assert.assertEquals(2, result.size());
    result = partialExecutor.getResultsBatch(13, 2);
    Assert.assertEquals(0, result.size());
}
Also used : SheetRow(org.teiid.translator.google.api.result.SheetRow)

Example 3 with SheetRow

use of org.teiid.translator.google.api.result.SheetRow in project teiid by teiid.

the class TestNativeSpreadsheet method testDirect.

@Test
public void testDirect() throws TranslatorException {
    SpreadsheetExecutionFactory sef = new SpreadsheetExecutionFactory();
    sef.setSupportsDirectQueryProcedure(true);
    String input = "call native('worksheet=x;query=$1 foo;limit=2', 'a')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    GoogleSpreadsheetConnection connection = Mockito.mock(GoogleSpreadsheetConnection.class);
    RowsResult result = Mockito.mock(RowsResult.class);
    Mockito.stub(result.iterator()).toReturn(Arrays.asList(new SheetRow()).iterator());
    Mockito.stub(connection.executeQuery("x", "'a' foo", null, 2, 0)).toReturn(result);
    ResultSetExecution execution = (ResultSetExecution) sef.createExecution(command, ec, rm, connection);
    execution.execute();
    List<?> vals = execution.next();
    assertTrue(vals.get(0) instanceof Object[]);
}
Also used : TranslationUtility(org.teiid.cdk.api.TranslationUtility) RowsResult(org.teiid.translator.google.api.result.RowsResult) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) SheetRow(org.teiid.translator.google.api.result.SheetRow) Command(org.teiid.language.Command) GoogleSpreadsheetConnection(org.teiid.translator.google.api.GoogleSpreadsheetConnection) Test(org.junit.Test)

Example 4 with SheetRow

use of org.teiid.translator.google.api.result.SheetRow in project teiid by teiid.

the class RowsResultTest method twoBatchCallsNeeded.

@Test
public void twoBatchCallsNeeded() {
    final List<SheetRow> firstPart = new ArrayList<SheetRow>();
    final List<SheetRow> secondPart = new ArrayList<SheetRow>();
    final List<SheetRow> all = new ArrayList<SheetRow>();
    firstPart.add(new SheetRow(new String[] { "a", "b", "c" }));
    firstPart.add(new SheetRow(new String[] { "a2", "b2", "c2" }));
    firstPart.add(new SheetRow(new String[] { "a3", "b3", "c3" }));
    secondPart.add(new SheetRow(new String[] { "a4", "b4", "c4" }));
    secondPart.add(new SheetRow(new String[] { "a5", "b5", "c5" }));
    all.addAll(firstPart);
    all.addAll(secondPart);
    RowsResult result = new RowsResult(new PartialResultExecutor() {

        int called = 0;

        @Override
        public List<SheetRow> getResultsBatch(int startIndex, int endIndex) {
            if (called++ > 2)
                Assert.fail("getResultsBatch at most twice");
            if (called == 1) {
                return firstPart;
            } else if (called == 2) {
                return secondPart;
            }
            // Shouldn't reach here.
            return null;
        }
    }, 3);
    int i = 0;
    for (SheetRow row : result) {
        Assert.assertEquals(row, all.get(i++));
    }
    Assert.assertEquals("Six rows should be in the result", 5, i);
}
Also used : SheetRow(org.teiid.translator.google.api.result.SheetRow) ArrayList(java.util.ArrayList) PartialResultExecutor(org.teiid.translator.google.api.result.PartialResultExecutor) List(java.util.List) ArrayList(java.util.ArrayList) RowsResult(org.teiid.translator.google.api.result.RowsResult) Test(org.junit.Test)

Example 5 with SheetRow

use of org.teiid.translator.google.api.result.SheetRow in project teiid by teiid.

the class RowsResultTest method noRows.

@Test
public void noRows() {
    final List<SheetRow> all = new ArrayList<SheetRow>();
    RowsResult result = new RowsResult(new PartialResultExecutor() {

        int called = 0;

        @Override
        public List<SheetRow> getResultsBatch(int startIndex, int endIndex) {
            if (called++ > 1)
                Assert.fail("getResultsBatch at once");
            return all;
        }
    }, 3);
    int i = 0;
    for (SheetRow row : result) {
        i++;
    }
    Assert.assertEquals("No iterations should be made", 0, i);
}
Also used : SheetRow(org.teiid.translator.google.api.result.SheetRow) ArrayList(java.util.ArrayList) PartialResultExecutor(org.teiid.translator.google.api.result.PartialResultExecutor) List(java.util.List) ArrayList(java.util.ArrayList) RowsResult(org.teiid.translator.google.api.result.RowsResult) Test(org.junit.Test)

Aggregations

SheetRow (org.teiid.translator.google.api.result.SheetRow)9 Test (org.junit.Test)8 RowsResult (org.teiid.translator.google.api.result.RowsResult)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 PartialResultExecutor (org.teiid.translator.google.api.result.PartialResultExecutor)6 TranslationUtility (org.teiid.cdk.api.TranslationUtility)1 Command (org.teiid.language.Command)1 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)1 ExecutionContext (org.teiid.translator.ExecutionContext)1 ResultSetExecution (org.teiid.translator.ResultSetExecution)1 GoogleSpreadsheetConnection (org.teiid.translator.google.api.GoogleSpreadsheetConnection)1