@Test public void testStringColumnPreIndexStatsCollectorForRandomString() throws Exception { FieldSpec spec = new DimensionFieldSpec("column1", DataType.STRING, true); AbstractColumnStatisticsCollector statsCollector = new StringColumnPreIndexStatsCollector(spec); statsCollector.collect("a"); Assert.assertTrue(statsCollector.isSorted()); statsCollector.collect("b"); Assert.assertTrue(statsCollector.isSorted()); statsCollector.collect("c"); Assert.assertTrue(statsCollector.isSorted()); statsCollector.collect("d"); Assert.assertTrue(statsCollector.isSorted()); statsCollector.collect("d"); Assert.assertTrue(statsCollector.isSorted()); statsCollector.collect("b"); Assert.assertFalse(statsCollector.isSorted()); statsCollector.collect("z"); Assert.assertFalse(statsCollector.isSorted()); statsCollector.collect("u"); Assert.assertFalse(statsCollector.isSorted()); statsCollector.seal(); Assert.assertEquals(statsCollector.getCardinality(), 6); Assert.assertEquals((statsCollector.getMinValue()).toString(), "a"); Assert.assertEquals((statsCollector.getMaxValue()).toString(), "z"); Assert.assertFalse(statsCollector.isSorted()); }
@Test public void testStringColumnPreIndexStatsCollectorForBoolean() throws Exception { FieldSpec spec = new DimensionFieldSpec("column1", DataType.BOOLEAN, true); AbstractColumnStatisticsCollector statsCollector = new StringColumnPreIndexStatsCollector(spec); statsCollector.collect("false"); Assert.assertTrue(statsCollector.isSorted()); statsCollector.collect("false"); Assert.assertTrue(statsCollector.isSorted()); statsCollector.collect("false"); Assert.assertTrue(statsCollector.isSorted()); statsCollector.collect("true"); Assert.assertTrue(statsCollector.isSorted()); statsCollector.collect("true"); Assert.assertTrue(statsCollector.isSorted()); statsCollector.collect("false"); Assert.assertFalse(statsCollector.isSorted()); statsCollector.collect("false"); Assert.assertFalse(statsCollector.isSorted()); statsCollector.collect("true"); Assert.assertFalse(statsCollector.isSorted()); statsCollector.seal(); Assert.assertEquals(statsCollector.getCardinality(), 2); Assert.assertEquals((statsCollector.getMinValue()).toString(), "false"); Assert.assertEquals((statsCollector.getMaxValue()).toString(), "true"); Assert.assertFalse(statsCollector.isSorted()); }
@Test public void testDoubleColumnPreIndexStatsCollector() throws Exception { FieldSpec spec = new DimensionFieldSpec("column1", DataType.DOUBLE, true); AbstractColumnStatisticsCollector statsCollector = new DoubleColumnPreIndexStatsCollector(spec); statsCollector.collect(new Integer(1)); Assert.assertTrue(statsCollector.isSorted()); statsCollector.collect(new Float(2)); Assert.assertTrue(statsCollector.isSorted()); statsCollector.collect(new Long(3)); Assert.assertTrue(statsCollector.isSorted()); statsCollector.collect(new Double(4)); Assert.assertTrue(statsCollector.isSorted()); statsCollector.collect(new Integer(4)); Assert.assertTrue(statsCollector.isSorted()); statsCollector.collect(new Float(2)); Assert.assertFalse(statsCollector.isSorted()); statsCollector.collect(new Double(40)); Assert.assertFalse(statsCollector.isSorted()); statsCollector.collect(new Double(20)); Assert.assertFalse(statsCollector.isSorted()); statsCollector.seal(); Assert.assertEquals(statsCollector.getCardinality(), 6); Assert.assertEquals(((Number) statsCollector.getMinValue()).intValue(), 1); Assert.assertEquals(((Number) statsCollector.getMaxValue()).intValue(), 40); Assert.assertFalse(statsCollector.isSorted()); }