Search in sources :

Example 81 with DrillRuntimeException

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

the class DescribeSchemaHandler method getPlan.

@Override
public PhysicalPlan getPlan(SqlNode sqlNode) {
    SqlIdentifier schema = ((SqlDescribeSchema) sqlNode).getSchema();
    SchemaPlus drillSchema = SchemaUtilites.findSchema(config.getConverter().getDefaultSchema(), schema.names);
    if (drillSchema != null) {
        StoragePlugin storagePlugin;
        try {
            storagePlugin = context.getStorage().getPlugin(schema.names.get(0));
        } catch (ExecutionSetupException e) {
            throw new DrillRuntimeException("Failure while retrieving storage plugin", e);
        }
        String properties;
        try {
            final Map configMap = mapper.convertValue(storagePlugin.getConfig(), Map.class);
            if (storagePlugin instanceof FileSystemPlugin) {
                transformWorkspaces(schema.names, configMap);
            }
            properties = mapper.writeValueAsString(configMap);
        } catch (JsonProcessingException e) {
            throw new DrillRuntimeException("Error while trying to convert storage config to json string", e);
        }
        return DirectPlan.createDirectPlan(context, new DescribeSchemaResult(Joiner.on(".").join(schema.names), properties));
    }
    throw UserException.validationError().message(String.format("Invalid schema name [%s]", Joiner.on(".").join(schema.names))).build(logger);
}
Also used : ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) FileSystemPlugin(org.apache.drill.exec.store.dfs.FileSystemPlugin) SchemaPlus(org.apache.calcite.schema.SchemaPlus) SerializableString(com.fasterxml.jackson.core.SerializableString) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) Map(java.util.Map) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SqlDescribeSchema(org.apache.calcite.sql.SqlDescribeSchema) StoragePlugin(org.apache.drill.exec.store.StoragePlugin)

Example 82 with DrillRuntimeException

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

the class DropFunctionHandler method unregister.

/**
 * Gets remote function registry with version.
 * Version is used to ensure that we update the same registry we removed jars from.
 * Looks for a jar to be deleted, if founds one,
 * attempts to update remote registry with list of jars, that excludes jar to be deleted.
 * If during update {@link VersionMismatchException} was detected,
 * attempts to repeat unregistration process till retry attempts exceeds the limit.
 * If retry attempts number hits 0, throws exception that failed to update remote function registry.
 *
 * @param jarName jar name
 * @param remoteFunctionRegistry remote function registry
 * @return jar that was unregistered, null otherwise
 */
private Jar unregister(String jarName, RemoteFunctionRegistry remoteFunctionRegistry) {
    int retryAttempts = remoteFunctionRegistry.getRetryAttempts();
    while (retryAttempts >= 0) {
        DataChangeVersion version = new DataChangeVersion();
        Registry registry = remoteFunctionRegistry.getRegistry(version);
        Jar jarToBeDeleted = null;
        List<Jar> jars = Lists.newArrayList();
        for (Jar j : registry.getJarList()) {
            if (j.getName().equals(jarName)) {
                jarToBeDeleted = j;
            } else {
                jars.add(j);
            }
        }
        if (jarToBeDeleted == null) {
            return null;
        }
        Registry updatedRegistry = Registry.newBuilder().addAllJar(jars).build();
        try {
            remoteFunctionRegistry.updateRegistry(updatedRegistry, version);
            return jarToBeDeleted;
        } catch (VersionMismatchException ex) {
            logger.debug("Failed to update function registry during unregistration, version mismatch was detected.", ex);
            retryAttempts--;
        }
    }
    throw new DrillRuntimeException("Failed to update remote function registry. Exceeded retry attempts limit.");
}
Also used : Jar(org.apache.drill.exec.proto.UserBitShared.Jar) Registry(org.apache.drill.exec.proto.UserBitShared.Registry) RemoteFunctionRegistry(org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry) DataChangeVersion(org.apache.drill.exec.store.sys.store.DataChangeVersion) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException)

Example 83 with DrillRuntimeException

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

the class ProfileResources method getQueryProfile.

