Search in sources :

Example 81 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project gradle by gradle.

the class CacheBackedTaskHistoryRepository method getDeclaredOutputFilePaths.

private static ImmutableSet<String> getDeclaredOutputFilePaths(final TaskProperties taskProperties, final StringInterner stringInterner) {
    final ImmutableSet.Builder<String> declaredOutputFilePaths = ImmutableSortedSet.naturalOrder();
    FileCollectionInternal outputFiles = (FileCollectionInternal) taskProperties.getOutputFiles();
    outputFiles.visitRootElements(new FileCollectionVisitor() {

        @Override
        public void visitCollection(FileCollectionInternal fileCollection) {
            addAllPaths(fileCollection, declaredOutputFilePaths, stringInterner);
        }

        @Override
        public void visitTree(FileTreeInternal fileTree) {
            DeprecationLogger.nagUserOfDeprecated("Adding file trees which are not directory trees as output files");
            addAllPaths(fileTree, declaredOutputFilePaths, stringInterner);
        }

        @Override
        public void visitDirectoryTree(DirectoryFileTree directoryTree) {
            addPath(directoryTree.getDir(), declaredOutputFilePaths, stringInterner);
        }
    });
    return declaredOutputFilePaths.build();
}
Also used : FileCollectionVisitor(org.gradle.api.internal.file.FileCollectionVisitor) ImmutableSet(com.google.common.collect.ImmutableSet) FileCollectionInternal(org.gradle.api.internal.file.FileCollectionInternal) DirectoryFileTree(org.gradle.api.internal.file.collections.DirectoryFileTree) FileTreeInternal(org.gradle.api.internal.file.FileTreeInternal)

Example 82 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project toolkit by googleapis.

the class RetryDefinitionsTransformer method createRetryCodesDefinition.

public static ImmutableMap<String, ImmutableSet<String>> createRetryCodesDefinition(DiagCollector diagCollector, InterfaceConfigProto interfaceConfigProto) {
    ImmutableMap.Builder<String, ImmutableSet<String>> builder = ImmutableMap.builder();
    for (RetryCodesDefinitionProto retryDef : interfaceConfigProto.getRetryCodesDefList()) {
        // Enforce ordering on set for baseline test consistency.
        Set<String> codes = new TreeSet<>();
        for (String codeText : retryDef.getRetryCodesList()) {
            try {
                codes.add(String.valueOf(codeText));
            } catch (IllegalArgumentException e) {
                diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "status code not found: '%s' (in interface %s)", codeText, interfaceConfigProto.getName()));
            }
        }
        builder.put(retryDef.getName(), (new ImmutableSet.Builder<String>()).addAll(codes).build());
    }
    if (diagCollector.getErrorCount() > 0) {
        return null;
    }
    return builder.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) TreeSet(java.util.TreeSet) RetryCodesDefinitionProto(com.google.api.codegen.RetryCodesDefinitionProto) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 83 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project toolkit by googleapis.

the class DiscoGapicInterfaceConfig method createInterfaceConfig.

