CardinalityAnalyzer implements Analyzer<CardinalityStatistics> { @Override public boolean analyze(String... record) { if (record == null) { return true; } cardinalityStatistics.resize(record.length); for (int i = 0; i < record.length; i++) { final CardinalityStatistics cardStats = cardinalityStatistics.get(i); cardStats.add(record[i]); cardStats.incrementCount(); } return true; }  @Override boolean analyze(String... record); @Override void init(); @Override void end(); @Override List<CardinalityStatistics> getResult(); @Override void close();  }
@Test public void testAnalyze() { String[] data = new String[] { "0", "1", "2", "3", "16", "17", "18", "19", "19" }; analyzer.init(); for (String col : data) { analyzer.analyze(col); } Assert.assertEquals(8, analyzer.getResult().get(0).getDistinctCount(), 0); Assert.assertEquals(1, analyzer.getResult().get(0).getDuplicateCount(), 0); data = new String[] { "" }; analyzer.init(); for (String col : data) { analyzer.analyze(col); } Assert.assertEquals(1, analyzer.getResult().get(0).getDistinctCount(), 0); Assert.assertEquals(0, analyzer.getResult().get(0).getDuplicateCount(), 0); analyzer.init(); Assert.assertTrue(analyzer.getResult().size() == 0); String[][] twoColumnsData = new String[][] { { "0", "1" }, { "1", "2" }, { "2", "3" }, { "3", "4" }, { "16", "17" }, { "17", "17" }, { "18", "18" }, { "19", "19" }, { "19", "19" }, { "20", "19" } }; for (String[] record : twoColumnsData) { analyzer.analyze(record); } Assert.assertEquals(9, analyzer.getResult().get(0).getDistinctCount(), 0); Assert.assertEquals(1, analyzer.getResult().get(0).getDuplicateCount(), 0); Assert.assertEquals(7, analyzer.getResult().get(1).getDistinctCount(), 0); Assert.assertEquals(3, analyzer.getResult().get(1).getDuplicateCount(), 0); }