/** * Convenient form of <code>getIdFromValue(value, 0)</code> */ final public int getIdFromValue(T value) throws IllegalArgumentException { return getIdFromValue(value, 0); }
public void addValue(T value) { int id = fullDict.getIdFromValue(value); valueToIdMap.put(value, id); }
@Override public void encode(String valueStr, byte[] output, int outputOffset) { try { int id = dict.getIdFromValue(valueStr, roundingFlag); BytesUtil.writeUnsigned(id, output, outputOffset, fixedLen); } catch (IllegalArgumentException ex) { for (int i = outputOffset; i < outputOffset + fixedLen; i++) { output[i] = defaultByte; } logger.error("Can't translate value " + valueStr + " to dictionary ID, roundingFlag " + roundingFlag + "." + " Using default value " + String.format(Locale.ROOT, "\\x%02X", defaultByte)); } }
@Override public void serialize(Object value, ByteBuffer buf) { int id = dict.getIdFromValue(value == null ? null : value.toString(), roundingFlag); BytesUtil.writeUnsigned(id, dict.getSizeOfId(), buf); }
private long runQueryIdByValueBytes(ArrayList<String> rawData, Dictionary<String> dict, int cardnality, int testTimes) { long startTime = System.currentTimeMillis(); int step = 1; for (int i = 0; i < testTimes; i++) { for (int j = 0; j < cardnality; j++) { step |= dict.getIdFromValue(rawData.get(j)); } } return System.currentTimeMillis() - startTime; }
private long runQueryId(ArrayList<String> rawData, Dictionary<String> dict, int cardnality, int testTimes) { long startTime = System.currentTimeMillis(); int step = 1; for (int i = 0; i < testTimes; i++) { for (int j = 0; j < cardnality; j++) { step |= dict.getIdFromValue(rawData.get(j)); } } return System.currentTimeMillis() - startTime; }
buf.append(", "); buf.append(s.toString()).append("=>").append(dict.getIdFromValue(s));
@Override public BitmapCounter valueOf(String[] values, MeasureDesc measureDesc, Map<TblColRef, Dictionary<String>> dictionaryMap) { checkArgument(values.length == 1, "expect 1 value, got %s", Arrays.toString(values)); current.clear(); if (values[0] == null) { return current; } int id; if (needDictionaryColumn(measureDesc.getFunction())) { TblColRef literalCol = measureDesc.getFunction().getParameter().getColRefs().get(0); Dictionary<String> dictionary = dictionaryMap.get(literalCol); id = dictionary.getIdFromValue(values[0]); } else { id = Integer.parseInt(values[0]); } current.add(id); return current; }
@Override public List<ByteArray> valueOf(String[] values, MeasureDesc measureDesc, Map<TblColRef, Dictionary<String>> dictionaryMap) { if (values.length != 1) throw new IllegalArgumentException(); //source input column value String literal = values[0]; // encode literal using dictionary TblColRef literalCol = getRawColumn(measureDesc.getFunction()); Dictionary<String> dictionary = dictionaryMap.get(literalCol); int keyEncodedValue = dictionary.getIdFromValue(literal); ByteArray key = new ByteArray(dictionary.getSizeOfId()); BytesUtil.writeUnsigned(keyEncodedValue, key.array(), key.offset(), dictionary.getSizeOfId()); List<ByteArray> valueList = new ArrayList<ByteArray>(1); valueList.add(key); return valueList; }
int[] rowIndex = new int[n]; for (int i = 0; i < n; i++) { rowIndex[i] = dict.getIdFromValue(row[i]);
@Override public List<ByteArray> reEncodeDictionary(List<ByteArray> value, MeasureDesc measureDesc, Map<TblColRef, Dictionary<String>> oldDicts, Map<TblColRef, Dictionary<String>> newDicts) { TblColRef colRef = getRawColumn(measureDesc.getFunction()); Dictionary<String> sourceDict = oldDicts.get(colRef); Dictionary<String> mergedDict = newDicts.get(colRef); int valueSize = value.size(); byte[] newIdBuf = new byte[valueSize * mergedDict.getSizeOfId()]; int bufOffset = 0; for (ByteArray c : value) { int oldId = BytesUtil.readUnsigned(c.array(), c.offset(), c.length()); int newId; String v = sourceDict.getValueFromId(oldId); if (v == null) { newId = mergedDict.nullId(); } else { newId = mergedDict.getIdFromValue(v); } BytesUtil.writeUnsigned(newId, newIdBuf, bufOffset, mergedDict.getSizeOfId()); c.reset(newIdBuf, bufOffset, mergedDict.getSizeOfId()); bufOffset += mergedDict.getSizeOfId(); } return value; } };
Assert.assertEquals(dict.getIdFromValue(value), dShrunkenDict.getIdFromValue(value));
int[] rowIndex = new int[tableDesc.getColumnCount()]; for (ColumnDesc column : tableDesc.getColumns()) { rowIndex[column.getZeroBasedIndex()] = dict.getIdFromValue(row[column.getZeroBasedIndex()]);
idInMergedDict = mergedDict.nullId(); } else { idInMergedDict = mergedDict.getIdFromValue(v);
/** * Convenient form of <code>getIdFromValue(value, 0)</code> */ final public int getIdFromValue(T value) throws IllegalArgumentException { return getIdFromValue(value, 0); }
/** * Convenient form of <code>getIdFromValue(value, 0)</code> */ final public int getIdFromValue(T value) throws IllegalArgumentException { return getIdFromValue(value, 0); }
public void addValue(T value) { int id = fullDict.getIdFromValue(value); valueToIdMap.put(value, id); }
@Override public void encode(String valueStr, byte[] output, int outputOffset) { try { int id = dict.getIdFromValue(valueStr, roundingFlag); BytesUtil.writeUnsigned(id, output, outputOffset, fixedLen); } catch (IllegalArgumentException ex) { for (int i = outputOffset; i < outputOffset + fixedLen; i++) { output[i] = defaultByte; } logger.error("Can't translate value " + valueStr + " to dictionary ID, roundingFlag " + roundingFlag + "." + " Using default value " + String.format(Locale.ROOT, "\\x%02X", defaultByte)); } }
@Override public void serialize(Object value, ByteBuffer buf) { int id = dict.getIdFromValue(value == null ? null : value.toString(), roundingFlag); BytesUtil.writeUnsigned(id, dict.getSizeOfId(), buf); }
@Override public List<ByteArray> valueOf(String[] values, MeasureDesc measureDesc, Map<TblColRef, Dictionary<String>> dictionaryMap) { if (values.length != 1) throw new IllegalArgumentException(); //source input column value String literal = values[0]; // encode literal using dictionary TblColRef literalCol = getRawColumn(measureDesc.getFunction()); Dictionary<String> dictionary = dictionaryMap.get(literalCol); int keyEncodedValue = dictionary.getIdFromValue(literal); ByteArray key = new ByteArray(dictionary.getSizeOfId()); BytesUtil.writeUnsigned(keyEncodedValue, key.array(), key.offset(), dictionary.getSizeOfId()); List<ByteArray> valueList = new ArrayList<ByteArray>(1); valueList.add(key); return valueList; }