Search in sources :

Example 11 with Pair

use of org.apache.commons.lang3.tuple.Pair in project presto by prestodb.

the class AccumuloClient method getColumnHandles.

private static List<AccumuloColumnHandle> getColumnHandles(ConnectorTableMetadata meta, String rowIdColumn) {
    // Get the column mappings from the table property or auto-generate columns if not defined
    Map<String, Pair<String, String>> mapping = AccumuloTableProperties.getColumnMapping(meta.getProperties()).orElse(autoGenerateMapping(meta.getColumns(), AccumuloTableProperties.getLocalityGroups(meta.getProperties())));
    // The list of indexed columns
    Optional<List<String>> indexedColumns = AccumuloTableProperties.getIndexColumns(meta.getProperties());
    // And now we parse the configured columns and create handles for the metadata manager
    ImmutableList.Builder<AccumuloColumnHandle> cBuilder = ImmutableList.builder();
    for (int ordinal = 0; ordinal < meta.getColumns().size(); ++ordinal) {
        ColumnMetadata cm = meta.getColumns().get(ordinal);
        // Special case if this column is the row ID
        if (cm.getName().equalsIgnoreCase(rowIdColumn)) {
            cBuilder.add(new AccumuloColumnHandle(rowIdColumn, Optional.empty(), Optional.empty(), cm.getType(), ordinal, "Accumulo row ID", false));
        } else {
            if (!mapping.containsKey(cm.getName())) {
                throw new InvalidParameterException(format("Misconfigured mapping for presto column %s", cm.getName()));
            }
            // Get the mapping for this column
            Pair<String, String> famqual = mapping.get(cm.getName());
            boolean indexed = indexedColumns.isPresent() && indexedColumns.get().contains(cm.getName().toLowerCase(Locale.ENGLISH));
            String comment = format("Accumulo column %s:%s. Indexed: %b", famqual.getLeft(), famqual.getRight(), indexed);
            // Create a new AccumuloColumnHandle object
            cBuilder.add(new AccumuloColumnHandle(cm.getName(), Optional.of(famqual.getLeft()), Optional.of(famqual.getRight()), cm.getType(), ordinal, comment, indexed));
        }
    }
    return cBuilder.build();
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) ImmutableList(com.google.common.collect.ImmutableList) AccumuloColumnConstraint(com.facebook.presto.accumulo.model.AccumuloColumnConstraint) InvalidParameterException(java.security.InvalidParameterException) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Pair(org.apache.commons.lang3.tuple.Pair)

Example 12 with Pair

use of org.apache.commons.lang3.tuple.Pair in project disunity by ata4.

the class BundleInfo method buildHeaderTable.

private Table<Integer, Integer, Object> buildHeaderTable(BundleHeader header) {
    TableBuilder table = new TableBuilder();
    table.row("Field", "Value");
    table.row("signature", header.signature());
    table.row("streamVersion", header.streamVersion());
    table.row("unityVersion", header.unityVersion());
    table.row("unityRevision", header.unityRevision());
    table.row("minimumStreamedBytes", header.minimumStreamedBytes());
    table.row("headerSize", header.headerSize());
    table.row("numberOfLevelsToDownload", header.numberOfLevelsToDownload());
    table.row("numberOfLevels", header.numberOfLevels());
    List<Pair<Long, Long>> levelByteEnds = header.levelByteEnd();
    for (int i = 0; i < levelByteEnds.size(); i++) {
        Pair<Long, Long> levelByteEnd = levelByteEnds.get(i);
        table.row("levelByteEnd[" + i + "][0]", levelByteEnd.getLeft());
        table.row("levelByteEnd[" + i + "][1]", levelByteEnd.getRight());
    }
    if (header.streamVersion() >= 2) {
        table.row("completeFileSize", header.completeFileSize());
    }
    if (header.streamVersion() >= 3) {
        table.row("dataHeaderSize", header.dataHeaderSize());
    }
    return table.get();
}
Also used : TableBuilder(info.ata4.disunity.cli.util.TableBuilder) Pair(org.apache.commons.lang3.tuple.Pair)

