-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
.../hbase/orm/extensions/componenttests/MultiDynamicColumnWithSameFamilyComponentSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.github.oemergenc.hbase.orm.extensions.componenttests | ||
|
||
import io.github.oemergenc.hbase.orm.extensions.dao.MultipleDynamicColumsWithSameFamilyDao | ||
|
||
import static io.github.oemergenc.hbase.orm.extensions.data.TestContent.getDefaultMultiHBDynamicColumWithSameFamilyRecord | ||
|
||
class MultiDynamicColumnWithSameFamilyComponentSpec extends AbstractComponentSpec { | ||
def dao = new MultipleDynamicColumsWithSameFamilyDao(bigTableHelper.connect()) | ||
|
||
def "Converting to get for dynamic qualifiers works"() { | ||
given: | ||
def staticId = UUID.randomUUID() as String | ||
def record = getDefaultMultiHBDynamicColumWithSameFamilyRecord(staticId) | ||
|
||
when: | ||
dao.persist(record) | ||
|
||
then: | ||
def resultResult = dao.getRecordForDynamicFamily(staticId, queriedQualifierParts) | ||
|
||
then: | ||
resultResult.isPresent() == isPresent | ||
|
||
where: | ||
queriedQualifierParts | isPresent | ||
["dv1_dp1_1", "otherId_1"] | true | ||
["dv1_dp1_2", "otherId_2"] | true | ||
["dv2_dp1_1", "otherId_1"] | true | ||
["dv2_dp1_2", "otherId_2"] | true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...b/oemergenc/hbase/orm/extensions/mapper/MultiDynamicColumnWithSameFamilyMapperSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.github.oemergenc.hbase.orm.extensions.mapper | ||
|
||
import io.github.oemergenc.hbase.orm.extensions.HBDynamicColumnObjectMapper | ||
import io.github.oemergenc.hbase.orm.extensions.domain.records.MultipleHBDynamicColumnsRecord | ||
import io.github.oemergenc.hbase.orm.extensions.domain.records.MultipleHBDynamicColumnsWithSameFamilyRecord | ||
import spock.lang.Specification | ||
|
||
import static io.github.oemergenc.hbase.orm.extensions.data.TestContent.getDefaultMultiHBDynamicColumWithSameFamilyRecord | ||
|
||
class MultiDynamicColumnWithSameFamilyMapperSpec extends Specification { | ||
def mapper = new HBDynamicColumnObjectMapper() | ||
|
||
def "Converting a record with multiple dynamic columns works"() { | ||
given: | ||
def staticId = UUID.randomUUID() as String | ||
def record = getDefaultMultiHBDynamicColumWithSameFamilyRecord(staticId) | ||
|
||
when: | ||
def result = mapper.writeValueAsResult(record) | ||
|
||
then: | ||
result | ||
result.getFamilyMap("dynamicFamily1".bytes)["df1#dv1_dp1_1:otherId_1".bytes] | ||
result.getFamilyMap("dynamicFamily1".bytes)["df1#dv1_dp1_2:otherId_2".bytes] | ||
result.getFamilyMap("dynamicFamily1".bytes)["df2#dv2_dp1_1:otherId_1".bytes] | ||
result.getFamilyMap("dynamicFamily1".bytes)["df2#dv2_dp1_2:otherId_2".bytes] | ||
result.getFamilyMap("staticFamily".bytes)['staticId'.bytes] | ||
|
||
when: | ||
def recordResult = mapper.readValue(result, MultipleHBDynamicColumnsWithSameFamilyRecord.class) | ||
|
||
then: | ||
recordResult | ||
recordResult.staticId == staticId | ||
|
||
and: | ||
recordResult.dynamicValues1.collect { it.dynamicPart1 }.containsAll(["dv1_dp1_1", "dv1_dp1_2"]) | ||
recordResult.dynamicValues1.collect { it.otherId }.containsAll(["otherId_1", "otherId_2"]) | ||
recordResult.dynamicValues1.collect { it.aString }.containsAll(["aString_1", "aString_2"]) | ||
|
||
and: | ||
recordResult.dynamicValues2.collect { it.dynamicPart1 }.containsAll(["dv2_dp1_1", "dv2_dp1_2"]) | ||
recordResult.dynamicValues2.collect { it.otherId }.containsAll(["otherId_1", "otherId_2"]) | ||
recordResult.dynamicValues2.collect { it.aString }.containsAll(["aString_1", "aString_2"]) | ||
recordResult.dynamicValues2.flatten { it.nodes } == [] | ||
} | ||
|
||
def "Converting to get for dynamic qualifiers works"() { | ||
given: | ||
def staticId = UUID.randomUUID() as String | ||
def record = getDefaultMultiHBDynamicColumWithSameFamilyRecord(staticId) | ||
|
||
when: | ||
mapper.writeValueAsResult(record) | ||
|
||
then: | ||
def get = mapper.getAsGet(MultipleHBDynamicColumnsRecord.class, staticId.bytes, "dynamicFamily1", queriedQualifierParts) | ||
|
||
then: | ||
get | ||
get.numFamilies() == expectedNumSize | ||
|
||
where: | ||
queriedQualifierParts | expectedNumSize | ||
["dynamicId1"] | 1 | ||
["dv1_dp1_1", "dv1_dp2_1"] | 1 | ||
["237912837"] | 1 | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
.../io/github/oemergenc/hbase/orm/extensions/dao/MultipleDynamicColumsWithSameFamilyDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.github.oemergenc.hbase.orm.extensions.dao; | ||
|
||
import io.github.oemergenc.hbase.orm.extensions.AbstractHBDynamicDAO; | ||
import io.github.oemergenc.hbase.orm.extensions.domain.records.MultipleHBDynamicColumnsWithSameFamilyRecord; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.hadoop.hbase.client.Connection; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Slf4j | ||
public class MultipleDynamicColumsWithSameFamilyDao extends AbstractHBDynamicDAO<String, MultipleHBDynamicColumnsWithSameFamilyRecord> { | ||
public MultipleDynamicColumsWithSameFamilyDao(Connection connection) { | ||
super(connection); | ||
} | ||
|
||
public Optional<MultipleHBDynamicColumnsWithSameFamilyRecord> getRecordForDynamicFamily(String rowKey, | ||
List<String> qualifierParts) { | ||
try { | ||
return Optional.ofNullable(getDynamicCell(rowKey, "dynamicFamily1", qualifierParts)); | ||
} catch (Exception e) { | ||
log.error("There was an error while trying to get column family data of hbdynamic column", e); | ||
e.printStackTrace(); | ||
} | ||
return Optional.empty(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...enc/hbase/orm/extensions/domain/records/MultipleHBDynamicColumnsWithSameFamilyRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.github.oemergenc.hbase.orm.extensions.domain.records; | ||
|
||
import com.flipkart.hbaseobjectmapper.DynamicQualifier; | ||
import com.flipkart.hbaseobjectmapper.Family; | ||
import com.flipkart.hbaseobjectmapper.HBColumn; | ||
import com.flipkart.hbaseobjectmapper.HBRecord; | ||
import com.flipkart.hbaseobjectmapper.HBRowKey; | ||
import com.flipkart.hbaseobjectmapper.HBTable; | ||
import io.github.oemergenc.hbase.orm.extensions.HBDynamicColumn; | ||
import io.github.oemergenc.hbase.orm.extensions.domain.dto.DependentWithListType; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@HBTable(name = "multiple_dynamic_columns_table", families = { | ||
@Family(name = "dynamicFamily1"), | ||
@Family(name = "staticFamily")}) | ||
public class MultipleHBDynamicColumnsWithSameFamilyRecord implements HBRecord<String> { | ||
|
||
@HBRowKey | ||
@HBColumn(family = "staticFamily", column = "staticId") | ||
private String staticId; | ||
|
||
@HBDynamicColumn(family = "dynamicFamily1", alias = "df1", qualifier = @DynamicQualifier(parts = {"dynamicPart1", "otherId"})) | ||
private List<DependentWithListType> dynamicValues1; | ||
|
||
@HBDynamicColumn(family = "dynamicFamily1", alias = "df2", qualifier = @DynamicQualifier(parts = {"dynamicPart1", "otherId"})) | ||
private List<DependentWithListType> dynamicValues2; | ||
|
||
@Override | ||
public String composeRowKey() { | ||
return staticId; | ||
} | ||
|
||
@Override | ||
public void parseRowKey(String rowKey) { | ||
this.staticId = rowKey; | ||
} | ||
} |