Search in sources :

Example 66 with ImmutableList

use of com.google.common.collect.ImmutableList in project querydsl by querydsl.

the class ReplaceVisitor method visit.

@SuppressWarnings("unchecked")
@Override
public Expression<?> visit(TemplateExpression<?> expr, C context) {
    ImmutableList.Builder builder = ImmutableList.builder();
    for (Object arg : expr.getArgs()) {
        if (arg instanceof Expression) {
            builder.add(((Expression<?>) arg).accept(this, context));
        } else {
            builder.add(arg);
        }
    }
    ImmutableList args = builder.build();
    if (args.equals(expr.getArgs())) {
        return expr;
    } else {
        if (expr instanceof Predicate) {
            return Expressions.booleanTemplate(expr.getTemplate(), args);
        } else {
            return ExpressionUtils.template(expr.getType(), expr.getTemplate(), args);
        }
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList)

Example 67 with ImmutableList

use of com.google.common.collect.ImmutableList in project presto by prestodb.

the class RedisRecordSetProvider method getRecordSet.

@Override
public RecordSet getRecordSet(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorSplit split, List<? extends ColumnHandle> columns) {
    RedisSplit redisSplit = convertSplit(split);
    ImmutableList.Builder<DecoderColumnHandle> handleBuilder = ImmutableList.builder();
    ImmutableMap.Builder<DecoderColumnHandle, FieldDecoder<?>> keyFieldDecoderBuilder = ImmutableMap.builder();
    ImmutableMap.Builder<DecoderColumnHandle, FieldDecoder<?>> valueFieldDecoderBuilder = ImmutableMap.builder();
    RowDecoder keyDecoder = registry.getRowDecoder(redisSplit.getKeyDataFormat());
    RowDecoder valueDecoder = registry.getRowDecoder(redisSplit.getValueDataFormat());
    for (ColumnHandle handle : columns) {
        RedisColumnHandle columnHandle = convertColumnHandle(handle);
        handleBuilder.add(columnHandle);
        if (!columnHandle.isInternal()) {
            if (columnHandle.isKeyDecoder()) {
                FieldDecoder<?> fieldDecoder = registry.getFieldDecoder(redisSplit.getKeyDataFormat(), columnHandle.getType().getJavaType(), columnHandle.getDataFormat());
                keyFieldDecoderBuilder.put(columnHandle, fieldDecoder);
            } else {
                FieldDecoder<?> fieldDecoder = registry.getFieldDecoder(redisSplit.getValueDataFormat(), columnHandle.getType().getJavaType(), columnHandle.getDataFormat());
                valueFieldDecoderBuilder.put(columnHandle, fieldDecoder);
            }
        }
    }
    ImmutableList<DecoderColumnHandle> handles = handleBuilder.build();
    ImmutableMap<DecoderColumnHandle, FieldDecoder<?>> keyFieldDecoders = keyFieldDecoderBuilder.build();
    ImmutableMap<DecoderColumnHandle, FieldDecoder<?>> valueFieldDecoders = valueFieldDecoderBuilder.build();
    return new RedisRecordSet(redisSplit, jedisManager, handles, keyDecoder, valueDecoder, keyFieldDecoders, valueFieldDecoders);
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) RedisHandleResolver.convertColumnHandle(com.facebook.presto.redis.RedisHandleResolver.convertColumnHandle) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) RowDecoder(com.facebook.presto.decoder.RowDecoder) ImmutableMap(com.google.common.collect.ImmutableMap) FieldDecoder(com.facebook.presto.decoder.FieldDecoder)

Example 68 with ImmutableList

use of com.google.common.collect.ImmutableList in project presto by prestodb.

the class TpchIndexProvider method getIndex.