@SuppressWarnings("resource")
private QueryProfile getQueryProfile(String queryId) {
    QueryId id = QueryIdHelper.getQueryIdFromString(queryId);
    // first check local running
    Foreman f = work.getBee().getForemanForQueryId(id);
    if (f != null) {
        QueryProfile queryProfile = f.getQueryManager().getQueryProfile();
        checkOrThrowProfileViewAuthorization(queryProfile);
        return queryProfile;
    }
    // then check remote running
    try {
        final TransientStore<QueryInfo> running = work.getContext().getProfileStoreContext().getRunningProfileStore();
        final QueryInfo info = running.get(queryId);
        if (info != null) {
            QueryProfile queryProfile = work.getContext().getController().getTunnel(info.getForeman()).requestQueryProfile(id).checkedGet(2, TimeUnit.SECONDS);
            checkOrThrowProfileViewAuthorization(queryProfile);
            return queryProfile;
        }
    } catch (Exception e) {
        logger.trace("Failed to find query as running profile.", e);
    }
    // then check blob store
    try {
        final PersistentStore<QueryProfile> profiles = work.getContext().getProfileStoreContext().getCompletedProfileStore();
        final QueryProfile queryProfile = profiles.get(queryId);
        if (queryProfile != null) {
            checkOrThrowProfileViewAuthorization(queryProfile);
            return queryProfile;
        }
    } catch (final Exception e) {
        throw new DrillRuntimeException("error while retrieving profile", e);
    }
    throw UserException.validationError().message("No profile with given query id '%s' exists. Please verify the query id.", queryId).build(logger);
}
Also used : QueryProfile(org.apache.drill.exec.proto.UserBitShared.QueryProfile) QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) Foreman(org.apache.drill.exec.work.foreman.Foreman) QueryInfo(org.apache.drill.exec.proto.UserBitShared.QueryInfo) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) UserException(org.apache.drill.common.exceptions.UserException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException)

Example 84 with DrillRuntimeException

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

the class AvroRecordReader method processPrimitive.

private void processPrimitive(final Object value, final Schema.Type type, final String fieldName, final MapOrListWriterImpl writer) {
    if (value == null) {
        return;
    }
    switch(type) {
        case STRING:
            byte[] binary = null;
            final int length;
            if (value instanceof Utf8) {
                binary = ((Utf8) value).getBytes();
                length = ((Utf8) value).getByteLength();
            } else {
                binary = value.toString().getBytes(Charsets.UTF_8);
                length = binary.length;
            }
            ensure(length);
            buffer.setBytes(0, binary);
            writer.varChar(fieldName).writeVarChar(0, length, buffer);
            break;
        case INT:
            writer.integer(fieldName).writeInt((Integer) value);
            break;
        case LONG:
            writer.bigInt(fieldName).writeBigInt((Long) value);
            break;
        case FLOAT:
            writer.float4(fieldName).writeFloat4((Float) value);
            break;
        case DOUBLE:
            writer.float8(fieldName).writeFloat8((Double) value);
            break;
        case BOOLEAN:
            writer.bit(fieldName).writeBit((Boolean) value ? 1 : 0);
            break;
        case BYTES:
            final ByteBuffer buf = (ByteBuffer) value;
            length = buf.remaining();
            ensure(length);
            buffer.setBytes(0, buf);
            writer.binary(fieldName).writeVarBinary(0, length, buffer);
            break;
        case NULL:
            // Nothing to do for null type
            break;
        case ENUM:
            final String symbol = value.toString();
            final byte[] b;
            try {
                b = symbol.getBytes("UTF-8");
            } catch (UnsupportedEncodingException e) {
                throw new DrillRuntimeException("Unable to read enum value for field: " + fieldName, e);
            }
            ensure(b.length);
            buffer.setBytes(0, b);
            writer.varChar(fieldName).writeVarChar(0, b.length, buffer);
            break;
        default:
            throw new DrillRuntimeException("Unhandled Avro type: " + type.toString());
    }
}
Also used : Utf8(org.apache.avro.util.Utf8) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) ByteBuffer(java.nio.ByteBuffer)

Example 85 with DrillRuntimeException

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

the class BsonRecordReader method writeString.

private void writeString(String readString, final MapOrListWriterImpl writer, String fieldName, boolean isList) {
    int length;
    byte[] strBytes;
    try {
        strBytes = readString.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new DrillRuntimeException("Unable to read string value for field: " + fieldName, e);
    }
    length = strBytes.length;
    ensure(length);
    workBuf.setBytes(0, strBytes);
    final VarCharHolder vh = new VarCharHolder();
    vh.buffer = workBuf;
    vh.start = 0;
    vh.end = length;
    if (isList == false) {
        writer.varChar(fieldName).write(vh);
    } else {
        writer.list.varChar().write(vh);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) VarCharHolder(org.apache.drill.exec.expr.holders.VarCharHolder)

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