@Override public ILogicalOperator visitIndexInsertDeleteUpsertOperator(IndexInsertDeleteUpsertOperator op, Void arg) throws AlgebricksException { List<Mutable<ILogicalExpression>> newPrimaryKeyExpressions = new ArrayList<>(); deepCopyExpressionRefs(newPrimaryKeyExpressions, op.getPrimaryKeyExpressions()); List<Mutable<ILogicalExpression>> newSecondaryKeyExpressions = new ArrayList<>(); deepCopyExpressionRefs(newSecondaryKeyExpressions, op.getSecondaryKeyExpressions()); Mutable<ILogicalExpression> newFilterExpression = new MutableObject<>(((AbstractLogicalExpression) op.getFilterExpression()).cloneExpression()); List<Mutable<ILogicalExpression>> newLSMComponentFilterExpressions = new ArrayList<>(); deepCopyExpressionRefs(newLSMComponentFilterExpressions, op.getAdditionalFilteringExpressions()); IndexInsertDeleteUpsertOperator indexInsertDeleteOp = new IndexInsertDeleteUpsertOperator( op.getDataSourceIndex(), newPrimaryKeyExpressions, newSecondaryKeyExpressions, newFilterExpression, op.getOperation(), op.isBulkload(), op.getNumberOfAdditionalNonFilteringFields()); indexInsertDeleteOp.setAdditionalFilteringExpressions(newLSMComponentFilterExpressions); return indexInsertDeleteOp; }
@Override public String visitIndexInsertDeleteUpsertOperator(IndexInsertDeleteUpsertOperator op, Boolean showDetails) { stringBuilder.setLength(0); String header = getIndexOpString(op.getOperation()); stringBuilder.append(header).append(op.getIndexName()).append(" on ") .append(str(op.getDataSourceIndex().getDataSource())).append(" from "); if (op.getOperation() == Kind.UPSERT) { stringBuilder.append(" replace:"); printExprList(op.getPrevSecondaryKeyExprs()); stringBuilder.append(" with:"); printExprList(op.getSecondaryKeyExpressions()); } else { printExprList(op.getSecondaryKeyExpressions()); } if (op.isBulkload()) { stringBuilder.append(" [bulkload]"); } appendSchema(op, showDetails); appendAnnotations(op, showDetails); appendPhysicalOperatorInfo(op, showDetails); return stringBuilder.toString(); }
@Override public Long visitIndexInsertDeleteUpsertOperator(IndexInsertDeleteUpsertOperator op, Void arg) throws AlgebricksException { return op.getInputs().get(0).getValue().accept(this, arg); }
@Override public Boolean visitIndexInsertDeleteUpsertOperator(IndexInsertDeleteUpsertOperator op, ILogicalOperator arg) throws AlgebricksException { AbstractLogicalOperator aop = (AbstractLogicalOperator) arg; if (aop.getOperatorTag() != LogicalOperatorTag.INDEX_INSERT_DELETE_UPSERT) { return Boolean.FALSE; } IndexInsertDeleteUpsertOperator insertOpArg = (IndexInsertDeleteUpsertOperator) copyAndSubstituteVar(op, arg); boolean isomorphic = VariableUtilities.varListEqualUnordered(op.getSchema(), insertOpArg.getSchema()); if (!op.getDataSourceIndex().equals(insertOpArg.getDataSourceIndex())) { isomorphic = false; } return isomorphic; }
List<LogicalVariable> secondaryKeys = new ArrayList<LogicalVariable>(); List<LogicalVariable> additionalFilteringKeys = null; getKeys(opInsDel.getPrimaryKeyExpressions(), primaryKeys); getKeys(opInsDel.getSecondaryKeyExpressions(), secondaryKeys); if (opInsDel.getAdditionalFilteringExpressions() != null) { additionalFilteringKeys = new ArrayList<LogicalVariable>(); getKeys(opInsDel.getAdditionalFilteringExpressions(), additionalFilteringKeys); if (opInsDel.isBulkload()) { op.setPhysicalOperator( new IndexBulkloadPOperator(primaryKeys, secondaryKeys, additionalFilteringKeys, opInsDel.getFilterExpression(), opInsDel.getDataSourceIndex())); } else { LogicalVariable upsertIndicatorVar = null; List<LogicalVariable> prevSecondaryKeys = null; LogicalVariable prevAdditionalFilteringKey = null; if (opInsDel.getOperation() == Kind.UPSERT) { upsertIndicatorVar = getKey(opInsDel.getUpsertIndicatorExpr().getValue()); prevSecondaryKeys = new ArrayList<LogicalVariable>(); getKeys(opInsDel.getPrevSecondaryKeyExprs(), prevSecondaryKeys); if (opInsDel.getPrevAdditionalFilteringExpression() != null) { prevAdditionalFilteringKey = ((VariableReferenceExpression) (opInsDel.getPrevAdditionalFilteringExpression()) .getValue()).getVariableReference(); additionalFilteringKeys, opInsDel.getFilterExpression(), opInsDel.getDataSourceIndex(), upsertIndicatorVar, prevSecondaryKeys, prevAdditionalFilteringKey, opInsDel.getNumberOfAdditionalNonFilteringFields()));
@Override public Void visitIndexInsertDeleteUpsertOperator(IndexInsertDeleteUpsertOperator op, Void arg) { for (Mutable<ILogicalExpression> e : op.getPrimaryKeyExpressions()) { e.getValue().getUsedVariables(usedVariables); } for (Mutable<ILogicalExpression> e : op.getSecondaryKeyExpressions()) { e.getValue().getUsedVariables(usedVariables); } if (op.getFilterExpression() != null) { op.getFilterExpression().getValue().getUsedVariables(usedVariables); } if (op.getAdditionalFilteringExpressions() != null) { for (Mutable<ILogicalExpression> e : op.getAdditionalFilteringExpressions()) { e.getValue().getUsedVariables(usedVariables); } } if (op.getPrevAdditionalFilteringExpression() != null) { op.getPrevAdditionalFilteringExpression().getValue().getUsedVariables(usedVariables); } if (op.getPrevSecondaryKeyExprs() != null) { for (Mutable<ILogicalExpression> e : op.getPrevSecondaryKeyExprs()) { e.getValue().getUsedVariables(usedVariables); } } if (op.getUpsertIndicatorExpr() != null) { op.getUpsertIndicatorExpr().getValue().getUsedVariables(usedVariables); } return null; }
if (descendantOp.getOperatorTag() == LogicalOperatorTag.INDEX_INSERT_DELETE_UPSERT) { IndexInsertDeleteUpsertOperator operator = (IndexInsertDeleteUpsertOperator) descendantOp; if (!operator.isBulkload() && operator.getPrevSecondaryKeyExprs() == null) { primaryKeyExprs = operator.getPrimaryKeyExpressions(); dataset = ((DatasetDataSource) operator.getDataSourceIndex().getDataSource()).getDataset(); break;
context.computeAndSetTypeEnvironmentForOperator(tokenUpdate); replicateOutput = tokenUpdate; indexUpdate = new IndexInsertDeleteUpsertOperator(dataSourceIndex, primaryIndexModificationOp.getPrimaryKeyExpressions(), tokenizeKeyExprs, filterExpression, primaryIndexModificationOp.getOperation(), primaryIndexModificationOp.isBulkload(), primaryIndexModificationOp.getAdditionalNonFilteringExpressions() == null ? 0 : primaryIndexModificationOp.getAdditionalNonFilteringExpressions().size()); indexUpdate.setSourceLocation(sourceLoc); indexUpdate.setAdditionalFilteringExpressions(filteringExpressions); indexUpdate.getInputs().add(new MutableObject<ILogicalOperator>(tokenUpdate)); } else { indexUpdate = new IndexInsertDeleteUpsertOperator(dataSourceIndex, primaryIndexModificationOp.getPrimaryKeyExpressions(), secondaryExpressions, filterExpression, primaryIndexModificationOp.getOperation(), primaryIndexModificationOp.getAdditionalNonFilteringExpressions() == null ? 0 : primaryIndexModificationOp.getAdditionalNonFilteringExpressions().size()); indexUpdate.setSourceLocation(sourceLoc); indexUpdate.setAdditionalFilteringExpressions(filteringExpressions); replicateOutput = indexUpdate; indexUpdate.setBeforeOpSecondaryKeyExprs(beforeOpSecondaryExpressions); if (filteringFields != null) { VariableReferenceExpression varRef = new VariableReferenceExpression(primaryIndexModificationOp.getBeforeOpFilterVar()); varRef.setSourceLocation(sourceLoc); indexUpdate.setBeforeOpAdditionalFilteringExpression( new MutableObject<ILogicalExpression>(varRef));
@Override public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema propagatedSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException { IndexInsertDeleteUpsertOperator indexInsertDeleteOp = (IndexInsertDeleteUpsertOperator) op; assert indexInsertDeleteOp.getOperation() == Kind.INSERT; assert indexInsertDeleteOp.isBulkload(); IMetadataProvider mp = context.getMetadataProvider(); IVariableTypeEnvironment typeEnv = context.getTypeEnvironment(op); JobSpecification spec = builder.getJobSpec(); RecordDescriptor inputDesc = JobGenHelper.mkRecordDescriptor( context.getTypeEnvironment(op.getInputs().get(0).getValue()), inputSchemas[0], context); Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> runtimeAndConstraints = mp.getIndexInsertRuntime(dataSourceIndex, propagatedSchema, inputSchemas, typeEnv, primaryKeys, secondaryKeys, additionalFilteringKeys, filterExpr, inputDesc, context, spec, true); IOperatorDescriptor opDesc = runtimeAndConstraints.first; opDesc.setSourceLocation(indexInsertDeleteOp.getSourceLocation()); builder.contributeHyracksOperator(indexInsertDeleteOp, opDesc); builder.contributeAlgebricksPartitionConstraint(opDesc, runtimeAndConstraints.second); ILogicalOperator src = indexInsertDeleteOp.getInputs().get(0).getValue(); builder.contributeGraphEdge(src, 0, indexInsertDeleteOp, 0); }
@Override public Void visitIndexInsertDeleteUpsertOperator(IndexInsertDeleteUpsertOperator op, Pair<LogicalVariable, LogicalVariable> pair) throws AlgebricksException { for (Mutable<ILogicalExpression> e : op.getPrimaryKeyExpressions()) { e.getValue().substituteVar(pair.first, pair.second); } for (Mutable<ILogicalExpression> e : op.getSecondaryKeyExpressions()) { e.getValue().substituteVar(pair.first, pair.second); } substVarTypes(op, pair); return null; }
Kind operation = insertDeleteUpsertOp.getOperation(); switch (operation) { case INSERT: opDesc.setSourceLocation(insertDeleteUpsertOp.getSourceLocation()); builder.contributeHyracksOperator(insertDeleteUpsertOp, opDesc); builder.contributeAlgebricksPartitionConstraint(opDesc, runtimeAndConstraints.second); ILogicalOperator src = insertDeleteUpsertOp.getInputs().get(0).getValue(); builder.contributeGraphEdge(src, 0, insertDeleteUpsertOp, 0);
@Override public Void visitIndexInsertDeleteUpsertOperator(IndexInsertDeleteUpsertOperator op, Integer indent) throws AlgebricksException { String header = getIndexOpString(op.getOperation()); addIndent(indent).append(header).append(op.getIndexName()).append(" on ") .append(str(op.getDataSourceIndex().getDataSource())).append(" from "); if (op.getOperation() == Kind.UPSERT) { buffer.append(" replace:"); pprintExprList(op.getPrevSecondaryKeyExprs(), indent); buffer.append(" with:"); pprintExprList(op.getSecondaryKeyExpressions(), indent); } else { pprintExprList(op.getSecondaryKeyExpressions(), indent); } if (op.isBulkload()) { buffer.append(" [bulkload]"); } return null; }
@Override public Void visitIndexInsertDeleteUpsertOperator(IndexInsertDeleteUpsertOperator op, Integer indent) throws AlgebricksException { String header = getIndexOpString(op.getOperation()); addIndent(indent).append("\"operator\": \"" + header + "\",\n"); addIndent(indent).append("\"index\": \"" + op.getIndexName() + "\",\n"); addIndent(indent).append("\"on\": \"").append(str(op.getDataSourceIndex().getDataSource()) + "\",\n"); addIndent(indent).append("\"from\": {"); if (op.getOperation() == Kind.UPSERT) { addIndent(indent).append("[\"replace\": \""); pprintExprList(op.getPrevSecondaryKeyExprs(), 0); buffer.append("\",\n"); addIndent(indent).append("\"with\": \""); pprintExprList(op.getSecondaryKeyExpressions(), 0); buffer.append("\"}"); } else { pprintExprList(op.getSecondaryKeyExpressions(), 0); } buffer.append("\n"); addIndent(indent).append("}"); if (op.isBulkload()) { buffer.append(",\n"); buffer.append("\"bulkload\": true"); } return null; }