static DiscoGapicInterfaceConfig createInterfaceConfig(DiscoApiModel model, String language, InterfaceConfigProto interfaceConfigProto, String interfaceNameOverride, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs) {
    ImmutableMap<String, ImmutableSet<String>> retryCodesDefinition = RetryDefinitionsTransformer.createRetryCodesDefinition(model.getDiagCollector(), interfaceConfigProto);
    ImmutableMap<String, RetrySettings> retrySettingsDefinition = RetryDefinitionsTransformer.createRetrySettingsDefinition(model.getDiagCollector(), interfaceConfigProto);
    List<DiscoGapicMethodConfig> methodConfigs = null;
    ImmutableMap<String, DiscoGapicMethodConfig> methodConfigMap = null;
    if (retryCodesDefinition != null && retrySettingsDefinition != null) {
        methodConfigMap = createMethodConfigMap(model, language, interfaceConfigProto, messageConfigs, resourceNameConfigs, retryCodesDefinition.keySet(), retrySettingsDefinition.keySet());
        methodConfigs = GapicInterfaceConfig.createMethodConfigs(methodConfigMap, interfaceConfigProto);
    }
    // TODO(andrealin)  Make non-null smokeTestConfig.
    SmokeTestConfig smokeTestConfig = null;
    // TODO(andrealin) IAM permissions configs.
    ImmutableList<String> requiredConstructorParams = ImmutableList.copyOf(interfaceConfigProto.getRequiredConstructorParamsList());
    for (String param : interfaceConfigProto.getRequiredConstructorParamsList()) {
        if (!CONSTRUCTOR_PARAMS.contains(param)) {
            model.getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Unsupported constructor param: %s", param));
        }
    }
    ImmutableList.Builder<SingleResourceNameConfig> resourcesBuilder = ImmutableList.builder();
    for (CollectionConfigProto collectionConfigProto : interfaceConfigProto.getCollectionsList()) {
        String entityName = collectionConfigProto.getEntityName();
        ResourceNameConfig resourceName = resourceNameConfigs.get(entityName);
        if (resourceName == null || !(resourceName instanceof SingleResourceNameConfig)) {
            model.getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Inconsistent configuration - single resource name %s specified for interface, " + " but was not found in GapicProductConfig configuration.", entityName));
            return null;
        }
        resourcesBuilder.add((SingleResourceNameConfig) resourceName);
    }
    ImmutableList<SingleResourceNameConfig> singleResourceNames = resourcesBuilder.build();
    ImmutableMap.Builder<MethodConfig, SingleResourceNameConfig> methodToSingleResourceNameMap = ImmutableMap.builder();
    if (methodConfigs != null) {
        for (MethodConfig methodConfig : methodConfigs) {
            Method method = ((DiscoveryMethodModel) methodConfig.getMethodModel()).getDiscoMethod();
            String canonicalMethodPath = DiscoGapicParser.getCanonicalPath(method);
            for (SingleResourceNameConfig nameConfig : singleResourceNames) {
                if (nameConfig.getNamePattern().equals(canonicalMethodPath)) {
                    methodToSingleResourceNameMap.put(methodConfig, nameConfig);
                }
            }
        }
    }
    String manualDoc = Strings.nullToEmpty(interfaceConfigProto.getLangDoc().get(language)).trim();
    String interfaceName = interfaceNameOverride != null ? interfaceNameOverride : DiscoGapicParser.getInterfaceName(interfaceConfigProto.getName()).toUpperCamel();
    if (model.getDiagCollector().hasErrors()) {
        return null;
    } else {
        return new AutoValue_DiscoGapicInterfaceConfig(methodConfigs, retryCodesDefinition, retrySettingsDefinition, requiredConstructorParams, manualDoc, interfaceNameOverride, new DiscoInterfaceModel(interfaceName, model), smokeTestConfig, methodToSingleResourceNameMap.build(), methodConfigMap, singleResourceNames);
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Method(com.google.api.codegen.discovery.Method) ImmutableMap(com.google.common.collect.ImmutableMap) RetrySettings(com.google.api.gax.retrying.RetrySettings) ImmutableSet(com.google.common.collect.ImmutableSet) CollectionConfigProto(com.google.api.codegen.CollectionConfigProto)

Example 84 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project toolkit by googleapis.

the class GapicInterfaceConfig method createInterfaceConfig.

/**
 * Creates an instance of GapicInterfaceConfig based on ConfigProto, linking up method
 * configurations with specified methods in methodConfigMap. On errors, null will be returned, and
 * diagnostics are reported to the model.
 */
@Nullable
static GapicInterfaceConfig createInterfaceConfig(DiagCollector diagCollector, String language, InterfaceConfigProto interfaceConfigProto, Interface apiInterface, String interfaceNameOverride, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs) {
    ImmutableMap<String, ImmutableSet<String>> retryCodesDefinition = RetryDefinitionsTransformer.createRetryCodesDefinition(diagCollector, interfaceConfigProto);
    ImmutableMap<String, RetrySettings> retrySettingsDefinition = RetryDefinitionsTransformer.createRetrySettingsDefinition(diagCollector, interfaceConfigProto);
    List<GapicMethodConfig> methodConfigs = null;
    ImmutableMap<String, GapicMethodConfig> methodConfigMap = null;
    if (retryCodesDefinition != null && retrySettingsDefinition != null) {
        methodConfigMap = createMethodConfigMap(diagCollector, language, interfaceConfigProto, apiInterface, messageConfigs, resourceNameConfigs, retryCodesDefinition.keySet(), retrySettingsDefinition.keySet());
        methodConfigs = createMethodConfigs(methodConfigMap, interfaceConfigProto);
    }
    SmokeTestConfig smokeTestConfig = createSmokeTestConfig(diagCollector, apiInterface, interfaceConfigProto);
    ImmutableList<FieldModel> iamResources = createIamResources(apiInterface.getModel(), interfaceConfigProto.getExperimentalFeatures().getIamResourcesList());
    ImmutableList<String> requiredConstructorParams = ImmutableList.<String>copyOf(interfaceConfigProto.getRequiredConstructorParamsList());
    for (String param : interfaceConfigProto.getRequiredConstructorParamsList()) {
        if (!CONSTRUCTOR_PARAMS.contains(param)) {
            diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Unsupported constructor param: %s", param));
        }
    }
    ImmutableList.Builder<SingleResourceNameConfig> resourcesBuilder = ImmutableList.builder();
    for (CollectionConfigProto collectionConfigProto : interfaceConfigProto.getCollectionsList()) {
        String entityName = collectionConfigProto.getEntityName();
        ResourceNameConfig resourceName = resourceNameConfigs.get(entityName);
        if (resourceName == null || !(resourceName instanceof SingleResourceNameConfig)) {
            diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Inconsistent configuration - single resource name %s specified for interface, " + " but was not found in GapicProductConfig configuration.", entityName));
            return null;
        }
        resourcesBuilder.add((SingleResourceNameConfig) resourceName);
    }
    ImmutableList<SingleResourceNameConfig> singleResourceNames = resourcesBuilder.build();
    String manualDoc = Strings.nullToEmpty(interfaceConfigProto.getLangDoc().get(language)).trim();
    if (diagCollector.hasErrors()) {
        return null;
    } else {
        return new AutoValue_GapicInterfaceConfig(interfaceNameOverride, new ProtoInterfaceModel(apiInterface), methodConfigs, smokeTestConfig, methodConfigMap, retryCodesDefinition, retrySettingsDefinition, iamResources, requiredConstructorParams, singleResourceNames, manualDoc);
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) RetrySettings(com.google.api.gax.retrying.RetrySettings) ImmutableSet(com.google.common.collect.ImmutableSet) CollectionConfigProto(com.google.api.codegen.CollectionConfigProto) Nullable(javax.annotation.Nullable)

Example 85 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project grakn by graknlabs.

the class QueryOperationExecutor method create.

private static QueryOperationExecutor create(Collection<VarPatternAdmin> patterns, GraknTx graph, ExecutionType executionType) {
    ImmutableSet<VarAndProperty> properties = patterns.stream().flatMap(pattern -> VarAndProperty.fromPattern(pattern, executionType)).collect(toImmutableSet());
    /*
            We build several many-to-many relations, indicated by a `Multimap<X, Y>`. These are used to represent
            the dependencies between properties and variables.

            `propDependencies.containsEntry(prop, var)` indicates that the property `prop` cannot be inserted until
            the concept represented by the variable `var` is created.

            For example, the property `$x isa $y` depends on the existence of the concept represented by `$y`.
         */
    Multimap<VarAndProperty, Var> propDependencies = HashMultimap.create();
    for (VarAndProperty property : properties) {
        for (Var requiredVar : property.executor().requiredVars()) {
            propDependencies.put(property, requiredVar);
        }
    }
    /*
            `varDependencies.containsEntry(var, prop)` indicates that the concept represented by the variable `var`
            cannot be created until the property `prop` is inserted.

            For example, the concept represented by `$x` will not exist before the property `$x isa $y` is inserted.
         */
    Multimap<Var, VarAndProperty> varDependencies = HashMultimap.create();
    for (VarAndProperty property : properties) {
        for (Var producedVar : property.executor().producedVars()) {
            varDependencies.put(producedVar, property);
        }
    }
    /*
            Equivalent vars are variables that must represent the same concept as another var.

                 $X label movie, sub entity;
                 $Y label movie;
                 $z isa $Y;

            In this example, `$z isa $Y` must not be inserted before `$Y` is. However, `$Y` does not have enough
            information to insert on its own. It also needs a super type!

            We know `$Y` must represent the same concept as `$X`, because they both share the same label property.
            Therefore, we can share their dependencies, such that:

                varDependencies.containsEntry($X, prop) <=> varDependencies.containsEntry($Y, prop)

            Therefore:

                varDependencies.containsEntry($X, `$X sub entity`) => varDependencies.containsEntry($Y, `$X sub entity`)

            Now we know that `$Y` depends on `$X sub entity` as well as `$X label movie`, which is enough information to
            insert the type!
         */
    Partition<Var> equivalentVars = Partition.singletons(Collections.emptyList());
    equivalentProperties(properties).asMap().values().forEach(vars -> {
        // These vars must refer to the same concept, so share their dependencies
        Collection<VarAndProperty> producers = vars.stream().flatMap(var -> varDependencies.get(var).stream()).collect(toList());
        Var first = vars.iterator().next();
        vars.forEach(var -> {
            varDependencies.replaceValues(var, producers);
            equivalentVars.merge(first, var);
        });
    });
    /*
            Together, `propDependencies` and `varDependencies` can be composed into a single many-to-many relation:

                dependencies = propDependencies ∘ varDependencies

            By doing so, we map _directly_ between properties, skipping the vars. For example, if we previously had:

                propDependencies.containsEntry(`$x isa $y`, `$y`);         // `$x isa $y` depends on `$y`
                varDependencies.containsEntry(`$y`, `$y label movie`);     // `$y` depends on `$y label movie`

            Then it follows that:

                dependencies.containsEntry(`$x isa $y`, `$y label movie`); // `$x isa $y` depends on `$y label movie`

            The `dependencies` relation contains all the information to decide what order to execute the properties.
         */
    Multimap<VarAndProperty, VarAndProperty> dependencies = composeMultimaps(propDependencies, varDependencies);
    return new QueryOperationExecutor(graph, properties, equivalentVars, ImmutableMultimap.copyOf(dependencies));
}
Also used : PropertyExecutor(ai.grakn.graql.internal.pattern.property.PropertyExecutor) Concept(ai.grakn.concept.Concept) InsertQuery(ai.grakn.graql.InsertQuery) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Answer(ai.grakn.graql.admin.Answer) Multimap(com.google.common.collect.Multimap) Multimaps(com.google.common.collect.Multimaps) HashMultimap(com.google.common.collect.HashMultimap) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Partition(ai.grakn.graql.internal.util.Partition) GraknTx(ai.grakn.GraknTx) Map(java.util.Map) QueryAnswer(ai.grakn.graql.internal.query.QueryAnswer) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Nullable(javax.annotation.Nullable) CommonUtil.toImmutableSet(ai.grakn.util.CommonUtil.toImmutableSet) Patterns(ai.grakn.graql.internal.pattern.Patterns) VarPropertyInternal(ai.grakn.graql.internal.pattern.property.VarPropertyInternal) GraqlQueryException(ai.grakn.exception.GraqlQueryException) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Set(java.util.Set) Maps(com.google.common.collect.Maps) Query(ai.grakn.graql.Query) Sets(com.google.common.collect.Sets) VarProperty(ai.grakn.graql.admin.VarProperty) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Var(ai.grakn.graql.Var) AutoValue(com.google.auto.value.AutoValue) DefineQuery(ai.grakn.graql.DefineQuery) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Optional(java.util.Optional) Queue(java.util.Queue) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) Var(ai.grakn.graql.Var)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)348 Set (java.util.Set)86 ImmutableList (com.google.common.collect.ImmutableList)73 Path (java.nio.file.Path)71 ImmutableMap (com.google.common.collect.ImmutableMap)69 IOException (java.io.IOException)67 Optional (java.util.Optional)65 Map (java.util.Map)63 List (java.util.List)60 BuildTarget (com.facebook.buck.model.BuildTarget)58 Test (org.junit.Test)55 HashMap (java.util.HashMap)42 Collection (java.util.Collection)34 HashSet (java.util.HashSet)33 SourcePath (com.facebook.buck.rules.SourcePath)31 ArrayList (java.util.ArrayList)31 TargetNode (com.facebook.buck.rules.TargetNode)28 BuildRule (com.facebook.buck.rules.BuildRule)26 VisibleForTesting (com.google.common.annotations.VisibleForTesting)25 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)25