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);
}
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;
}
Aggregations