Search in sources :

Example 71 with DrillRuntimeException

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

the class ZookeeperClient method create.

/**
 * Creates the given path without placing any data in.
 *
 * @param path  target path
 */
public void create(final String path) {
    Preconditions.checkNotNull(path, "path is required");
    final String target = PathUtils.join(root, path);
    try {
        curator.create().withMode(mode).forPath(target);
        getCache().rebuildNode(target);
    } catch (final Exception e) {
        throw new DrillRuntimeException("unable to put ", e);
    }
}
Also used : DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) KeeperException(org.apache.zookeeper.KeeperException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException)

Example 72 with DrillRuntimeException

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

the class RemoteFunctionRegistry method prepareStores.

/**
 * Connects to three stores: REGISTRY, UNREGISTRATION, JARS.
 * Puts in REGISTRY store with default instance of remote function registry if store is initiated for the first time.
 * Registers unregistration listener in UNREGISTRATION store.
 */
private void prepareStores(PersistentStoreProvider storeProvider, ClusterCoordinator coordinator) {
    try {
        PersistentStoreConfig<Registry> registrationConfig = PersistentStoreConfig.newProtoBuilder(SchemaUserBitShared.Registry.WRITE, SchemaUserBitShared.Registry.MERGE).name("udf").persist().build();
        registry = storeProvider.getOrCreateVersionedStore(registrationConfig);
        registry.putIfAbsent(registry_path, Registry.getDefaultInstance());
    } catch (StoreException e) {
        throw new DrillRuntimeException("Failure while loading remote registry.", e);
    }
    TransientStoreConfig<String> unregistrationConfig = TransientStoreConfig.newJacksonBuilder(mapper, String.class).name("udf/unregister").build();
    unregistration = coordinator.getOrCreateTransientStore(unregistrationConfig);
    unregistration.addListener(unregistrationListener);
    TransientStoreConfig<String> jarsConfig = TransientStoreConfig.newJacksonBuilder(mapper, String.class).name("udf/jars").build();
    jars = coordinator.getOrCreateTransientStore(jarsConfig);
}
Also used : Registry(org.apache.drill.exec.proto.UserBitShared.Registry) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) StoreException(org.apache.drill.exec.exception.StoreException)

Example 73 with DrillRuntimeException

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

the class RemoteFunctionRegistry method createArea.

/**
 * Concatenates udf are with root directory.
 * Creates udf area, if area does not exist.
 * Checks if area exists and is directory, if it is writable for current user,
 * throws {@link DrillRuntimeException} otherwise.
 *
 * @param fs file system where area should be created or checked
 * @param root root directory
 * @param directory directory path
 * @return path to area
 */
private Path createArea(FileSystem fs, String root, String directory) {
    Path path = new Path(new File(root, directory).toURI().getPath());
    String fullPath = path.toUri().getPath();
    try {
        fs.mkdirs(path);
        Preconditions.checkState(fs.exists(path), "Area [%s] must exist", fullPath);
        FileStatus fileStatus = fs.getFileStatus(path);
        Preconditions.checkState(fileStatus.isDirectory(), "Area [%s] must be a directory", fullPath);
        FsPermission permission = fileStatus.getPermission();
        // It is considered that process user has write rights on directory if:
        // 1. process user is owner of the directory and has write rights
        // 2. process user is in group that has write rights
        // 3. any user has write rights
        Preconditions.checkState((ImpersonationUtil.getProcessUserName().equals(fileStatus.getOwner()) && permission.getUserAction().implies(FsAction.WRITE)) || (Sets.newHashSet(ImpersonationUtil.getProcessUserGroupNames()).contains(fileStatus.getGroup()) && permission.getGroupAction().implies(FsAction.WRITE)) || permission.getOtherAction().implies(FsAction.WRITE), "Area [%s] must be writable and executable for application user", fullPath);
    } catch (Exception e) {
        if (e instanceof DrillRuntimeException) {
            throw (DrillRuntimeException) e;
        }
        // throws
        DrillRuntimeException.format(e, "Error during udf area creation [%s] on file system [%s]", fullPath, fs.getUri());
    }
    logger.info("Created remote udf area [{}] on file system [{}]", fullPath, fs.getUri());
    return path;
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) FsPermission(org.apache.hadoop.fs.permission.FsPermission) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) File(java.io.File) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) IOException(java.io.IOException) StoreException(org.apache.drill.exec.exception.StoreException) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException)

Example 74 with DrillRuntimeException

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

the class RangeExprEvaluator method evalCastFunc.

