Search in sources :

Example 31 with Triple

use of org.apache.commons.lang3.tuple.Triple in project alluxio by Alluxio.

the class PermissionCheckTest method getPermissionGroup.

@Test
public void getPermissionGroup() throws Exception {
    ArrayList<Triple<String, String, Mode>> permissions = new ArrayList<>();
    permissions.add(new ImmutableTriple<>(TEST_USER_1.getUser(), TEST_USER_1.getGroup(), new Mode((short) 0754)));
    LockedInodePath lockedInodePath = getLockedInodePath(permissions);
    try (SetAndRestoreAuthenticatedUser u = new SetAndRestoreAuthenticatedUser(TEST_USER_3.getUser())) {
        PermissionChecker checker = new PermissionChecker(mInodeTree);
        Mode.Bits actual = checker.getPermission(lockedInodePath);
        Assert.assertEquals(Mode.Bits.READ_EXECUTE, actual);
    }
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) MutableLockedInodePath(alluxio.master.file.meta.MutableLockedInodePath) LockedInodePath(alluxio.master.file.meta.LockedInodePath) SetAndRestoreAuthenticatedUser(alluxio.SetAndRestoreAuthenticatedUser) Mode(alluxio.security.authorization.Mode) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 32 with Triple

use of org.apache.commons.lang3.tuple.Triple in project asterixdb by apache.

the class RemoveUnusedAssignAndAggregateRule method collectUnusedAssignedVars.

private void collectUnusedAssignedVars(Mutable<ILogicalOperator> opRef, Set<LogicalVariable> accumulatedUsedVarFromRootSet, boolean first, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    if (!first) {
        context.addToDontApplySet(this, op);
    }
    Set<LogicalVariable> assignVarsSetInThisOp = new HashSet<>();
    Set<LogicalVariable> usedVarsSetInThisOp = new HashSet<>();
    // Add used variables in this operator to the accumulated used variables set?
    boolean addUsedVarsInThisOp = true;
    // ASSIGN, AGGREGATE, UNNEST, UNIONALL, or GROUP operator found?
    boolean targetOpFound = false;
    switch(op.getOperatorTag()) {
        case ASSIGN:
            AssignOperator assign = (AssignOperator) op;
            assignVarsSetInThisOp.addAll(assign.getVariables());
            targetOpFound = true;
            break;
        case AGGREGATE:
            AggregateOperator agg = (AggregateOperator) op;
            assignVarsSetInThisOp.addAll(agg.getVariables());
            targetOpFound = true;
            break;
        case UNNEST:
            UnnestOperator uOp = (UnnestOperator) op;
            LogicalVariable pVar = uOp.getPositionalVariable();
            if (pVar != null) {
                assignVarsSetInThisOp.add(pVar);
                targetOpFound = true;
            }
            break;
        case UNIONALL:
            UnionAllOperator unionOp = (UnionAllOperator) op;
            for (Triple<LogicalVariable, LogicalVariable, LogicalVariable> varMapping : unionOp.getVariableMappings()) {
                assignVarsSetInThisOp.add(varMapping.third);
            }
            targetOpFound = true;
            // Don't add used variables in UNIONALL.
            addUsedVarsInThisOp = false;
            break;
        case GROUP:
            GroupByOperator groupByOp = (GroupByOperator) op;
            for (Pair<LogicalVariable, Mutable<ILogicalExpression>> decorMapping : groupByOp.getDecorList()) {
                LogicalVariable decorVar = decorMapping.first;
                if (decorVar != null) {
                    assignVarsSetInThisOp.add(decorVar);
                    targetOpFound = true;
                } else {
                    // A decor var mapping can have a variable reference expression without a new variable
                    // definition, which is for rebinding the referred variable.
                    VariableReferenceExpression varExpr = (VariableReferenceExpression) decorMapping.second.getValue();
                    LogicalVariable reboundDecorVar = varExpr.getVariableReference();
                    assignVarsSetInThisOp.add(reboundDecorVar);
                }
            }
            break;
        default:
            break;
    }
    if (targetOpFound) {
        assignedVarMap.put(opRef, assignVarsSetInThisOp);
        assignedVarSet.addAll(assignVarsSetInThisOp);
    }
    if (addUsedVarsInThisOp) {
        VariableUtilities.getUsedVariables(op, usedVarsSetInThisOp);
        accumulatedUsedVarFromRootSet.addAll(usedVarsSetInThisOp);
        // paths in the plan.
        if (accumulatedUsedVarFromRootMap.containsKey(opRef)) {
            accumulatedUsedVarFromRootMap.get(opRef).addAll(accumulatedUsedVarFromRootSet);
        } else {
            accumulatedUsedVarFromRootMap.put(opRef, new HashSet<LogicalVariable>(accumulatedUsedVarFromRootSet));
        }
    } else {
        accumulatedUsedVarFromRootMap.put(opRef, new HashSet<LogicalVariable>(accumulatedUsedVarFromRootSet));
    }
    for (Mutable<ILogicalOperator> c : op.getInputs()) {
        collectUnusedAssignedVars(c, new HashSet<LogicalVariable>(accumulatedUsedVarFromRootSet), false, context);
    }
    if (op.hasNestedPlans()) {
        AbstractOperatorWithNestedPlans opWithNested = (AbstractOperatorWithNestedPlans) op;
        for (ILogicalPlan plan : opWithNested.getNestedPlans()) {
            for (Mutable<ILogicalOperator> r : plan.getRoots()) {
                collectUnusedAssignedVars(r, new HashSet<LogicalVariable>(accumulatedUsedVarFromRootSet), false, context);
            }
        }
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) GroupByOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) UnnestOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator) Mutable(org.apache.commons.lang3.mutable.Mutable) UnionAllOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.UnionAllOperator) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) AggregateOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator) ILogicalPlan(org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan) HashSet(java.util.HashSet) AbstractOperatorWithNestedPlans(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans)

