/** * Tests whether v remains the same when encoded and decoded with the given encoder. * * @throws IllegalArgumentException * if the test fails. */ public static <V> void testEncoder(Encoder<V> encoder, V v) { try { if (!v.equals(encoder.decode(encoder.encode(v)))) throw new IllegalArgumentException("something wrong with " + encoder.getClass().getName() + " -- doesn't encode and decode " + v + " properly"); } catch (ClassCastException e) { throw new IllegalArgumentException( encoder.getClass().getName() + " doesn't encode " + v.getClass().getName()); } }
@Override public boolean hasNext() { if (hasNext) return true; while (true) { if (!source.hasNext()) return false; try { next = encoder.decode(source.next().get()); return hasNext = true; } catch (ValueFormatException vfe) { if (!lossy) throw vfe; } } }
/** * Returns either the {@link #DIR_COLF} or a decoded string version of the colf. * * @param colf * the column family */ public static String getType(Text colf) { if (colf.equals(DIR_COLF)) return colf.toString() + ":"; return Long.toString(Ingest.encoder.decode(colf.getBytes())) + ":"; }
private long getRowCountFromTable(String tableName, Text signalColumn, Authorizations authorizations) { try { LOGGER.debug("BEGIN getRowCountFromTable(%s)", tableName); Scanner scanner = createScanner(tableName, null, authorizations); try { scanner.fetchColumnFamily(signalColumn); IteratorSetting countingIterator = new IteratorSetting( 100, CountingIterator.class.getSimpleName(), CountingIterator.class ); scanner.addScanIterator(countingIterator); GRAPH_LOGGER.logStartIterator(tableName, scanner); long count = 0; for (Map.Entry<Key, Value> entry : scanner) { Long countForKey = LongCombiner.FIXED_LEN_ENCODER.decode(entry.getValue().get()); LOGGER.debug("getRowCountFromTable(%s): %s: %d", tableName, entry.getKey().getRow(), countForKey); count += countForKey; } LOGGER.debug("getRowCountFromTable(%s): TOTAL: %d", tableName, count); return count; } finally { scanner.close(); } } catch (TableNotFoundException ex) { throw new VertexiumException("Could not get count from table: " + tableName, ex); } }
private long getRowCountFromTable(String tableName, Text signalColumn, Authorizations authorizations) { try { LOGGER.debug("BEGIN getRowCountFromTable(%s)", tableName); Scanner scanner = createScanner(tableName, null, authorizations); try { scanner.fetchColumnFamily(signalColumn); IteratorSetting countingIterator = new IteratorSetting( 100, CountingIterator.class.getSimpleName(), CountingIterator.class ); scanner.addScanIterator(countingIterator); GRAPH_LOGGER.logStartIterator(tableName, scanner); long count = 0; for (Map.Entry<Key, Value> entry : scanner) { Long countForKey = LongCombiner.FIXED_LEN_ENCODER.decode(entry.getValue().get()); LOGGER.debug("getRowCountFromTable(%s): %s: %d", tableName, entry.getKey().getRow(), countForKey); count += countForKey; } LOGGER.debug("getRowCountFromTable(%s): TOTAL: %d", tableName, count); return count; } finally { scanner.close(); } } catch (TableNotFoundException ex) { throw new VertexiumException("Could not get count from table: " + tableName, ex); } }
public static AtomKeyValueParser parse(Key key, Value value) throws IOException { AtomKeyValueParser atom = new AtomKeyValueParser(); String row = key.getRow().toString(); int splitPoint = row.indexOf(DELIMITER); if (splitPoint != -1) { atom.setCollectionName(row.substring(0, splitPoint)); int delim = key.getRow().find(DELIMITER); byte[] b = key.getRow().getBytes(); long diff = LongCombiner.FIXED_LEN_ENCODER.decode(Arrays.copyOfRange(b, delim + 1, key.getRow().getLength())); long time = (Long.MAX_VALUE - diff); atom.setUpdated(new Date(time)); } else { throw new IllegalArgumentException("Atom entry is missing row parts: " + key); } atom.setId(AtomKeyValueParser.encodeId(key.getColumnFamily().toString())); String colf = key.getColumnFamily().toString(); splitPoint = colf.indexOf(DELIMITER); if (splitPoint != -1 && splitPoint + 1 != colf.length()) { atom.setValue(colf.substring(0, splitPoint)); atom.setUuid(colf.substring(splitPoint + 1)); } else { throw new IllegalArgumentException("Atom entry is missing column qualifier parts: " + key); } atom.setColumnVisibility(key.getColumnQualifier().toString()); return atom; }
private void prepNext() { Map.Entry<Key, Value> eA; Map.Entry<Text, Value> eB = itBreset.next(); if (!itBreset.hasNext()) { eA = itAonce.next(); // advance itA if (itAonce.hasNext()) // STOP if no more itA itBreset = BrowMap.tailMap(getTextAfterColumn()).entrySet().iterator(); else return; } else eA = itAonce.peek(); Text cola = eA.getKey().getColumnQualifier(); Key nk = new Key(cola, EMPTY_TEXT, eB.getKey()); long a = LEX.decode(eA.getValue().get()); long b = LEX.decode(eB.getValue().get()); long da = degMap.get(cola); long db = degMap.get(eB.getKey()); double nd = Math.min(((double)a)/da, ((double)b)/db); /// (da * db); // full calc is 1 - 2* Value nv = new Value(LEXDOUBLE.encode(nd)); //new Value(Double.toString(nd).getBytes(UTF_8)); nextEntry = new AbstractMap.SimpleImmutableEntry<>(nk, nv); }
@Override public boolean hasNext() { if (hasNext) return true; while (true) { if (!source.hasNext()) return false; try { next = encoder.decode(source.next().get()); return hasNext = true; } catch (ValueFormatException vfe) { if (!lossy) throw vfe; } } }
/** * Tests whether v remains the same when encoded and decoded with the given encoder. * * @throws IllegalArgumentException * if the test fails. */ public static <V> void testEncoder(Encoder<V> encoder, V v) { try { if (!v.equals(encoder.decode(encoder.encode(v)))) throw new IllegalArgumentException("something wrong with " + encoder.getClass().getName() + " -- doesn't encode and decode " + v + " properly"); } catch (ClassCastException e) { throw new IllegalArgumentException( encoder.getClass().getName() + " doesn't encode " + v.getClass().getName()); } }
private void assertCountEquals(long expectedCount, Text tableName, String rowId, RawRecordMetadata eventMetadata, String groupingIdentifier) { Text expectedColumnFamily = new Text(groupingIdentifier + RawRecordMetadata.DELIMITER + tableName); Assert.assertTrue("Didn't have entry for " + expectedColumnFamily + ", " + rowId, assertContainsKey(eventMetadata, expectedColumnFamily, rowId)); Iterator<Value> values = getCorrespondingValue(eventMetadata, expectedColumnFamily, rowId).iterator(); Assert.assertTrue(values.hasNext()); Assert.assertEquals(expectedCount, (long) SummingCombiner.VAR_LEN_ENCODER.decode(values.next().get())); Assert.assertFalse(values.hasNext()); }
private static double sumValues(SortedMap<Key,Value> map) { BigDecimal d = new BigDecimal(0); for (Value value : map.values()) { d = d.add(DECIMAL_ENCODER.decode(value.get())); } return d.doubleValue(); }
public static long getLastCachedTid(BigInteger machineId) throws Exception { long oldTid = 0; String timestampPath = String.format("/snowflake/hosts/%s/timestamp", machineId); Stat stat = curator.checkExists().forPath(timestampPath); if (stat == null) { curator.create().creatingParentContainersIfNeeded().forPath(timestampPath); } else { byte[] data = curator.getData().forPath(timestampPath); oldTid = LongCombiner.FIXED_LEN_ENCODER.decode(data); } return oldTid; }