Search in sources :

Example 96 with ImmutableSet

use of com.google.common.collect.ImmutableSet in project hive by apache.

the class HiveTableScan method buildColIndxsFrmReloptHT.

private static Pair<ImmutableList<Integer>, ImmutableSet<Integer>> buildColIndxsFrmReloptHT(RelOptHiveTable relOptHTable, RelDataType scanRowType) {
    RelDataType relOptHtRowtype = relOptHTable.getRowType();
    ImmutableList<Integer> neededColIndxsFrmReloptHT;
    Builder<Integer> neededColIndxsFrmReloptHTBldr = new ImmutableList.Builder<Integer>();
    ImmutableSet<Integer> viurtualOrPartColIndxsInTS;
    ImmutableSet.Builder<Integer> viurtualOrPartColIndxsInTSBldr = new ImmutableSet.Builder<Integer>();
    Map<String, Integer> colNameToPosInReloptHT = HiveCalciteUtil.getRowColNameIndxMap(relOptHtRowtype.getFieldList());
    List<String> colNamesInScanRowType = scanRowType.getFieldNames();
    int partOrVirtualColStartPosInrelOptHtRowtype = relOptHTable.getNonPartColumns().size();
    int tmp;
    for (int i = 0; i < colNamesInScanRowType.size(); i++) {
        tmp = colNameToPosInReloptHT.get(colNamesInScanRowType.get(i));
        neededColIndxsFrmReloptHTBldr.add(tmp);
        if (tmp >= partOrVirtualColStartPosInrelOptHtRowtype) {
            viurtualOrPartColIndxsInTSBldr.add(i);
        }
    }
    neededColIndxsFrmReloptHT = neededColIndxsFrmReloptHTBldr.build();
    viurtualOrPartColIndxsInTS = viurtualOrPartColIndxsInTSBldr.build();
    return new Pair<ImmutableList<Integer>, ImmutableSet<Integer>>(neededColIndxsFrmReloptHT, viurtualOrPartColIndxsInTS);
}
Also used : RelBuilder(org.apache.calcite.tools.RelBuilder) RexBuilder(org.apache.calcite.rex.RexBuilder) Builder(com.google.common.collect.ImmutableList.Builder) RelDataType(org.apache.calcite.rel.type.RelDataType) ImmutableSet(com.google.common.collect.ImmutableSet) Pair(org.apache.calcite.util.Pair)

Example 97 with ImmutableSet

use of com.google.common.collect.ImmutableSet in project bazel by bazelbuild.

the class SkylarkAttr method createAttribute.