Example 13 with Pair

use of org.apache.commons.lang3.tuple.Pair in project midpoint by Evolveum.

the class ShadowIntegrityCheckResultHandler method checkShadow.

private void checkShadow(ShadowCheckResult checkResult, PrismObject<ShadowType> shadow, Task workerTask, OperationResult result) throws SchemaException {
    ShadowType shadowType = shadow.asObjectable();
    ObjectReferenceType resourceRef = shadowType.getResourceRef();
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Checking shadow {} (resource {})", ObjectTypeUtil.toShortString(shadowType), resourceRef != null ? resourceRef.getOid() : "(null)");
    }
    statistics.incrementShadows();
    if (resourceRef == null) {
        checkResult.recordError(Statistics.NO_RESOURCE_OID, new SchemaException("No resourceRef"));
        fixNoResourceIfRequested(checkResult, Statistics.NO_RESOURCE_OID);
        applyFixes(checkResult, shadow, workerTask, result);
        return;
    }
    String resourceOid = resourceRef.getOid();
    if (resourceOid == null) {
        checkResult.recordError(Statistics.NO_RESOURCE_OID, new SchemaException("Null resource OID"));
        fixNoResourceIfRequested(checkResult, Statistics.NO_RESOURCE_OID);
        applyFixes(checkResult, shadow, workerTask, result);
        return;
    }
    PrismObject<ResourceType> resource = resources.get(resourceOid);
    if (resource == null) {
        statistics.incrementResources();
        try {
            resource = provisioningService.getObject(ResourceType.class, resourceOid, null, workerTask, result);
        } catch (ObjectNotFoundException e) {
            checkResult.recordError(Statistics.NO_RESOURCE, new ObjectNotFoundException("Resource object does not exist: " + e.getMessage(), e));
            fixNoResourceIfRequested(checkResult, Statistics.NO_RESOURCE);
            applyFixes(checkResult, shadow, workerTask, result);
            return;
        } catch (SchemaException e) {
            checkResult.recordError(Statistics.CANNOT_GET_RESOURCE, new SchemaException("Resource object has schema problems: " + e.getMessage(), e));
            return;
        } catch (CommonException | RuntimeException e) {
            checkResult.recordError(Statistics.CANNOT_GET_RESOURCE, new SystemException("Resource object cannot be fetched for some reason: " + e.getMessage(), e));
            return;
        }
        resources.put(resourceOid, resource);
    }
    checkResult.setResource(resource);
    ShadowKindType kind = shadowType.getKind();
    if (kind == null) {
        // TODO or simply assume account?
        checkResult.recordError(Statistics.NO_KIND_SPECIFIED, new SchemaException("No kind specified"));
        return;
    }
    if (checkExtraData) {
        checkOrFixShadowActivationConsistency(checkResult, shadow, fixExtraData);
    }
    PrismObject<ShadowType> fetchedShadow = null;
    if (checkFetch) {
        fetchedShadow = fetchShadow(checkResult, shadow, resource, workerTask, result);
        if (fetchedShadow != null) {
            shadow.setUserData(KEY_EXISTS_ON_RESOURCE, "true");
        }
    }
    if (checkOwners) {
        List<PrismObject<FocusType>> owners = searchOwners(shadow, result);
        if (owners != null) {
            shadow.setUserData(KEY_OWNERS, owners);
            if (owners.size() > 1) {
                checkResult.recordError(Statistics.MULTIPLE_OWNERS, new SchemaException("Multiple owners: " + owners));
            }
        }
        if (shadowType.getSynchronizationSituation() == SynchronizationSituationType.LINKED && (owners == null || owners.isEmpty())) {
            checkResult.recordError(Statistics.LINKED_WITH_NO_OWNER, new SchemaException("Linked shadow with no owner"));
        }
        if (shadowType.getSynchronizationSituation() != SynchronizationSituationType.LINKED && owners != null && !owners.isEmpty()) {
            checkResult.recordError(Statistics.NOT_LINKED_WITH_OWNER, new SchemaException("Shadow with an owner but not marked as linked (marked as " + shadowType.getSynchronizationSituation() + ")"));
        }
    }
    String intent = shadowType.getIntent();
    if (checkIntents && (intent == null || intent.isEmpty())) {
        checkResult.recordWarning(Statistics.NO_INTENT_SPECIFIED, "None or empty intent");
    }
    if (fixIntents && (intent == null || intent.isEmpty())) {
        doFixIntent(checkResult, fetchedShadow, shadow, resource, workerTask, result);
    }
    Pair<String, ShadowKindType> key = new ImmutablePair<>(resourceOid, kind);
    ObjectTypeContext context = contextMap.get(key);
    if (context == null) {
        context = new ObjectTypeContext();
        context.setResource(resource);
        RefinedResourceSchema resourceSchema;
        try {
            resourceSchema = RefinedResourceSchemaImpl.getRefinedSchema(context.getResource(), LayerType.MODEL, prismContext);
        } catch (SchemaException e) {
            checkResult.recordError(Statistics.CANNOT_GET_REFINED_SCHEMA, new SchemaException("Couldn't derive resource schema: " + e.getMessage(), e));
            return;
        }
        if (resourceSchema == null) {
            checkResult.recordError(Statistics.NO_RESOURCE_REFINED_SCHEMA, new SchemaException("No resource schema"));
            return;
        }
        context.setObjectClassDefinition(resourceSchema.getRefinedDefinition(kind, shadowType));
        if (context.getObjectClassDefinition() == null) {
            // TODO or warning only?
            checkResult.recordError(Statistics.NO_OBJECT_CLASS_REFINED_SCHEMA, new SchemaException("No refined object class definition for kind=" + kind + ", intent=" + intent));
            return;
        }
        contextMap.put(key, context);
    }
    try {
        provisioningService.applyDefinition(shadow, workerTask, result);
    } catch (SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
        checkResult.recordError(Statistics.OTHER_FAILURE, new SystemException("Couldn't apply definition to shadow from repo", e));
        return;
    }
    Set<RefinedAttributeDefinition<?>> identifiers = new HashSet<>();
    Collection<? extends RefinedAttributeDefinition<?>> primaryIdentifiers = context.getObjectClassDefinition().getPrimaryIdentifiers();
    identifiers.addAll(primaryIdentifiers);
    identifiers.addAll(context.getObjectClassDefinition().getSecondaryIdentifiers());
    PrismContainer<ShadowAttributesType> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer == null) {
        // might happen on unfinished shadows?
        checkResult.recordError(Statistics.OTHER_FAILURE, new SchemaException("No attributes container"));
        return;
    }
    for (RefinedAttributeDefinition<?> identifier : identifiers) {
        PrismProperty property = attributesContainer.getValue().findProperty(identifier.getName());
        if (property == null || property.size() == 0) {
            checkResult.recordWarning(Statistics.OTHER_FAILURE, "No value for identifier " + identifier.getName());
            continue;
        }
        if (property.size() > 1) {
            // we don't expect multi-valued identifiers
            checkResult.recordError(Statistics.OTHER_FAILURE, new SchemaException("Multi-valued identifier " + identifier.getName() + " with values " + property.getValues()));
            continue;
        }
        // size == 1
        String value = (String) property.getValue().getValue();
        if (value == null) {
            checkResult.recordWarning(Statistics.OTHER_FAILURE, "Null value for identifier " + identifier.getName());
            continue;
        }
        if (checkUniqueness) {
            if (!checkDuplicatesOnPrimaryIdentifiersOnly || primaryIdentifiers.contains(identifier)) {
                addIdentifierValue(checkResult, context, identifier.getName(), value, shadow);
            }
        }
        if (checkNormalization) {
            doCheckNormalization(checkResult, identifier, value, context);
        }
    }
    applyFixes(checkResult, shadow, workerTask, result);
}
Also used : ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) HashSet(java.util.HashSet) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ShadowAttributesType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) CommonException(com.evolveum.midpoint.util.exception.CommonException) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)

