use of org.apache.hop.databases.cassandra.datastax.TableMetaData in project hop by apache.
the class DriverCqlRowHandlerTest method testBatchInsert.
@Test
public void testBatchInsert() throws Exception {
DriverKeyspace keyspace = mock(DriverKeyspace.class);
when(keyspace.getName()).thenReturn("ks");
Session session = mock(Session.class);
TableMetaData familyMeta = mock(TableMetaData.class);
ArrayList<Object[]> batch = new ArrayList<>();
batch.add(new Object[] { 1L, "a" });
batch.add(new Object[] { 2L, "b" });
RowMeta rowMeta = new RowMeta();
rowMeta.addValueMeta(new ValueMetaInteger("id"));
rowMeta.addValueMeta(new ValueMetaString("a spaced name"));
when(familyMeta.getTableName()).thenReturn("tab tab");
when(familyMeta.columnExistsInSchema(anyString())).thenReturn(true);
DriverCqlRowHandler rowHandler = new DriverCqlRowHandler(keyspace, session, true);
rowHandler.batchInsert(rowMeta, batch, familyMeta, null, true, null);
verify(session, times(1)).execute(argThat(new ArgumentMatcher<Statement>() {
@Override
public boolean matches(Object argument) {
Statement stmt = (Statement) argument;
return stmt.toString().equals("BEGIN UNLOGGED BATCH INSERT INTO ks.\"tab tab\" (id,\"a spaced name\") " + "VALUES (1,'a');INSERT INTO ks.\"tab tab\" (id,\"a spaced name\") VALUES (2,'b');APPLY BATCH;");
}
}));
}
use of org.apache.hop.databases.cassandra.datastax.TableMetaData in project hop by apache.
the class DriverCqlRowHandlerTest method testBatchInsertIgnoreColumns.
@Test
public void testBatchInsertIgnoreColumns() throws Exception {
DriverKeyspace keyspace = mock(DriverKeyspace.class);
when(keyspace.getName()).thenReturn("ks");
Session session = mock(Session.class);
TableMetaData familyMeta = mock(TableMetaData.class);
when(familyMeta.getTableName()).thenReturn("tab");
ArrayList<Object[]> batch = new ArrayList<>();
batch.add(new Object[] { 1, 1L, 2L, 3L, 4L });
batch.add(new Object[] { 2, 5L, 6L, 7L, 8L });
RowMeta rowMeta = new RowMeta();
rowMeta.addValueMeta(new ValueMetaInteger("nope"));
rowMeta.addValueMeta(new ValueMetaInteger("there1"));
rowMeta.addValueMeta(new ValueMetaInteger("not there"));
rowMeta.addValueMeta(new ValueMetaInteger("there2"));
rowMeta.addValueMeta(new ValueMetaInteger("also not there"));
when(familyMeta.columnExistsInSchema(anyString())).then(args -> {
return ((String) args.getArguments()[0]).startsWith("there");
});
DriverCqlRowHandler rowHandler = new DriverCqlRowHandler(keyspace, session, true);
rowHandler.setUnloggedBatch(false);
rowHandler.batchInsert(rowMeta, batch, familyMeta, "TWO", false, null);
verify(session, times(1)).execute(argThat(new ArgumentMatcher<Statement>() {
@Override
public boolean matches(Object argument) {
Statement stmt = (Statement) argument;
return stmt.toString().equals("BEGIN BATCH INSERT INTO ks.tab (there1,there2) " + "VALUES (1,3);INSERT INTO ks.tab (there1,there2) VALUES (5,7);APPLY BATCH;") && stmt.getConsistencyLevel().equals(ConsistencyLevel.TWO);
}
}));
}
Aggregations