Search in sources :

Example 6 with RowsResult

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

the class RowsResultTest method offsetTestOne.

@Test
public void offsetTestOne() {
    final List<SheetRow> all = new ArrayList<SheetRow>();
    all.add(new SheetRow(new String[] { "a", "b", "c" }));
    all.add(new SheetRow(new String[] { "a2", "b2", "c2" }));
    all.add(new SheetRow(new String[] { "a3", "b3", "c3" }));
    all.add(new SheetRow(new String[] { "a4", "b4", "c4" }));
    all.add(new SheetRow(new String[] { "a5", "b5", "c5" }));
    all.add(new SheetRow(new String[] { "a6", "b6", "c6" }));
    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 3 times");
            ArrayList<SheetRow> result = new ArrayList<SheetRow>();
            if (called == 1) {
                result.add(all.get(1));
                result.add(all.get(2));
            } else if (called == 2) {
                result.add(all.get(3));
                result.add(all.get(4));
            } else if (called == 3)
                result.add(all.get(5));
            return result;
        }
    }, 2);
    result.setOffset(1);
    result.setLimit(6);
    int i = 1;
    for (SheetRow row : result) {
        Assert.assertEquals(all.get(i++), row);
    }
    Assert.assertEquals("5 iterations should be made", 5, i - 1);
}
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 7 with RowsResult

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

the class RowsResultTest method offsetTest.

@Test
public void offsetTest() {
    final List<SheetRow> all = new ArrayList<SheetRow>();
    all.add(new SheetRow(new String[] { "a", "b", "c" }));
    all.add(new SheetRow(new String[] { "a2", "b2", "c2" }));
    all.add(new SheetRow(new String[] { "a3", "b3", "c3" }));
    all.add(new SheetRow(new String[] { "a4", "b4", "c4" }));
    all.add(new SheetRow(new String[] { "a5", "b5", "c5" }));
    all.add(new SheetRow(new String[] { "a6", "b6", "c6" }));
    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 most 2 times");
            ArrayList<SheetRow> result = new ArrayList<SheetRow>();
            if (called == 1) {
                result.add(all.get(3));
                result.add(all.get(4));
            } else if (called == 2)
                result.add(all.get(5));
            return result;
        }
    }, 2);
    result.setOffset(3);
    result.setLimit(3);
    int i = 3;
    for (SheetRow row : result) {
        Assert.assertEquals(all.get(i++), row);
    }
    Assert.assertEquals("3 iterations should be made", 3, i - 3);
}
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 8 with RowsResult

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

the class RowsResultTest method simpleIteration.

@Test
public void simpleIteration() {
    final List<SheetRow> rows = new ArrayList<SheetRow>();
    rows.add(new SheetRow(new String[] { "a", "b", "c" }));
    rows.add(new SheetRow(new String[] { "a2", "b2", "c2" }));
    rows.add(new SheetRow(new String[] { "a3", "b3", "c3" }));
    RowsResult result = new RowsResult(new PartialResultExecutor() {

        boolean called = false;

        @Override
        public List<SheetRow> getResultsBatch(int startIndex, int endIndex) {
            if (called)
                Assert.fail("getResultsBatch should've been called only once");
            called = true;
            return rows;
        }
    }, 10);
    int i = 0;
    for (SheetRow row : result) {
        Assert.assertEquals(row, rows.get(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

RowsResult (org.teiid.translator.google.api.result.RowsResult)8 Test (org.junit.Test)7 SheetRow (org.teiid.translator.google.api.result.SheetRow)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