Created
June 12, 2012 17:24
-
-
Save mushkevych/2918841 to your computer and use it in GitHub Desktop.
Surus blog examples
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
public class Example { | |
@HRowKey | |
public byte[] key; | |
@HProperty(family = "stat", identifier = "number_of_users") | |
public long numberOfUsers; | |
@HMapProperty(family = "stat", identifier = "months", keyType = String.class, valueType = Integer.class) | |
public Map<String, Integer> months = new HashMap<String, Integer>(); | |
@HMapFamily(family = "family_mapping", keyType = Integer.class, valueType = Integer.class) | |
public Map<Integer, Integer> familyMapping = new HashMap<Integer, Integer>(); | |
@HMapFamily(family = "nested_maps", keyType = Long.class, valueType = Map.class) | |
@HNestedMap(keyType = Long.class, valueType = Integer.class) | |
public Map<Long, Map<Long, Integer>> nestedMaps = new HashMap<Long, Map<Long, Integer>>(); | |
} |
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
// declare and initialize Example instance | |
Example example = new Example(); | |
example.numberOfUsers=... | |
// declare EntityService | |
EntityService<Example> esExample = new EntityService<Example>(Example.class); | |
// get Put object | |
Put put = esExample.insert(example); |
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
@Override | |
protected void map(ImmutableBytesWritable key, Result result, Context context) throws IOException, InterruptedException { | |
int vertexA = Bytes.toInt(key.get()); | |
Example example = esExample.parseResult(result); | |
... | |
} |
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
// create Get object | |
HTable tExample = ... | |
Get get = new Get(ID_IN_BYTES); | |
Result result = tExample.get(get); | |
Example example = esExample.parseResult(result); |
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
@Override | |
protected void reduce(ImmutableBytesWritable key, Iterable<ImmutableBytesWritable> values, Context context) throws IOException, InterruptedException { | |
int vertexA = Bytes.toInt(key.get()); | |
for (ImmutableBytesWritable entry : values) { | |
Example example = create Example instance of "entry" | |
Put putA = esExample.insert(example); | |
putA.setWriteToWAL(false); | |
context.write(HBASE_KEY_DUMMY, putA); | |
} | |
} |
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
<TableSchema name="tbl_example"> | |
<ColumnSchema name="family_mapping" BLOCKCACHE="false" VERSIONS="1"/> | |
<ColumnSchema name="stat" BLOCKCACHE="false" VERSIONS="1"/> | |
<ColumnSchema name="nested_maps" BLOCKCACHE="false" VERSIONS="1"/> | |
</TableSchema> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment