use of org.apache.hop.core.row.value.ValueMetaNumber in project hop by apache.
the class MemoryGroupBy method processRow.
@Override
public boolean processRow() throws HopException {
// get row!
Object[] r = getRow();
if (first) {
if ((r == null) && (!meta.isAlwaysGivingBackOneRow())) {
setOutputDone();
return false;
}
String val = getVariable(Const.HOP_AGGREGATION_ALL_NULLS_ARE_ZERO, "N");
allNullsAreZero = ValueMetaBase.convertStringToBoolean(val);
val = getVariable(Const.HOP_AGGREGATION_MIN_NULL_IS_VALUED, "N");
minNullIsValued = ValueMetaBase.convertStringToBoolean(val);
compatibilityMode = ValueMetaBase.convertStringToBoolean(getVariable(Const.HOP_COMPATIBILITY_MEMORY_GROUP_BY_SUM_AVERAGE_RETURN_NUMBER_TYPE, "N"));
// What is the output looking like?
//
data.inputRowMeta = getInputRowMeta();
//
if (data.inputRowMeta == null) {
data.inputRowMeta = getPipelineMeta().getPrevTransformFields(this, getTransformMeta());
}
data.outputRowMeta = data.inputRowMeta.clone();
meta.getFields(data.outputRowMeta, getTransformName(), null, null, this, metadataProvider);
// Do all the work we can beforehand
// Calculate indexes, loop up fields, etc.
//
data.subjectnrs = new int[meta.getSubjectField().length];
data.groupnrs = new int[meta.getGroupField().length];
// If the transform does not receive any rows, we can not lookup field position indexes
if (r != null) {
for (int i = 0; i < meta.getSubjectField().length; i++) {
if (meta.getAggregateType()[i] == MemoryGroupByMeta.TYPE_GROUP_COUNT_ANY) {
data.subjectnrs[i] = 0;
} else {
data.subjectnrs[i] = data.inputRowMeta.indexOfValue(meta.getSubjectField()[i]);
}
if (data.subjectnrs[i] < 0) {
logError(BaseMessages.getString(PKG, "MemoryGroupBy.Log.AggregateSubjectFieldCouldNotFound", meta.getSubjectField()[i]));
setErrors(1);
stopAll();
return false;
}
}
for (int i = 0; i < meta.getGroupField().length; i++) {
data.groupnrs[i] = data.inputRowMeta.indexOfValue(meta.getGroupField()[i]);
if (data.groupnrs[i] < 0) {
logError(BaseMessages.getString(PKG, "MemoryGroupBy.Log.GroupFieldCouldNotFound", meta.getGroupField()[i]));
setErrors(1);
stopAll();
return false;
}
}
}
// Create a metadata value for the counter Integers
//
data.valueMetaInteger = new ValueMetaInteger("count");
data.valueMetaNumber = new ValueMetaNumber("sum");
// Initialize the group metadata
//
initGroupMeta(data.inputRowMeta);
}
if (first) {
// Only calculate data.aggMeta here, not for every new aggregate.
//
newAggregate(r, null);
// for speed: groupMeta+aggMeta
//
data.groupAggMeta = new RowMeta();
data.groupAggMeta.addRowMeta(data.groupMeta);
data.groupAggMeta.addRowMeta(data.aggMeta);
}
//
if (r == null) {
// no more input to be expected... (or none received in the first place)
handleLastOfGroup();
setOutputDone();
return false;
}
if (first || data.newBatch) {
first = false;
data.newBatch = false;
}
addToAggregate(r);
if (checkFeedback(getLinesRead())) {
if (log.isBasic()) {
logBasic(BaseMessages.getString(PKG, "MemoryGroupBy.LineNumber") + getLinesRead());
}
}
return true;
}
use of org.apache.hop.core.row.value.ValueMetaNumber in project hop by apache.
the class CheckSumTest method testHexOutput_adler32.
@Test
public void testHexOutput_adler32() throws Exception {
MockRowListener results = executeHexTest(CheckSumMeta.CheckSumType.ADLER32, "xyz", new ValueMetaString("test"));
assertEquals(1, results.getWritten().size());
assertEquals(Long.valueOf("47645036"), results.getWritten().get(0)[1]);
results = executeHexTest(CheckSumMeta.CheckSumType.ADLER32, 10.8, new ValueMetaNumber("test"));
assertEquals(1, results.getWritten().size());
assertEquals(Long.valueOf("32243912"), results.getWritten().get(0)[1]);
results = executeHexTest(CheckSumMeta.CheckSumType.ADLER32, 10.82, new ValueMetaNumber("test"));
assertEquals(1, results.getWritten().size());
assertEquals(Long.valueOf("48627962"), results.getWritten().get(0)[1]);
byte[] input = IOUtils.toByteArray(getFile("/checksum.svg").getContent().getInputStream());
results = executeHexTest(CheckSumMeta.CheckSumType.ADLER32, input, new ValueMetaBinary("test"));
assertEquals(1, results.getWritten().size());
assertEquals(Long.valueOf("3864809454"), results.getWritten().get(0)[1]);
}
use of org.apache.hop.core.row.value.ValueMetaNumber in project hop by apache.
the class CheckSumTest method testHexOutput_md5.
@Test
public void testHexOutput_md5() throws Exception {
MockRowListener results = executeHexTest(CheckSumMeta.CheckSumType.MD5, "xyz", new ValueMetaString("test"));
assertEquals(1, results.getWritten().size());
assertEquals("d16fb36f0911f878998c136191af705e", results.getWritten().get(0)[1]);
results = executeHexTest(CheckSumMeta.CheckSumType.MD5, 10.8, new ValueMetaNumber("test"));
assertEquals(1, results.getWritten().size());
assertEquals("372df98e33ac1bf6b26d225361ba7eb5", results.getWritten().get(0)[1]);
results = executeHexTest(CheckSumMeta.CheckSumType.MD5, 10.82, new ValueMetaNumber("test"));
assertEquals(1, results.getWritten().size());
assertEquals("68b142f87143c917f29d178aa1715957", results.getWritten().get(0)[1]);
byte[] input = IOUtils.toByteArray(getFile("/checksum.svg").getContent().getInputStream());
results = executeHexTest(CheckSumMeta.CheckSumType.MD5, input, new ValueMetaBinary("test"));
assertEquals(1, results.getWritten().size());
assertEquals("056c290e3639d0f15db479810973d601", results.getWritten().get(0)[1]);
}
use of org.apache.hop.core.row.value.ValueMetaNumber in project hop by apache.
the class CheckSumTest method testHexOutput_sha384.
@Test
public void testHexOutput_sha384() throws Exception {
MockRowListener results = executeHexTest(CheckSumMeta.CheckSumType.SHA384, "xyz", new ValueMetaString("test"));
assertEquals(1, results.getWritten().size());
assertEquals("edcb0f4721e6578d900e4c24ad4b19e194ab6c87f8243bfc6b11754dd8b0bbde4f30b1d18197932b6376da004dcd97c4", results.getWritten().get(0)[1]);
results = executeHexTest(CheckSumMeta.CheckSumType.SHA384, 10.8, new ValueMetaNumber("test"));
assertEquals(1, results.getWritten().size());
assertEquals("bf42c2b293b7562deca2acccc99f85b33aa150603608d610495dc45e0fb55b60c808ce466213edcf6ca184d97305b20d", results.getWritten().get(0)[1]);
results = executeHexTest(CheckSumMeta.CheckSumType.SHA384, 10.82, new ValueMetaNumber("test"));
assertEquals(1, results.getWritten().size());
assertEquals("96adb3d911a5b02f7604b9f8159d5baf21a6719162887792b7232f91fe19fefeaf9438dc1e09685a33c998897a7e76e2", results.getWritten().get(0)[1]);
byte[] input = IOUtils.toByteArray(getFile("/checksum.svg").getContent().getInputStream());
results = executeHexTest(CheckSumMeta.CheckSumType.SHA384, input, new ValueMetaBinary("test"));
assertEquals(1, results.getWritten().size());
assertEquals("ef97e467e4fc1894abcdfd589481ff9c269322f7f2f42fde41468d7ac1f2bcd10db6f797f58e531419c886a43d1d8cd0", results.getWritten().get(0)[1]);
}
use of org.apache.hop.core.row.value.ValueMetaNumber in project hop by apache.
the class CheckSumTest method testHexOutput_sha256.
@Test
public void testHexOutput_sha256() throws Exception {
MockRowListener results = executeHexTest(CheckSumMeta.CheckSumType.SHA256, "xyz", new ValueMetaString("test"));
assertEquals(1, results.getWritten().size());
assertEquals("3608bca1e44ea6c4d268eb6db02260269892c0b42b86bbf1e77a6fa16c3c9282", results.getWritten().get(0)[1]);
results = executeHexTest(CheckSumMeta.CheckSumType.SHA256, 10.8, new ValueMetaNumber("test"));
assertEquals(1, results.getWritten().size());
assertEquals("b52b603f9ec86c382a8483cad4f788f2f927535a76ad1388caedcef5e3c3c813", results.getWritten().get(0)[1]);
results = executeHexTest(CheckSumMeta.CheckSumType.SHA256, 10.82, new ValueMetaNumber("test"));
assertEquals(1, results.getWritten().size());
assertEquals("45cbb96ff9625490cd675a7a39fecad6c167c1ed9b8957f53224fcb3e4a1e4a1", results.getWritten().get(0)[1]);
byte[] input = IOUtils.toByteArray(getFile("/org/apache/hop/pipeline/transforms/loadfileinput/files/hop.jpg").getContent().getInputStream());
results = executeHexTest(CheckSumMeta.CheckSumType.SHA256, input, new ValueMetaBinary("test"));
assertEquals(1, results.getWritten().size());
assertEquals("51165cf63a5b08470272cbf75f6bfb439fad977a451866a25b5ebb3767f31872", results.getWritten().get(0)[1]);
}
Aggregations