public final void testPartitionedStorePlan() throws IOException, PlanningException {
FileFragment[] frags = StorageManager.splitNG(conf, "default.score", score.getMeta(), score.getPath(),
Integer.MAX_VALUE);
QueryUnitAttemptId id = LocalTajoTestingUtility.newQueryUnitAttemptId(masterPlan);
Path workDir = CommonTestingUtil.getTestDir("target/test-data/testPartitionedStorePlan");
TaskAttemptContext ctx = new TaskAttemptContext(conf, id, new FileFragment[] { frags[0] }, workDir);
ctx.setEnforcer(new Enforcer());
Expr context = analyzer.parse(QUERIES[7]);
LogicalPlan plan = planner.createPlan(session, context);
int numPartitions = 3;
Column key1 = new Column("default.score.deptname", Type.TEXT);
Column key2 = new Column("default.score.class", Type.TEXT);
DataChannel dataChannel = new DataChannel(masterPlan.newExecutionBlockId(), masterPlan.newExecutionBlockId(),
ShuffleType.HASH_SHUFFLE, numPartitions);
dataChannel.setShuffleKeys(new Column[]{key1, key2});
ctx.setDataChannel(dataChannel);
LogicalNode rootNode = optimizer.optimize(plan);
TableMeta outputMeta = CatalogUtil.newTableMeta(dataChannel.getStoreType());
FileSystem fs = sm.getFileSystem();
PhysicalPlanner phyPlanner = new PhysicalPlannerImpl(conf,sm);
PhysicalExec exec = phyPlanner.createPlan(ctx, rootNode);
exec.init();
exec.next();
exec.close();
Path path = new Path(workDir, "output");
FileStatus [] list = fs.listStatus(path);
assertEquals(numPartitions, list.length);
FileFragment[] fragments = new FileFragment[list.length];
int i = 0;
for (FileStatus status : list) {
fragments[i++] = new FileFragment("partition", status.getPath(), 0, status.getLen());
}
Scanner scanner = new MergeScanner(conf, rootNode.getOutSchema(), outputMeta, TUtil.newList(fragments));
scanner.init();
Tuple tuple;
i = 0;
while ((tuple = scanner.next()) != null) {
assertEquals(6, tuple.get(2).asInt4()); // sum
assertEquals(3, tuple.get(3).asInt4()); // max
assertEquals(1, tuple.get(4).asInt4()); // min
i++;
}
assertEquals(10, i);
scanner.close();
// Examine the statistics information
assertEquals(10, ctx.getResultStats().getNumRows().longValue());
}