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);
}
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]);
}
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;
}
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);
}
}
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()");
}
}
Aggregations