Search in sources :

Example 16 with SchemaBuilder

use of org.apache.drill.exec.record.metadata.SchemaBuilder in project drill by apache.

the class TestScanOrchestratorLateSchema method testLateSchemaSelectDisjoint.

/**
 * Test SELECT a, c FROM table(a, b)
 */
@Test
public void testLateSchemaSelectDisjoint() {
    ScanOrchestratorBuilder builder = new MockScanBuilder();
    // SELECT a, c ...
    builder.projection(RowSetTestUtils.projectList("a", "c"));
    ScanSchemaOrchestrator orchestrator = new ScanSchemaOrchestrator(fixture.allocator(), builder);
    // ... FROM file
    ReaderSchemaOrchestrator reader = orchestrator.startReader();
    // Create the table loader
    ResultSetLoader loader = reader.makeTableLoader(null);
    // file schema (a, b)
    reader.startBatch();
    RowSetLoader writer = loader.writer();
    writer.addColumn(SchemaBuilder.columnSchema("a", MinorType.INT, DataMode.REQUIRED));
    writer.addColumn(SchemaBuilder.columnSchema("b", MinorType.VARCHAR, DataMode.REQUIRED));
    // Create a batch of data.
    writer.addRow(1, "fred").addRow(2, "wilma");
    reader.endBatch();
    // Verify
    TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).addNullable("c", MinorType.INT).buildSchema();
    SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(1, null).addRow(2, null).build();
    new RowSetComparison(expected).verifyAndClearAll(fixture.wrap(orchestrator.output()));
    orchestrator.close();
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) ResultSetLoader(org.apache.drill.exec.physical.resultSet.ResultSetLoader) ScanOrchestratorBuilder(org.apache.drill.exec.physical.impl.scan.project.ScanSchemaOrchestrator.ScanOrchestratorBuilder) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) MockScanBuilder(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.MockScanBuilder) RowSetLoader(org.apache.drill.exec.physical.resultSet.RowSetLoader) ScanSchemaOrchestrator(org.apache.drill.exec.physical.impl.scan.project.ScanSchemaOrchestrator) ReaderSchemaOrchestrator(org.apache.drill.exec.physical.impl.scan.project.ReaderSchemaOrchestrator) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 17 with SchemaBuilder

use of org.apache.drill.exec.record.metadata.SchemaBuilder in project drill by apache.

the class TestScanOrchestratorLateSchema method testLateSchemaWildcard.

/**
 * Test SELECT * from an early-schema table of (a, b)
 */
@Test
public void testLateSchemaWildcard() {
    ScanOrchestratorBuilder builder = new MockScanBuilder();
    // SELECT * ...
    builder.projection(RowSetTestUtils.projectAll());
    ScanSchemaOrchestrator orchestrator = new ScanSchemaOrchestrator(fixture.allocator(), builder);
    // ... FROM table
    ReaderSchemaOrchestrator reader = orchestrator.startReader();
    // Create the table loader
    ResultSetLoader loader = reader.makeTableLoader(null);
    // Late schema: no batch provided up front.
    assertFalse(reader.hasSchema());
    // Start a batch and discover a schema: (a, b)
    reader.startBatch();
    RowSetLoader writer = loader.writer();
    writer.addColumn(SchemaBuilder.columnSchema("a", MinorType.INT, DataMode.REQUIRED));
    writer.addColumn(SchemaBuilder.columnSchema("b", MinorType.VARCHAR, DataMode.REQUIRED));
    // Create a batch of data using the discovered schema
    writer.addRow(1, "fred").addRow(2, "wilma");
    reader.endBatch();
    // Verify
    TupleMetadata tableSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).buildSchema();
    SingleRowSet expected = fixture.rowSetBuilder(tableSchema).addRow(1, "fred").addRow(2, "wilma").build();
    new RowSetComparison(expected).verifyAndClearAll(fixture.wrap(orchestrator.output()));
    orchestrator.close();
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) ResultSetLoader(org.apache.drill.exec.physical.resultSet.ResultSetLoader) ScanOrchestratorBuilder(org.apache.drill.exec.physical.impl.scan.project.ScanSchemaOrchestrator.ScanOrchestratorBuilder) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) MockScanBuilder(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.MockScanBuilder) RowSetLoader(org.apache.drill.exec.physical.resultSet.RowSetLoader) ScanSchemaOrchestrator(org.apache.drill.exec.physical.impl.scan.project.ScanSchemaOrchestrator) ReaderSchemaOrchestrator(org.apache.drill.exec.physical.impl.scan.project.ReaderSchemaOrchestrator) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 18 with SchemaBuilder

use of org.apache.drill.exec.record.metadata.SchemaBuilder in project drill by apache.

the class TestDirectConverter method testStringToDateTimeDefault.

/**
 * Test VARCHAR to DATE, TIME and TIMESTAMP conversion
 * using default ISO formats.
 */
