Search in sources :

Example 11 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-cassandra-plugin by pentaho.

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);
        }
    }));
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) Statement(com.datastax.driver.core.Statement) ArgumentMatcher(org.mockito.ArgumentMatcher) ArrayList(java.util.ArrayList) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) Matchers.anyString(org.mockito.Matchers.anyString) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Example 12 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-cassandra-plugin by pentaho.

the class DriverCQLRowHandlerTest method testQueryRowsTimestamp.

@Test
public void testQueryRowsTimestamp() {
    Row row = mock(Row.class);
    when(row.getLong(0)).thenReturn(1L);
    when(row.getTimestamp(1)).thenReturn(new Date(1520538054000L));
    when(row.getDate(2)).thenReturn(LocalDate.fromYearMonthDay(2018, 03, 12));
    assertEquals(1L, DriverCQLRowHandler.readValue(new ValueMetaInteger("row"), row, 0));
    assertEquals(new Date(1520538054000L), DriverCQLRowHandler.readValue(new ValueMetaTimestamp("timestamp"), row, 1));
    assertEquals(LocalDate.fromYearMonthDay(2018, 03, 12), DriverCQLRowHandler.readValue(new ValueMetaDate("datestamp"), row, 2));
}
Also used : ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) Row(com.datastax.driver.core.Row) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Date(java.util.Date) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) LocalDate(com.datastax.driver.core.LocalDate) Test(org.junit.Test)

Example 13 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.

the class KettleDatabaseRepository method insertStepDatabase.

public synchronized void insertStepDatabase(ObjectId id_transformation, ObjectId id_step, ObjectId id_database) throws KettleException {
    // First check if the relationship is already there.
    // There is no need to store it twice!
    RowMetaAndData check = getStepDatabase(id_step);
    if (check.getInteger(0) == null) {
        RowMetaAndData table = new RowMetaAndData();
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_STEP_DATABASE_ID_TRANSFORMATION), id_transformation);
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_STEP_DATABASE_ID_STEP), id_step);
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_STEP_DATABASE_ID_DATABASE), id_database);
        connectionDelegate.insertTableRow(KettleDatabaseRepository.TABLE_R_STEP_DATABASE, table);
    }
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger)

Example 14 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.

the class KettleDatabaseRepository method insertClusterSlave.

public synchronized ObjectId insertClusterSlave(ClusterSchema clusterSchema, SlaveServer slaveServer) throws KettleException {
    ObjectId id = connectionDelegate.getNextClusterSlaveID();
    RowMetaAndData table = new RowMetaAndData();
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_CLUSTER_SLAVE_ID_CLUSTER_SLAVE), id);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_CLUSTER_SLAVE_ID_CLUSTER), clusterSchema.getObjectId());
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_CLUSTER_SLAVE_ID_SLAVE), slaveServer.getObjectId());
    connectionDelegate.insertTableRow(KettleDatabaseRepository.TABLE_R_CLUSTER_SLAVE, table);
    return id;
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger)

Example 15 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.

the class KettleDatabaseRepository method insertJobEntryDatabase.

public synchronized void insertJobEntryDatabase(ObjectId id_job, ObjectId id_jobentry, ObjectId id_database) throws KettleException {
    // First check if the relationship is already there.
    // There is no need to store it twice!
    RowMetaAndData check = getJobEntryDatabase(id_jobentry);
    if (check.getInteger(0) == null) {
        RowMetaAndData table = new RowMetaAndData();
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_DATABASE_ID_JOB), id_job);
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_DATABASE_ID_JOBENTRY), id_jobentry);
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_DATABASE_ID_DATABASE), id_database);
        connectionDelegate.insertTableRow(KettleDatabaseRepository.TABLE_R_JOBENTRY_DATABASE, table);
    }
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger)

Aggregations

ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)314 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)209 RowMeta (org.pentaho.di.core.row.RowMeta)146 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)137 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)113 Test (org.junit.Test)90 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)89 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)64 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)61 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)57 KettleException (org.pentaho.di.core.exception.KettleException)41 LongObjectId (org.pentaho.di.repository.LongObjectId)38 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)34 ObjectId (org.pentaho.di.repository.ObjectId)33 ArrayList (java.util.ArrayList)32 KettleStepException (org.pentaho.di.core.exception.KettleStepException)26 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)21 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)20 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)18 SQLException (java.sql.SQLException)17