Example 14 with Pair

use of org.apache.commons.lang3.tuple.Pair in project RFToolsDimensions by McJty.

the class GuiDimletWorkbench method updateList.

private void updateList() {
    if (!listDirty) {
        return;
    }
    listDirty = false;
    itemList.removeChildren();
    Map<DimletKey, Settings> dimlets = KnownDimletConfiguration.getKnownDimlets();
    String filter = searchBar.getText().toLowerCase();
    // First remove all dimlets with the same name and also apply the filter already
    Map<Pair<DimletType, String>, DimletKey> uniquelyNamedDimlets = new HashMap<>();
    for (DimletKey key : dimlets.keySet()) {
        String name = KnownDimletConfiguration.getDisplayName(key);
        if (dimletMatches(filter, key, name)) {
            Pair<DimletType, String> k = Pair.of(key.getType(), name);
            if (!uniquelyNamedDimlets.containsKey(k)) {
                uniquelyNamedDimlets.put(k, key);
            }
        }
    }
    List<DimletKey> keys = new ArrayList<>(uniquelyNamedDimlets.values());
    keys.sort((a, b) -> {
        int rc = a.getType().compareTo(b.getType());
        if (rc == 0) {
            return a.getId().compareTo(b.getId());
        } else {
            return rc;
        }
    });
    keys.stream().forEach(key -> addItemToList(key, itemList));
    if (itemList.getFirstSelected() >= itemList.getChildCount()) {
        itemList.setFirstSelected(0);
    }
}
Also used : HashMap(java.util.HashMap) DimletType(mcjty.rftoolsdim.dimensions.dimlets.types.DimletType) ArrayList(java.util.ArrayList) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey) Settings(mcjty.rftoolsdim.config.Settings) Pair(org.apache.commons.lang3.tuple.Pair)

