/** * Filters for records of the visits relation where the year of visit is equal to a * specified value. The URL of all visit records passing the filter is emitted. * * Output Format: * 0: URL */ @Override public void map(Record record, Collector<Record> out) throws Exception { // Parse date string with the format YYYY-MM-DD and extract the year String dateString = record.getField(1, StringValue.class).getValue(); int year = Integer.parseInt(dateString.substring(0,4)); if (year == YEARFILTER) { record.setNull(1); out.collect(record); } } }
/** * Filters for documents that contain all of the given keywords and projects the records on the URL field. * * Output Format: * 0: URL */ @Override public void map(Record record, Collector<Record> out) throws Exception { // FILTER // Only collect the document if all keywords are contained String docText = record.getField(1, StringValue.class).toString(); boolean allContained = true; for (String kw : KEYWORDS) { if (!docText.contains(kw)) { allContained = false; break; } } if (allContained) { record.setNull(1); out.collect(record); } } }
@Test public void testSetNullInt() { try { Record record = this.generateFilledDenseRecord(58); record.setNull(42); assertTrue(record.getNumFields() == 58); assertTrue(record.getField(42, IntValue.class) == null); } catch (Throwable t) { Assert.fail("Test failed due to an exception: " + t.getMessage()); } }
@Test public void testSetNullLong() { try { Record record = this.generateFilledDenseRecord(58); long mask = generateRandomBitmask(58); record.setNull(mask); for (int i = 0; i < 58; i++) { if (((1l << i) & mask) != 0) { assertTrue(record.getField(i, IntValue.class) == null); } } assertTrue(record.getNumFields() == 58); } catch (Throwable t) { Assert.fail("Test failed due to an exception: " + t.getMessage()); } }
@Test public void testSetNullLongArray() { try { Record record = this.generateFilledDenseRecord(612); long[] mask = {1L, 1L, 1L, 1L}; record.setNull(mask); assertTrue(record.getField(0, IntValue.class) == null); assertTrue(record.getField(64, IntValue.class) == null); assertTrue(record.getField(128, IntValue.class) == null); assertTrue(record.getField(192, IntValue.class) == null); mask = new long[10]; for (int i = 0; i < mask.length; i++) { int offset = i * Long.SIZE; int numFields = ((offset + Long.SIZE) < record.getNumFields()) ? Long.SIZE : record.getNumFields() - offset; mask[i] = this.generateRandomBitmask(numFields); } record.setNull(mask); } catch (Throwable t) { Assert.fail("Test failed due to an exception: " + t.getMessage()); } }