private Statistics evalCastFunc(FunctionHolderExpression holderExpr, Statistics input) {
    try {
        DrillSimpleFuncHolder funcHolder = (DrillSimpleFuncHolder) holderExpr.getHolder();
        DrillSimpleFunc interpreter = funcHolder.createInterpreter();
        final ValueHolder minHolder, maxHolder;
        TypeProtos.MinorType srcType = holderExpr.args.get(0).getMajorType().getMinorType();
        TypeProtos.MinorType destType = holderExpr.getMajorType().getMinorType();
        if (srcType.equals(destType)) {
            // same type cast ==> NoOp.
            return input;
        } else if (!CAST_FUNC.containsKey(srcType) || !CAST_FUNC.get(srcType).contains(destType)) {
            // cast func between srcType and destType is NOT allowed.
            return null;
        }
        switch(srcType) {
            case INT:
                minHolder = ValueHolderHelper.getIntHolder(((IntStatistics) input).getMin());
                maxHolder = ValueHolderHelper.getIntHolder(((IntStatistics) input).getMax());
                break;
            case BIGINT:
                minHolder = ValueHolderHelper.getBigIntHolder(((LongStatistics) input).getMin());
                maxHolder = ValueHolderHelper.getBigIntHolder(((LongStatistics) input).getMax());
                break;
            case FLOAT4:
                minHolder = ValueHolderHelper.getFloat4Holder(((FloatStatistics) input).getMin());
                maxHolder = ValueHolderHelper.getFloat4Holder(((FloatStatistics) input).getMax());
                break;
            case FLOAT8:
                minHolder = ValueHolderHelper.getFloat8Holder(((DoubleStatistics) input).getMin());
                maxHolder = ValueHolderHelper.getFloat8Holder(((DoubleStatistics) input).getMax());
                break;
            case DATE:
                minHolder = ValueHolderHelper.getDateHolder(((LongStatistics) input).getMin());
                maxHolder = ValueHolderHelper.getDateHolder(((LongStatistics) input).getMax());
                break;
            default:
                return null;
        }
        final ValueHolder[] args1 = { minHolder };
        final ValueHolder[] args2 = { maxHolder };
        final ValueHolder minFuncHolder = InterpreterEvaluator.evaluateFunction(interpreter, args1, holderExpr.getName());
        final ValueHolder maxFuncHolder = InterpreterEvaluator.evaluateFunction(interpreter, args2, holderExpr.getName());
        switch(destType) {
            // TODO : need handle # of nulls.
            case INT:
                return getStatistics(((IntHolder) minFuncHolder).value, ((IntHolder) maxFuncHolder).value);
            case BIGINT:
                return getStatistics(((BigIntHolder) minFuncHolder).value, ((BigIntHolder) maxFuncHolder).value);
            case FLOAT4:
                return getStatistics(((Float4Holder) minFuncHolder).value, ((Float4Holder) maxFuncHolder).value);
            case FLOAT8:
                return getStatistics(((Float8Holder) minFuncHolder).value, ((Float8Holder) maxFuncHolder).value);
            case TIMESTAMP:
                return getStatistics(((TimeStampHolder) minFuncHolder).value, ((TimeStampHolder) maxFuncHolder).value);
            default:
                return null;
        }
    } catch (Exception e) {
        throw new DrillRuntimeException("Error in evaluating function of " + holderExpr.getName());
    }
}
Also used : LongStatistics(org.apache.parquet.column.statistics.LongStatistics) FloatStatistics(org.apache.parquet.column.statistics.FloatStatistics) IntStatistics(org.apache.parquet.column.statistics.IntStatistics) DoubleStatistics(org.apache.parquet.column.statistics.DoubleStatistics) ValueHolder(org.apache.drill.exec.expr.holders.ValueHolder) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) TypeProtos(org.apache.drill.common.types.TypeProtos) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) DrillSimpleFuncHolder(org.apache.drill.exec.expr.fn.DrillSimpleFuncHolder) DrillSimpleFunc(org.apache.drill.exec.expr.DrillSimpleFunc)

Example 75 with DrillRuntimeException

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

the class MappifyUtility method mappify.

public static DrillBuf mappify(FieldReader reader, BaseWriter.ComplexWriter writer, DrillBuf buffer) {
    // Currently we expect single map as input
    if (DataMode.REPEATED == reader.getType().getMode() || !(reader.getType().getMinorType() == TypeProtos.MinorType.MAP)) {
        throw new DrillRuntimeException("kvgen function only supports Simple maps as input");
    }
    BaseWriter.ListWriter listWriter = writer.rootAsList();
    listWriter.startList();
    BaseWriter.MapWriter mapWriter = listWriter.map();
    // Iterate over the fields in the map
    Iterator<String> fieldIterator = reader.iterator();
    while (fieldIterator.hasNext()) {
        String str = fieldIterator.next();
        FieldReader fieldReader = reader.reader(str);
        // Skip the field if its null
        if (fieldReader.isSet() == false) {
            mapWriter.end();
            continue;
        }
        // writing a new field, start a new map
        mapWriter.start();
        // write "key":"columnname" into the map
        VarCharHolder vh = new VarCharHolder();
        byte[] b = str.getBytes(Charsets.UTF_8);
        buffer = buffer.reallocIfNeeded(b.length);
        buffer.setBytes(0, b);
        vh.start = 0;
        vh.end = b.length;
        vh.buffer = buffer;
        mapWriter.varChar(fieldKey).write(vh);
        // Write the value to the map
        MapUtility.writeToMapFromReader(fieldReader, mapWriter);
        mapWriter.end();
    }
    listWriter.endList();
    return buffer;
}
Also used : BaseWriter(org.apache.drill.exec.vector.complex.writer.BaseWriter) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) VarCharHolder(org.apache.drill.exec.expr.holders.VarCharHolder) FieldReader(org.apache.drill.exec.vector.complex.reader.FieldReader)

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 Bson (org.bson.conversions.Bson)9 MaterializedField (org.apache.drill.exec.record.MaterializedField)8 List (java.util.List)7 RexNode (org.apache.calcite.rex.RexNode)7 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)7 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