Search in sources :

Example 96 with DrillRuntimeException

use of org.apache.drill.common.exceptions.DrillRuntimeException in project drill by apache.

the class AvroRecordReader method next.

@Override
public int next() {
    final Stopwatch watch = Stopwatch.createStarted();
    if (reader == null) {
        throw new IllegalStateException("Avro reader is not open.");
    }
    if (!reader.hasNext()) {
        return 0;
    }
    int recordCount = 0;
    writer.allocate();
    writer.reset();
    try {
        for (GenericContainer container = null; recordCount < DEFAULT_BATCH_SIZE && reader.hasNext() && !reader.pastSync(end); recordCount++) {
            writer.setPosition(recordCount);
            container = reader.next(container);
            processRecord(container, container.getSchema());
        }
        writer.setValueCount(recordCount);
    } catch (IOException e) {
        throw new DrillRuntimeException(e);
    }
    logger.debug("Read {} records in {} ms", recordCount, watch.elapsed(TimeUnit.MILLISECONDS));
    return recordCount;
}
Also used : Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) GenericContainer(org.apache.avro.generic.GenericContainer) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException)

Example 97 with DrillRuntimeException

use of org.apache.drill.common.exceptions.DrillRuntimeException in project drill by apache.

the class FileSelection method createFromDirectories.

public static FileSelection createFromDirectories(final List<String> dirPaths, final FileSelection selection, final String cacheFileRoot) {
    Stopwatch timer = Stopwatch.createStarted();
    final String root = selection.getSelectionRoot();
    if (Strings.isNullOrEmpty(root)) {
        throw new DrillRuntimeException("Selection root is null or empty" + root);
    }
    if (dirPaths == null || dirPaths.isEmpty()) {
        throw new DrillRuntimeException("List of directories is null or empty");
    }
    List<String> dirs = Lists.newArrayList();
    if (selection.hadWildcard()) {
        // for wildcard the directory list should have already been expanded
        for (FileStatus status : selection.getFileStatuses()) {
            dirs.add(status.getPath().toString());
        }
    } else {
        for (String s : dirPaths) {
            dirs.add(s);
        }
    }
    final Path rootPath = handleWildCard(root);
    // final URI uri = dirPaths.get(0).toUri();
    final URI uri = selection.getFileStatuses().get(0).getPath().toUri();
    final Path path = new Path(uri.getScheme(), uri.getAuthority(), rootPath.toUri().getPath());
    FileSelection fileSel = new FileSelection(null, dirs, path.toString(), cacheFileRoot, false);
    fileSel.setHadWildcard(selection.hadWildcard());
    logger.info("FileSelection.createFromDirectories() took {} ms ", timer.elapsed(TimeUnit.MILLISECONDS));
    return fileSel;
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) Stopwatch(com.google.common.base.Stopwatch) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) URI(java.net.URI)

Example 98 with DrillRuntimeException

use of org.apache.drill.common.exceptions.DrillRuntimeException in project drill by apache.

the class DrillSimpleFuncHolder method renderEnd.

@Override
public HoldingContainer renderEnd(ClassGenerator<?> classGenerator, HoldingContainer[] inputVariables, JVar[] workspaceJVars, FieldReference fieldReference) {
    //for the argument is not, then raise exception.
    for (int i = 0; i < inputVariables.length; i++) {
        if (getParameters()[i].isConstant() && !inputVariables[i].isConstant()) {
            throw new DrillRuntimeException(String.format("The argument '%s' of Function '%s' has to be constant!", getParameters()[i].getName(), this.getRegisteredNames()[0]));
        }
    }
    generateBody(classGenerator, BlockType.SETUP, setupBody(), inputVariables, workspaceJVars, true);
    HoldingContainer c = generateEvalBody(classGenerator, inputVariables, evalBody(), workspaceJVars, fieldReference);
    generateBody(classGenerator, BlockType.RESET, resetBody(), null, workspaceJVars, false);
    generateBody(classGenerator, BlockType.CLEANUP, cleanupBody(), null, workspaceJVars, false);
    return c;
}
Also used : HoldingContainer(org.apache.drill.exec.expr.ClassGenerator.HoldingContainer) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException)

Example 99 with DrillRuntimeException

use of org.apache.drill.common.exceptions.DrillRuntimeException in project drill by apache.

the class MapUtility method writeToMapFromReader.

/*
   * Function to read a value from the field reader, detect the type, construct the appropriate value holder
   * and use the value holder to write to the Map.
   */
