use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult in project drill by apache.
the class TestProjectionFilter method testSchemaFilter.
@Test
public void testSchemaFilter() {
TupleMetadata schema = new SchemaBuilder().add(A_COL.copy()).add(B_COL.copy()).addMap("m").add("a", MinorType.INT).resumeSchema().build();
ProjectionFilter filter = new SchemaProjectionFilter(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);
assertFalse(filter.isProjected("c"));
assertFalse(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"));
}
try {
ColumnMetadata aMap = MetadataUtils.newMap("a", new TupleSchema());
filter.projection(aMap);
fail();
} catch (UserException e) {
assertTrue(e.getMessage().contains("type conflict"));
}
ProjResult result = filter.projection(MAP_COL);
assertTrue(result.isProjected);
ProjectionFilter child = result.mapFilter;
assertTrue(child.isProjected("a"));
assertFalse(child.isProjected("b"));
}
use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult in project drill by apache.
the class TestProjectionFilter method testCompoundFilterMixed2.
@Test
public void testCompoundFilterMixed2() {
ProjectionFilter filter = new CompoundProjectionFilter(ProjectionFilter.PROJECT_NONE, ProjectionFilter.PROJECT_ALL);
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);
}
use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult in project drill by apache.
the class TestProjectionFilter method testGenericMap.
@Test
public void testGenericMap() {
RequestedTuple projSet = Projections.parse(RowSetTestUtils.projectList("a", "m"));
ProjectionFilter filter = new DirectProjectionFilter(projSet, EmptyErrorContext.INSTANCE);
assertTrue(filter.isProjected("a"));
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 testCompoundPermissive.
@Test
public void testCompoundPermissive() {
ProjectionFilter filter = new CompoundProjectionFilter(ProjectionFilter.PROJECT_ALL, 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 ColumnBuilder method buildMapArray.
private ColumnState buildMapArray(ContainerState parent, ColumnMetadata columnSchema) {
final ProjectionFilter projFilter = parent.projection();
final ProjResult projResult = projFilter.projection(columnSchema);
// Create the map's offset vector.
final RepeatedMapVector mapVector;
final UInt4Vector offsetVector;
if (projResult.isProjected) {
// Creating the map 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 mapColSchema = columnSchema.cloneEmpty();
// vectors can be cached.
assert columnSchema.tupleSchema().isEmpty();
mapVector = new RepeatedMapVector(mapColSchema.schema(), parent.loader().allocator(), null);
offsetVector = mapVector.getOffsetVector();
} else {
mapVector = null;
offsetVector = null;
}
// Create the writer using the offset vector
final AbstractObjectWriter writer = MapWriter.buildMapArray(columnSchema, mapVector, new ArrayList<>());
// Wrap the offset vector in a vector state
VectorState offsetVectorState;
if (!projResult.isProjected) {
offsetVectorState = new NullVectorState();
} else {
offsetVectorState = new OffsetVectorState((((AbstractArrayWriter) writer.array()).offsetWriter()), offsetVector, writer.array().entry().events());
}
final VectorState mapVectorState = new MapVectorState(mapVector, offsetVectorState);
// Assemble it all into the column state.
final MapArrayState mapState = new MapArrayState(parent.loader(), parent.vectorCache().childCache(columnSchema.name()), projResult.mapFilter);
return new MapColumnState(mapState, writer, mapVectorState, parent.isVersioned());
}
Aggregations