paul-rogers 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_r361605652
 
 

 ##########
 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:
   I see the challenge. Might be better to use two distinct classes to model 
the different implementations. The two "state" classes can have the same API to 
hide the differences from other code.
   
   This class is responsible for translating Result Set Loader events into "do 
the right thing" actions on the underlying vectors.
   
   For example, I'd imagine that rollover will be different between the two: 
the DICT has one offset vector, the Repeated DICT has two. Same is true for 
vector allocation.
   
   This is tricky; I can't work it out in the abstract. Maybe play with the 
code to see what works.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to