KazydubB commented on a change in pull request #1870: DRILL-7359: Add support for DICT type in RowSet Framework URL: https://github.com/apache/drill/pull/1870#discussion_r361600501
########## File path: exec/java-exec/src/main/java/org/apache/drill/exec/physical/resultSet/impl/TupleState.java ########## @@ -567,4 +574,187 @@ public void dump(HierarchicalFormatter format) { .endArray() .endObject(); } + + public static class DictColumnState extends BaseContainerColumnState { + protected final DictState dictState; + protected boolean isVersioned; + protected final ColumnMetadata outputSchema; + // Indicates if value is accessed by key + protected final boolean valueProjected; + + public DictColumnState(DictState dictState, + AbstractObjectWriter writer, + VectorState vectorState, + boolean isVersioned, + boolean valueProjected) { + super(dictState.loader(), writer, vectorState); + this.dictState = dictState; + dictState.bindColumnState(this); + this.isVersioned = isVersioned; + if (isVersioned) { + outputSchema = schema().cloneEmpty(); + } else { + outputSchema = schema(); + } + dictState.bindOutputSchema(outputSchema.tupleSchema()); + this.valueProjected = valueProjected; + } + + @Override + public void buildOutput(TupleState tupleState) { + outputIndex = tupleState.addOutputColumn(vector(), outputSchema()); + } + + public DictState dictState() { + return dictState; + } + + @Override + public ContainerState container() { + return dictState; + } + + @Override + public boolean isProjected() { + return dictState.hasProjections(); + } + + public boolean isVersioned() { + return isVersioned; + } + + @Override + public ColumnMetadata outputSchema() { return outputSchema; } + } + + public static abstract class DictState extends MapState { + + public DictState(LoaderInternals events, + ResultVectorCache vectorCache, + ProjectionSet projectionSet) { + super(events, vectorCache, projectionSet); + } + + public void bindColumnState(ColumnState colState) { + super.bindColumnState(colState); + writer().bindListener(this); + } + + @Override + public boolean isDict() { + return true; + } + + @Override + protected boolean isVersioned() { + return ((DictColumnState) parentColumn).isVersioned(); + } + + @Override + public void dump(HierarchicalFormatter format) { + format.startObject(this) + .attribute("column", parentColumn.schema().name()) + .attribute("cardinality", innerCardinality()) + .endObject(); + } + } + + public static class SingleDictState extends DictState { + + public SingleDictState(LoaderInternals events, + ResultVectorCache vectorCache, + ProjectionSet projectionSet) { + super(events, vectorCache, projectionSet); + } + + @Override + public AbstractTupleWriter writer() { + return (AbstractTupleWriter) parentColumn.writer().dict().tuple(); + } + } + + public static class DictArrayState extends DictState { + + public DictArrayState(LoaderInternals events, + ResultVectorCache vectorCache, + ProjectionSet projectionSet) { + super(events, vectorCache, projectionSet); + } + + @Override + public int addOutputColumn(ValueVector vector, ColumnMetadata colSchema) { + final RepeatedDictVector repeatedDictVector = parentColumn.vector(); + DictVector dictVector = (DictVector) repeatedDictVector.getDataVector(); + if (isVersioned()) { + dictVector.putChild(colSchema.name(), vector); + } + final int index = outputSchema.addColumn(colSchema); + assert dictVector.size() == outputSchema.size(); + assert dictVector.getField().getChildren().size() == outputSchema.size(); + return index; + } + + @Override + public AbstractTupleWriter writer() { + return (AbstractTupleWriter) parentColumn.writer().array().dict().tuple(); + } + } + + public static class DictVectorState implements VectorState { + + private final ValueVector vector; Review comment: This class is used for both `DictVector` and `RepeatedDictVector`. Unlike for `MAP`, they do not have a common parent class (other than `RepeatedValueVector` interface). Should this be changed to `RepeatedValueVector` or should I create another `VectorState` for `RepeatedDictVector`? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services