Search in sources :

Example 11 with ValueMetaBinary

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

the class LoadFileInputTest method testByteArray.

@Test
public void testByteArray() throws Exception {
    RowMetaInterface mockedRowMetaInterface = mock(RowMetaInterface.class);
    stepLoadFileInput.data.outputRowMeta = mockedRowMetaInterface;
    stepLoadFileInput.data.convertRowMeta = mockedRowMetaInterface;
    Mockito.doReturn(new ValueMetaString()).when(mockedRowMetaInterface).getValueMeta(anyInt());
    // byte array
    Mockito.doReturn(new ValueMetaBinary()).when(mockedRowMetaInterface).getValueMeta(anyInt());
    ((LoadFileInputMeta) runtimeSMI).setEncoding("UTF-8");
    stepInputFiles.addFile(getFile("pentaho_splash.png"));
    inputField = new LoadFileInputField();
    inputField.setType(ValueMetaInterface.TYPE_BINARY);
    ((LoadFileInputMeta) runtimeSMI).setInputFields(new LoadFileInputField[] { inputField });
    assertNotNull(stepLoadFileInput.getOneRow());
    assertArrayEquals(IOUtils.toByteArray(getFile("pentaho_splash.png").getContent().getInputStream()), stepLoadFileInput.data.filecontent);
}
Also used : ValueMetaBinary(org.pentaho.di.core.row.value.ValueMetaBinary) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Test(org.junit.Test)

Example 12 with ValueMetaBinary

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

the class CheckSumTest method testHexOutput_md5_compatibilityMode.

@Test
public void testHexOutput_md5_compatibilityMode() throws Exception {
    MockRowListener results = executeHexTest(2, true, "xyz", new ValueMetaString("test"), false);
    assertEquals(1, results.getWritten().size());
    assertEquals("FD6FFD6F0911FD78FDFD1361FDFD705E", results.getWritten().get(0)[1]);
    results = executeHexTest(2, true, 10.8, new ValueMetaNumber("test"), false);
    assertEquals(1, results.getWritten().size());
    assertEquals("372DFDFD33FD1BFDFD6D225361FD7EFD", results.getWritten().get(0)[1]);
    results = executeHexTest(2, true, 10.82, new ValueMetaNumber("test"), false);
    assertEquals(1, results.getWritten().size());
    assertEquals("68FD42FD7143FD17FD17FDFD715957", results.getWritten().get(0)[1]);
    byte[] input = IOUtils.toByteArray(getFile("/org/pentaho/di/trans/steps/loadfileinput/files/pentaho_splash.png").getContent().getInputStream());
    results = executeHexTest(2, true, input, new ValueMetaBinary("test"), false);
    assertEquals(1, results.getWritten().size());
    assertEquals("FDFDFDFD051FFDFDFD50FD62FDFDFD13", 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 13 with ValueMetaBinary

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

the class DatabaseLookupUTest method createDatabaseMeta.

private DatabaseLookupMeta createDatabaseMeta() throws KettleException {
    MySQLDatabaseMeta mysql = new MySQLDatabaseMeta();
    mysql.setName("MySQL");
    DatabaseMeta dbMeta = new DatabaseMeta();
    dbMeta.setDatabaseInterface(mysql);
    DatabaseLookupMeta meta = new DatabaseLookupMeta();
    meta.setDatabaseMeta(dbMeta);
    meta.setTablename("VirtualTable");
    meta.setTableKeyField(new String[] { ID_FIELD });
    meta.setKeyCondition(new String[] { "=" });
    meta.setReturnValueNewName(new String[] { "returned value" });
    meta.setReturnValueField(new String[] { BINARY_FIELD });
    meta.setReturnValueDefaultType(new int[] { ValueMetaInterface.TYPE_BINARY });
    meta.setStreamKeyField1(new String[0]);
    meta.setStreamKeyField2(new String[0]);
    meta.setReturnValueDefault(new String[] { "" });
    meta = spy(meta);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            RowMetaInterface row = (RowMetaInterface) invocation.getArguments()[0];
            ValueMetaInterface v = new ValueMetaBinary(BINARY_FIELD);
            row.addValueMeta(v);
            return null;
        }
    }).when(meta).getFields(any(RowMetaInterface.class), anyString(), any(RowMetaInterface[].class), any(StepMeta.class), any(VariableSpace.class), any(Repository.class), any(IMetaStore.class));
    return meta;
}
Also used : VariableSpace(org.pentaho.di.core.variables.VariableSpace) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) ValueMetaBinary(org.pentaho.di.core.row.value.ValueMetaBinary) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) Repository(org.pentaho.di.repository.Repository) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 14 with ValueMetaBinary

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

