@Test public void testDecode() throws Exception { CubeDesc cubeDesc = CubeManager.getInstance(getTestConfig()) .getCube("test_kylin_cube_with_slr_ready") .getDescriptor(); HBaseColumnDesc hbaseCol = cubeDesc.getHbaseMapping().getColumnFamily()[0].getColumns()[0]; MeasureCodec codec = new MeasureCodec(hbaseCol.getMeasures()); BigDecimal sum = new BigDecimal("333.1234567"); BigDecimal min = new BigDecimal("333.1111111"); BigDecimal max = new BigDecimal("333.1999999"); LongMutable count = new LongMutable(2); LongMutable item_count = new LongMutable(100); ByteBuffer buf = ByteBuffer.allocate(RowConstants.ROWVALUE_BUFFER_SIZE); codec.encode(new Object[] {sum, min, max, count, item_count}, buf); buf.flip(); byte[] valueBytes = new byte[buf.limit()]; System.arraycopy(buf.array(), 0, valueBytes, 0, buf.limit()); RowValueDecoder rowValueDecoder = new RowValueDecoder(hbaseCol); for (MeasureDesc measure : cubeDesc.getMeasures()) { FunctionDesc aggrFunc = measure.getFunction(); int index = hbaseCol.findMeasure(aggrFunc); rowValueDecoder.setProjectIndex(index); } rowValueDecoder.decodeAndConvertJavaObj(valueBytes); Object[] measureValues = rowValueDecoder.getValues(); // BigDecimal.ROUND_HALF_EVEN in BigDecimalSerializer assertEquals("[333.1235, 333.1111, 333.2000, 2, 100]", Arrays.toString(measureValues)); }
@Override public CapabilityResult.CapabilityInfluence influenceCapabilityCheck( Collection<TblColRef> unmatchedDimensions, Collection<FunctionDesc> unmatchedAggregations, SQLDigest digest, MeasureDesc measureDesc) { TblColRef extendedCol = getExtendedColumn(measureDesc.getFunction()); if (!unmatchedDimensions.contains(extendedCol)) { return null; } if (digest.filterColumns.contains(extendedCol)) { return null; } unmatchedDimensions.remove(extendedCol); return new CapabilityResult.CapabilityInfluence() { @Override public double suggestCostMultiplier() { return 0.9; } }; }
@Test public void testValidateMeasureNamesDuplicated() throws IOException { FunctionRule rule = new FunctionRule(); File f = new File(LocalFileMetadataTestCase.LOCALMETA_TEST_DATA + "/cube_desc/ssb.json"); CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class); MeasureDesc measureDescDuplicated = desc.getMeasures().get(1); desc.getMeasures().add(measureDescDuplicated); desc.init(config, metadataManager.getAllTablesMap()); ValidateContext vContext = new ValidateContext(); rule.validate(desc, vContext); vContext.print(System.out); assertTrue(vContext.getResults().length >= 1); assertEquals( "There is duplicated measure's name: " + measureDescDuplicated.getName(), vContext.getResults()[0].getMessage()); }
@Override public void adjustSqlDigest(MeasureDesc measureDesc, SQLDigest sqlDigest) { FunctionDesc extendColumnFunc = measureDesc.getFunction(); List<TblColRef> hosts = getExtendedColumnHosts(extendColumnFunc); TblColRef extended = getExtendedColumn(extendColumnFunc); if (!sqlDigest.groupbyColumns.contains(extended)) { return; } sqlDigest.aggregations.add(extendColumnFunc); sqlDigest.groupbyColumns.remove(extended); sqlDigest.groupbyColumns.addAll(hosts); sqlDigest.metricColumns.add(extended); }