use of org.apache.drill.exec.store.mock.MockTableDef.MockScanEntry in project drill by apache.
the class MockScanBatchCreator method getBatch.
//private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(MockScanBatchCreator.class);
@Override
public ScanBatch getBatch(FragmentContext context, MockSubScanPOP config, List<RecordBatch> children) throws ExecutionSetupException {
Preconditions.checkArgument(children.isEmpty());
final List<MockScanEntry> entries = config.getReadEntries();
final List<RecordReader> readers = Lists.newArrayList();
for (final MockTableDef.MockScanEntry e : entries) {
if (e.isExtended()) {
readers.add(new ExtendedMockRecordReader(context, e));
} else {
readers.add(new MockRecordReader(context, e));
}
}
return new ScanBatch(config, context, readers.iterator());
}
use of org.apache.drill.exec.store.mock.MockTableDef.MockScanEntry in project drill by axbaretto.
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 (SchemaPath.DYNAMIC_STAR.equals(col)) {
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.MockScanEntry 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 (SchemaPath.DYNAMIC_STAR.equals(col)) {
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.MockScanEntry in project drill by axbaretto.
the class MockGroupScanPOP method applyAssignments.
@SuppressWarnings("unchecked")
@Override
public void applyAssignments(List<DrillbitEndpoint> endpoints) {
Preconditions.checkArgument(endpoints.size() <= getReadEntries().size());
mappings = new LinkedList[endpoints.size()];
int i = 0;
for (MockScanEntry e : this.getReadEntries()) {
if (i == endpoints.size()) {
i -= endpoints.size();
}
LinkedList<MockScanEntry> entries = mappings[i];
if (entries == null) {
entries = new LinkedList<MockScanEntry>();
mappings[i] = entries;
}
entries.add(e);
i++;
}
}
use of org.apache.drill.exec.store.mock.MockTableDef.MockScanEntry in project drill by axbaretto.
the class MockScanBatchCreator method getBatch.
@Override
public ScanBatch getBatch(ExecutorFragmentContext context, MockSubScanPOP config, List<RecordBatch> children) throws ExecutionSetupException {
Preconditions.checkArgument(children.isEmpty());
final List<MockScanEntry> entries = config.getReadEntries();
final List<RecordReader> readers = new LinkedList<>();
for (final MockTableDef.MockScanEntry e : entries) {
if (e.isExtended()) {
readers.add(new ExtendedMockRecordReader(e));
} else {
readers.add(new MockRecordReader(context, e));
}
}
return new ScanBatch(config, context, readers);
}
Aggregations