use of org.apache.hyracks.algebricks.common.exceptions.NotImplementedException in project asterixdb by apache.
the class CreateMBREvalFactory method createScalarEvaluator.
@Override
public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
private final IPointable inputArg0 = new VoidPointable();
private final IPointable inputArg1 = new VoidPointable();
private final IPointable inputArg2 = new VoidPointable();
private IScalarEvaluator eval0 = recordEvalFactory.createScalarEvaluator(ctx);
private IScalarEvaluator eval1 = dimensionEvalFactory.createScalarEvaluator(ctx);
private IScalarEvaluator eval2 = coordinateEvalFactory.createScalarEvaluator(ctx);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
eval0.evaluate(tuple, inputArg0);
eval1.evaluate(tuple, inputArg1);
eval2.evaluate(tuple, inputArg2);
byte[] data0 = inputArg0.getByteArray();
byte[] data1 = inputArg1.getByteArray();
byte[] data2 = inputArg2.getByteArray();
int startOffset0 = inputArg0.getStartOffset();
int startOffset1 = inputArg1.getStartOffset();
int startOffset2 = inputArg2.getStartOffset();
try {
if (data0[startOffset0] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG || data1[startOffset1] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG || data2[startOffset2] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG) {
out.writeByte(ATypeTag.SERIALIZED_MISSING_TYPE_TAG);
result.set(resultStorage);
return;
}
if (data0[startOffset0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG || data1[startOffset1] == ATypeTag.SERIALIZED_NULL_TYPE_TAG || data2[startOffset2] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
result.set(resultStorage);
return;
}
resultStorage.reset();
if (data1[startOffset1] != ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
throw new TypeMismatchException(BuiltinFunctions.CREATE_MBR, 1, data1[startOffset1], ATypeTag.SERIALIZED_INT32_TYPE_TAG);
}
int dimension = AInt32SerializerDeserializer.getInt(data1, startOffset1 + 1);
if (data2[startOffset2] != ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
throw new TypeMismatchException(BuiltinFunctions.CREATE_MBR, 2, data2[startOffset2], ATypeTag.SERIALIZED_INT32_TYPE_TAG);
}
int coordinate = AInt32SerializerDeserializer.getInt(data2, startOffset2 + 1);
double value;
if (dimension == 2) {
ATypeTag tag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data0[startOffset0]);
switch(tag) {
case POINT:
switch(coordinate) {
// 0 is for min x, 1 is for min y, 2
case 0:
// max x, and 3 for max y
case 2:
{
double x = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.X));
value = x;
}
break;
case 1:
case 3:
{
double y = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y));
value = y;
}
break;
default:
{
throw new NotImplementedException(coordinate + " is not a valid coordinate option");
}
}
break;
case LINE:
value = Double.MAX_VALUE;
switch(coordinate) {
case 0:
{
value = Double.MAX_VALUE;
double startX = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.X));
double endX = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.X));
value = Math.min(Math.min(startX, endX), value);
}
break;
case 1:
{
value = Double.MAX_VALUE;
double startY = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.Y));
double endY = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.Y));
value = Math.min(Math.min(startY, endY), value);
}
break;
case 2:
{
value = Double.MIN_VALUE;
double startX = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.X));
double endX = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.X));
value = Math.max(Math.min(startX, endX), value);
}
break;
case 3:
{
value = Double.MIN_VALUE;
double startY = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.Y));
double endY = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.Y));
value = Math.max(Math.min(startY, endY), value);
}
break;
default:
{
throw new NotImplementedException(coordinate + " is not a valid coordinate option");
}
}
break;
case POLYGON:
int numOfPoints = AInt16SerializerDeserializer.getShort(data0, startOffset0 + APolygonSerializerDeserializer.getNumberOfPointsOffset());
switch(coordinate) {
case 0:
{
value = Double.MAX_VALUE;
for (int i = 0; i < numOfPoints; i++) {
double x = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.X));
value = Math.min(x, value);
}
}
break;
case 1:
{
value = Double.MAX_VALUE;
for (int i = 0; i < numOfPoints; i++) {
double y = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.Y));
value = Math.min(y, value);
}
}
break;
case 2:
{
value = Double.MIN_VALUE;
for (int i = 0; i < numOfPoints; i++) {
double x = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.X));
value = Math.max(x, value);
}
}
break;
case 3:
{
value = Double.MIN_VALUE;
for (int i = 0; i < numOfPoints; i++) {
double y = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.Y));
value = Math.max(y, value);
}
}
break;
default:
{
throw new NotImplementedException(coordinate + " is not a valid coordinate option");
}
}
break;
case CIRCLE:
switch(coordinate) {
case 0:
{
double x = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getCenterPointCoordinateOffset(Coordinate.X));
double radius = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getRadiusOffset());
value = x - radius;
}
break;
case 1:
{
double y = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getCenterPointCoordinateOffset(Coordinate.Y));
double radius = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getRadiusOffset());
value = y - radius;
}
break;
case 2:
{
double x = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getCenterPointCoordinateOffset(Coordinate.X));
double radius = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getRadiusOffset());
value = x + radius;
}
break;
case 3:
{
double y = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getCenterPointCoordinateOffset(Coordinate.Y));
double radius = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getRadiusOffset());
value = y + radius;
}
break;
default:
{
throw new NotImplementedException(coordinate + " is not a valid coordinate option");
}
}
break;
case RECTANGLE:
switch(coordinate) {
case 0:
{
value = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ARectangleSerializerDeserializer.getBottomLeftCoordinateOffset(Coordinate.X));
}
break;
case 1:
{
value = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ARectangleSerializerDeserializer.getBottomLeftCoordinateOffset(Coordinate.Y));
}
break;
case 2:
{
value = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ARectangleSerializerDeserializer.getUpperRightCoordinateOffset(Coordinate.X));
}
break;
case 3:
{
value = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ARectangleSerializerDeserializer.getUpperRightCoordinateOffset(Coordinate.Y));
}
break;
default:
{
throw new NotImplementedException(coordinate + " is not a valid coordinate option");
}
}
break;
default:
throw new TypeMismatchException(BuiltinFunctions.CREATE_MBR, 0, data0[startOffset0], ATypeTag.SERIALIZED_POINT_TYPE_TAG, ATypeTag.SERIALIZED_LINE_TYPE_TAG, ATypeTag.SERIALIZED_POLYGON_TYPE_TAG, ATypeTag.SERIALIZED_CIRCLE_TYPE_TAG, ATypeTag.SERIALIZED_RECTANGLE_TYPE_TAG);
}
} else {
throw new NotImplementedException(dimension + "D is not supported");
}
out.writeByte(ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
out.writeDouble(value);
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
use of org.apache.hyracks.algebricks.common.exceptions.NotImplementedException in project asterixdb by apache.
the class SetAlgebricksPhysicalOperatorsRule method getKeysAndLoad.
private static LogicalVariable getKeysAndLoad(Mutable<ILogicalExpression> payloadExpr, List<Mutable<ILogicalExpression>> keyExpressions, List<LogicalVariable> keys) {
LogicalVariable payload;
if (payloadExpr.getValue().getExpressionTag() != LogicalExpressionTag.VARIABLE) {
throw new NotImplementedException();
}
payload = ((VariableReferenceExpression) payloadExpr.getValue()).getVariableReference();
for (Mutable<ILogicalExpression> kExpr : keyExpressions) {
ILogicalExpression e = kExpr.getValue();
if (e.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
throw new NotImplementedException();
}
keys.add(((VariableReferenceExpression) e).getVariableReference());
}
return payload;
}
use of org.apache.hyracks.algebricks.common.exceptions.NotImplementedException in project asterixdb by apache.
the class SubplanPOperator method contributeRuntimeOperator.
@Override
public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema opSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException {
SubplanOperator subplan = (SubplanOperator) op;
if (subplan.getNestedPlans().size() != 1) {
throw new NotImplementedException("Subplan currently works only for one nested plan with one root.");
}
AlgebricksPipeline[] subplans = compileSubplans(inputSchemas[0], subplan, opSchema, context);
assert subplans.length == 1;
AlgebricksPipeline np = subplans[0];
RecordDescriptor inputRecordDesc = JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op.getInputs().get(0).getValue()), inputSchemas[0], context);
IMissingWriterFactory[] missingWriterFactories = new IMissingWriterFactory[np.getOutputWidth()];
for (int i = 0; i < missingWriterFactories.length; i++) {
missingWriterFactories[i] = context.getMissingWriterFactory();
}
SubplanRuntimeFactory runtime = new SubplanRuntimeFactory(np, missingWriterFactories, inputRecordDesc, null);
RecordDescriptor recDesc = JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op), opSchema, context);
builder.contributeMicroOperator(subplan, runtime, recDesc);
ILogicalOperator src = op.getInputs().get(0).getValue();
builder.contributeGraphEdge(src, 0, op, 0);
}
use of org.apache.hyracks.algebricks.common.exceptions.NotImplementedException in project asterixdb by apache.
the class SinkWritePOperator method contributeRuntimeOperator.
@Override
public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema propagatedSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException {
WriteOperator write = (WriteOperator) op;
int[] columns = new int[write.getExpressions().size()];
int i = 0;
for (Mutable<ILogicalExpression> exprRef : write.getExpressions()) {
ILogicalExpression expr = exprRef.getValue();
if (expr.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
throw new NotImplementedException("Only writing variable expressions is supported.");
}
VariableReferenceExpression varRef = (VariableReferenceExpression) expr;
LogicalVariable v = varRef.getVariableReference();
columns[i++] = inputSchemas[0].findVariable(v);
}
RecordDescriptor recDesc = JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op), propagatedSchema, context);
RecordDescriptor inputDesc = JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op.getInputs().get(0).getValue()), inputSchemas[0], context);
IPrinterFactory[] pf = JobGenHelper.mkPrinterFactories(inputSchemas[0], context.getTypeEnvironment(op), context, columns);
IMetadataProvider<?, ?> mp = context.getMetadataProvider();
Pair<IPushRuntimeFactory, AlgebricksPartitionConstraint> runtime = mp.getWriteFileRuntime(write.getDataSink(), columns, pf, inputDesc);
builder.contributeMicroOperator(write, runtime.first, recDesc, runtime.second);
ILogicalOperator src = write.getInputs().get(0).getValue();
builder.contributeGraphEdge(src, 0, write, 0);
}
use of org.apache.hyracks.algebricks.common.exceptions.NotImplementedException in project asterixdb by apache.
the class EnforceStructuralPropertiesRule method addPartitioningEnforcers.
private void addPartitioningEnforcers(ILogicalOperator op, int i, IPartitioningProperty pp, IPhysicalPropertiesVector required, IPhysicalPropertiesVector deliveredByChild, INodeDomain domain, IOptimizationContext context) throws AlgebricksException {
if (pp != null) {
IPhysicalOperator pop;
switch(pp.getPartitioningType()) {
case UNPARTITIONED:
{
List<OrderColumn> ordCols = computeOrderColumns(deliveredByChild);
if (ordCols.isEmpty()) {
pop = new RandomMergeExchangePOperator();
} else {
if (op.getAnnotations().containsKey(OperatorAnnotations.USE_RANGE_CONNECTOR)) {
IRangeMap rangeMap = (IRangeMap) op.getAnnotations().get(OperatorAnnotations.USE_RANGE_CONNECTOR);
pop = new RangePartitionMergeExchangePOperator(ordCols, domain, rangeMap);
} else {
OrderColumn[] sortColumns = new OrderColumn[ordCols.size()];
sortColumns = ordCols.toArray(sortColumns);
pop = new SortMergeExchangePOperator(sortColumns);
}
}
break;
}
case UNORDERED_PARTITIONED:
{
List<LogicalVariable> varList = new ArrayList<>(((UnorderedPartitionedProperty) pp).getColumnSet());
String hashMergeHint = context.getMetadataProvider().getConfig().get(HASH_MERGE);
if (hashMergeHint == null || !hashMergeHint.equalsIgnoreCase(TRUE_CONSTANT)) {
pop = new HashPartitionExchangePOperator(varList, domain);
break;
}
List<ILocalStructuralProperty> cldLocals = deliveredByChild.getLocalProperties();
List<ILocalStructuralProperty> reqdLocals = required.getLocalProperties();
boolean propWasSet = false;
pop = null;
if (reqdLocals != null && cldLocals != null && allAreOrderProps(cldLocals)) {
AbstractLogicalOperator c = (AbstractLogicalOperator) op.getInputs().get(i).getValue();
Map<LogicalVariable, EquivalenceClass> ecs = context.getEquivalenceClassMap(c);
List<FunctionalDependency> fds = context.getFDList(c);
if (PropertiesUtil.matchLocalProperties(reqdLocals, cldLocals, ecs, fds)) {
List<OrderColumn> orderColumns = getOrderColumnsFromGroupingProperties(reqdLocals, cldLocals);
pop = new HashPartitionMergeExchangePOperator(orderColumns, varList, domain);
propWasSet = true;
}
}
if (!propWasSet) {
pop = new HashPartitionExchangePOperator(varList, domain);
}
break;
}
case ORDERED_PARTITIONED:
{
pop = new RangePartitionExchangePOperator(((OrderedPartitionedProperty) pp).getOrderColumns(), domain, null);
break;
}
case BROADCAST:
{
pop = new BroadcastExchangePOperator(domain);
break;
}
case RANDOM:
{
RandomPartitioningProperty rpp = (RandomPartitioningProperty) pp;
INodeDomain nd = rpp.getNodeDomain();
pop = new RandomPartitionExchangePOperator(nd);
break;
}
default:
{
throw new NotImplementedException("Enforcer for " + pp.getPartitioningType() + " partitioning type has not been implemented.");
}
}
Mutable<ILogicalOperator> ci = op.getInputs().get(i);
ExchangeOperator exchg = new ExchangeOperator();
exchg.setPhysicalOperator(pop);
setNewOp(ci, exchg, context);
exchg.setExecutionMode(AbstractLogicalOperator.ExecutionMode.PARTITIONED);
OperatorPropertiesUtil.computeSchemaAndPropertiesRecIfNull(exchg, context);
context.computeAndSetTypeEnvironmentForOperator(exchg);
if (AlgebricksConfig.DEBUG) {
AlgebricksConfig.ALGEBRICKS_LOGGER.fine(">>>> Added partitioning enforcer " + exchg.getPhysicalOperator() + ".\n");
printOp((AbstractLogicalOperator) op);
}
}
}
Aggregations