@Test
public void testStringToDateTimeDefault() {
    TupleMetadata outputSchema = new SchemaBuilder().add("date", MinorType.DATE).add("time", MinorType.TIME).add("ts", MinorType.TIMESTAMP).buildSchema();
    TupleMetadata inputSchema = new SchemaBuilder().add("date", MinorType.VARCHAR).add("time", MinorType.VARCHAR).add("ts", MinorType.VARCHAR).buildSchema();
    ConversionTestFixture testFixture = new ConversionTestFixture(fixture.allocator(), outputSchema);
    testFixture.createConvertersFor(inputSchema);
    RowSet actual = testFixture.addRow("2019-03-28", "12:34:56", "2019-03-28T12:34:56").build();
    LocalTime lt = LocalTime.of(12, 34, 56);
    LocalDate ld = LocalDate.of(2019, 3, 28);
    Instant ts = LocalDateTime.of(ld, lt).toInstant(ZoneOffset.UTC);
    final SingleRowSet expected = fixture.rowSetBuilder(outputSchema).addRow(ld, lt, ts).build();
    RowSetUtilities.verify(expected, actual);
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) LocalTime(java.time.LocalTime) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) Instant(java.time.Instant) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) LocalDate(java.time.LocalDate) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 19 with SchemaBuilder

use of org.apache.drill.exec.record.metadata.SchemaBuilder in project drill by apache.

the class TestDirectConverter method testSpecialConversionType.

/**
 * Test the specialized types: conversation to/from string.
 */
@Test
public void testSpecialConversionType() {
    StandardConversions conversions = StandardConversions.builder().build();
    TupleMetadata schema = new SchemaBuilder().add("time", MinorType.TIME).add("date", MinorType.DATE).add("ts", MinorType.TIMESTAMP).add("interval", MinorType.INTERVAL).add("year", MinorType.INTERVALYEAR).add("day", MinorType.INTERVALDAY).add("int", MinorType.INT).add("bi", MinorType.BIGINT).add("str", MinorType.VARCHAR).buildSchema();
    ColumnMetadata timeCol = schema.metadata("time");
    ColumnMetadata dateCol = schema.metadata("date");
    ColumnMetadata tsCol = schema.metadata("ts");
    ColumnMetadata intervalCol = schema.metadata("interval");
    ColumnMetadata yearCol = schema.metadata("year");
    ColumnMetadata dayCol = schema.metadata("day");
    ColumnMetadata intCol = schema.metadata("int");
    ColumnMetadata bigIntCol = schema.metadata("bi");
    ColumnMetadata stringCol = schema.metadata("str");
    // TIME
    expect(ConversionType.NONE, conversions.analyze(timeCol, timeCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(timeCol, stringCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, timeCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(intCol, timeCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(timeCol, intCol));
    // DATE
    expect(ConversionType.NONE, conversions.analyze(dateCol, dateCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(dateCol, stringCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, dateCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(bigIntCol, dateCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(dateCol, bigIntCol));
    // TIMESTAMP
    expect(ConversionType.NONE, conversions.analyze(tsCol, tsCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(tsCol, stringCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, tsCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(bigIntCol, tsCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(tsCol, bigIntCol));
    // INTERVAL
    expect(ConversionType.NONE, conversions.analyze(intervalCol, intervalCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(intervalCol, stringCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, intervalCol));
    // INTERVALYEAR
    expect(ConversionType.NONE, conversions.analyze(yearCol, yearCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(yearCol, stringCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, yearCol));
    // INTERVALDAY
    expect(ConversionType.NONE, conversions.analyze(dayCol, dayCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(dayCol, stringCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, dayCol));
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) 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)

Example 20 with SchemaBuilder

use of org.apache.drill.exec.record.metadata.SchemaBuilder in project drill by apache.

the class TestDirectConverter method testImplicitConversionIntTruncation.

/**
 * The column accessors provide only int setters. For performance, the int value is
 * assumed to be of the correct range for the target column. If not, truncation of
 * the highest bytes occurs.
 * <p>
 * The assumption is, if the reader or other code expects that overflow might
 * occur, that code should be implemented in the client (or in a type conversion
 * shim), leaving the normal code path to optimize for the 99% of the cases where
 * the value is in the proper range.
 */
@Test
public void testImplicitConversionIntTruncation() {
    TupleMetadata schema = new SchemaBuilder().add("ti", MinorType.TINYINT).add("si", MinorType.SMALLINT).buildSchema();
    // Test allowed implicit conversions.
    RowSet actual = new RowSetBuilder(fixture.allocator(), schema).addRow(Byte.MAX_VALUE + 1, Short.MAX_VALUE + 1).addRow(Byte.MAX_VALUE + 2, Short.MAX_VALUE + 2).build();
    // Build the expected vector without a type converter.
    final SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(Byte.MIN_VALUE, Short.MIN_VALUE).addRow(Byte.MIN_VALUE + 1, Short.MIN_VALUE + 1).build();
    RowSetUtilities.verify(expected, actual);
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)1095 Test (org.junit.Test)1020 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)1008 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)588 SubOperatorTest (org.apache.drill.test.SubOperatorTest)407 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)288 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)263 ClusterTest (org.apache.drill.test.ClusterTest)245 EvfTest (org.apache.drill.categories.EvfTest)203 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)188 JsonTest (org.apache.drill.categories.JsonTest)110 ResultSetLoader (org.apache.drill.exec.physical.resultSet.ResultSetLoader)108 DirectRowSet (org.apache.drill.exec.physical.rowSet.DirectRowSet)108 RowSetLoader (org.apache.drill.exec.physical.resultSet.RowSetLoader)85 BatchSchemaBuilder (org.apache.drill.exec.record.BatchSchemaBuilder)83 ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)68 UserException (org.apache.drill.common.exceptions.UserException)62 BatchSchema (org.apache.drill.exec.record.BatchSchema)62 VectorContainer (org.apache.drill.exec.record.VectorContainer)58 BaseTest (org.apache.drill.test.BaseTest)57