Search in sources :

Example 6 with ProjectionFilter

use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.

the class TestScanLevelProjection method testStrictProvidedSchemaWildcard.

/**
 * Wildcard projection with a strict schema is the same as a non-strict
 * schema, except that the projection type is different.
 */
@Test
public void testStrictProvidedSchemaWildcard() {
    TupleMetadata providedSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.BIGINT).buildSchema();
    providedSchema.setProperty(TupleMetadata.IS_STRICT_SCHEMA_PROP, Boolean.TRUE.toString());
    final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectAll(), ScanTestUtils.parsers(), providedSchema);
    assertEquals(ScanProjectionType.STRICT_SCHEMA_WILDCARD, scanProj.projectionType());
    assertEquals(2, scanProj.columns().size());
    assertEquals("a", scanProj.columns().get(0).name());
    assertTrue(scanProj.columns().get(0) instanceof UnresolvedColumn);
    assertEquals("b", scanProj.columns().get(1).name());
    assertTrue(scanProj.columns().get(1) instanceof UnresolvedColumn);
    // Make up a reader schema and test the projection set.
    TupleMetadata readerSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.BIGINT).add("c", MinorType.INT).buildSchema();
    ProjectionFilter projSet = scanProj.readerProjection();
    assertTrue(isProjected(projSet, readerSchema.metadata("a")));
    assertTrue(isProjected(projSet, readerSchema.metadata("b")));
    assertFalse(isProjected(projSet, readerSchema.metadata("c")));
}
Also used : ProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter) UnresolvedColumn(org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 7 with ProjectionFilter

use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.

the class TestScanLevelProjection method testWildcardAndColumns.

/**
 * Can include both a wildcard and a column name. The Project
 * operator will fill in the column, the scan framework just ignores
 * the extra column.
 */
@Test
public void testWildcardAndColumns() {
    ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList(SchemaPath.DYNAMIC_STAR, "a"), ScanTestUtils.parsers());
    assertTrue(scanProj.projectAll());
    assertFalse(scanProj.isEmptyProjection());
    assertEquals(2, scanProj.requestedCols().size());
    assertEquals(1, scanProj.columns().size());
    // Verify tuple projection
    RequestedTuple outputProj = scanProj.rootProjection();
    assertEquals(2, outputProj.projections().size());
    assertNotNull(outputProj.get(SchemaPath.DYNAMIC_STAR));
    assertTrue(outputProj.get(SchemaPath.DYNAMIC_STAR).isWildcard());
    assertNotNull(outputProj.get("a"));
    // Make up a reader schema and test the projection set.
    TupleMetadata readerSchema = new SchemaBuilder().add("a", MinorType.INT).add("c", MinorType.INT).buildSchema();
    ProjectionFilter projSet = scanProj.readerProjection();
    assertTrue(isProjected(projSet, readerSchema.metadata("a")));
    assertTrue(isProjected(projSet, readerSchema.metadata("c")));
}
Also used : ProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter) RequestedTuple(org.apache.drill.exec.physical.resultSet.project.RequestedTuple) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 8 with ProjectionFilter

use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.

the class TestScanLevelProjection method testMap.

/**
 * Map projection occurs when a query contains project-list items with
 * a dot, such as "a.b". We may not know the type of "b", but have
 * just learned that "a" must be a map.
 */
@Test
public void testMap() {
    // SELECT a.x, b.x, a.y, b.y, c
    // We infer a and b are maps.
    final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList("a.x", "b.x", "a.y", "b.y", "c"), ScanTestUtils.parsers());
    assertFalse(scanProj.projectAll());
    assertFalse(scanProj.isEmptyProjection());
    assertEquals(3, scanProj.columns().size());
    assertEquals("a", scanProj.columns().get(0).name());
    assertEquals("b", scanProj.columns().get(1).name());
    assertEquals("c", scanProj.columns().get(2).name());
    // Verify column type
    assertTrue(scanProj.columns().get(0) instanceof UnresolvedColumn);
    // Inferred map structure
    final RequestedColumn a = ((UnresolvedColumn) scanProj.columns().get(0)).element();
    assertTrue(a.isTuple());
    assertTrue(a.tuple().isProjected("x"));
    assertTrue(a.tuple().isProjected("y"));
    assertFalse(a.tuple().isProjected("z"));
    final RequestedColumn c = ((UnresolvedColumn) scanProj.columns().get(2)).element();
    assertTrue(c.isSimple());
    // Verify tuple projection
    RequestedTuple outputProj = scanProj.rootProjection();
    assertEquals(3, outputProj.projections().size());
    assertNotNull(outputProj.get("a"));
    assertTrue(outputProj.get("a").isTuple());
    // Make up a reader schema and test the projection set.
    TupleMetadata readerSchema = new SchemaBuilder().addMap("a").add("x", MinorType.INT).add("y", MinorType.INT).resumeSchema().addMap("b").add("x", MinorType.INT).add("y", MinorType.INT).resumeSchema().add("c", MinorType.INT).add("d", MinorType.INT).buildSchema();
    // Verify the projection set as if we were a reader. Note that the
    // projection type is used here for testing; should not be used by
    // an actual reader.
    ProjectionFilter projSet = scanProj.readerProjection();
    assertTrue(isProjected(projSet, readerSchema.metadata("a")));
    assertTrue(isProjected(projSet, readerSchema.metadata("c")));
    assertFalse(isProjected(projSet, readerSchema.metadata("d")));
}
Also used : ProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter) UnresolvedColumn(org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn) RequestedTuple(org.apache.drill.exec.physical.resultSet.project.RequestedTuple) RequestedColumn(org.apache.drill.exec.physical.resultSet.project.RequestedColumn) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 9 with ProjectionFilter