// TODO : This should be templatized and generated using freemarker
public static void writeToMapFromReader(FieldReader fieldReader, BaseWriter.MapWriter mapWriter) {
    try {
        MajorType valueMajorType = fieldReader.getType();
        MinorType valueMinorType = valueMajorType.getMinorType();
        boolean repeated = false;
        if (valueMajorType.getMode() == TypeProtos.DataMode.REPEATED) {
            repeated = true;
        }
        switch(valueMinorType) {
            case TINYINT:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).tinyInt());
                } else {
                    fieldReader.copyAsValue(mapWriter.tinyInt(MappifyUtility.fieldValue));
                }
                break;
            case SMALLINT:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).smallInt());
                } else {
                    fieldReader.copyAsValue(mapWriter.smallInt(MappifyUtility.fieldValue));
                }
                break;
            case BIGINT:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).bigInt());
                } else {
                    fieldReader.copyAsValue(mapWriter.bigInt(MappifyUtility.fieldValue));
                }
                break;
            case INT:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).integer());
                } else {
                    fieldReader.copyAsValue(mapWriter.integer(MappifyUtility.fieldValue));
                }
                break;
            case UINT1:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).uInt1());
                } else {
                    fieldReader.copyAsValue(mapWriter.uInt1(MappifyUtility.fieldValue));
                }
                break;
            case UINT2:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).uInt2());
                } else {
                    fieldReader.copyAsValue(mapWriter.uInt2(MappifyUtility.fieldValue));
                }
                break;
            case UINT4:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).uInt4());
                } else {
                    fieldReader.copyAsValue(mapWriter.uInt4(MappifyUtility.fieldValue));
                }
                break;
            case UINT8:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).uInt8());
                } else {
                    fieldReader.copyAsValue(mapWriter.uInt8(MappifyUtility.fieldValue));
                }
                break;
            case DECIMAL9:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).decimal9());
                } else {
                    fieldReader.copyAsValue(mapWriter.decimal9(MappifyUtility.fieldValue));
                }
                break;
            case DECIMAL18:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).decimal18());
                } else {
                    fieldReader.copyAsValue(mapWriter.decimal18(MappifyUtility.fieldValue));
                }
                break;
            case DECIMAL28SPARSE:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).decimal28Sparse());
                } else {
                    fieldReader.copyAsValue(mapWriter.decimal28Sparse(MappifyUtility.fieldValue));
                }
                break;
            case DECIMAL38SPARSE:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).decimal38Sparse());
                } else {
                    fieldReader.copyAsValue(mapWriter.decimal38Sparse(MappifyUtility.fieldValue));
                }
                break;
            case DATE:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).date());
                } else {
                    fieldReader.copyAsValue(mapWriter.date(MappifyUtility.fieldValue));
                }
                break;
            case TIME:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).time());
                } else {
                    fieldReader.copyAsValue(mapWriter.time(MappifyUtility.fieldValue));
                }
                break;
            case TIMESTAMP:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).timeStamp());
                } else {
                    fieldReader.copyAsValue(mapWriter.timeStamp(MappifyUtility.fieldValue));
                }
                break;
            case INTERVAL:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).interval());
                } else {
                    fieldReader.copyAsValue(mapWriter.interval(MappifyUtility.fieldValue));
                }
                break;
            case INTERVALDAY:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).intervalDay());
                } else {
                    fieldReader.copyAsValue(mapWriter.intervalDay(MappifyUtility.fieldValue));
                }
                break;
            case INTERVALYEAR:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).intervalYear());
                } else {
                    fieldReader.copyAsValue(mapWriter.intervalYear(MappifyUtility.fieldValue));
                }
                break;
            case FLOAT4:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).float4());
                } else {
                    fieldReader.copyAsValue(mapWriter.float4(MappifyUtility.fieldValue));
                }
                break;
            case FLOAT8:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).float8());
                } else {
                    fieldReader.copyAsValue(mapWriter.float8(MappifyUtility.fieldValue));
                }
                break;
            case BIT:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).bit());
                } else {
                    fieldReader.copyAsValue(mapWriter.bit(MappifyUtility.fieldValue));
                }
                break;
            case VARCHAR:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).varChar());
                } else {
                    fieldReader.copyAsValue(mapWriter.varChar(MappifyUtility.fieldValue));
                }
                break;
            case VARBINARY:
                if (repeated) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).varBinary());
                } else {
                    fieldReader.copyAsValue(mapWriter.varBinary(MappifyUtility.fieldValue));
                }
                break;
            case MAP:
                if (valueMajorType.getMode() == TypeProtos.DataMode.REPEATED) {
                    fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).map());
                } else {
                    fieldReader.copyAsValue(mapWriter.map(MappifyUtility.fieldValue));
                }
                break;
            case LIST:
                fieldReader.copyAsValue(mapWriter.list(MappifyUtility.fieldValue).list());
                break;
            default:
                throw new DrillRuntimeException(String.format("kvgen does not support input of type: %s", valueMinorType));
        }
    } catch (ClassCastException e) {
        final MaterializedField field = fieldReader.getField();
        throw new DrillRuntimeException(String.format(TYPE_MISMATCH_ERROR, field.getPath(), field.getType()));
    }
}
Also used : MajorType(org.apache.drill.common.types.TypeProtos.MajorType) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) MaterializedField(org.apache.drill.exec.record.MaterializedField) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException)

