@Override public String value(Bundle bundle, BundleField[] fields) { return bundle.getValue(fields[pos]).toString(); } }
@Override public void appendBundleToString(Bundle row, StringBuilder stringBuilder) { stringBuilder.append("<tr>"); for (BundleField field : row.getFormat()) { ValueObject o = row.getValue(field); stringBuilder.append("<td>").append(o).append("</td>"); } stringBuilder.append("</tr>\n"); }
public String template(Bundle bundle) { filter(bundle); BundleField[] bound = BundleFilter.getBindings(bundle, fieldSet); return bundle.getValue(bound[bound.length - 1]).toString(); }
private static Bundle cloneBundle(Bundle input) { Bundle output = input.createBundle(); Iterator<BundleField> fieldIterator = input.getFormat().iterator(); while (fieldIterator.hasNext()) { BundleField field = fieldIterator.next(); output.setValue(field, input.getValue(field)); } return output; }
@Override public void merge(Bundle nextBundle, MergedRow mergedRow) { ValueObject nextValue = nextBundle.getValue(from); if (nextValue == null) { return; } ValueObject value = mergedRow.getValue(to); ValueObject mergedValue = merge(nextValue, value); mergedRow.setValue(to, mergedValue); }
@Override public boolean updateChildData(DataTreeNodeUpdater state, DataTreeNode childNode, Config conf) { Bundle bundle = state.getBundle(); if (keyAccess == null) { keyAccess = bundle.getFormat().getField(conf.key); } return updateCounter(bundle, bundle.getValue(keyAccess)); }
@Override public boolean updateChildData(DataTreeNodeUpdater state, DataTreeNode tn, Config conf) { Bundle p = state.getBundle(); if (keyAccess == null) { keyAccess = p.getFormat().getField(conf.key); } updateCounter(p.getValue(keyAccess)); return true; }
protected void mergeBundles(Bundle orig, Bundle nBundle) { for (BundleField bf : nBundle) { orig.setValue(orig.getFormat().getField(bf.getName()), nBundle.getValue(bf)); } }
@Override public void process(Bundle row, StreamEmitter emitter) { String keyValue = row.getValue(row.getFormat().getField(key)).asString().asNative(); String hashValue = row.getValue(row.getFormat().getField(hash)).asString().asNative(); if (keyValue != null) { if (currentHash != null && hashValue != null && !currentHash.equals(hashValue)) { releaseMap(emitter); } currentHash = hashValue; joinAndEmit(keyValue, row, emitter); } }
protected Bundle makeAltBundle(Bundle bundle) { ListBundleFormat format = new ListBundleFormat(); Bundle alt = new ListBundle(format); for (int i = 0; i < columns.length; i++) { BundleField field = format.getField(columns[i]); alt.setValue(field, bundle.getValue(bundle.getFormat().getField(columns[i]))); } return alt; }
@Override public boolean updateChildData(DataTreeNodeUpdater state, DataTreeNode childNode, Config conf) { Bundle p = state.getBundle(); if (keyAccess == null) { keyAccess = p.getFormat().getField(conf.key); } ValueObject o = p.getValue(keyAccess); if (o != null) { bloom.setSeen(Raw.get(ValueUtil.asNativeString(o))); } return true; }
public static ValueObject applyFilter(String filterText) throws Exception { Bundle bundle = defaultBundle(); ValueFilterMapValue filter = Configs.decodeObject(ValueFilterMapValue.class, filterText); return filter.filterValue(bundle.getValue("params"), bundle); }
@Test public void basicJoin() throws Exception { BundleFilter concat = Configs.decodeObject(BundleFilterConcat.class, "in = [a, b], out = b, join = \", \""); Bundle bundle = new ListBundle(); BundleFilter setup = Configs.decodeObject( BundleFilter.class, "chain: [{from.const: hi, to: a}, {from.const: there, to: b}]"); setup.filter(bundle); concat.filter(bundle); assertEquals("hi, there", bundle.getValue(bundle.getFormat().getField("b")).toString()); } }
@Test public void testMean() { BundleFilterNum bfn = new BundleFilterNum("n2:3:5:7:11:13:17:19,mean,v0,set", null); Bundle bundle = new ListBundle(); bundle.setValue(bundle.getFormat().getField("c1"), ValueFactory.create(-1)); bfn.filter(bundle); assertEquals("9.625", bundle.getValue(bundle.getFormat().getField("c1")).toString()); }
@Test public void testVariance() { BundleFilterNum bfn = new BundleFilterNum("n2:3:5:7:11:13:17:19,variance,v0,set", null); Bundle bundle = new ListBundle(); bundle.setValue(bundle.getFormat().getField("c1"), ValueFactory.create(-1)); bfn.filter(bundle); assertEquals("35.734375", bundle.getValue(bundle.getFormat().getField("c1")).toString()); }
@Test public void testPop() { BundleFilterNum bfn = new BundleFilterNum("n1:2:3,pop,v0,set", null); Bundle bundle = new ListBundle(); bundle.setValue(bundle.getFormat().getField("c1"), ValueFactory.create(-1)); bfn.filter(bundle); assertEquals("2", bundle.getValue(bundle.getFormat().getField("c1")).toString()); }
@Test public void testAdd() { BundleFilterNum bfn = new BundleFilterNum("c0,n3,add,v1,set", null); Bundle bundle = new ListBundle(); bundle.setValue(bundle.getFormat().getField("c0"), ValueFactory.create(3)); bundle.setValue(bundle.getFormat().getField("c1"), ValueFactory.create(4)); bfn.filter(bundle); assertEquals(bundle.getValue(bundle.getFormat().getField("c1")).toString(), "6"); }
@Test public void testMult() { BundleFilterNum bfn = new BundleFilterNum("c0,n3,*,v1,set", null); Bundle bundle = new ListBundle(); bundle.setValue(bundle.getFormat().getField("c0"), ValueFactory.create(3)); bundle.setValue(bundle.getFormat().getField("c1"), ValueFactory.create(4)); bfn.filter(bundle); assertEquals("9", bundle.getValue(bundle.getFormat().getField("c1")).toString()); }
@Test public void testInsertArrayString() { BundleFilterNum bfn = new BundleFilterNum("c0,mean,v1,set", null); Bundle bundle = new ListBundle(); bundle.setValue(bundle.getFormat().getField("c0"), ValueFactory.create("1,2,3,4,5")); bundle.setValue(bundle.getFormat().getField("c1"), ValueFactory.create(0.0)); bfn.filter(bundle); assertEquals(ValueFactory.create(3.0), bundle.getValue(bundle.getFormat().getField("c1"))); }