Search in sources :

Example 1 with MockColumn

use of org.apache.drill.exec.store.mock.MockTableDef.MockColumn in project drill by apache.

the class MockGroupScanPOP method clone.

@Override
public GroupScan clone(List<SchemaPath> columns) {
    if (columns.isEmpty()) {
        throw new IllegalArgumentException("No columns for mock scan");
    }
    List<MockColumn> mockCols = new ArrayList<>();
    Pattern p = Pattern.compile("(\\w+)_([isdb])(\\d*)");
    for (SchemaPath path : columns) {
        String col = path.getLastSegment().getNameSegment().getPath();
        if (col.equals("*")) {
            return this;
        }
        Matcher m = p.matcher(col);
        if (!m.matches()) {
            throw new IllegalArgumentException("Badly formatted mock column name: " + col);
        }
        @SuppressWarnings("unused") String name = m.group(1);
        String type = m.group(2);
        String length = m.group(3);
        int width = 10;
        if (!length.isEmpty()) {
            width = Integer.parseInt(length);
        }
        MinorType minorType;
        switch(type) {
            case "i":
                minorType = MinorType.INT;
                break;
            case "s":
                minorType = MinorType.VARCHAR;
                break;
            case "d":
                minorType = MinorType.FLOAT8;
                break;
            case "b":
                minorType = MinorType.BIT;
                break;
            default:
                throw new IllegalArgumentException("Unsupported field type " + type + " for mock column " + col);
        }
        MockTableDef.MockColumn mockCol = new MockColumn(col, minorType, DataMode.REQUIRED, width, 0, 0, null, 1, null);
        mockCols.add(mockCol);
    }
    MockScanEntry entry = readEntries.get(0);
    MockColumn[] types = new MockColumn[mockCols.size()];
    mockCols.toArray(types);
    MockScanEntry newEntry = new MockScanEntry(entry.records, true, 0, 1, types);
    List<MockScanEntry> newEntries = new ArrayList<>();
    newEntries.add(newEntry);
    return new MockGroupScanPOP(url, newEntries);
}
Also used : Pattern(java.util.regex.Pattern) MockScanEntry(org.apache.drill.exec.store.mock.MockTableDef.MockScanEntry) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) SchemaPath(org.apache.drill.common.expression.SchemaPath) MockColumn(org.apache.drill.exec.store.mock.MockTableDef.MockColumn) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) MockColumn(org.apache.drill.exec.store.mock.MockTableDef.MockColumn)

Example 2 with MockColumn

use of org.apache.drill.exec.store.mock.MockTableDef.MockColumn in project drill by apache.

the class ExtendedMockRecordReader method buildColumnDefs.

private ColumnDef[] buildColumnDefs() {
    List<ColumnDef> defs = new ArrayList<>();
    // Look for duplicate names. Bad things happen when the same name
    // appears twice. We must do this here because some tests create
    // a physical plan directly, meaning that this is the first
    // opportunity to review the column definitions.
    Set<String> names = new HashSet<>();
    MockColumn[] cols = config.getTypes();
    for (int i = 0; i < cols.length; i++) {
        MockTableDef.MockColumn col = cols[i];
        if (names.contains(col.name)) {
            throw new IllegalArgumentException("Duplicate column name: " + col.name);
        }
        names.add(col.name);
        int repeat = Math.min(1, col.getRepeatCount());
        if (repeat == 1) {
            defs.add(new ColumnDef(col));
        } else {
            for (int j = 0; j < repeat; j++) {
                defs.add(new ColumnDef(col, j + 1));
            }
        }
    }
    ColumnDef[] defArray = new ColumnDef[defs.size()];
    defs.toArray(defArray);
    return defArray;
}
Also used : ArrayList(java.util.ArrayList) MockColumn(org.apache.drill.exec.store.mock.MockTableDef.MockColumn) MockColumn(org.apache.drill.exec.store.mock.MockTableDef.MockColumn) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)2 MockColumn (org.apache.drill.exec.store.mock.MockTableDef.MockColumn)2 HashSet (java.util.HashSet)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 SchemaPath (org.apache.drill.common.expression.SchemaPath)1 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)1 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)1 MockScanEntry (org.apache.drill.exec.store.mock.MockTableDef.MockScanEntry)1