Example 33 with Triple

use of org.apache.commons.lang3.tuple.Triple in project asterixdb by apache.

the class ResolveVariableRule method resolveInternal.

// Resolves an undefined name to a dataset or a fully qualified variable/field-access path
// based on the given information of dataset matches and candidate paths.
private boolean resolveInternal(Mutable<ILogicalExpression> funcRef, boolean hasMatchedDataset, Collection<Pair<ILogicalExpression, List<String>>> varAccessCandidates, String unresolvedVarName, Triple<Boolean, String, String> fullyQualifiedDatasetPathCandidateFromParent, Mutable<ILogicalExpression> parentFuncRef, IOptimizationContext context) throws AlgebricksException {
    AbstractFunctionCallExpression func = (AbstractFunctionCallExpression) funcRef.getValue();
    int numVarCandidates = varAccessCandidates.size();
    // The resolution order: 1. field-access 2. datasets (standalone-name or fully-qualified)
    if (numVarCandidates > 0) {
        if (numVarCandidates == 1) {
            resolveAsFieldAccess(funcRef, varAccessCandidates.iterator().next());
        } else {
            // More than one possibilities.
            throw new AlgebricksException("Cannot resolve ambiguous alias reference for undefined identifier " + unresolvedVarName);
        }
    } else if (hasMatchedDataset) {
        // Rewrites the "resolve" function to a "dataset" function and only keep the dataset name argument.
        func.setFunctionInfo(FunctionUtil.getFunctionInfo(BuiltinFunctions.DATASET));
        Mutable<ILogicalExpression> datasetNameExpression = func.getArguments().get(0);
        func.getArguments().clear();
        func.getArguments().add(datasetNameExpression);
    } else if (fullyQualifiedDatasetPathCandidateFromParent.first) {
        // Rewrites the parent "field-access" function to a "dataset" function.
        AbstractFunctionCallExpression parentFunc = (AbstractFunctionCallExpression) parentFuncRef.getValue();
        parentFunc.setFunctionInfo(FunctionUtil.getFunctionInfo(BuiltinFunctions.DATASET));
        parentFunc.getArguments().clear();
        parentFunc.getArguments().add(new MutableObject<>(new ConstantExpression(new AsterixConstantValue(new AString(fullyQualifiedDatasetPathCandidateFromParent.second + "." + fullyQualifiedDatasetPathCandidateFromParent.third)))));
    } else {
        MetadataProvider metadataProvider = (MetadataProvider) context.getMetadataProvider();
        // Cannot find any resolution.
        throw new AlgebricksException("Cannot find dataset " + unresolvedVarName + " in dataverse " + metadataProvider.getDefaultDataverseName() + " nor an alias with name " + unresolvedVarName);
    }
    return true;
}
Also used : Mutable(org.apache.commons.lang3.mutable.Mutable) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) MetadataProvider(org.apache.asterix.metadata.declared.MetadataProvider) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) AString(org.apache.asterix.om.base.AString)