private static Attribute.Builder<?> createAttribute(Type<?> type, SkylarkDict<String, Object> arguments, FuncallExpression ast, Environment env) throws EvalException, ConversionException {
    // We use an empty name now so that we can set it later.
    // This trick makes sense only in the context of Skylark (builtin rules should not use it).
    Attribute.Builder<?> builder = Attribute.attr("", type);
    Object defaultValue = arguments.get(DEFAULT_ARG);
    if (!EvalUtils.isNullOrNone(defaultValue)) {
        if (defaultValue instanceof UserDefinedFunction) {
            // Computed attribute. Non label type attributes already caused a type check error.
            SkylarkCallbackFunction callback = new SkylarkCallbackFunction((UserDefinedFunction) defaultValue, ast, env);
            // SkylarkComputedDefaultTemplate needs to know the names of all attributes that it depends
            // on. However, this method does not know anything about other attributes.
            // We solve this problem by asking the SkylarkCallbackFunction for the parameter names used
            // in the function definition, which must be the names of attributes used by the callback.
            builder.value(new SkylarkComputedDefaultTemplate(type, callback.getParameterNames(), callback, ast.getLocation()));
        } else {
            builder.defaultValue(defaultValue, env.getGlobals().label());
        }
    }
    for (String flag : SkylarkList.castSkylarkListOrNoneToList(arguments.get(FLAGS_ARG), String.class, FLAGS_ARG)) {
        builder.setPropertyFlag(flag);
    }
    if (containsNonNoneKey(arguments, MANDATORY_ARG) && (Boolean) arguments.get(MANDATORY_ARG)) {
        builder.setPropertyFlag("MANDATORY");
    }
    // TODO(laurentlb): Deprecated, remove in August 2016 (use allow_empty instead).
    if (containsNonNoneKey(arguments, NON_EMPTY_ARG) && (Boolean) arguments.get(NON_EMPTY_ARG)) {
        builder.setPropertyFlag("NON_EMPTY");
    }
    if (containsNonNoneKey(arguments, ALLOW_EMPTY_ARG) && !(Boolean) arguments.get(ALLOW_EMPTY_ARG)) {
        builder.setPropertyFlag("NON_EMPTY");
    }
    if (containsNonNoneKey(arguments, EXECUTABLE_ARG) && (Boolean) arguments.get(EXECUTABLE_ARG)) {
        builder.setPropertyFlag("EXECUTABLE");
        if (!containsNonNoneKey(arguments, CONFIGURATION_ARG)) {
            throw new EvalException(ast.getLocation(), "cfg parameter is mandatory when executable=True is provided. Please see " + "https://www.bazel.build/versions/master/docs/skylark/rules.html#configurations " + "for more details.");
        }
    }
    // TODO(laurentlb): Deprecated, remove in August 2016 (use allow_single_file).
    if (containsNonNoneKey(arguments, SINGLE_FILE_ARG) && (Boolean) arguments.get(SINGLE_FILE_ARG)) {
        if (containsNonNoneKey(arguments, ALLOW_SINGLE_FILE_ARG)) {
            throw new EvalException(ast.getLocation(), "Cannot specify both single_file (deprecated) and allow_single_file");
        }
        builder.setPropertyFlag("SINGLE_ARTIFACT");
    }
    if (containsNonNoneKey(arguments, ALLOW_FILES_ARG) && containsNonNoneKey(arguments, ALLOW_SINGLE_FILE_ARG)) {
        throw new EvalException(ast.getLocation(), "Cannot specify both allow_files and allow_single_file");
    }
    if (containsNonNoneKey(arguments, ALLOW_FILES_ARG)) {
        Object fileTypesObj = arguments.get(ALLOW_FILES_ARG);
        setAllowedFileTypes(ALLOW_FILES_ARG, fileTypesObj, ast, builder);
    } else if (containsNonNoneKey(arguments, ALLOW_SINGLE_FILE_ARG)) {
        Object fileTypesObj = arguments.get(ALLOW_SINGLE_FILE_ARG);
        setAllowedFileTypes(ALLOW_SINGLE_FILE_ARG, fileTypesObj, ast, builder);
        builder.setPropertyFlag("SINGLE_ARTIFACT");
    } else if (type.getLabelClass() == LabelClass.DEPENDENCY) {
        builder.allowedFileTypes(FileTypeSet.NO_FILE);
    }
    Object ruleClassesObj = arguments.get(ALLOW_RULES_ARG);
    if (ruleClassesObj != null && ruleClassesObj != Runtime.NONE) {
        builder.allowedRuleClasses(SkylarkList.castSkylarkListOrNoneToList(ruleClassesObj, String.class, "allowed rule classes for attribute definition"));
    }
    List<Object> values = SkylarkList.castSkylarkListOrNoneToList(arguments.get(VALUES_ARG), Object.class, VALUES_ARG);
    if (!Iterables.isEmpty(values)) {
        builder.allowedValues(new AllowedValueSet(values));
    }
    if (containsNonNoneKey(arguments, PROVIDERS_ARG)) {
        Object obj = arguments.get(PROVIDERS_ARG);
        SkylarkType.checkType(obj, SkylarkList.class, PROVIDERS_ARG);
        ImmutableList<ImmutableSet<SkylarkProviderIdentifier>> providersList = buildProviderPredicate((SkylarkList<?>) obj, PROVIDERS_ARG, ast.getLocation());
        builder.mandatoryProvidersList(providersList);
    }
    if (containsNonNoneKey(arguments, CONFIGURATION_ARG)) {
        Object trans = arguments.get(CONFIGURATION_ARG);
        if (trans.equals("data")) {
            builder.cfg(ConfigurationTransition.DATA);
        } else if (trans.equals("host")) {
            builder.cfg(ConfigurationTransition.HOST);
        } else if (trans instanceof SplitTransition<?>) {
            builder.cfg((SplitTransition<?>) trans);
        } else if (!trans.equals("target")) {
            throw new EvalException(ast.getLocation(), "cfg must be either 'data', 'host', or 'target'.");
        }
    }
    if (containsNonNoneKey(arguments, ASPECTS_ARG)) {
        Object obj = arguments.get(ASPECTS_ARG);
        SkylarkType.checkType(obj, SkylarkList.class, ASPECTS_ARG);
        List<SkylarkAspect> aspects = ((SkylarkList<?>) obj).getContents(SkylarkAspect.class, "aspects");
        for (SkylarkAspect aspect : aspects) {
            builder.aspect(aspect, ast.getLocation());
        }
    }
    return builder;
}
Also used : SkylarkCallbackFunction(com.google.devtools.build.lib.syntax.SkylarkCallbackFunction) UserDefinedFunction(com.google.devtools.build.lib.syntax.UserDefinedFunction) Attribute(com.google.devtools.build.lib.packages.Attribute) EvalException(com.google.devtools.build.lib.syntax.EvalException) SkylarkList(com.google.devtools.build.lib.syntax.SkylarkList) SplitTransition(com.google.devtools.build.lib.packages.Attribute.SplitTransition) ImmutableSet(com.google.common.collect.ImmutableSet) SkylarkAspect(com.google.devtools.build.lib.packages.SkylarkAspect) SkylarkComputedDefaultTemplate(com.google.devtools.build.lib.packages.Attribute.SkylarkComputedDefaultTemplate) AllowedValueSet(com.google.devtools.build.lib.packages.Attribute.AllowedValueSet)

