@Override
        public ByteBuffer create(final int depth, final ByteBuffer parentRowKey, final StoredValues storedValues) {
            final long timeMs = storedValueKeyFactory.getTimeMs(storedValues);
            final long groupHash = storedValueKeyFactory.getGroupHash(depth, storedValues);

            ByteBuffer byteBuffer;

            // If this is a grouping key then we need to add the depth first.
            if (depth == 0) {
                // Create a time based top level group key. <DEPTH><TIME_MS><GROUP_HASH>
                byteBuffer = byteBufferFactory.acquire(Byte.BYTES + Long.BYTES + Long.BYTES);
                byteBuffer.put((byte) depth);
                byteBuffer.putLong(timeMs);
                byteBuffer.putLong(groupHash);
            } else if (isDetailLevel(depth)) {
                // This is a detail level - non-grouped row.
                // Create a time based child unique key. <DEPTH><TIME_MS><PARENT_GROUP_HASHES...><UNIQUE_ID>
                byteBuffer = byteBufferFactory.acquire(parentRowKey.limit() + Long.BYTES);
                byteBuffer.put((byte) depth);
                byteBuffer.putLong(timeMs);
                // Add parent group hashes.
                for (int index = Byte.BYTES + Long.BYTES; index < parentRowKey.limit(); index += Long.BYTES) {
                    byteBuffer.putLong(parentRowKey.getLong(index));
                }
                byteBuffer.putLong(uniqueIdProvider.getUniqueId());
            } else {
                // Create a time based child group key. <DEPTH><TIME_MS><PARENT_GROUP_HASHES...><GROUP_HASH>
                byteBuffer = byteBufferFactory.acquire(parentRowKey.limit() + Long.BYTES);
                byteBuffer.put((byte) depth);
                byteBuffer.putLong(timeMs);
                // Add parent group hashes.
                for (int index = Byte.BYTES + Long.BYTES; index < parentRowKey.limit(); index += Long.BYTES) {
                    byteBuffer.putLong(parentRowKey.getLong(index));
                }
                byteBuffer.putLong(groupHash);
            }

            return byteBuffer.flip();
        }
Creates a nested time based group key. <DEPTH><TIME_MS><PARENT_GROUP_HASH><GROUP_HASH>
stroom-query/stroom-query-common/src/main/java/stroom/query/common/v2/LmdbRowKeyFactoryFactory.java