use of com.baidu.hugegraph.backend.serializer.TableBackendEntry in project incubator-hugegraph by apache.
the class PostgresqlSerializer method writeIndex.
@Override
public BackendEntry writeIndex(HugeIndex index) {
TableBackendEntry entry = newBackendEntry(index);
/*
* When field-values is null and elementIds size is 0, it is
* meaningful for deletion of index data in secondary/range index.
*/
if (index.fieldValues() == null && index.elementIds().size() == 0) {
entry.column(HugeKeys.INDEX_LABEL_ID, index.indexLabel().longId());
} else {
Object value = index.fieldValues();
if (value != null && "\u0000".equals(value)) {
value = Strings.EMPTY;
}
entry.column(HugeKeys.FIELD_VALUES, value);
entry.column(HugeKeys.INDEX_LABEL_ID, index.indexLabel().longId());
entry.column(HugeKeys.ELEMENT_IDS, IdUtil.writeStoredString(index.elementId()));
entry.column(HugeKeys.EXPIRED_TIME, index.expiredTime());
entry.subId(index.elementId());
}
return entry;
}
use of com.baidu.hugegraph.backend.serializer.TableBackendEntry in project incubator-hugegraph by apache.
the class TableBackendEntryTest method testColumnWithCardinalityList.
@Test
public void testColumnWithCardinalityList() {
TableBackendEntry entry = new TableBackendEntry(HugeType.VERTEX);
entry.column(HugeKeys.PROPERTIES, "v1", Cardinality.LIST);
Assert.assertEquals(ImmutableList.of("v1"), entry.column(HugeKeys.PROPERTIES));
entry.column(HugeKeys.PROPERTIES, "v2", Cardinality.LIST);
Assert.assertEquals(ImmutableList.of("v1", "v2"), entry.column(HugeKeys.PROPERTIES));
entry.column(HugeKeys.PROPERTIES, "v3", Cardinality.LIST);
Assert.assertEquals(ImmutableList.of("v1", "v2", "v3"), entry.column(HugeKeys.PROPERTIES));
entry.column(HugeKeys.PROPERTIES, "v2", Cardinality.LIST);
Assert.assertEquals(ImmutableList.of("v1", "v2", "v3", "v2"), entry.column(HugeKeys.PROPERTIES));
}
use of com.baidu.hugegraph.backend.serializer.TableBackendEntry in project incubator-hugegraph by apache.
the class TableBackendEntryTest method testId.
@Test
public void testId() {
TableBackendEntry entry = new TableBackendEntry(HugeType.VERTEX);
Assert.assertNull(entry.id());
Id id = IdGenerator.of(1L);
entry.id(id);
Assert.assertEquals(HugeType.VERTEX, entry.type());
Assert.assertEquals(id, entry.id());
Assert.assertNull(entry.subId());
entry.subId(id);
Assert.assertEquals(id, entry.subId());
}
use of com.baidu.hugegraph.backend.serializer.TableBackendEntry in project incubator-hugegraph by apache.
the class TableBackendEntryTest method testColumnWithCardinalitySet.
@Test
public void testColumnWithCardinalitySet() {
TableBackendEntry entry = new TableBackendEntry(HugeType.VERTEX);
entry.column(HugeKeys.PROPERTIES, "v1", Cardinality.SET);
Assert.assertEquals(ImmutableSet.of("v1"), entry.column(HugeKeys.PROPERTIES));
entry.column(HugeKeys.PROPERTIES, "v2", Cardinality.SET);
Assert.assertEquals(ImmutableSet.of("v1", "v2"), entry.column(HugeKeys.PROPERTIES));
entry.column(HugeKeys.PROPERTIES, "v3", Cardinality.SET);
Assert.assertEquals(ImmutableSet.of("v1", "v2", "v3"), entry.column(HugeKeys.PROPERTIES));
entry.column(HugeKeys.PROPERTIES, "v2", Cardinality.SET);
Assert.assertEquals(ImmutableSet.of("v1", "v2", "v3"), entry.column(HugeKeys.PROPERTIES));
}
use of com.baidu.hugegraph.backend.serializer.TableBackendEntry in project incubator-hugegraph by apache.
the class TableBackendEntryTest method testColumnWithCardinalitySingle.
@Test
public void testColumnWithCardinalitySingle() {
TableBackendEntry entry = new TableBackendEntry(HugeType.VERTEX);
entry.column(HugeKeys.ID, "v1", Cardinality.SINGLE);
Assert.assertEquals("v1", entry.column(HugeKeys.ID));
entry.column(HugeKeys.ID, "v2", Cardinality.SINGLE);
Assert.assertEquals("v2", entry.column(HugeKeys.ID));
Assert.assertThrows(ClassCastException.class, () -> {
entry.column(HugeKeys.ID, "v3", Cardinality.SET);
});
}
Aggregations