Search in sources :

Example 91 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.

the class TestFileScanLifecycle method testPartitionColumnTwoDigits.

/**
 * Test the obscure case that the partition column contains two digits:
 * dir11. Also tests the obscure case that the output only has partition
 * columns.
 */
@Test
public void testPartitionColumnTwoDigits() {
    Path filePath = new Path("file:/w/0/1/2/3/4/5/6/7/8/9/10/d11/z.csv");
    FileScanLifecycleBuilder builder = new FileScanLifecycleBuilder();
    builder.rootDir(MOCK_ROOT_PATH);
    builder.maxPartitionDepth(11);
    builder.projection(RowSetTestUtils.projectList("a", "b", FileScanUtils.partitionColName(11)));
    builder.fileSplits(Collections.singletonList(new DummyFileWork(filePath)));
    builder.useLegacyWildcardExpansion(true);
    builder.readerFactory(new FileReaderFactory() {

        @Override
        public ManagedReader newReader(FileSchemaNegotiator negotiator) {
            return new MockEarlySchemaReader(negotiator, 1);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    assertTrue(reader.next());
    TupleMetadata expectedSchema = new SchemaBuilder().addAll(SCHEMA).add(FileScanUtils.partitionColName(11), PARTITION_COL_TYPE).build();
    RowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(10, "fred", "d11").addRow(20, "wilma", "d11").build();
    RowSetUtilities.verify(expected, fixture.wrap(reader.output()));
    assertFalse(reader.next());
    reader.close();
    scan.close();
}
Also used : SchemaPath(org.apache.drill.common.expression.SchemaPath) Path(org.apache.hadoop.fs.Path) RowBatchReader(org.apache.drill.exec.physical.impl.scan.RowBatchReader) ManagedReader(org.apache.drill.exec.physical.impl.scan.v3.ManagedReader) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) DummyFileWork(org.apache.drill.exec.physical.impl.scan.v3.file.BaseFileScanTest.DummyFileWork) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) ScanLifecycle(org.apache.drill.exec.physical.impl.scan.v3.lifecycle.ScanLifecycle) BaseTestScanLifecycle(org.apache.drill.exec.physical.impl.scan.v3.lifecycle.BaseTestScanLifecycle) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 92 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.

the class TestFileScanLifecycle method testAllColumns.

@Test
public void testAllColumns() {
    FileScanLifecycleBuilder builder = new FileScanLifecycleBuilder();
    builder.rootDir(MOCK_ROOT_PATH);
    builder.maxPartitionDepth(3);
    builder.projection(FileScanUtils.projectAllWithMetadata(3));
    builder.fileSplits(Collections.singletonList(new DummyFileWork(MOCK_FILE_PATH)));
    builder.useLegacyWildcardExpansion(true);
    builder.readerFactory(new FileReaderFactory() {

        @Override
        public ManagedReader newReader(FileSchemaNegotiator negotiator) {
            return new MockEarlySchemaReader(negotiator, 1);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    assertSame(ProjectionType.ALL, scan.schemaTracker().projectionType());
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    assertTrue(reader.next());
    TupleMetadata expectedSchema = new SchemaBuilder().addAll(SCHEMA).add(FileScanUtils.FULLY_QUALIFIED_NAME_COL, IMPLICIT_COL_TYPE).add(FileScanUtils.FILE_PATH_COL, IMPLICIT_COL_TYPE).add(FileScanUtils.FILE_NAME_COL, IMPLICIT_COL_TYPE).add(FileScanUtils.SUFFIX_COL, IMPLICIT_COL_TYPE).add(FileScanUtils.partitionColName(0), PARTITION_COL_TYPE).add(FileScanUtils.partitionColName(1), PARTITION_COL_TYPE).add(FileScanUtils.partitionColName(2), PARTITION_COL_TYPE).build();
    RowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(10, "fred", MOCK_FILE_FQN, MOCK_FILE_DIR_PATH, MOCK_FILE_NAME, MOCK_SUFFIX, MOCK_DIR0, MOCK_DIR1, null).addRow(20, "wilma", MOCK_FILE_FQN, MOCK_FILE_DIR_PATH, MOCK_FILE_NAME, MOCK_SUFFIX, MOCK_DIR0, MOCK_DIR1, null).build();
    RowSetUtilities.verify(expected, fixture.wrap(reader.output()));
    assertFalse(reader.next());
    reader.close();
    scan.close();
}
Also used : RowBatchReader(org.apache.drill.exec.physical.impl.scan.RowBatchReader) DummyFileWork(org.apache.drill.exec.physical.impl.scan.v3.file.BaseFileScanTest.DummyFileWork) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) ManagedReader(org.apache.drill.exec.physical.impl.scan.v3.ManagedReader) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) ScanLifecycle(org.apache.drill.exec.physical.impl.scan.v3.lifecycle.ScanLifecycle) BaseTestScanLifecycle(org.apache.drill.exec.physical.impl.scan.v3.lifecycle.BaseTestScanLifecycle) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 93 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.

the class TestCsvWithSchema method testRequiredColDefault.

/**
 * Use a user-provided default value for a missing required column.
 */
@Test
public void testRequiredColDefault() throws Exception {
    String tableName = "missingReq";
    String tablePath = buildTable(tableName, multi3Contents);
    try {
        enableSchemaSupport();
        String schemaSql = SCHEMA_SQL.replace("id int not null", "id int not null default '-1'");
        run(schemaSql, tablePath);
        String sql = "SELECT id, `name`, `date` FROM " + tablePath;
        RowSet actual = client.queryBuilder().sql(sql).rowSet();
        TupleMetadata expectedSchema = new SchemaBuilder().add("id", MinorType.INT).add("name", MinorType.VARCHAR).addNullable("date", MinorType.DATE).buildSchema();
        RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(-1, "dino", LocalDate.of(2018, 9, 1)).build();
        RowSetUtilities.verify(expected, actual);
    } finally {
        resetSchemaSupport();
    }
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 94 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.

the class TestCsvWithSchema method testMissingRequiredCol.

/**
 * Show that the projection framework generates a reasonable default value
 * if told to create a required column that does not exist. In this case,
 * the default default [sic] value for an INT column is 0. There is no
 * "default" value set in the schema, so we use a "default default" instead.)
 */
@Test
public void testMissingRequiredCol() throws Exception {
    String tableName = "missingReq";
    String tablePath = buildTable(tableName, multi3Contents);
    try {
        enableSchemaSupport();
        run(SCHEMA_SQL, tablePath);
        String sql = "SELECT id, `name` FROM " + tablePath;
        RowSet actual = client.queryBuilder().sql(sql).rowSet();
        TupleMetadata expectedSchema = new SchemaBuilder().add("id", MinorType.INT).add("name", MinorType.VARCHAR).buildSchema();
        RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(0, "dino").build();
        RowSetUtilities.verify(expected, actual);
    } finally {
        resetSchemaSupport();
    }
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 95 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.

the class TestCsvWithSchema method testWildcardStrictSchema.

/**
 * Test wildcard projection with a strict schema: only schema columns are
 * projected.
 */
@Test
public void testWildcardStrictSchema() throws Exception {
    String tableName = "wildcardStrict";
    String tablePath = buildTable(tableName, multi1Contents, reordered2Contents, nameOnlyContents);
    try {
        enableSchemaSupport();
        String sql = SCHEMA_SQL + " PROPERTIES ('" + TupleMetadata.IS_STRICT_SCHEMA_PROP + "'='true')";
        run(sql, tablePath);
        sql = "SELECT * FROM " + tablePath + "ORDER BY id";
        RowSet actual = client.queryBuilder().sql(sql).rowSet();
        TupleMetadata expectedSchema = new SchemaBuilder().add("id", MinorType.INT).addNullable("date", MinorType.DATE).add("gender", MinorType.VARCHAR).add("comment", MinorType.VARCHAR).buildSchema();
        RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(0, null, "NA", "ABC").addRow(1, LocalDate.of(2019, 1, 18), "female", "ABC").addRow(2, LocalDate.of(2019, 1, 19), "male", "ABC").addRow(3, LocalDate.of(2001, 1, 16), "NA", "ABC").addRow(4, LocalDate.of(2019, 5, 4), "NA", "ABC").build();
        RowSetUtilities.verify(expected, actual);
    } finally {
        resetSchemaSupport();
    }
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Aggregations

RowSet (org.apache.drill.exec.physical.rowSet.RowSet)725 Test (org.junit.Test)690 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)583 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)574 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)297 ClusterTest (org.apache.drill.test.ClusterTest)253 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)233 DirectRowSet (org.apache.drill.exec.physical.rowSet.DirectRowSet)137 SubOperatorTest (org.apache.drill.test.SubOperatorTest)128 JsonTest (org.apache.drill.categories.JsonTest)112 EvfTest (org.apache.drill.categories.EvfTest)107 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)97 RowSetLoader (org.apache.drill.exec.physical.resultSet.RowSetLoader)63 ResultSetLoader (org.apache.drill.exec.physical.resultSet.ResultSetLoader)61 QueryBuilder (org.apache.drill.test.QueryBuilder)61 MockRecordBatch (org.apache.drill.exec.physical.impl.MockRecordBatch)60 OperatorTest (org.apache.drill.categories.OperatorTest)53 VectorContainer (org.apache.drill.exec.record.VectorContainer)31 RowBatchReader (org.apache.drill.exec.physical.impl.scan.RowBatchReader)28 QuerySummary (org.apache.drill.test.QueryBuilder.QuerySummary)27