Search in sources :

Example 1 with ColumnsArrayParser

use of org.apache.drill.exec.physical.impl.scan.columns.ColumnsArrayParser in project drill by apache.

the class TestColumnsArrayParser method testColumnsElements.

@Test
public void testColumnsElements() {
    ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList(ColumnsScanFramework.COLUMNS_COL + "[3]", ColumnsScanFramework.COLUMNS_COL + "[1]"), ScanTestUtils.parsers(new ColumnsArrayParser(true)));
    assertFalse(scanProj.projectAll());
    assertEquals(2, scanProj.requestedCols().size());
    assertEquals(1, scanProj.columns().size());
    assertEquals(ColumnsScanFramework.COLUMNS_COL, scanProj.columns().get(0).name());
    // Verify column type
    assertTrue(scanProj.columns().get(0) instanceof UnresolvedColumnsArrayColumn);
    UnresolvedColumnsArrayColumn colsCol = (UnresolvedColumnsArrayColumn) scanProj.columns().get(0);
    boolean[] indexes = colsCol.selectedIndexes();
    assertNotNull(indexes);
    assertEquals(4, indexes.length);
    assertFalse(indexes[0]);
    assertTrue(indexes[1]);
    assertFalse(indexes[0]);
    assertTrue(indexes[1]);
}
Also used : UnresolvedColumnsArrayColumn(org.apache.drill.exec.physical.impl.scan.columns.UnresolvedColumnsArrayColumn) ScanLevelProjection(org.apache.drill.exec.physical.impl.scan.project.ScanLevelProjection) ColumnsArrayParser(org.apache.drill.exec.physical.impl.scan.columns.ColumnsArrayParser) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 2 with ColumnsArrayParser

use of org.apache.drill.exec.physical.impl.scan.columns.ColumnsArrayParser in project drill by apache.

the class TestColumnsArrayParser method testMetadataColumnsWithColumnsArray.

/**
 * The `columns` column is special: can't be used with other column names.
 * Make sure that the rule <i>does not</i> apply to implicit columns.
 */
@Test
public void testMetadataColumnsWithColumnsArray() {
    Path filePath = new Path("hdfs:///w/x/y/z.csv");
    ImplicitColumnManager metadataManager = new ImplicitColumnManager(fixture.getOptionManager(), standardOptions(filePath));
    ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList(ScanTestUtils.FILE_NAME_COL, ColumnsScanFramework.COLUMNS_COL, ScanTestUtils.SUFFIX_COL), ScanTestUtils.parsers(new ColumnsArrayParser(true), metadataManager.projectionParser()));
    assertFalse(scanProj.projectAll());
    assertEquals(3, scanProj.columns().size());
    assertEquals(ScanTestUtils.FILE_NAME_COL, scanProj.columns().get(0).name());
    assertEquals(ColumnsScanFramework.COLUMNS_COL, scanProj.columns().get(1).name());
    assertEquals(ScanTestUtils.SUFFIX_COL, scanProj.columns().get(2).name());
    // Verify column type
    assertTrue(scanProj.columns().get(0) instanceof FileMetadataColumn);
    assertTrue(scanProj.columns().get(1) instanceof UnresolvedColumnsArrayColumn);
    assertTrue(scanProj.columns().get(2) instanceof FileMetadataColumn);
}
Also used : SchemaPath(org.apache.drill.common.expression.SchemaPath) Path(org.apache.hadoop.fs.Path) ImplicitColumnManager(org.apache.drill.exec.physical.impl.scan.file.ImplicitColumnManager) UnresolvedColumnsArrayColumn(org.apache.drill.exec.physical.impl.scan.columns.UnresolvedColumnsArrayColumn) ScanLevelProjection(org.apache.drill.exec.physical.impl.scan.project.ScanLevelProjection) ColumnsArrayParser(org.apache.drill.exec.physical.impl.scan.columns.ColumnsArrayParser) FileMetadataColumn(org.apache.drill.exec.physical.impl.scan.file.FileMetadataColumn) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 3 with ColumnsArrayParser

use of org.apache.drill.exec.physical.impl.scan.columns.ColumnsArrayParser in project drill by apache.

the class TestColumnsArrayParser method testTwoColumnsArray.