@Override
public ConnectorIndex getIndex(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorIndexHandle indexHandle, List<ColumnHandle> lookupSchema, List<ColumnHandle> outputSchema) {
    TpchIndexHandle tpchIndexHandle = (TpchIndexHandle) indexHandle;
    Map<ColumnHandle, NullableValue> fixedValues = TupleDomain.extractFixedValues(tpchIndexHandle.getFixedValues()).get();
    checkArgument(lookupSchema.stream().noneMatch(handle -> fixedValues.keySet().contains(handle)), "Lookup columnHandles are not expected to overlap with the fixed value predicates");
    // Establish an order for the fixedValues
    List<ColumnHandle> fixedValueColumns = ImmutableList.copyOf(fixedValues.keySet());
    // Extract the fixedValues as their raw values and types
    List<Object> rawFixedValues = new ArrayList<>(fixedValueColumns.size());
    List<Type> rawFixedTypes = new ArrayList<>(fixedValueColumns.size());
    for (ColumnHandle fixedValueColumn : fixedValueColumns) {
        rawFixedValues.add(fixedValues.get(fixedValueColumn).getValue());
        rawFixedTypes.add(((TpchColumnHandle) fixedValueColumn).getType());
    }
    // Establish the schema after we append the fixed values to the lookup keys.
    List<ColumnHandle> finalLookupSchema = ImmutableList.<ColumnHandle>builder().addAll(lookupSchema).addAll(fixedValueColumns).build();
    Optional<TpchIndexedData.IndexedTable> indexedTable = indexedData.getIndexedTable(tpchIndexHandle.getTableName(), tpchIndexHandle.getScaleFactor(), tpchIndexHandle.getIndexColumnNames());
    checkState(indexedTable.isPresent());
    TpchIndexedData.IndexedTable table = indexedTable.get();
    // Compute how to map from the final lookup schema to the table index key order
    List<Integer> keyRemap = computeRemap(handleToNames(finalLookupSchema), table.getKeyColumns());
    Function<RecordSet, RecordSet> keyFormatter = key -> new MappedRecordSet(new AppendingRecordSet(key, rawFixedValues, rawFixedTypes), keyRemap);
    // Compute how to map from the output of the indexed data to the expected output schema
    List<Integer> outputRemap = computeRemap(table.getOutputColumns(), handleToNames(outputSchema));
    Function<RecordSet, RecordSet> outputFormatter = output -> new MappedRecordSet(output, outputRemap);
    return new TpchConnectorIndex(keyFormatter, outputFormatter, table);
}
Also used : ConnectorIndexHandle(com.facebook.presto.spi.ConnectorIndexHandle) Function(com.google.common.base.Function) ConnectorIndexProvider(com.facebook.presto.spi.connector.ConnectorIndexProvider) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) RecordSet(com.facebook.presto.spi.RecordSet) ArrayList(java.util.ArrayList) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ConnectorSession(com.facebook.presto.spi.ConnectorSession) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Collectors.toList(java.util.stream.Collectors.toList) ImmutableList(com.google.common.collect.ImmutableList) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) Type(com.facebook.presto.spi.type.Type) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ConnectorIndex(com.facebook.presto.spi.ConnectorIndex) Optional(java.util.Optional) MappedRecordSet(com.facebook.presto.split.MappedRecordSet) NullableValue(com.facebook.presto.spi.predicate.NullableValue) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) ArrayList(java.util.ArrayList) NullableValue(com.facebook.presto.spi.predicate.NullableValue) Type(com.facebook.presto.spi.type.Type) MappedRecordSet(com.facebook.presto.split.MappedRecordSet) RecordSet(com.facebook.presto.spi.RecordSet) MappedRecordSet(com.facebook.presto.split.MappedRecordSet)

Example 69 with ImmutableList

use of com.google.common.collect.ImmutableList in project presto by prestodb.

the class PrestoVerifier method run.