use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.

the class TestScanLevelProjection method testProvidedSchemaWildcard.

@Test
public void testProvidedSchemaWildcard() {
    TupleMetadata providedSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.BIGINT).buildSchema();
    final ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectAll(), ScanTestUtils.parsers(), providedSchema);
    assertEquals(ScanProjectionType.SCHEMA_WILDCARD, scanProj.projectionType());
    assertEquals(2, scanProj.columns().size());
    ColumnProjection aCol = scanProj.columns().get(0);
    assertEquals("a", aCol.name());
    assertTrue(aCol instanceof UnresolvedColumn);
    assertSame(providedSchema.metadata("a"), ((UnresolvedColumn) aCol).metadata());
    ColumnProjection bCol = scanProj.columns().get(1);
    assertEquals("b", bCol.name());
    assertTrue(bCol instanceof UnresolvedColumn);
    assertSame(providedSchema.metadata("b"), ((UnresolvedColumn) bCol).metadata());
    ProjectionFilter projSet = scanProj.readerProjection();
    assertTrue(isProjected(projSet, providedSchema.metadata("a")));
    assertTrue(isProjected(projSet, providedSchema.metadata("b")));
}
Also used : ProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter) UnresolvedColumn(org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 10 with ProjectionFilter

use of org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter in project drill by apache.

the class TestSchemaTrackerDefined method testDynamicDefinedSchema.

/**
 * If a schema is defined, then the planner has combined the projection
 * list with schema information to produce the final output schema
 * at plan time. The planner might leave some columns as dynamic type:
 * the schema (like projection) says which columns are wanted. But, like
 * a full dynamic schema, the types may not be known.
 */
@Test
public void testDynamicDefinedSchema() {
    // Simulate SELECT a, b, c ...
    // With a plan-provided defined schema
    final ScanSchemaConfigBuilder builder = new ScanSchemaConfigBuilder().projection(RowSetTestUtils.projectList("a", "b", "c"));
    final TupleMetadata definedSchema = new SchemaBuilder().addDynamic("a").add("b", MinorType.BIGINT).add("c", MinorType.VARCHAR).buildSchema();
    builder.definedSchema(definedSchema);
    final ScanSchemaTracker schemaTracker = builder.build();
    assertTrue(schemaTracker instanceof ProjectionSchemaTracker);
    assertSame(ProjectionType.SOME, schemaTracker.projectionType());
    assertFalse(schemaTracker.isResolved());
    // Reader input schema is partially defined
    final TupleMetadata reader1InputSchema = schemaTracker.readerInputSchema();
    assertEquals(definedSchema, reader1InputSchema);
    ProjectionFilter filter = schemaTracker.projectionFilter(ERROR_CONTEXT);
    assertTrue(filter instanceof DynamicSchemaFilter);
    // Pretend the reader dutifully provided two of the columns
    TupleMetadata readerOutputSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.BIGINT).buildSchema();
    schemaTracker.applyReaderSchema(readerOutputSchema, ERROR_CONTEXT);
    // Reader schema is now fully resolved
    assertTrue(schemaTracker.isResolved());
    final TupleMetadata reader2InputSchema = schemaTracker.readerInputSchema();
    TupleMetadata expected = new SchemaBuilder().addAll(readerOutputSchema).add("c", MinorType.VARCHAR).build();
    assertEquals(expected, reader2InputSchema);
    // Pretend an class fills in the the missing columns
    TupleMetadata missingColSchema = new SchemaBuilder().add("c", MinorType.VARCHAR).buildSchema();
    schemaTracker.applyReaderSchema(missingColSchema, ERROR_CONTEXT);
    // Final schema sent downstream
    final TupleMetadata outputSchema = schemaTracker.outputSchema();
    assertEquals(expected, outputSchema);
}
Also used : ProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) BaseTest(org.apache.drill.test.BaseTest) EvfTest(org.apache.drill.categories.EvfTest)

Aggregations

ProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter)42 EvfTest (org.apache.drill.categories.EvfTest)36 Test (org.junit.Test)36 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)35 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)33 BaseTest (org.apache.drill.test.BaseTest)24 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)13 SubOperatorTest (org.apache.drill.test.SubOperatorTest)12 ProjResult (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult)7 RequestedTuple (org.apache.drill.exec.physical.resultSet.project.RequestedTuple)6 UnresolvedColumn (org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn)5 UserException (org.apache.drill.common.exceptions.UserException)3 DynamicTupleFilter (org.apache.drill.exec.physical.impl.scan.v3.schema.DynamicSchemaFilter.DynamicTupleFilter)3 ProjectionParseResult (org.apache.drill.exec.physical.impl.scan.v3.schema.ScanProjectionParser.ProjectionParseResult)2 RequestedColumn (org.apache.drill.exec.physical.resultSet.project.RequestedColumn)2 UnresolvedWildcardColumn (org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedWildcardColumn)1