@Test public void testRemoveUselessNodes() { int imageWidth = 10; int imageHeight = 10; int tileLeftX = 0; int tileTopY = 0; int tileSizeX = 3; int tileSizeY = 3; int tileMargin = 1; Graph graph = checkGraph(imageWidth); ProcessingTile tile = AbstractTileSegmenter.buildTile(tileLeftX, tileTopY, tileSizeX, tileSizeY, tileMargin, imageWidth, imageHeight); Int2ObjectMap<Node> borderNodes = new Int2ObjectLinkedOpenHashMap<Node>(1); Node node = graph.getNodeAt(0); borderNodes.put(node.getId(), node); graph.removeUselessNodes(borderNodes, tile); assertEquals(1, graph.getNodeCount()); }
/** * Group all documents based on a dimension's value. * * @param startDocId Start document id of the range to be grouped * @param endDocId End document id (exclusive) of the range to be grouped * @param dimensionId Index of the dimension to group on * @return Map from dimension value to a pair of start docId and end docId (exclusive) */ public Int2ObjectMap<IntPair> groupOnDimension(int startDocId, int endDocId, int dimensionId) { int startDocIdOffset = startDocId - _startDocId; int endDocIdOffset = endDocId - _startDocId; Int2ObjectMap<IntPair> rangeMap = new Int2ObjectLinkedOpenHashMap<>(); int dimensionOffset = dimensionId * V1Constants.Numbers.INTEGER_SIZE; int currentValue = _dataBuffer.getInt(startDocIdOffset * _docSize + dimensionOffset); int groupStartDocId = startDocId; for (int i = startDocIdOffset + 1; i < endDocIdOffset; i++) { int value = _dataBuffer.getInt(i * _docSize + dimensionOffset); if (value != currentValue) { int groupEndDocId = i + _startDocId; rangeMap.put(currentValue, new IntPair(groupStartDocId, groupEndDocId)); currentValue = value; groupStartDocId = groupEndDocId; } } rangeMap.put(currentValue, new IntPair(groupStartDocId, endDocId)); return rangeMap; }
private void updateFTable(final String tableName, final Filter filter, Map<byte[], Object> colValues, final TableDescriptor td) { /* * Truncate from in memory Truncate from WAL Truncate from Tiers 1 to N */ Map<Integer, Object> columnIdxToValueMap = new Int2ObjectLinkedOpenHashMap<>(colValues.size()); for (Map.Entry<byte[], Object> entry : colValues.entrySet()) { final int idx = td.getColumnByName(Bytes.toString(entry.getKey())).getIndex(); columnIdxToValueMap.put(idx, entry.getValue()); } try { updateInMemory(tableName, filter, columnIdxToValueMap, td); /** * To keep it simple, instead of truncating from the WAL flush the WAL and truncate the tier * stores truncating WAL has the following complexities 1. WAL stores full blocks, truncation * will need the blocks to be exploded and rewritten to new files. 2. More thread sync issues * between truncate, scan, WAL monitor and eviction threads. * * As a side effect some WAL records which are not yet ready to go to tiers (time based * eviction from memory(future)) will be pushed to tier. */ flushWALDataToTiers(tableName, td); updateInTiers(tableName, filter, columnIdxToValueMap, td); } catch (Exception e) { logger.error("Exception while truncating table data", e); throw new TruncateTableException(e.getMessage()); } }