use of java.util.stream.Stream in project ddf by codice.
the class Associated method getAssociations.
public Collection<Edge> getAssociations(String metacardId) throws UnsupportedQueryException, SourceUnavailableException, FederationException {
Map<String, Metacard> metacardMap = query(withNonrestrictedTags(forRootAndParents(metacardId)));
if (metacardMap.isEmpty()) {
return Collections.emptyList();
}
Metacard root = metacardMap.get(metacardId);
Collection<Metacard> parents = metacardMap.values().stream().filter(m -> !m.getId().equals(metacardId)).collect(Collectors.toList());
Map<String, Metacard> childMetacardMap = query(withNonrestrictedTags(forChildAssociations(root)));
Collection<Edge> parentEdges = createParentEdges(parents, root);
Collection<Edge> childrenEdges = createChildEdges(childMetacardMap.values(), root);
Collection<Edge> edges = Stream.of(parentEdges, childrenEdges).flatMap(Collection::stream).collect(Collectors.toList());
return edges;
}
use of java.util.stream.Stream in project cassandra by apache.
the class SecondaryIndexManager method reload.
/**
* Drops and adds new indexes associated with the underlying CF
*/
public void reload() {
// figure out what needs to be added and dropped.
Indexes tableIndexes = baseCfs.metadata().indexes;
indexes.keySet().stream().filter(indexName -> !tableIndexes.has(indexName)).forEach(this::removeIndex);
// some may not have been created here yet, only added to schema
for (IndexMetadata tableIndex : tableIndexes) addIndex(tableIndex);
}
use of java.util.stream.Stream in project cassandra by apache.
the class SSTableExport method main.
/**
* Given arguments specifying an SSTable, and optionally an output file, export the contents of the SSTable to JSON.
*
* @param args
* command lines arguments
* @throws ConfigurationException
* on configuration failure (wrong params given)
*/
public static void main(String[] args) throws ConfigurationException {
CommandLineParser parser = new PosixParser();
try {
cmd = parser.parse(options, args);
} catch (ParseException e1) {
System.err.println(e1.getMessage());
printUsage();
System.exit(1);
}
if (cmd.getArgs().length != 1) {
System.err.println("You must supply exactly one sstable");
printUsage();
System.exit(1);
}
String[] keys = cmd.getOptionValues(KEY_OPTION);
HashSet<String> excludes = new HashSet<>(Arrays.asList(cmd.getOptionValues(EXCLUDE_KEY_OPTION) == null ? new String[0] : cmd.getOptionValues(EXCLUDE_KEY_OPTION)));
String ssTableFileName = new File(cmd.getArgs()[0]).getAbsolutePath();
if (!new File(ssTableFileName).exists()) {
System.err.println("Cannot find file " + ssTableFileName);
System.exit(1);
}
Descriptor desc = Descriptor.fromFilename(ssTableFileName);
try {
TableMetadata metadata = metadataFromSSTable(desc);
if (cmd.hasOption(ENUMERATE_KEYS_OPTION)) {
try (KeyIterator iter = new KeyIterator(desc, metadata)) {
JsonTransformer.keysToJson(null, iterToStream(iter), cmd.hasOption(RAW_TIMESTAMPS), metadata, System.out);
}
} else {
SSTableReader sstable = SSTableReader.openNoValidation(desc, TableMetadataRef.forOfflineTools(metadata));
IPartitioner partitioner = sstable.getPartitioner();
final ISSTableScanner currentScanner;
if ((keys != null) && (keys.length > 0)) {
List<AbstractBounds<PartitionPosition>> bounds = Arrays.stream(keys).filter(key -> !excludes.contains(key)).map(metadata.partitionKeyType::fromString).map(partitioner::decorateKey).sorted().map(DecoratedKey::getToken).map(token -> new Bounds<>(token.minKeyBound(), token.maxKeyBound())).collect(Collectors.toList());
currentScanner = sstable.getScanner(bounds.iterator());
} else {
currentScanner = sstable.getScanner();
}
Stream<UnfilteredRowIterator> partitions = iterToStream(currentScanner).filter(i -> excludes.isEmpty() || !excludes.contains(metadata.partitionKeyType.getString(i.partitionKey().getKey())));
if (cmd.hasOption(DEBUG_OUTPUT_OPTION)) {
AtomicLong position = new AtomicLong();
partitions.forEach(partition -> {
position.set(currentScanner.getCurrentPosition());
if (!partition.partitionLevelDeletion().isLive()) {
System.out.println("[" + metadata.partitionKeyType.getString(partition.partitionKey().getKey()) + "]@" + position.get() + " " + partition.partitionLevelDeletion());
}
if (!partition.staticRow().isEmpty()) {
System.out.println("[" + metadata.partitionKeyType.getString(partition.partitionKey().getKey()) + "]@" + position.get() + " " + partition.staticRow().toString(metadata, true));
}
partition.forEachRemaining(row -> {
System.out.println("[" + metadata.partitionKeyType.getString(partition.partitionKey().getKey()) + "]@" + position.get() + " " + row.toString(metadata, false, true));
position.set(currentScanner.getCurrentPosition());
});
});
} else {
JsonTransformer.toJson(currentScanner, partitions, cmd.hasOption(RAW_TIMESTAMPS), metadata, System.out);
}
}
} catch (IOException e) {
// throwing exception outside main with broken pipe causes windows cmd to hang
e.printStackTrace(System.err);
}
System.exit(0);
}
use of java.util.stream.Stream in project crate by crate.
the class TransportKillNodeAction method broadcast.
public void broadcast(Request request, ActionListener<KillResponse> listener, Collection<String> excludedNodeIds) {
Stream<DiscoveryNode> nodes = StreamSupport.stream(clusterService.state().nodes().spliterator(), false);
Collection<DiscoveryNode> filteredNodes = nodes.filter(node -> !excludedNodeIds.contains(node.getId())).collect(Collectors.toList());
listener = new MultiActionListener<>(filteredNodes.size(), KillResponse.MERGE_FUNCTION, listener);
DefaultTransportResponseHandler<KillResponse> responseHandler = new DefaultTransportResponseHandler<KillResponse>(listener) {
@Override
public KillResponse newInstance() {
return new KillResponse(0);
}
};
for (DiscoveryNode node : filteredNodes) {
transportService.sendRequest(node, name, request, responseHandler);
}
}
use of java.util.stream.Stream in project crate by crate.
the class BlobPathITest method testDataIsStoredInTableSpecificBlobPath.
@Test
public void testDataIsStoredInTableSpecificBlobPath() throws Exception {
launchNodeAndInitClient(configureGlobalBlobPath());
Path tableBlobPath = createTempDir("tableBlobPath");
Settings indexSettings = Settings.builder().put(oneShardAndZeroReplicas()).put(BlobIndicesService.SETTING_INDEX_BLOBS_PATH, tableBlobPath.toString()).build();
blobAdminClient.createBlobTable("test", indexSettings).get();
client.put("test", "abcdefg");
String digest = "2fb5e13419fc89246865e7a324f476ec624e8740";
try (Stream<Path> files = Files.walk(tableBlobPath)) {
assertThat(files.anyMatch(i -> digest.equals(i.getFileName().toString())), is(true));
}
}
Aggregations