@Override public Put writeProperty(final Put put, Property property) { byte[] type = PropertyValueUtils.Bytes.getTypeByte(property.getValue()); byte[] bytesWithoutType = PropertyValueUtils.Bytes.getRawBytesWithoutType(property.getValue()); put.addColumn(CF_PROPERTY_TYPE_BYTES, Bytes.toBytes(property.getKey()), type); put.addColumn(CF_PROPERTY_VALUE_BYTES, Bytes.toBytes(property.getKey()), bytesWithoutType); return put; }
@Override public Properties readProperties(final Result res) { Properties properties = Properties.create(); // Get Map<Qualifier, Value> which is Map<PropertyKey, TypeByte> Map<byte[], byte[]> typeFamilyMap = res.getFamilyMap(CF_PROPERTY_TYPE_BYTES); // Get Map<Qualifier, Value> which is Map<PropertyKey, ValueBytesWithoutType> Map<byte[], byte[]> valueFamilyMap = res.getFamilyMap(CF_PROPERTY_VALUE_BYTES); for (Map.Entry<byte[], byte[]> propertyColumn : typeFamilyMap.entrySet()) { properties.set( Bytes.toString(propertyColumn.getKey()), PropertyValueUtils.Bytes.createFromTypeValueBytes( propertyColumn.getValue(), valueFamilyMap.get(propertyColumn.getKey()))); } return properties; }
Bytes.toBytesBinary(key), compareOp, new BinaryComparator(PropertyValueUtils.Bytes.getRawBytesWithoutType(min))); Bytes.toBytesBinary(key), negate ? CompareFilter.CompareOp.NOT_EQUAL : CompareFilter.CompareOp.EQUAL, PropertyValueUtils.Bytes.getTypeByte(min));
Bytes.toBytesBinary(key), compareOp, PropertyValueUtils.Bytes.getRawBytesWithoutType(value)); Bytes.toBytesBinary(key), compareOp, PropertyValueUtils.Bytes.getTypeByte(value));
/** * Test the toHBaseFilter function */ @Test public void testToHBaseFilter() { HBasePropLargerThan<Vertex> vertexFilter = new HBasePropLargerThan<>(propertyKey, propertyValue, isInclude); FilterList expectedFilter = new FilterList(FilterList.Operator.MUST_PASS_ALL); SingleColumnValueFilter valueFilter = new SingleColumnValueFilter( Bytes.toBytesBinary(CF_PROPERTY_VALUE), Bytes.toBytesBinary(propertyKey), isInclude ? CompareFilter.CompareOp.GREATER_OR_EQUAL : CompareFilter.CompareOp.GREATER, new BinaryComparator(PropertyValueUtils.Bytes.getRawBytesWithoutType(propertyValue))); // Define that the entire row will be skipped if the column is not found valueFilter.setFilterIfMissing(true); SingleColumnValueFilter typeFilter = new SingleColumnValueFilter( Bytes.toBytesBinary(CF_PROPERTY_TYPE), Bytes.toBytesBinary(propertyKey), CompareFilter.CompareOp.EQUAL, PropertyValueUtils.Bytes.getTypeByte(propertyValue)); // Define that the entire row will be skipped if the column is not found typeFilter.setFilterIfMissing(true); expectedFilter.addFilter(valueFilter); expectedFilter.addFilter(typeFilter); assertEquals("Failed during filter comparison for type [" + propertyType + "].", expectedFilter.toString(), vertexFilter.toHBaseFilter(false).toString()); }
/** * Test the toHBaseFilter function */ @Test public void testToHBaseFilter() { HBasePropEquals<Vertex> vertexFilter = new HBasePropEquals<>(propertyKey, propertyValue); FilterList expectedFilter = new FilterList(FilterList.Operator.MUST_PASS_ALL); SingleColumnValueFilter valueFilter = new SingleColumnValueFilter( Bytes.toBytesBinary(CF_PROPERTY_VALUE), Bytes.toBytesBinary(propertyKey), CompareFilter.CompareOp.EQUAL, PropertyValueUtils.Bytes.getRawBytesWithoutType(propertyValue)); // Define that the entire row will be skipped if the column is not found valueFilter.setFilterIfMissing(true); SingleColumnValueFilter typeFilter = new SingleColumnValueFilter( Bytes.toBytesBinary(CF_PROPERTY_TYPE), Bytes.toBytesBinary(propertyKey), CompareFilter.CompareOp.EQUAL, PropertyValueUtils.Bytes.getTypeByte(propertyValue)); // Define that the entire row will be skipped if the column is not found typeFilter.setFilterIfMissing(true); expectedFilter.addFilter(valueFilter); expectedFilter.addFilter(typeFilter); assertEquals("Failed during filter comparison for type [" + propertyType + "].", expectedFilter.toString(), vertexFilter.toHBaseFilter(false).toString()); }
/** * Test static function {@link PropertyValueUtils.Bytes#getRawBytesWithoutType(PropertyValue)} */ @Test public void testGetRawBytesWithoutType() { assertArrayEquals(Arrays.copyOfRange(propertyValue.getRawBytes(), 1, propertyValue.getRawBytes().length), PropertyValueUtils.Bytes.getRawBytesWithoutType(propertyValue)); }
/** * Test static function {@link PropertyValueUtils.Bytes#createFromTypeValueBytes(byte[], byte[])}} */ @Test public void testCreateFromTypeValueBytes() { assertEquals(propertyValue, PropertyValueUtils.Bytes .createFromTypeValueBytes(new byte[] {type}, Arrays.copyOfRange(propertyValue.getRawBytes(), 1, propertyValue.getRawBytes().length))); } }
/** * Test static function {@link PropertyValueUtils.Bytes#getTypeByte(PropertyValue)} */ @Test public void testGetTypeByte() { assertArrayEquals(new byte[] {type}, PropertyValueUtils.Bytes.getTypeByte(propertyValue)); }