Example 15 with Pair

use of org.apache.commons.lang3.tuple.Pair in project ImmersiveEngineering by BluSunrize.

the class ConnModelReal method getQuads.

@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
    if (side == null && state instanceof IExtendedBlockState) {
        IExtendedBlockState iExtendedBlockState = (IExtendedBlockState) state;
        ExtBlockstateAdapter ad = new ExtBlockstateAdapter(iExtendedBlockState, null, ExtBlockstateAdapter.ONLY_OBJ_CALLBACK);
        int x = 0, z = 0;
        if (iExtendedBlockState.getUnlistedProperties().containsKey(IEProperties.CONNECTIONS)) {
            Set<Connection> conns = iExtendedBlockState.getValue(IEProperties.CONNECTIONS);
            if (conns != null && conns.size() > 0) {
                BlockPos tmp = conns.iterator().next().start;
                x = (tmp.getX() % 16 + 16) % 16;
                z = (tmp.getZ() % 16 + 16) % 16;
            }
        }
        Pair<Byte, ExtBlockstateAdapter> key = new ImmutablePair<>((byte) ((x << 4) | z), ad);
        IBakedModel ret = cache.get(key);
        if (ret == null) {
            ret = new AssembledBakedModel(iExtendedBlockState, textureAtlasSprite, base, rand);
            cache.put(key, ret);
        }
        return ret.getQuads(state, side, rand);
    }
    return base.getQuads(state, side, rand);
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Aggregations

Pair (org.apache.commons.lang3.tuple.Pair)111 ArrayList (java.util.ArrayList)98 Mutable (org.apache.commons.lang3.mutable.Mutable)97 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)87 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)86 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)75 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)73 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)63 Pair (org.apache.hyracks.algebricks.common.utils.Pair)62 MutableObject (org.apache.commons.lang3.mutable.MutableObject)42 List (java.util.List)35 HashMap (java.util.HashMap)34 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)32 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)30 Collectors (java.util.stream.Collectors)29 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)29 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)29 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)27 HashSet (java.util.HashSet)25 File (java.io.File)24