Github user ppadma commented on a diff in the pull request: https://github.com/apache/drill/pull/1161#discussion_r177175974 --- Diff: exec/java-exec/src/test/java/org/apache/drill/test/rowSet/HyperRowSetImpl.java --- @@ -45,8 +50,67 @@ public RowSetReader buildReader(HyperRowSet rowSet, SelectionVector4 sv4) { TupleMetadata schema = rowSet.schema(); HyperRowIndex rowIndex = new HyperRowIndex(sv4); return new RowSetReaderImpl(schema, rowIndex, - buildContainerChildren(rowSet.container(), - new MetadataRetrieval(schema))); + buildContainerChildren(rowSet.container(), schema)); + } + } + + public static class HyperRowSetBuilderImpl implements HyperRowSetBuilder { + + private final BufferAllocator allocator; + private final List<VectorContainer> batches = new ArrayList<>(); + private int totalRowCount; + + public HyperRowSetBuilderImpl(BufferAllocator allocator) { + this.allocator = allocator; + } + + @Override + public void addBatch(SingleRowSet rowSet) { + if (rowSet.rowCount() == 0) { + return; + } + if (rowSet.indirectionType() != SelectionVectorMode.NONE) { + throw new IllegalArgumentException("Batches must not have a selection vector."); + } + batches.add(rowSet.container()); + totalRowCount += rowSet.rowCount(); + } + + @Override + public void addBatch(VectorContainer container) { + if (container.getRecordCount() == 0) { + return; + } + if (container.getSchema().getSelectionVectorMode() != SelectionVectorMode.NONE) { + throw new IllegalArgumentException("Batches must not have a selection vector."); + } + batches.add(container); + totalRowCount += container.getRecordCount(); + } + + @SuppressWarnings("resource") + @Override + public HyperRowSet build() throws SchemaChangeException { + SelectionVector4 sv4 = new SelectionVector4(allocator, totalRowCount); + ExpandableHyperContainer hyperContainer = new ExpandableHyperContainer(); + for (VectorContainer container : batches) { + hyperContainer.addBatch(container); + } + + // TODO: This has a bug. If the hyperset has two batches with unions, + // and the first union contains only VARCHAR, while the second contains --- End diff -- is there a JIRA for this bug ?
---