/**
 * Requesting `columns` twice: second is ignored.
 */
@Test
public void testTwoColumnsArray() {
    ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList(ColumnsScanFramework.COLUMNS_COL, ColumnsScanFramework.COLUMNS_COL), ScanTestUtils.parsers(new ColumnsArrayParser(false)));
    assertFalse(scanProj.projectAll());
    assertEquals(2, scanProj.requestedCols().size());
    assertEquals(1, scanProj.columns().size());
    assertEquals(ColumnsScanFramework.COLUMNS_COL, scanProj.columns().get(0).name());
}
Also used : ScanLevelProjection(org.apache.drill.exec.physical.impl.scan.project.ScanLevelProjection) ColumnsArrayParser(org.apache.drill.exec.physical.impl.scan.columns.ColumnsArrayParser) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 4 with ColumnsArrayParser

use of org.apache.drill.exec.physical.impl.scan.columns.ColumnsArrayParser in project drill by apache.

the class TestColumnsArrayParser method testColumnsArray.

/**
 * Test the special "columns" column that asks to return all columns
 * as an array. No need for early schema. This case is special: it actually
 * creates the one and only table column to match the desired output column.
 */
@Test
public void testColumnsArray() {
    ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectList(ColumnsScanFramework.COLUMNS_COL), ScanTestUtils.parsers(new ColumnsArrayParser(true)));
    assertFalse(scanProj.projectAll());
    assertEquals(1, scanProj.requestedCols().size());
    assertEquals(1, scanProj.columns().size());
    assertEquals(ColumnsScanFramework.COLUMNS_COL, scanProj.columns().get(0).name());
    // Verify column type
    assertTrue(scanProj.columns().get(0) instanceof UnresolvedColumnsArrayColumn);
}
Also used : UnresolvedColumnsArrayColumn(org.apache.drill.exec.physical.impl.scan.columns.UnresolvedColumnsArrayColumn) ScanLevelProjection(org.apache.drill.exec.physical.impl.scan.project.ScanLevelProjection) ColumnsArrayParser(org.apache.drill.exec.physical.impl.scan.columns.ColumnsArrayParser) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 5 with ColumnsArrayParser

use of org.apache.drill.exec.physical.impl.scan.columns.ColumnsArrayParser in project drill by apache.

the class TestColumnsArrayParser method testRequiredWildcard.

@Test
public void testRequiredWildcard() {
    ScanLevelProjection scanProj = ScanLevelProjection.build(RowSetTestUtils.projectAll(), ScanTestUtils.parsers(new ColumnsArrayParser(true)));
    assertTrue(scanProj.projectAll());
    assertEquals(1, scanProj.requestedCols().size());
    assertEquals(1, scanProj.columns().size());
    assertEquals(ColumnsScanFramework.COLUMNS_COL, scanProj.columns().get(0).name());
    // Verify column type
    assertTrue(scanProj.columns().get(0) instanceof UnresolvedColumnsArrayColumn);
}
Also used : UnresolvedColumnsArrayColumn(org.apache.drill.exec.physical.impl.scan.columns.UnresolvedColumnsArrayColumn) ScanLevelProjection(org.apache.drill.exec.physical.impl.scan.project.ScanLevelProjection) ColumnsArrayParser(org.apache.drill.exec.physical.impl.scan.columns.ColumnsArrayParser) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

ColumnsArrayParser (org.apache.drill.exec.physical.impl.scan.columns.ColumnsArrayParser)8 ScanLevelProjection (org.apache.drill.exec.physical.impl.scan.project.ScanLevelProjection)8 SubOperatorTest (org.apache.drill.test.SubOperatorTest)8 Test (org.junit.Test)8 UnresolvedColumnsArrayColumn (org.apache.drill.exec.physical.impl.scan.columns.UnresolvedColumnsArrayColumn)7 SchemaPath (org.apache.drill.common.expression.SchemaPath)1 FileMetadataColumn (org.apache.drill.exec.physical.impl.scan.file.FileMetadataColumn)1 ImplicitColumnManager (org.apache.drill.exec.physical.impl.scan.file.ImplicitColumnManager)1 Path (org.apache.hadoop.fs.Path)1