Example 34 with Triple

use of org.apache.commons.lang3.tuple.Triple in project gatk by broadinstitute.

the class CoverageModelEMComputeBlock method getBiasLatentPosteriorDataRegularized.

/**
     * Calculates the contribution of the target-space block represented by this compute node
     * to the E-step for $z_{s\mu}$ w/ regularization. The result is a triple
     * of INDArrays (contribGMatrix, contribZ, contribFilter). The first two were defined
     * in {@link CoverageModelEMComputeBlock#getBiasLatentPosteriorDataUnregularized()}. The third
     * INDArray is:
     *
     *      contribFilter = [W]^T [F.W]
     *
     * @return an {@link ImmutableTriple} of contribGMatrix (left), contribZ (middle), contribFilter (right)
     */
@QueriesICG
public ImmutableTriple<INDArray, INDArray, INDArray> getBiasLatentPosteriorDataRegularized() {
    assertBiasCovariatesEnabled();
    final ImmutablePair<INDArray, INDArray> unreg = getBiasLatentPosteriorDataUnregularized();
    final INDArray contribFilter = getINDArrayFromCache(CoverageModelICGCacheNode.W_tl).transpose().mmul(getINDArrayFromCache(CoverageModelICGCacheNode.F_W_tl));
    return new ImmutableTriple<>(unreg.left, unreg.right, contribFilter);
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple)

Example 35 with Triple

use of org.apache.commons.lang3.tuple.Triple in project gatk-protected by broadinstitute.

the class CoverageModelEMComputeBlock method getBiasLatentPosteriorDataRegularized.

/**
     * Calculates the contribution of the target-space block represented by this compute node
     * to the E-step for $z_{s\mu}$ w/ regularization. The result is a triple
     * of INDArrays (contribGMatrix, contribZ, contribFilter). The first two were defined
     * in {@link CoverageModelEMComputeBlock#getBiasLatentPosteriorDataUnregularized()}. The third
     * INDArray is:
     *
     *      contribFilter = [W]^T [F.W]
     *
     * @return an {@link ImmutableTriple} of contribGMatrix (left), contribZ (middle), contribFilter (right)
     */
@QueriesICG
public ImmutableTriple<INDArray, INDArray, INDArray> getBiasLatentPosteriorDataRegularized() {
    assertBiasCovariatesEnabled();
    final ImmutablePair<INDArray, INDArray> unreg = getBiasLatentPosteriorDataUnregularized();
    final INDArray contribFilter = getINDArrayFromCache(CoverageModelICGCacheNode.W_tl).transpose().mmul(getINDArrayFromCache(CoverageModelICGCacheNode.F_W_tl));
    return new ImmutableTriple<>(unreg.left, unreg.right, contribFilter);
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple)

Aggregations

Triple (org.apache.commons.lang3.tuple.Triple)51 ArrayList (java.util.ArrayList)20 ImmutableTriple (org.apache.commons.lang3.tuple.ImmutableTriple)18 List (java.util.List)13 Pair (org.apache.commons.lang3.tuple.Pair)10 Test (org.junit.Test)8 Collectors (java.util.stream.Collectors)7 java.util (java.util)6 Organization (alfio.model.user.Organization)5 Event (alfio.model.Event)4 Ticket (alfio.model.Ticket)4 TicketReservation (alfio.model.TicketReservation)4 IOException (java.io.IOException)4 BlockPos (net.minecraft.util.math.BlockPos)4 Mutable (org.apache.commons.lang3.mutable.Mutable)4 Triple (org.apache.hyracks.algebricks.common.utils.Triple)4 alfio.model (alfio.model)3 TicketCategory (alfio.model.TicketCategory)3 TemplateManager (alfio.util.TemplateManager)3 LockedInodePath (alluxio.master.file.meta.LockedInodePath)3