use of com.datastax.driver.core.ResultSet in project apex-malhar by apache.
the class AbstractUpsertOutputOperatorCodecsTest method testForListPrepend.
@Test
public void testForListPrepend() throws Exception {
User aUser = new User();
String userId = "user" + System.currentTimeMillis();
aUser.setUserid(userId);
FullName fullName = new FullName("first1" + System.currentTimeMillis(), "last1" + System.currentTimeMillis());
aUser.setUsername(fullName);
List<Integer> topScores = new ArrayList<>();
topScores.add(1);
topScores.add(2);
aUser.setTopScores(topScores);
UpsertExecutionContext<User> originalEntry = new UpsertExecutionContext<>();
originalEntry.setPayload(aUser);
UpsertExecutionContext<User> subsequentUpdateForTopScores = new UpsertExecutionContext<>();
subsequentUpdateForTopScores.setListPlacementStyle(UpsertExecutionContext.ListPlacementStyle.PREPEND_TO_EXISTING_LIST);
subsequentUpdateForTopScores.setCollectionMutationStyle(UpsertExecutionContext.CollectionMutationStyle.ADD_TO_EXISTING_COLLECTION);
subsequentUpdateForTopScores.setNullHandlingMutationStyle(UpsertExecutionContext.NullHandlingMutationStyle.IGNORE_NULL_COLUMNS);
User oldUser = new User();
oldUser.setUserid(userId);
List<Integer> topScoresAppended = new ArrayList<>();
topScoresAppended.add(3);
oldUser.setTopScores(topScoresAppended);
subsequentUpdateForTopScores.setPayload(oldUser);
userUpsertOperator.beginWindow(2);
userUpsertOperator.input.process(originalEntry);
userUpsertOperator.input.process(subsequentUpdateForTopScores);
userUpsertOperator.endWindow();
ResultSet results = userUpsertOperator.session.execute("SELECT * FROM unittests.users WHERE userid = '" + userId + "'");
List<Row> rows = results.all();
Row userRow = rows.get(0);
List<Integer> topScoresEntry = userRow.getList("top_scores", Integer.class);
assertEquals(3, topScoresEntry.size());
assertEquals("" + 3, "" + topScoresEntry.get(0));
}
use of com.datastax.driver.core.ResultSet in project apex-malhar by apache.
the class AbstractUpsertOutputOperatorCodecsTest method testForSingleRowInsertWithTTL.
@Test
public void testForSingleRowInsertWithTTL() throws Exception {
User aUser = new User();
aUser.setUserid("userWithTTL" + System.currentTimeMillis());
FullName fullName = new FullName("firstname" + System.currentTimeMillis(), "lasName" + System.currentTimeMillis());
aUser.setUsername(fullName);
Address address = new Address("city1", "Street1", 12, null);
aUser.setCurrentaddress(address);
UpsertExecutionContext<User> anUpdate = new UpsertExecutionContext<>();
anUpdate.setOverridingTTL(5000);
anUpdate.setPayload(aUser);
userUpsertOperator.beginWindow(7);
userUpsertOperator.input.process(anUpdate);
userUpsertOperator.endWindow();
ResultSet results = userUpsertOperator.session.execute("SELECT * FROM unittests.users WHERE userid = '" + aUser.getUserid() + "'");
List<Row> rows = results.all();
assertEquals(rows.size(), 1);
assertTrue(results.isExhausted());
}
use of com.datastax.driver.core.ResultSet in project apex-malhar by apache.
the class AbstractUpsertOutputOperatorCodecsTest method testForListPrependAndExplicitNullForSomeColumns.
@Test
public void testForListPrependAndExplicitNullForSomeColumns() throws Exception {
User aUser = new User();
String userId = "user" + System.currentTimeMillis();
aUser.setUserid(userId);
FullName fullName = new FullName("first24" + System.currentTimeMillis(), "last" + System.currentTimeMillis());
aUser.setUsername(fullName);
List<Integer> topScores = new ArrayList<>();
topScores.add(1);
topScores.add(2);
aUser.setTopScores(topScores);
UpsertExecutionContext<User> originalEntry = new UpsertExecutionContext<>();
originalEntry.setPayload(aUser);
UpsertExecutionContext<User> subsequentUpdateForTopScores = new UpsertExecutionContext<>();
subsequentUpdateForTopScores.setListPlacementStyle(UpsertExecutionContext.ListPlacementStyle.PREPEND_TO_EXISTING_LIST);
subsequentUpdateForTopScores.setCollectionMutationStyle(UpsertExecutionContext.CollectionMutationStyle.ADD_TO_EXISTING_COLLECTION);
subsequentUpdateForTopScores.setNullHandlingMutationStyle(UpsertExecutionContext.NullHandlingMutationStyle.SET_NULL_COLUMNS);
User oldUser = new User();
oldUser.setUserid(userId);
List<Integer> topScoresAppended = new ArrayList<>();
topScoresAppended.add(3);
oldUser.setTopScores(topScoresAppended);
subsequentUpdateForTopScores.setPayload(oldUser);
userUpsertOperator.beginWindow(6);
userUpsertOperator.input.process(originalEntry);
userUpsertOperator.input.process(subsequentUpdateForTopScores);
userUpsertOperator.endWindow();
ResultSet results = userUpsertOperator.session.execute("SELECT * FROM unittests.users WHERE userid = '" + userId + "'");
List<Row> rows = results.all();
Row userRow = rows.get(0);
FullName name = userRow.get("username", FullName.class);
assertEquals(null, name);
}
use of com.datastax.driver.core.ResultSet in project apex-malhar by apache.
the class AbstractUpsertOutputOperatorCodecsTest method testForCollectionRemovalAndIfExists.
@Test
public void testForCollectionRemovalAndIfExists() throws Exception {
User aUser = new User();
String userId = "user" + System.currentTimeMillis();
aUser.setUserid(userId);
FullName fullName = new FullName("first12" + System.currentTimeMillis(), "last12" + System.currentTimeMillis());
aUser.setUsername(fullName);
Set<String> emails = new HashSet<>();
emails.add(new String("1"));
emails.add(new String("2"));
aUser.setEmails(emails);
UpsertExecutionContext<User> originalEntry = new UpsertExecutionContext<>();
originalEntry.setPayload(aUser);
UpsertExecutionContext<User> subsequentUpdateForEmails = new UpsertExecutionContext<>();
subsequentUpdateForEmails.setCollectionMutationStyle(UpsertExecutionContext.CollectionMutationStyle.REMOVE_FROM_EXISTING_COLLECTION);
subsequentUpdateForEmails.setNullHandlingMutationStyle(UpsertExecutionContext.NullHandlingMutationStyle.IGNORE_NULL_COLUMNS);
subsequentUpdateForEmails.setUpdateOnlyIfPrimaryKeyExists(true);
User oldUser = new User();
// overriding with a non-existent user id
oldUser.setUserid(userId + System.currentTimeMillis());
Set<String> updatedEmails = new HashSet<>();
updatedEmails.add(new String("1"));
oldUser.setEmails(updatedEmails);
subsequentUpdateForEmails.setPayload(oldUser);
userUpsertOperator.beginWindow(4);
userUpsertOperator.input.process(originalEntry);
userUpsertOperator.input.process(subsequentUpdateForEmails);
userUpsertOperator.endWindow();
ResultSet results = userUpsertOperator.session.execute("SELECT * FROM unittests.users WHERE userid = '" + userId + "'");
List<Row> rows = results.all();
Row userRow = rows.get(0);
Set<String> existingEmailsEntry = userRow.getSet("emails", String.class);
assertEquals(2, existingEmailsEntry.size());
assertEquals("" + 1, "" + existingEmailsEntry.iterator().next());
}
use of com.datastax.driver.core.ResultSet in project FlareBot by FlareBot.
the class FlareBot method migrations.
public void migrations() {
CassandraController.runTask(session -> {
session.execute("CREATE TABLE IF NOT EXISTS flarebot.announces (" + "guild_id varchar PRIMARY KEY," + "channel_id varchar)");
ResultSet set = session.execute("SELECT * FROM flarebot.announces");
Row row;
while ((row = set.one()) != null) {
FlareBotManager.instance().getGuild(row.getString(0)).setMusicAnnounceChannelId(row.getString(1));
}
session.execute("CREATE TABLE IF NOT EXISTS flarebot.prefixes (" + "guild_id varchar PRIMARY KEY, " + "prefix varchar" + ")");
set = session.execute("SELECT * FROM flarebot.prefixes;");
while ((row = set.one()) != null) {
FlareBotManager.instance().getGuild(row.getString(0)).setPrefix(row.getString(1).charAt(0));
}
});
}
Aggregations