Search in sources :

Example 1 with MockScanEntry

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());
}
Also used : MockScanEntry(org.apache.drill.exec.store.mock.MockTableDef.MockScanEntry) RecordReader(org.apache.drill.exec.store.RecordReader) MockScanEntry(org.apache.drill.exec.store.mock.MockTableDef.MockScanEntry) ScanBatch(org.apache.drill.exec.physical.impl.ScanBatch)

Example 2 with MockScanEntry

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);
}
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 3 with MockScanEntry

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);
}
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 4 with MockScanEntry

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++;
    }
}
Also used : MockScanEntry(org.apache.drill.exec.store.mock.MockTableDef.MockScanEntry) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)

Example 5 with MockScanEntry

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);
}
Also used : MockScanEntry(org.apache.drill.exec.store.mock.MockTableDef.MockScanEntry) RecordReader(org.apache.drill.exec.store.RecordReader) MockScanEntry(org.apache.drill.exec.store.mock.MockTableDef.MockScanEntry) ScanBatch(org.apache.drill.exec.physical.impl.ScanBatch) LinkedList(java.util.LinkedList)

Aggregations

MockScanEntry (org.apache.drill.exec.store.mock.MockTableDef.MockScanEntry)8 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)4 SchemaPath (org.apache.drill.common.expression.SchemaPath)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)2 ScanBatch (org.apache.drill.exec.physical.impl.ScanBatch)2 RecordReader (org.apache.drill.exec.store.RecordReader)2 MockColumn (org.apache.drill.exec.store.mock.MockTableDef.MockColumn)2 OperatorRecordBatch (org.apache.drill.exec.physical.impl.protocol.OperatorRecordBatch)1 ScanOperatorExec (org.apache.drill.exec.physical.impl.scan.ScanOperatorExec)1 BasicScanFactory (org.apache.drill.exec.physical.impl.scan.framework.BasicScanFactory)1 ManagedReader (org.apache.drill.exec.physical.impl.scan.framework.ManagedReader)1 ManagedScanFramework (org.apache.drill.exec.physical.impl.scan.framework.ManagedScanFramework)1 ScanFrameworkBuilder (org.apache.drill.exec.physical.impl.scan.framework.ManagedScanFramework.ScanFrameworkBuilder)1