use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult in project drill by apache.
the class ColumnBuilder method buildSingleDict.
private ColumnState buildSingleDict(ContainerState parent, ColumnMetadata columnSchema) {
final ProjectionFilter projFilter = parent.projection();
final ProjResult projResult = projFilter.projection(columnSchema);
// Create the dict's offset vector.
final DictVector dictVector;
final UInt4Vector offsetVector;
if (projResult.isProjected) {
// Creating the dict vector will create its contained vectors if we
// give it a materialized field with children. So, instead pass a clone
// without children so we can add them.
final ColumnMetadata dictColMetadata = columnSchema.cloneEmpty();
// vectors can be cached.
assert columnSchema.tupleSchema().isEmpty();
dictVector = new DictVector(dictColMetadata.schema(), parent.loader().allocator(), null);
offsetVector = dictVector.getOffsetVector();
} else {
dictVector = null;
offsetVector = null;
}
// Create the writer using the offset vector
final AbstractObjectWriter writer = ObjectDictWriter.buildDict(columnSchema, dictVector, new ArrayList<>());
// Wrap the offset vector in a vector state
final VectorState offsetVectorState;
if (!projResult.isProjected) {
offsetVectorState = new NullVectorState();
} else {
offsetVectorState = new OffsetVectorState((((AbstractArrayWriter) writer.dict()).offsetWriter()), offsetVector, writer.dict().entry().events());
}
final VectorState mapVectorState = new TupleState.SingleDictVectorState(dictVector, offsetVectorState);
// Assemble it all into the column state.
final SingleDictState dictArrayState = new SingleDictState(parent.loader(), parent.vectorCache().childCache(columnSchema.name()), projResult.mapFilter);
return new TupleState.DictColumnState(dictArrayState, writer, mapVectorState, parent.isVersioned());
}
use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult in project drill by apache.
the class TestProjectionFilter method testProjectList.
@Test
public void testProjectList() {
RequestedTuple projSet = Projections.parse(RowSetTestUtils.projectList("a", "c", "m.a"));
ProjectionFilter filter = new DirectProjectionFilter(projSet, EmptyErrorContext.INSTANCE);
assertTrue(filter.isProjected("a"));
assertTrue(filter.projection(A_COL).isProjected);
assertFalse(filter.isProjected("b"));
assertFalse(filter.projection(B_COL).isProjected);
assertFalse(filter.isEmpty());
ProjResult result = filter.projection(MAP_COL);
assertTrue(result.isProjected);
ProjectionFilter child = result.mapFilter;
assertTrue(child.isProjected("a"));
assertFalse(child.isProjected("b"));
result = filter.projection(MAP_COL2);
assertFalse(result.isProjected);
assertSame(ProjectionFilter.PROJECT_NONE, result.mapFilter);
}
use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult in project drill by apache.
the class TestProjectionFilter method testImplicitAll.
@Test
public void testImplicitAll() {
ProjectionFilter filter = ProjectionFilter.PROJECT_ALL;
assertTrue(filter.isProjected("a"));
assertTrue(filter.projection(A_COL).isProjected);
ColumnMetadata specialCol = MetadataUtils.newScalar("special", Types.optional(MinorType.BIGINT));
specialCol.setBooleanProperty(ColumnMetadata.EXCLUDE_FROM_WILDCARD, true);
assertFalse(filter.projection(specialCol).isProjected);
assertFalse(filter.isEmpty());
ProjResult result = filter.projection(MAP_COL);
assertTrue(result.isProjected);
assertSame(ProjectionFilter.PROJECT_ALL, result.mapFilter);
}
use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult in project drill by apache.
the class TestProjectionFilter method testTypeFilter.
@Test
public void testTypeFilter() {
TupleMetadata schema = new SchemaBuilder().add(A_COL.copy()).add(B_COL.copy()).addMap("m").add("a", MinorType.INT).resumeSchema().build();
ProjectionFilter filter = new TypeProjectionFilter(schema, EmptyErrorContext.INSTANCE);
assertFalse(filter.isEmpty());
assertTrue(filter.isProjected("a"));
assertTrue(filter.projection(A_COL).isProjected);
assertTrue(filter.isProjected("b"));
assertTrue(filter.projection(B_COL).isProjected);
assertTrue(filter.isProjected("c"));
assertTrue(filter.projection(MetadataUtils.newScalar("c", Types.required(MinorType.BIGINT))).isProjected);
ColumnMetadata typeConflict = MetadataUtils.newScalar("a", Types.required(MinorType.BIGINT));
try {
filter.projection(typeConflict);
fail();
} catch (UserException e) {
assertTrue(e.getMessage().contains("conflict"));
}
ColumnMetadata modeConflict = MetadataUtils.newScalar("a", Types.optional(MinorType.INT));
try {
filter.projection(modeConflict);
fail();
} catch (UserException e) {
assertTrue(e.getMessage().contains("conflict"));
}
ProjResult result = filter.projection(MAP_COL);
assertTrue(result.isProjected);
ProjectionFilter child = result.mapFilter;
assertTrue(child.isProjected("a"));
assertTrue(child.isProjected("b"));
result = filter.projection(MAP_COL2);
assertTrue(result.isProjected);
assertSame(ProjectionFilter.PROJECT_ALL, result.mapFilter);
try {
ColumnMetadata aMap = MetadataUtils.newMap("a", new TupleSchema());
filter.projection(aMap);
fail();
} catch (UserException e) {
assertTrue(e.getMessage().contains("type conflict"));
}
}
use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult in project drill by apache.
the class TestProjectionFilter method testEmptyProjectList.
@Test
public void testEmptyProjectList() {
ProjectionFilter filter = new DirectProjectionFilter(Projections.projectNone(), EmptyErrorContext.INSTANCE);
assertFalse(filter.isProjected("a"));
assertFalse(filter.projection(A_COL).isProjected);
assertTrue(filter.isEmpty());
ProjResult result = filter.projection(MAP_COL);
assertFalse(result.isProjected);
assertSame(ProjectionFilter.PROJECT_NONE, result.mapFilter);
}
Aggregations