Example 100 with DrillRuntimeException

use of org.apache.drill.common.exceptions.DrillRuntimeException in project drill by apache.

the class AsyncPageReader method nextInternal.

@Override
protected void nextInternal() throws IOException {
    ReadStatus readStatus = null;
    String name = parentColumnReader.columnChunkMetaData.toString();
    try {
        Stopwatch timer = Stopwatch.createStarted();
        parentColumnReader.parentReader.getOperatorContext().getStats().startWait();
        // get the result of execution
        asyncPageRead.poll().get();
        synchronized (pageQueue) {
            boolean pageQueueFull = pageQueue.remainingCapacity() == 0;
            // get the data if no exception has been thrown
            readStatus = pageQueue.take();
            if (readStatus.pageData == null || readStatus == ReadStatus.EMPTY) {
                throw new DrillRuntimeException("Unexpected end of data");
            }
            // have been no new read tasks scheduled. In that case, schedule a new read.
            if (pageQueueFull) {
                asyncPageRead.offer(threadPool.submit(new AsyncPageReaderTask(debugName, pageQueue)));
            }
        }
        long timeBlocked = timer.elapsed(TimeUnit.NANOSECONDS);
        parentColumnReader.parentReader.getOperatorContext().getStats().stopWait();
        stats.timeDiskScanWait.addAndGet(timeBlocked);
        stats.timeDiskScan.addAndGet(readStatus.getDiskScanTime());
        if (readStatus.isDictionaryPage) {
            stats.numDictPageLoads.incrementAndGet();
            stats.timeDictPageLoads.addAndGet(timeBlocked + readStatus.getDiskScanTime());
        } else {
            stats.numDataPageLoads.incrementAndGet();
            stats.timeDataPageLoads.addAndGet(timeBlocked + readStatus.getDiskScanTime());
        }
        pageHeader = readStatus.getPageHeader();
        do {
            if (pageHeader.getType() == PageType.DICTIONARY_PAGE) {
                readDictionaryPageData(readStatus, parentColumnReader);
                // get the result of execution
                asyncPageRead.poll().get();
                synchronized (pageQueue) {
                    boolean pageQueueFull = pageQueue.remainingCapacity() == 0;
                    // get the data if no exception has been thrown
                    readStatus = pageQueue.take();
                    if (readStatus.pageData == null || readStatus == ReadStatus.EMPTY) {
                        break;
                    }
                    // have been no new read tasks scheduled. In that case, schedule a new read.
                    if (pageQueueFull) {
                        asyncPageRead.offer(threadPool.submit(new AsyncPageReaderTask(debugName, pageQueue)));
                    }
                }
                assert (readStatus.pageData != null);
                pageHeader = readStatus.getPageHeader();
            }
        } while (pageHeader.getType() == PageType.DICTIONARY_PAGE);
        pageHeader = readStatus.getPageHeader();
        pageData = getDecompressedPageData(readStatus);
        assert (pageData != null);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (Exception e) {
        handleAndThrowException(e, "Error reading page data");
    }
}
Also used : Stopwatch(com.google.common.base.Stopwatch) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) UserException(org.apache.drill.common.exceptions.UserException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) IOException(java.io.IOException)

Aggregations

DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)184 IOException (java.io.IOException)76 VersionMismatchException (org.apache.drill.exec.exception.VersionMismatchException)18 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)15 UserException (org.apache.drill.common.exceptions.UserException)13 Path (org.apache.hadoop.fs.Path)13 KeeperException (org.apache.zookeeper.KeeperException)12 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)12 NoSuchElementException (java.util.NoSuchElementException)11 Stopwatch (com.google.common.base.Stopwatch)10 TypeProtos (org.apache.drill.common.types.TypeProtos)9 MaterializedField (org.apache.drill.exec.record.MaterializedField)9 Bson (org.bson.conversions.Bson)9 RexNode (org.apache.calcite.rex.RexNode)7 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)7 ArrayList (java.util.ArrayList)6 ValueHolder (org.apache.drill.exec.expr.holders.ValueHolder)6 VarCharHolder (org.apache.drill.exec.expr.holders.VarCharHolder)6 Registry (org.apache.drill.exec.proto.UserBitShared.Registry)6 Admin (org.apache.hadoop.hbase.client.Admin)6