Search in sources :

Example 16 with Accessor

use of org.apache.calcite.avatica.util.Cursor.Accessor in project calcite-avatica by apache.

the class StructImplTest method testStructAccessor.

@Test
public void testStructAccessor() throws Exception {
    // Create rows based on the inputValues data
    List<List<Object>> rows = new ArrayList<>();
    for (Object o : columnInputBundle.inputValues) {
        rows.add(Collections.singletonList(o));
    }
    try (Cursor cursor = new ListIteratorCursor(rows.iterator())) {
        List<Accessor> accessors = cursor.createAccessors(Collections.singletonList(columnInputBundle.metaData), Unsafe.localCalendar(), null);
        Accessor accessor = accessors.get(0);
        int i = 0;
        while (cursor.next()) {
            Struct s = accessor.getObject(Struct.class);
            Object[] expectedStructAttributes = columnInputBundle.expectedValues.get(i).getAttributes();
            Object[] actualStructAttributes = s.getAttributes();
            assertArrayEquals(expectedStructAttributes, actualStructAttributes);
            i++;
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Accessor(org.apache.calcite.avatica.util.Cursor.Accessor) Struct(java.sql.Struct) Test(org.junit.Test)

Aggregations

Accessor (org.apache.calcite.avatica.util.Cursor.Accessor)16 List (java.util.List)13 ColumnMetaData (org.apache.calcite.avatica.ColumnMetaData)13 Test (org.junit.Test)11 ArrayType (org.apache.calcite.avatica.ColumnMetaData.ArrayType)7 Array (java.sql.Array)5 ArrayList (java.util.ArrayList)5 ScalarType (org.apache.calcite.avatica.ColumnMetaData.ScalarType)5 Struct (java.sql.Struct)4 StructType (org.apache.calcite.avatica.ColumnMetaData.StructType)3 Rep (org.apache.calcite.avatica.ColumnMetaData.Rep)2 ArrayAccessor (org.apache.calcite.avatica.util.AbstractCursor.ArrayAccessor)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Calendar (java.util.Calendar)1 ArrayImpl (org.apache.calcite.avatica.util.ArrayImpl)1 Cursor (org.apache.calcite.avatica.util.Cursor)1 ListIteratorCursor (org.apache.calcite.avatica.util.ListIteratorCursor)1