public ImmutableBitSet selectColumns(ImmutableBitSet selectedColBlocks) { ImmutableBitSet result = ImmutableBitSet.EMPTY; for (int i = 0; i < selectedColBlocks.trueBitCount(); i++) { result = result.or(colBlocks[selectedColBlocks.trueBitAt(i)]); } return result; }
public int getMaxLength() { int ret = 0; for (int i = 0; i < colAll.trueBitCount(); i++) { ret += codeSystem.maxCodeLength(colAll.trueBitAt(i)); } return ret; }
public int sizeOf(ImmutableBitSet selectedCols) { int size = 0; for (int i = 0; i < selectedCols.trueBitCount(); i++) { int c = selectedCols.trueBitAt(i); size += cols[c].length(); } return size; }
public int getMaxColumnLength(ImmutableBitSet selectedCols) { int result = 0; for (int i = 0; i < selectedCols.trueBitCount(); i++) { int c = selectedCols.trueBitAt(i); result += codeSystem.maxCodeLength(c); } return result; }
@Override public int hashCode() { int hash = 1; for (int i = 0; i < info.colAll.trueBitCount(); i++) { int c = info.colAll.trueBitAt(i); hash = (31 * hash) + cols[c].hashCode(); } return hash; }
public void loadColumnsFromColumnBlocks(ImmutableBitSet[] selectedColumnBlocks, ImmutableBitSet selectedCols, ByteBuffer buf) { int pos = buf.position(); for (ImmutableBitSet selectedColBlock : selectedColumnBlocks) { for (int i = 0; i < selectedColBlock.trueBitCount(); i++) { int c = selectedColBlock.trueBitAt(i); int len = info.codeSystem.codeLength(c, buf); if (selectedCols.get(c)) { cols[c].reset(buf.array(), buf.arrayOffset() + pos, len); } pos += len; buf.position(pos); } } }
public void fetchNext(GTRecord result) { if (hasNext() == false) throw new IllegalArgumentException(); for (int i = 0; i < selectedColBlocks.trueBitCount(); i++) { int c = selectedColBlocks.trueBitAt(i); result.loadCellBlock(c, cellBlockBuffers[c]); } cur++; } }
/** set record to the codes of specified values, reuse given space to hold the codes */ public GTRecord setValues(ImmutableBitSet selectedCols, ByteArray space, Object... values) { assert selectedCols.cardinality() == values.length; ByteBuffer buf = space.asBuffer(); int pos = buf.position(); for (int i = 0; i < selectedCols.trueBitCount(); i++) { int c = selectedCols.trueBitAt(i); info.codeSystem.encodeColumnValue(c, values[i], buf); int newPos = buf.position(); cols[c].reset(buf.array(), buf.arrayOffset() + pos, newPos - pos); pos = newPos; } return this; }
@Override public MeasureAggregator<?>[] newMetricsAggregators(ImmutableBitSet columns, String[] aggrFunctions) { assert columns.trueBitCount() == aggrFunctions.length; MeasureAggregator<?>[] result = new MeasureAggregator[aggrFunctions.length]; for (int i = 0; i < result.length; i++) { int col = columns.trueBitAt(i); result[i] = MeasureAggregator.create(aggrFunctions[i], info.getColumnType(col)); } return result; }
@SuppressWarnings("unchecked") protected void aggregate(MeasureAggregator[] aggregators, GTRecord record) { for (int i = 0; i < aggregators.length; i++) { int c = metrics.trueBitAt(i); Object metric = codeSystem.decodeColumnValue(c, record.cols[c].asBuffer()); aggregators[i].aggregate(metric); } }
/** write data to given buffer, like serialize */ public void exportColumns(ImmutableBitSet selectedCols, ByteBuffer buf) { for (int i = 0; i < selectedCols.trueBitCount(); i++) { int c = selectedCols.trueBitAt(i); buf.put(cols[c].array(), cols[c].offset(), cols[c].length()); } }
/** decode and return the values of this record */ public Object[] getValues(ImmutableBitSet selectedCols, Object[] result) { assert selectedCols.cardinality() == result.length; for (int i = 0; i < selectedCols.trueBitCount(); i++) { result[i] = decodeValue(selectedCols.trueBitAt(i)); } return result; }
private int compareToInternal(GTRecord o, ImmutableBitSet participateCols) { assert this.info == o.info; // reference equal for performance IGTComparator comparator = info.codeSystem.getComparator(); int comp = 0; for (int i = 0; i < participateCols.trueBitCount(); i++) { int c = participateCols.trueBitAt(i); comp = comparator.compare(cols[c], o.cols[c]); if (comp != 0) return comp; } return comp; }
private byte[] createKey(GTRecord record) { byte[] result = new byte[keyLength]; int offset = 0; for (int i = 0; i < dimensions.trueBitCount(); i++) { int c = dimensions.trueBitAt(i); final ByteArray byteArray = record.cols[c]; final int columnLength = info.codeSystem.maxCodeLength(c); System.arraycopy(byteArray.array(), byteArray.offset(), result, offset, byteArray.length()); offset += columnLength; } assert offset == result.length; return result; }
ByPassChecker(int aggregateBufferSizeLimit) { this.aggregateBufferSizeLimit = aggregateBufferSizeLimit; //init groupOffsetsInLastKey int p = 0; int idx = 0; this.groupOffsetsInLastKey = new int[groupBy.trueBitCount()]; for (int i = 0; i < dimensions.trueBitCount(); i++) { int c = dimensions.trueBitAt(i); int l = info.codeSystem.maxCodeLength(c); if (groupBy.get(c)) groupOffsetsInLastKey[idx++] = p; p += l; } }
/** write data to given buffer, like serialize */ public void exportColumns(ImmutableBitSet selectedCols, ByteArray buf) { int pos = 0; for (int i = 0; i < selectedCols.trueBitCount(); i++) { int c = selectedCols.trueBitAt(i); Preconditions.checkNotNull(cols[c].array()); System.arraycopy(cols[c].array(), cols[c].offset(), buf.array(), buf.offset() + pos, cols[c].length()); pos += cols[c].length(); } buf.setLength(pos); }
public BufferedMeasureCodec createMeasureCodec() { DataType[] metricTypes = new DataType[aggrMetrics.trueBitCount()]; for (int i = 0; i < metricTypes.length; i++) { metricTypes[i] = info.getColumnType(aggrMetrics.trueBitAt(i)); } BufferedMeasureCodec codec = new BufferedMeasureCodec(metricTypes); codec.setBufferSize(info.getMaxColumnLength(aggrMetrics)); return codec; }
@Override public int compareTo(MergeSlot o) { long cuboidComp = this.currentCuboidId - o.currentCuboidId; if (cuboidComp != 0) return cuboidComp < 0 ? -1 : 1; // note GTRecord.equals() don't work because the two GTRecord comes from different GridTable ImmutableBitSet pk = this.currentRecord.getInfo().getPrimaryKey(); for (int i = 0; i < pk.trueBitCount(); i++) { int c = pk.trueBitAt(i); int comp = this.currentRecord.get(c).compareTo(o.currentRecord.get(c)); if (comp != 0) return comp; } return 0; }
@Override public int compare(GTRecord a, GTRecord b) { assert a.getInfo() == b.getInfo(); int comp; ImmutableBitSet allColumns = a.getInfo().getAllColumns(); for (int i = 0; i < allColumns.trueBitCount(); i++) { int c = allColumns.trueBitAt(i); comp = comparator.compare(a.get(c), b.get(c)); if (comp != 0) return comp; } return 0; // equals } }
private void encodeDims(GTRecord record, ImmutableBitSet selectedCols, ByteArray buf, byte defaultValue) { int pos = 0; for (int i = 0; i < selectedCols.trueBitCount(); i++) { int c = selectedCols.trueBitAt(i); ByteArray columnC = record.get(c); if (columnC.array() != null) { System.arraycopy(record.get(c).array(), columnC.offset(), buf.array(), buf.offset() + pos, columnC.length()); pos += columnC.length(); } else { int maxLength = record.getInfo().getCodeSystem().maxCodeLength(c); Arrays.fill(buf.array(), buf.offset() + pos, buf.offset() + pos + maxLength, defaultValue); pos += maxLength; } } buf.setLength(pos); }