Search in sources :

Example 1 with DrillColumnMetaDataList

use of org.apache.drill.jdbc.impl.DrillColumnMetaDataList in project drill by apache.

the class DrillColumnMetaDataListTest method setUp.

@Before
public void setUp() throws Exception {
    emptyList = new DrillColumnMetaDataList();
    // Create mock columns
    final MaterializedField exampleIntField = mock(MaterializedField.class);
    MajorType exampleIntType = MajorType.newBuilder().setMinorType(MinorType.INT).build();
    when(exampleIntField.getPath()).thenReturn("/path/to/testInt");
    when(exampleIntField.getType()).thenReturn(exampleIntType);
    when(exampleIntField.getDataMode()).thenReturn(DataMode.OPTIONAL);
    final MaterializedField exampleStringField = mock(MaterializedField.class);
    MajorType exampleStringType = MajorType.newBuilder().setMinorType(MinorType.VARCHAR).build();
    when(exampleStringField.getPath()).thenReturn("/path/to/testString");
    when(exampleStringField.getType()).thenReturn(exampleStringType);
    when(exampleStringField.getDataMode()).thenReturn(DataMode.REQUIRED);
    oneElementList = new DrillColumnMetaDataList();
    BatchSchema oneElementSchema = mock(BatchSchema.class);
    when(oneElementSchema.getFieldCount()).thenReturn(1);
    doAnswer(new Answer<MaterializedField>() {

        @Override
        public MaterializedField answer(InvocationOnMock invocationOnMock) throws Throwable {
            Integer index = (Integer) invocationOnMock.getArguments()[0];
            if (index == 0) {
                return exampleIntField;
            }
            return null;
        }
    }).when(oneElementSchema).getColumn(Mockito.anyInt());
    List<Class<?>> oneClassList = new ArrayList<>();
    oneClassList.add(Integer.class);
    oneElementList.updateColumnMetaData("testCatalog", "testSchema", "testTable", oneElementSchema, oneClassList);
    twoElementList = new DrillColumnMetaDataList();
    BatchSchema twoElementSchema = mock(BatchSchema.class);
    when(twoElementSchema.getFieldCount()).thenReturn(2);
    doAnswer(new Answer<MaterializedField>() {

        @Override
        public MaterializedField answer(InvocationOnMock invocationOnMock) throws Throwable {
            Integer index = (Integer) invocationOnMock.getArguments()[0];
            if (index == 0) {
                return exampleIntField;
            } else if (index == 1) {
                return exampleStringField;
            }
            return null;
        }
    }).when(twoElementSchema).getColumn(Mockito.anyInt());
    List<Class<?>> twoClassList = new ArrayList<>();
    twoClassList.add(Integer.class);
    twoClassList.add(String.class);
    twoElementList.updateColumnMetaData("testCatalog", "testSchema", "testTable", twoElementSchema, twoClassList);
}
Also used : BatchSchema(org.apache.drill.exec.record.BatchSchema) DrillColumnMetaDataList(org.apache.drill.jdbc.impl.DrillColumnMetaDataList) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) ArrayList(java.util.ArrayList) MaterializedField(org.apache.drill.exec.record.MaterializedField) Before(org.junit.Before)

Aggregations

ArrayList (java.util.ArrayList)1 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)1 BatchSchema (org.apache.drill.exec.record.BatchSchema)1 MaterializedField (org.apache.drill.exec.record.MaterializedField)1 DrillColumnMetaDataList (org.apache.drill.jdbc.impl.DrillColumnMetaDataList)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1