the class SecretKeyGeneratorMeta method getFields.

@Override
public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    ValueMetaInterface v;
    if (isOutputKeyInBinary()) {
        v = new ValueMetaBinary(secretKeyFieldName);
    } else {
        v = new ValueMetaString(secretKeyFieldName);
    }
    v.setOrigin(name);
    row.addValueMeta(v);
    if (!Utils.isEmpty(getAlgorithmFieldName())) {
        v = new ValueMetaString(algorithmFieldName);
        v.setOrigin(name);
        row.addValueMeta(v);
    }
    if (!Utils.isEmpty(getSecretKeyLengthFieldName())) {
        v = new ValueMetaInteger(secretKeyLengthFieldName);
        v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
        v.setOrigin(name);
        row.addValueMeta(v);
    }
}
Also used : ValueMetaBinary(org.pentaho.di.core.row.value.ValueMetaBinary) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 15 with ValueMetaBinary

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

the class Database method getQueryFieldsFromDatabaseMetaData.

public RowMetaInterface getQueryFieldsFromDatabaseMetaData() throws Exception {
    ResultSet columns = connection.getMetaData().getColumns("", "", databaseMeta.getName(), "");
    RowMetaInterface rowMeta = new RowMeta();
    while (columns.next()) {
        ValueMetaInterface valueMeta = null;
        String name = columns.getString("COLUMN_NAME");
        String type = columns.getString("SOURCE_DATA_TYPE");
        int size = columns.getInt("COLUMN_SIZE");
        if (type.equals("Integer") || type.equals("Long")) {
            valueMeta = new ValueMetaInteger();
        } else if (type.equals("BigDecimal") || type.equals("BigNumber")) {
            valueMeta = new ValueMetaBigNumber();
        } else if (type.equals("Double") || type.equals("Number")) {
            valueMeta = new ValueMetaNumber();
        } else if (type.equals("String")) {
            valueMeta = new ValueMetaString();
        } else if (type.equals("Date")) {
            valueMeta = new ValueMetaDate();
        } else if (type.equals("Boolean")) {
            valueMeta = new ValueMetaBoolean();
        } else if (type.equals("Binary")) {
            valueMeta = new ValueMetaBinary();
        } else if (type.equals("Timestamp")) {
            valueMeta = new ValueMetaTimestamp();
        } else if (type.equals("Internet Address")) {
            valueMeta = new ValueMetaInternetAddress();
        }
        if (valueMeta != null) {
            valueMeta.setName(name);
            valueMeta.setComments(name);
            valueMeta.setLength(size);
            valueMeta.setOriginalColumnTypeName(type);
            valueMeta.setConversionMask(columns.getString("SOURCE_MASK"));
            valueMeta.setDecimalSymbol(columns.getString("SOURCE_DECIMAL_SYMBOL"));
            valueMeta.setGroupingSymbol(columns.getString("SOURCE_GROUPING_SYMBOL"));
            valueMeta.setCurrencySymbol(columns.getString("SOURCE_CURRENCY_SYMBOL"));
            rowMeta.addValueMeta(valueMeta);
        } else {
            log.logBasic("Database.getQueryFields() ValueMetaInterface mapping not resolved for the column " + name);
            rowMeta = null;
            break;
        }
    }
    if (rowMeta != null && !rowMeta.isEmpty()) {
        return rowMeta;
    } else {
        throw new Exception("Error in Database.getQueryFields()");
    }
}
Also used : ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaInternetAddress(org.pentaho.di.core.row.value.ValueMetaInternetAddress) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) Savepoint(java.sql.Savepoint) KettleValueException(org.pentaho.di.core.exception.KettleValueException) BatchUpdateException(java.sql.BatchUpdateException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) SQLException(java.sql.SQLException) KettleDatabaseBatchException(org.pentaho.di.core.exception.KettleDatabaseBatchException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) ValueMetaBinary(org.pentaho.di.core.row.value.ValueMetaBinary) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaBigNumber(org.pentaho.di.core.row.value.ValueMetaBigNumber) ResultSet(java.sql.ResultSet) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate)

Aggregations

ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)31 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)29 Test (org.junit.Test)24 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)20 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)15 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)13 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)13 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)13 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)12 ValueMetaInternetAddress (org.pentaho.di.core.row.value.ValueMetaInternetAddress)11 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)10 RowMeta (org.pentaho.di.core.row.RowMeta)6 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)6 StepMeta (org.pentaho.di.trans.step.StepMeta)3 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2