Created
July 20, 2017 20:22
-
-
Save jsanda/9ce6aa7cb6be079f906a21e4a1fdb9ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// and then the age of enlightenment | |
private Map<String,String> getMappingTable() { | |
// You only want to prepare the query once. Best to do it when you initialize the session. | |
PreparedStatement findMappings = session.prepare( | |
"SELECT project_id, project_name " + | |
"FROM openshift_metrics.metrics_mappings " + | |
"WHERE token(project_id) > ? AND token(project_id) <= ?"); | |
RxSession rxSession = new RxSessionImpl(session); | |
Map<String,String> mappings = new HashMap<>(); | |
if (hasMappingTable()) { | |
Observable.from(getTokenRanges()) | |
.flatMap(tokenRange -> { | |
BoundStatement boundStatement = findMappings.bind().setToken(0, tokenRange.getStart()) | |
.setToken(1, tokenRange.getEnd()); | |
return rxSession.execute(boundStatement); | |
}) | |
.flatMap(Observable::from) | |
.collect(HashMap::new, ((map, row) -> map.put(row.getString(0), row.getString(1))) ) | |
.toBlocking() | |
.firstOrDefault(new HashMap<>()); | |
} | |
return Collections.emptyMap(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment