Search in sources :

Example 1 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet 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 2 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet 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)

Example 3 with RowSet

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

the class TestDirectConverter method testImplicitConversion.

/**
 * Tests the implicit conversions provided by the column writer itself.
 * No conversion mechanism is needed in this case.
 */
@Test
public void testImplicitConversion() {
    TupleMetadata schema = new SchemaBuilder().add("ti", MinorType.TINYINT).add("si", MinorType.SMALLINT).add("int", MinorType.INT).add("bi", MinorType.BIGINT).add("fl", MinorType.FLOAT4).add("db", MinorType.FLOAT8).add("dec", MinorType.VARDECIMAL, 10, 0).buildSchema();
    // Test allowed implicit conversions.
    RowSet actual = new RowSetBuilder(fixture.allocator(), schema).addRow(11, 12, 13, 14, 15, 16, // int
    17).addRow(21L, 22L, 23L, 24L, 25L, 26L, // long
    27L).addRow(31F, 32F, 33F, 34F, 35F, 36F, // float
    37F).addRow(41D, 42D, 43D, 44D, 45D, 46D, // double
    47D).addRow(dec(51), dec(52), dec(53), dec(54), dec(55), dec(56), // decimal
    dec(57)).build();
    final SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(11, 12, 13, 14L, 15F, 16D, dec(17)).addRow(21, 22, 23, 24L, 25F, 26D, dec(27)).addRow(31, 32, 33, 34L, 35F, 36D, dec(37)).addRow(41, 42, 43, 44L, 45F, 46D, dec(47)).addRow(51, 52, 53, 54L, 55L, 56D, dec(57)).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)

Example 4 with RowSet

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

the class TestDirectConverter method testStringToInterval.

/**
 * Implicit conversion from String to period using default ISO
 * format.
 */
@Test
public void testStringToInterval() {
    TupleMetadata outputSchema = new SchemaBuilder().add("id", MinorType.INTERVALDAY).add("iy", MinorType.INTERVALYEAR).add("int", MinorType.INTERVAL).buildSchema();
    TupleMetadata inputSchema = new SchemaBuilder().add("id", MinorType.VARCHAR).add("iy", MinorType.VARCHAR).add("int", MinorType.VARCHAR).buildSchema();
    ConversionTestFixture testFixture = new ConversionTestFixture(fixture.allocator(), outputSchema);
    testFixture.createConvertersFor(inputSchema);
    RowSet actual = testFixture.addRow("P2DT3H4M5S", "P9Y8M", "P9Y8M2DT3H4M5S").build();
    Period p1 = Period.days(2).plusHours(3).plusMinutes(4).plusSeconds(5);
    Period p2 = Period.years(9).plusMonths(8);
    Period p3 = p1.plus(p2);
    final SingleRowSet expected = fixture.rowSetBuilder(outputSchema).addRow(p1, p2, p3).build();
    RowSetUtilities.verify(expected, actual);
}
Also used : 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) Period(org.joda.time.Period) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 5 with RowSet

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

the class TestDirectConverter method doTestBlanks.

private void doTestBlanks(DataMode mode, String frameworkOption, String colOption, Integer value) {
    TupleMetadata outputSchema = new SchemaBuilder().add("col", MinorType.INT, mode).buildSchema();
    ColumnMetadata colSchema = outputSchema.metadata("col");
    colSchema.setProperty(ColumnMetadata.DEFAULT_VALUE_PROP, "20");
    TupleMetadata inputSchema = new SchemaBuilder().addNullable("col", MinorType.VARCHAR).buildSchema();
    if (colOption != null) {
        colSchema = inputSchema.metadata("col");
        colSchema.setProperty(ColumnMetadata.BLANK_AS_PROP, colOption);
    }
    Map<String, String> props = null;
    if (frameworkOption != null) {
        props = new HashMap<>();
        props.put(ColumnMetadata.BLANK_AS_PROP, frameworkOption);
    }
    ConversionTestFixture testFixture = new ConversionTestFixture(fixture.allocator(), outputSchema);
    testFixture.withProperties(props);
    testFixture.createConvertersFor(inputSchema);
    try {
        testFixture.addSingleCol("").addSingleCol("  ").addSingleCol("10").addSingleCol(" 11  ");
    } catch (Exception e) {
        testFixture.build().clear();
        throw e;
    }
    RowSet actual = testFixture.build();
    final SingleRowSet expected = fixture.rowSetBuilder(outputSchema).addSingleCol(value).addSingleCol(value).addSingleCol(10).addSingleCol(11).build();
    RowSetUtilities.verify(expected, actual);
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) 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) UserException(org.apache.drill.common.exceptions.UserException)

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