@Test public void testIngest() { MeasureType<HLLCounter> mtype = (MeasureType<HLLCounter>) MeasureTypeFactory.create(HLLCMeasureType.FUNC_COUNT_DISTINCT, DataType.getType("hllc(10)")); MeasureIngester<HLLCounter> ingester = mtype.newIngester(); HLLCounter hllc; hllc = ingester.valueOf(new String[] { null }, null, null); assertEquals(0, hllc.getCountEstimate()); hllc = ingester.valueOf(new String[] { null, null }, null, null); assertEquals(0, hllc.getCountEstimate()); hllc = ingester.valueOf(new String[] { "" }, null, null); assertEquals(1, hllc.getCountEstimate()); hllc = ingester.valueOf(new String[] { "", null }, null, null); assertEquals(1, hllc.getCountEstimate()); hllc = ingester.valueOf(new String[] { "abc" }, null, null); assertEquals(1, hllc.getCountEstimate()); }
@Override public MeasureIngester<HLLCounter> newIngester() { return new MeasureIngester<HLLCounter>() { private static final long serialVersionUID = 1L; HLLCounter current = new HLLCounter(dataType.getPrecision()); @Override public HLLCounter valueOf(String[] values, MeasureDesc measureDesc, Map<TblColRef, Dictionary<String>> dictionaryMap) { HLLCounter hllc = current; hllc.clear(); if (values.length == 1) { if (values[0] != null) hllc.add(values[0]); } else { boolean allNull = true; StringBuilder buf = new StringBuilder(); for (String v : values) { allNull = (allNull && v == null); buf.append(v); } if (!allNull) hllc.add(buf.toString()); } return hllc; } @Override public void reset() { current = new HLLCounter(dataType.getPrecision()); } }; }
HLLCMeasureType extends MeasureType<HLLCounter> { @Override public MeasureIngester<HLLCounter> newIngester() { return new MeasureIngester<HLLCounter>() { private static final long serialVersionUID = 1L; HLLCounter current = new HLLCounter(dataType.getPrecision()); @Override public HLLCounter valueOf(String[] values, MeasureDesc measureDesc, Map<TblColRef, Dictionary<String>> dictionaryMap) { HLLCounter hllc = current; hllc.clear(); if (values.length == 1) { if (values[0] != null) hllc.add(values[0]); } else { boolean allNull = true; StringBuilder buf = new StringBuilder(); for (String v : values) { allNull = (allNull && v == null); buf.append(v); } if (!allNull) hllc.add(buf.toString()); } return hllc; } @Override public void reset() { current = new HLLCounter(dataType.getPrecision()); } }; } }
HLLCMeasureType extends MeasureType<HLLCounter> { @Override public MeasureIngester<HLLCounter> newIngester() { return new MeasureIngester<HLLCounter>() { private static final long serialVersionUID = 1L; HLLCounter current = new HLLCounter(dataType.getPrecision()); @Override public HLLCounter valueOf(String[] values, MeasureDesc measureDesc, Map<TblColRef, Dictionary<String>> dictionaryMap) { HLLCounter hllc = current; hllc.clear(); if (values.length == 1) { if (values[0] != null) hllc.add(values[0]); } else { boolean allNull = true; StringBuilder buf = new StringBuilder(); for (String v : values) { allNull = (allNull && v == null); buf.append(v); } if (!allNull) hllc.add(buf.toString()); } return hllc; } @Override public void reset() { current = new HLLCounter(dataType.getPrecision()); } }; } HLLCMeasureType(DataType dataType); }
HLLCMeasureType extends MeasureType<HLLCounter> { @Override public MeasureIngester<HLLCounter> newIngester() { return new MeasureIngester<HLLCounter>() { private static final long serialVersionUID = 1L; HLLCounter current = new HLLCounter(dataType.getPrecision()); @Override public HLLCounter valueOf(String[] values, MeasureDesc measureDesc, Map<TblColRef, Dictionary<String>> dictionaryMap) { HLLCounter hllc = current; hllc.clear(); if (values.length == 1) { if (values[0] != null) hllc.add(values[0]); } else { boolean allNull = true; StringBuilder buf = new StringBuilder(); for (String v : values) { allNull = (allNull && v == null); buf.append(v); } if (!allNull) hllc.add(buf.toString()); } return hllc; } @Override public void reset() { current = new HLLCounter(dataType.getPrecision()); } }; } HLLCMeasureType(DataType dataType); void validate(FunctionDesc functionDesc); @Override boolean isMemoryHungry(); @Override MeasureIngester<HLLCounter> newIngester(); @Override MeasureAggregator<HLLCounter> newAggregator(); @Override boolean needRewrite(); @Override Map<String, Class<?>> getRewriteCalciteAggrFunctions(); static boolean isCountDistinct(FunctionDesc func); }
HLLCMeasureType extends MeasureType<HLLCounter> { @Override public MeasureIngester<HLLCounter> newIngester() { return new MeasureIngester<HLLCounter>() { private static final long serialVersionUID = 1L; HLLCounter current = new HLLCounter(dataType.getPrecision()); @Override public HLLCounter valueOf(String[] values, MeasureDesc measureDesc, Map<TblColRef, Dictionary<String>> dictionaryMap) { HLLCounter hllc = current; hllc.clear(); if (values.length == 1) { if (values[0] != null) hllc.add(values[0]); } else { boolean allNull = true; StringBuilder buf = new StringBuilder(); for (String v : values) { allNull = (allNull && v == null); buf.append(v); } if (!allNull) hllc.add(buf.toString()); } return hllc; } @Override public void reset() { current = new HLLCounter(dataType.getPrecision()); } }; } HLLCMeasureType(DataType dataType); void validate(FunctionDesc functionDesc); @Override boolean isMemoryHungry(); @Override MeasureIngester<HLLCounter> newIngester(); @Override MeasureAggregator<HLLCounter> newAggregator(); @Override boolean needRewrite(); @Override Map<String, Class<?>> getRewriteCalciteAggrFunctions(); static boolean isCountDistinct(FunctionDesc func); static final String FUNC_COUNT_DISTINCT; static final String DATATYPE_HLLC; }