public int run(String[] args) throws Exception {
    if (args.length > 0) {
        System.setProperty("config", args[0]);
    }
    ImmutableList.Builder<Module> builder = ImmutableList.<Module>builder().add(new PrestoVerifierModule()).addAll(getAdditionalModules());
    Bootstrap app = new Bootstrap(builder.build());
    Injector injector = app.strictConfig().initialize();
    try {
        VerifierConfig config = injector.getInstance(VerifierConfig.class);
        injector.injectMembers(this);
        Set<String> supportedEventClients = injector.getInstance(Key.get(new TypeLiteral<Set<String>>() {
        }, Names.named(SUPPORTED_EVENT_CLIENTS)));
        for (String clientType : config.getEventClients()) {
            checkArgument(supportedEventClients.contains(clientType), "Unsupported event client: %s", clientType);
        }
        Set<EventClient> eventClients = injector.getInstance(Key.get(new TypeLiteral<Set<EventClient>>() {
        }));
        VerifierDao dao = new DBI(config.getQueryDatabase()).onDemand(VerifierDao.class);
        ImmutableList.Builder<QueryPair> queriesBuilder = ImmutableList.builder();
        for (String suite : config.getSuites()) {
            queriesBuilder.addAll(dao.getQueriesBySuite(suite, config.getMaxQueries()));
        }
        List<QueryPair> queries = queriesBuilder.build();
        queries = applyOverrides(config, queries);
        queries = filterQueryTypes(new SqlParser(getParserOptions()), config, queries);
        queries = filterQueries(queries);
        if (config.getShadowWrites()) {
            Sets.SetView<QueryType> allowedTypes = Sets.union(config.getTestQueryTypes(), config.getControlQueryTypes());
            checkArgument(!Sets.intersection(allowedTypes, ImmutableSet.of(CREATE, MODIFY)).isEmpty(), "CREATE or MODIFY queries must be allowed in test or control to use write shadowing");
            queries = rewriteQueries(new SqlParser(getParserOptions()), config, queries);
        }
        // Load jdbc drivers if needed
        if (config.getAdditionalJdbcDriverPath() != null) {
            List<URL> urlList = getUrls(config.getAdditionalJdbcDriverPath());
            URL[] urls = new URL[urlList.size()];
            urlList.toArray(urls);
            if (config.getTestJdbcDriverName() != null) {
                loadJdbcDriver(urls, config.getTestJdbcDriverName());
            }
            if (config.getControlJdbcDriverName() != null) {
                loadJdbcDriver(urls, config.getControlJdbcDriverName());
            }
        }
        // TODO: construct this with Guice
        Verifier verifier = new Verifier(System.out, config, eventClients);
        return verifier.run(queries);
    } finally {
        injector.getInstance(LifeCycleManager.class).stop();
    }
}
Also used : ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) DBI(org.skife.jdbi.v2.DBI) URL(java.net.URL) TypeLiteral(com.google.inject.TypeLiteral) Injector(com.google.inject.Injector) Sets(com.google.common.collect.Sets) Bootstrap(io.airlift.bootstrap.Bootstrap) SqlParser(com.facebook.presto.sql.parser.SqlParser) EventClient(io.airlift.event.client.EventClient) LifeCycleManager(io.airlift.bootstrap.LifeCycleManager) Module(com.google.inject.Module)

Example 70 with ImmutableList

use of com.google.common.collect.ImmutableList in project stash-codesearch-plugin by palantir.

the class SearchServlet method getSoyRankingList.

// Generate a list of ranking aggregation entries for Soy
private static ImmutableList<ImmutableMap<String, Object>> getSoyRankingList(Terms aggregation, long totalCount) {
    ImmutableList.Builder<ImmutableMap<String, Object>> builder = ImmutableList.builder();
    long otherCount = totalCount;
    for (Terms.Bucket bucket : aggregation.getBuckets()) {
        String key = bucket.getKey();
        long count = bucket.getDocCount();
        otherCount -= count;
        builder.add(ImmutableMap.<String, Object>of("key", key, "count", count, "proportion", ((double) count) / totalCount));
    }
    if (otherCount > 0) {
        builder.add(ImmutableMap.<String, Object>of("other", true, "key", "Other", "count", otherCount, "proportion", ((double) otherCount / totalCount)));
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) QueryBuilders.queryString(org.elasticsearch.index.query.QueryBuilders.queryString) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)552 Path (java.nio.file.Path)130 List (java.util.List)112 SourcePath (com.facebook.buck.rules.SourcePath)91 Test (org.junit.Test)78 Step (com.facebook.buck.step.Step)76 ImmutableMap (com.google.common.collect.ImmutableMap)69 IOException (java.io.IOException)64 ArrayList (java.util.ArrayList)63 Map (java.util.Map)62 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)52 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)52 BuildTarget (com.facebook.buck.model.BuildTarget)47 ImmutableSet (com.google.common.collect.ImmutableSet)44 MkdirStep (com.facebook.buck.step.fs.MkdirStep)39 Arguments (com.spectralogic.ds3autogen.api.models.Arguments)38 Optional (java.util.Optional)38 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)36 HumanReadableException (com.facebook.buck.util.HumanReadableException)36 HashMap (java.util.HashMap)35