Example 98 with ImmutableSet

use of com.google.common.collect.ImmutableSet in project bazel by bazelbuild.

the class SkyQueryEnvironment method getTargetsMatchingPattern.

@ThreadSafe
@Override
public QueryTaskFuture<Void> getTargetsMatchingPattern(final QueryExpression owner, String pattern, Callback<Target> callback) {
    // Directly evaluate the target pattern, making use of packages in the graph.
    Pair<TargetPattern, ImmutableSet<PathFragment>> patternToEvalAndSubdirectoriesToExclude;
    try {
        patternToEvalAndSubdirectoriesToExclude = getPatternAndExcludes(pattern);
    } catch (TargetParsingException tpe) {
        try {
            reportBuildFileError(owner, tpe.getMessage());
        } catch (QueryException qe) {
            return immediateFailedFuture(qe);
        }
        return immediateSuccessfulFuture(null);
    } catch (InterruptedException ie) {
        return immediateCancelledFuture();
    }
    TargetPattern patternToEval = patternToEvalAndSubdirectoriesToExclude.getFirst();
    ImmutableSet<PathFragment> subdirectoriesToExclude = patternToEvalAndSubdirectoriesToExclude.getSecond();
    AsyncFunction<TargetParsingException, Void> reportBuildFileErrorAsyncFunction = new AsyncFunction<TargetParsingException, Void>() {

        @Override
        public ListenableFuture<Void> apply(TargetParsingException exn) throws QueryException {
            reportBuildFileError(owner, exn.getMessage());
            return Futures.immediateFuture(null);
        }
    };
    ListenableFuture<Void> evalFuture = patternToEval.evalAsync(resolver, subdirectoriesToExclude, callback, QueryException.class, executor);
    return QueryTaskFutureImpl.ofDelegate(Futures.catchingAsync(evalFuture, TargetParsingException.class, reportBuildFileErrorAsyncFunction));
}
Also used : QueryException(com.google.devtools.build.lib.query2.engine.QueryException) TargetPattern(com.google.devtools.build.lib.cmdline.TargetPattern) ImmutableSet(com.google.common.collect.ImmutableSet) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) AsyncFunction(com.google.common.util.concurrent.AsyncFunction) ThreadSafe(com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe)

Example 99 with ImmutableSet

use of com.google.common.collect.ImmutableSet in project bazel by bazelbuild.

the class J2ObjcAspect method java.

