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);
}
}
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);
}
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;
}
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());
}
}
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;
}
Aggregations