writer.finish();
Schema schema = writer.getSchema();
Tuple tuple = TypesUtils.createTuple(schema);
BasicTable.Writer writer1 = new BasicTable.Writer(pathTable, conf);
int part = 0;
TableInserter inserter = writer1.getInserter("part" + part, true);
TypesUtils.resetTuple(tuple);
Tuple record1;
try {
record1 = TypesUtils.createTuple(new Schema("f1:int, f2:string"));
} catch (ParseException e) {
e.printStackTrace();
throw new IOException(e);
}
Tuple record2;
try {
record2 = TypesUtils.createTuple(new Schema("f1:int, f2:string"));
} catch (ParseException e) {
e.printStackTrace();
throw new IOException(e);
}
Tuple record3;
try {
record3 = TypesUtils.createTuple(new Schema("f1:int, f2:string"));
} catch (ParseException e) {
e.printStackTrace();
throw new IOException(e);
}
// add data to row 1
// m1:map(string)
Map<String, String> m1 = new HashMap<String, String>();
m1.put("a", "A");
m1.put("b", "B");
m1.put("c", "C");
tuple.set(0, m1);
// m2:map(map(int))
HashMap<String, Map> m2 = new HashMap<String, Map>();
Map<String, Integer> m31 = new HashMap<String, Integer>();
m31.put("m311", 311);
m31.put("m321", 321);
m31.put("m331", 331);
Map<String, Integer> m32 = new HashMap<String, Integer>();
m32.put("m411", 411);
m32.put("m421", 421);
m32.put("m431", 431);
m2.put("x", m31);
m2.put("y", m32);
tuple.set(1, m2);
// m4:map(map(record(f1:int,f2:string)))
record1.set(0, 11);
record1.set(1, "record row 1.1");
Map<String, Tuple> m51 = new HashMap<String, Tuple>();
Map<String, Tuple> m52 = new HashMap<String, Tuple>();
Map<String, Tuple> m53 = new HashMap<String, Tuple>();
m51.put("ma4", (Tuple) record1);
m52.put("ma41", (Tuple) record1);
m53.put("ma43", (Tuple) record1);
record2.set(0, 12);
record2.set(1, "record row 1.2");
m51.put("mb4", (Tuple) record2);
m52.put("mb42", (Tuple) record2);
m53.put("ma43", (Tuple) record2);
System.out.println("record1-1: " + record1.toString());
record3.set(0, 13);
record3.set(1, "record row 1.3");
System.out.println("record1-3: " + record1.toString());
m51.put("mc4", (Tuple) record3);
m52.put("mc42", (Tuple) record3);
m53.put("ma43", (Tuple) record3);
Map<String, Map> m4 = new HashMap<String, Map>();
m4.put("a4", m51);
m4.put("b4", m52);
m4.put("c4", m53);
m4.put("d4", m53);
m4.put("ma43", m53);
tuple.set(2, m4);
int row = 0;
inserter.insert(new BytesWritable(String.format("k%d%d", part + 1, row + 1)
.getBytes()), tuple);
// row 2
row++;
TypesUtils.resetTuple(tuple);
TypesUtils.resetTuple(record1);
TypesUtils.resetTuple(record2);
TypesUtils.resetTuple(record3);
m1.clear();
m2.clear();
m31.clear();
m32.clear();
m4.clear();
m51.clear();
m52.clear();
m53.clear();
// m1:map(string)
m1.put("a", "A2");
m1.put("b2", "B2");
m1.put("c2", "C2");
tuple.set(0, m1);
// m2:map(map(int))
m31.put("m321", 321);
m31.put("m322", 322);
m31.put("m323", 323);
m2.put("z", m31);
tuple.set(1, m2);
// m4:map(map(record(f1:int,f2:string)))
record1.set(0, 21);
record1.set(1, "record row 2.1");
m51.put("ma4", (Tuple) record1);
m52.put("ma41", (Tuple) record1);
m53.put("ma43", (Tuple) record1);
record2.set(0, 22);
record2.set(1, "record row 2.2");
m51.put("mb4", (Tuple) record2);
m52.put("mb42", (Tuple) record2);
m53.put("ma43", (Tuple) record2);
record3.set(0, 33);
record3.set(1, "record row 3.3");
m51.put("mc4", (Tuple) record3);
m52.put("mc42", (Tuple) record3);
m53.put("ma43", (Tuple) record3);
m4.put("a4", m51);
m4.put("b4", m52);
m4.put("ma43", m53);
tuple.set(2, m4);
inserter.insert(new BytesWritable(String.format("k%d%d", part + 1, row + 1)
.getBytes()), tuple);
// finish building table, closing out the inserter, writer, writer1
inserter.close();
writer1.finish();
writer.close();
}