Search in sources :

Example 91 with ValueMetaNumber

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

the class CheckSumTest method testHexOutput_sha256.

@Test
public void testHexOutput_sha256() throws Exception {
    MockRowListener results = executeHexTest(4, false, "xyz", new ValueMetaString("test"), false);
    assertEquals(1, results.getWritten().size());
    assertEquals("3608bca1e44ea6c4d268eb6db02260269892c0b42b86bbf1e77a6fa16c3c9282", results.getWritten().get(0)[1]);
    results = executeHexTest(4, false, 10.8, new ValueMetaNumber("test"), false);
    assertEquals(1, results.getWritten().size());
    assertEquals("b52b603f9ec86c382a8483cad4f788f2f927535a76ad1388caedcef5e3c3c813", results.getWritten().get(0)[1]);
    results = executeHexTest(4, false, 10.82, new ValueMetaNumber("test"), false);
    assertEquals(1, results.getWritten().size());
    assertEquals("45cbb96ff9625490cd675a7a39fecad6c167c1ed9b8957f53224fcb3e4a1e4a1", results.getWritten().get(0)[1]);
    byte[] input = IOUtils.toByteArray(getFile("/org/pentaho/di/trans/steps/loadfileinput/files/pentaho_splash.png").getContent().getInputStream());
    results = executeHexTest(4, false, input, new ValueMetaBinary("test"), false);
    assertEquals(1, results.getWritten().size());
    assertEquals("6914d0cb9296d658569570c23924ea4822be73f0ee3bc46d11651fb4041a43e1", results.getWritten().get(0)[1]);
}
Also used : ValueMetaBinary(org.pentaho.di.core.row.value.ValueMetaBinary) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) Test(org.junit.Test)

Example 92 with ValueMetaNumber

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

the class Formula2IT method testIsNonText_EmptyStringIsNull.

@Test
public void testIsNonText_EmptyStringIsNull() throws KettleException {
    FieldAccessorUtl.ensureEmptyStringIsNotNull(false);
    final String fIsText = "ISNONTEXT([" + KEY_ARG + "])";
    assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaString(KEY_ARG)), new Object[] { "1" }, false);
    assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaString(KEY_ARG)), new Object[] { "a" }, false);
    assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaString(KEY_ARG)), new Object[] { null }, true);
    // assertBooleanFormula( fIsText, buildRowMeta( new ValueMetaString( KEY_ARG ) ), new Object[] { "" }, true ); //
    // TODO: Is it correct?
    // 
    assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaString(KEY_ARG)), new Object[] { "" }, false);
    // TODO: Is it correct?
    assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaString(KEY_ARG)), new Object[] { "   " }, false);
    assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaNumber(KEY_ARG)), new Object[] { 1 }, true);
    assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaNumber(KEY_ARG)), new Object[] { 0 }, true);
    assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaNumber(KEY_ARG)), new Object[] { -1.0 }, true);
    assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaNumber(KEY_ARG)), new Object[] { null }, true);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Test(org.junit.Test)

Example 93 with ValueMetaNumber

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

the class Formula2IT method testIsNonText_EmptyStringIsNotNull.

@Test
public void testIsNonText_EmptyStringIsNotNull() throws KettleException {
    FieldAccessorUtl.ensureEmptyStringIsNotNull(true);
    final String fIsText = "ISNONTEXT([" + KEY_ARG + "])";
    assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaString(KEY_ARG)), new Object[] { "1" }, false);
    assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaString(KEY_ARG)), new Object[] { "a" }, false);
    assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaString(KEY_ARG)), new Object[] { null }, true);
    assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaString(KEY_ARG)), new Object[] { "" }, false);
    assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaString(KEY_ARG)), new Object[] { "   " }, false);
    assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaNumber(KEY_ARG)), new Object[] { 1 }, true);
    assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaNumber(KEY_ARG)), new Object[] { 0 }, true);
    assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaNumber(KEY_ARG)), new Object[] { -1.0 }, true);
    assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaNumber(KEY_ARG)), new Object[] { null }, true);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Test(org.junit.Test)

Example 94 with ValueMetaNumber

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

the class FormulaIT method getTestRowMetaAndData.

List<RowMetaAndData> getTestRowMetaAndData() {
    List<RowMetaAndData> list = new ArrayList<RowMetaAndData>();
    Object[] row = new Object[] { null };
    RowMetaInterface rm = new RowMeta();
    rm.addValueMeta(new ValueMetaNumber("n"));
    list.add(new RowMetaAndData(rm, row));
    return list;
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface)

Example 95 with ValueMetaNumber

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

the class DriverCQLRowHandlerTest method testQueryRows.

@Test
public void testQueryRows() throws Exception {
    List<Object[]> rowList = new ArrayList<Object[]>();
    rowList.add(new Object[] { 1L, "a", 0.2d });
    rowList.add(new Object[] { 2L, "b", 42d });
    DriverKeyspace keyspace = mock(DriverKeyspace.class);
    Session session = mock(Session.class);
    ResultSet rs = mock(ResultSet.class);
    mockColumnDefinitions(rs, DataType.cint(), DataType.text(), DataType.cdouble());
    when(session.execute(anyString())).thenReturn(rs);
    Iterator<Object[]> it = rowList.iterator();
    when(rs.isExhausted()).then(invoc -> {
        return !it.hasNext();
    });
    when(rs.one()).then(invocation -> {
        Object[] rowArr = it.next();
        Row row = mock(Row.class);
        when(row.getObject(anyInt())).then(invoc -> {
            return rowArr[(int) invoc.getArguments()[0]];
        });
        when(row.getLong(0)).thenReturn((long) rowArr[0]);
        when(row.getDouble(2)).thenReturn((double) rowArr[2]);
        return row;
    });
    DriverCQLRowHandler rowHandler = new DriverCQLRowHandler(keyspace, session, true);
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaInteger("a"));
    rowMeta.addValueMeta(new ValueMetaString("b"));
    rowMeta.addValueMeta(new ValueMetaNumber("c"));
    rowHandler.newRowQuery(mock(StepInterface.class), "tab", "select * from tab", null, null, mock(LogChannelInterface.class));
    List<Object[]> resultRows = getNextOutputRows(rowHandler, rowMeta);
    assertEquals(2, resultRows.size());
    assertEquals(2L, resultRows.get(1)[0]);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepInterface(org.pentaho.di.trans.step.StepInterface) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ResultSet(com.datastax.driver.core.ResultSet) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) Row(com.datastax.driver.core.Row) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Aggregations

ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)95 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)75 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)52 Test (org.junit.Test)51 RowMeta (org.pentaho.di.core.row.RowMeta)39 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)34 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)34 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)32 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)30 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)25 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)20 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)16 ValueMetaInternetAddress (org.pentaho.di.core.row.value.ValueMetaInternetAddress)15 KettleException (org.pentaho.di.core.exception.KettleException)12 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)11 KettleStepException (org.pentaho.di.core.exception.KettleStepException)7 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 RowSet (org.pentaho.di.core.RowSet)6 RowAdapter (org.pentaho.di.trans.step.RowAdapter)6