List of usage examples for java.lang Long highestOneBit
public static long highestOneBit(long i)
From source file:Main.java
public static void main(String[] args) { long l = 100; System.out.println("Number = " + l); System.out.println("Binary = " + Long.toBinaryString(l)); System.out.println("Lowest one bit = " + Long.highestOneBit(l)); }
From source file:org.apache.kylin.engine.mr.common.CubeStatsReader.java
/** * Estimate the cuboid's size//from ww w . j ava 2 s . c om * * @return the cuboid size in M bytes */ private static double estimateCuboidStorageSize(CubeSegment cubeSegment, long cuboidId, long rowCount, long baseCuboidId, List<Integer> rowKeyColumnLength) { int rowkeyLength = cubeSegment.getRowKeyPreambleSize(); KylinConfig kylinConf = cubeSegment.getConfig(); long mask = Long.highestOneBit(baseCuboidId); long parentCuboidIdActualLength = (long) Long.SIZE - Long.numberOfLeadingZeros(baseCuboidId); for (int i = 0; i < parentCuboidIdActualLength; i++) { if ((mask & cuboidId) > 0) { rowkeyLength += rowKeyColumnLength.get(i); //colIO.getColumnLength(columnList.get(i)); } mask = mask >> 1; } // add the measure length int normalSpace = rowkeyLength; int countDistinctSpace = 0; for (MeasureDesc measureDesc : cubeSegment.getCubeDesc().getMeasures()) { DataType returnType = measureDesc.getFunction().getReturnDataType(); if (measureDesc.getFunction().getExpression().equals(FunctionDesc.FUNC_COUNT_DISTINCT)) { countDistinctSpace += returnType.getStorageBytesEstimate(); } else { normalSpace += returnType.getStorageBytesEstimate(); } } double cuboidSizeRatio = kylinConf.getJobCuboidSizeRatio(); double cuboidSizeMemHungryRatio = kylinConf.getJobCuboidSizeCountDistinctRatio(); double ret = (1.0 * normalSpace * rowCount * cuboidSizeRatio + 1.0 * countDistinctSpace * rowCount * cuboidSizeMemHungryRatio) / (1024L * 1024L); return ret; }
From source file:org.apache.kylin.engine.mr.steps.CubeSamplingTest.java
private void addCuboidBitSet(long cuboidId, List<Integer[]> allCuboidsBitSet) { Integer[] indice = new Integer[Long.bitCount(cuboidId)]; long mask = Long.highestOneBit(baseCuboidId); int position = 0; for (int i = 0; i < ROW_LENGTH; i++) { if ((mask & cuboidId) > 0) { indice[position] = i;//w w w . j a va 2s . co m position++; } mask = mask >> 1; } allCuboidsBitSet.add(indice); }
From source file:org.apache.kylin.engine.spark.SparkCubing.java
private Map<Long, HLLCounter> sampling(final JavaRDD<List<String>> rowJavaRDD, final String cubeName, String segmentId) throws Exception { CubeInstance cubeInstance = CubeManager.getInstance(KylinConfig.getInstanceFromEnv()) .reloadCubeLocal(cubeName);/*from www. j a va 2s. c o m*/ CubeSegment cubeSegment = cubeInstance.getSegmentById(segmentId); CubeDesc cubeDesc = cubeInstance.getDescriptor(); CuboidScheduler cuboidScheduler = new CuboidScheduler(cubeDesc); List<Long> allCuboidIds = cuboidScheduler.getAllCuboidIds(); final HashMap<Long, HLLCounter> zeroValue = Maps.newHashMap(); for (Long id : allCuboidIds) { zeroValue.put(id, new HLLCounter(cubeDesc.getConfig().getCubeStatsHLLPrecision())); } CubeJoinedFlatTableEnrich flatDesc = new CubeJoinedFlatTableEnrich( EngineFactory.getJoinedFlatTableDesc(cubeSegment), cubeDesc); final int[] rowKeyColumnIndexes = flatDesc.getRowKeyColumnIndexes(); final int nRowKey = cubeDesc.getRowkey().getRowKeyColumns().length; final long baseCuboidId = Cuboid.getBaseCuboidId(cubeDesc); final Map<Long, Integer[]> allCuboidsBitSet = Maps.newHashMapWithExpectedSize(allCuboidIds.size()); final ByteArray[] row_hashcodes = new ByteArray[nRowKey]; for (Long cuboidId : allCuboidIds) { Integer[] cuboidBitSet = new Integer[Long.bitCount(cuboidId)]; long mask = Long.highestOneBit(baseCuboidId); int position = 0; for (int i = 0; i < nRowKey; i++) { if ((mask & cuboidId) > 0) { cuboidBitSet[position] = i; position++; } mask = mask >> 1; } allCuboidsBitSet.put(cuboidId, cuboidBitSet); } for (int i = 0; i < nRowKey; ++i) { row_hashcodes[i] = new ByteArray(); } final HashMap<Long, HLLCounter> samplingResult = rowJavaRDD.aggregate(zeroValue, new Function2<HashMap<Long, HLLCounter>, List<String>, HashMap<Long, HLLCounter>>() { final HashFunction hashFunction = Hashing.murmur3_128(); @Override public HashMap<Long, HLLCounter> call(HashMap<Long, HLLCounter> v1, List<String> v2) throws Exception { for (int i = 0; i < nRowKey; i++) { Hasher hc = hashFunction.newHasher(); String colValue = v2.get(rowKeyColumnIndexes[i]); if (colValue != null) { row_hashcodes[i].set(hc.putString(colValue).hash().asBytes()); } else { row_hashcodes[i].set(hc.putInt(0).hash().asBytes()); } } for (Map.Entry<Long, Integer[]> entry : allCuboidsBitSet.entrySet()) { Hasher hc = hashFunction.newHasher(); HLLCounter counter = v1.get(entry.getKey()); final Integer[] cuboidBitSet = entry.getValue(); for (int position = 0; position < cuboidBitSet.length; position++) { hc.putBytes(row_hashcodes[cuboidBitSet[position]].array()); } counter.add(hc.hash().asBytes()); } return v1; } }, new Function2<HashMap<Long, HLLCounter>, HashMap<Long, HLLCounter>, HashMap<Long, HLLCounter>>() { @Override public HashMap<Long, HLLCounter> call(HashMap<Long, HLLCounter> v1, HashMap<Long, HLLCounter> v2) throws Exception { Preconditions.checkArgument(v1.size() == v2.size()); Preconditions.checkArgument(v1.size() > 0); for (Map.Entry<Long, HLLCounter> entry : v1.entrySet()) { final HLLCounter counter1 = entry.getValue(); final HLLCounter counter2 = v2.get(entry.getKey()); counter1.merge(Preconditions.checkNotNull(counter2, "counter cannot be null")); } return v1; } }); return samplingResult; }