private ConfiguredAspect java(ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) throws InterruptedException {
    JavaCompilationArgsProvider compilationArgsProvider = base.getProvider(JavaCompilationArgsProvider.class);
    JavaSourceInfoProvider sourceInfoProvider = base.getProvider(JavaSourceInfoProvider.class);
    JavaGenJarsProvider genJarProvider = base.getProvider(JavaGenJarsProvider.class);
    ImmutableSet.Builder<Artifact> javaSourceFilesBuilder = ImmutableSet.builder();
    ImmutableSet.Builder<Artifact> javaSourceJarsBuilder = ImmutableSet.builder();
    if (sourceInfoProvider != null) {
        javaSourceFilesBuilder.addAll(sourceInfoProvider.getSourceFiles());
        javaSourceJarsBuilder.addAll(sourceInfoProvider.getSourceJars()).addAll(sourceInfoProvider.getSourceJarsForJarFiles());
    }
    if (genJarProvider != null && genJarProvider.getGenSourceJar() != null) {
        javaSourceJarsBuilder.add(genJarProvider.getGenSourceJar());
    }
    ImmutableSet<Artifact> javaSourceFiles = javaSourceFilesBuilder.build();
    ImmutableSet<Artifact> javaSourceJars = javaSourceJarsBuilder.build();
    J2ObjcSource j2ObjcSource = javaJ2ObjcSource(ruleContext, javaSourceFiles, javaSourceJars);
    J2ObjcMappingFileProvider depJ2ObjcMappingFileProvider = depJ2ObjcMappingFileProvider(ruleContext);
    J2ObjcMappingFileProvider directJ2ObjcMappingFileProvider;
    if (Iterables.isEmpty(j2ObjcSource.getObjcSrcs())) {
        directJ2ObjcMappingFileProvider = new J2ObjcMappingFileProvider.Builder().build();
    } else {
        directJ2ObjcMappingFileProvider = createJ2ObjcTranspilationAction(ruleContext, javaSourceFiles, javaSourceJars, depJ2ObjcMappingFileProvider, compilationArgsProvider, j2ObjcSource);
    }
    return buildAspect(base, ruleContext, parameters, j2ObjcSource, directJ2ObjcMappingFileProvider, JAVA_DEPENDENT_ATTRIBUTES);
}
Also used : JavaCompilationArgsProvider(com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider) ImmutableSet(com.google.common.collect.ImmutableSet) JavaSourceInfoProvider(com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider) JavaGenJarsProvider(com.google.devtools.build.lib.rules.java.JavaGenJarsProvider) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) ProtoCompileActionBuilder(com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 100 with ImmutableSet

use of com.google.common.collect.ImmutableSet in project bazel by bazelbuild.

the class ProtocolBuffers2Support method getIncludes.

public ImmutableSet<PathFragment> getIncludes() {
    ImmutableSet.Builder<PathFragment> searchPathEntriesBuilder = new ImmutableSet.Builder<PathFragment>().add(getWorkspaceRelativeOutputDir());
    if (attributes.needsPerProtoIncludes()) {
        PathFragment generatedProtoDir = new PathFragment(getWorkspaceRelativeOutputDir(), ruleContext.getLabel().getPackageFragment());
        searchPathEntriesBuilder.add(generatedProtoDir).addAll(Iterables.transform(getGeneratedProtoOutputs(getHeaderExtension()), PARENT_PATHFRAGMENT));
    }
    return searchPathEntriesBuilder.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)196 Path (java.nio.file.Path)65 BuildTarget (com.facebook.buck.model.BuildTarget)58 ImmutableMap (com.google.common.collect.ImmutableMap)44 ImmutableList (com.google.common.collect.ImmutableList)43 IOException (java.io.IOException)42 Optional (java.util.Optional)37 Test (org.junit.Test)32 SourcePath (com.facebook.buck.rules.SourcePath)31 TargetNode (com.facebook.buck.rules.TargetNode)28 BuildRule (com.facebook.buck.rules.BuildRule)26 Map (java.util.Map)26 List (java.util.List)25 Set (java.util.Set)25 HumanReadableException (com.facebook.buck.util.HumanReadableException)23 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)22 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)21 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)20 TargetGraph (com.facebook.buck.rules.TargetGraph)19 VisibleForTesting (com.google.common.annotations.VisibleForTesting)19