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);
}
}
}
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);
}
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);
}
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();
}
}
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();
}
Aggregations