Search in sources :

Example 31 with SchemaBuilder

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

the class TestDirectConverter method testSchemaMerge.

@Test
public void testSchemaMerge() {
    TupleMetadata providedSchema = new SchemaBuilder().add("a", MinorType.INT).addNullable("b", MinorType.INT).add("c", MinorType.INT).build();
    providedSchema.setBooleanProperty("foo", true);
    TupleMetadata readerSchema = new SchemaBuilder().add("a", MinorType.VARCHAR).add("b", MinorType.VARCHAR).add("d", MinorType.VARCHAR).build();
    TupleMetadata expected = new SchemaBuilder().add("a", MinorType.INT).addNullable("b", MinorType.INT).add("d", MinorType.VARCHAR).build();
    TupleMetadata mergedSchema = FixedReceiver.Builder.mergeSchemas(providedSchema, readerSchema);
    assertTrue(expected.isEquivalent(mergedSchema));
    assertTrue(mergedSchema.booleanProperty("foo"));
}
Also used : 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 32 with SchemaBuilder

use of org.apache.drill.exec.record.metadata.SchemaBuilder 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 33 with SchemaBuilder

use of org.apache.drill.exec.record.metadata.SchemaBuilder 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)

Example 34 with SchemaBuilder

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

the class TestDirectConverter method testDecimalFromString.

@Test
public void testDecimalFromString() {
    TupleMetadata outputSchema = new SchemaBuilder().add("id", MinorType.INT).add("dec", MinorType.VARDECIMAL, 4, 2).buildSchema();
    TupleMetadata inputSchema = new SchemaBuilder().add("id", MinorType.INT).add("dec", MinorType.VARCHAR).buildSchema();
    ConversionTestFixture testFixture = new ConversionTestFixture(fixture.allocator(), outputSchema);
    testFixture.createConvertersFor(inputSchema);
    RowSet actual = testFixture.addRow(1, "0").addRow(2, "-0").addRow(3, "0.12").addRow(4, "1.23").addRow(5, "12.34").addRow(6, "23.456").addRow(7, "-99.99").build();
    final SingleRowSet expected = fixture.rowSetBuilder(outputSchema).addRow(1, dec("0")).addRow(2, dec("-0")).addRow(3, dec("0.12")).addRow(4, dec("1.23")).addRow(5, dec("12.34")).addRow(6, dec("23.46")).addRow(7, dec("-99.99")).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) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 35 with SchemaBuilder

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

the class TestDirectConverter method testNumberToStringConversion.

/**
 * Test the standard string-to-type conversion using an ad-hoc conversion
 * from the input type (the type used by the row set builder) to the output
 * (vector) type.
 */
@Test
public void testNumberToStringConversion() {
    // Create the schema
    TupleMetadata outputSchema = new SchemaBuilder().add("ti", MinorType.VARCHAR).add("si", MinorType.VARCHAR).add("int", MinorType.VARCHAR).add("bi", MinorType.VARCHAR).add("fl", MinorType.VARCHAR).add("db", MinorType.VARCHAR).buildSchema();
    TupleMetadata inputSchema = 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).buildSchema();
    // The setObject() method won't do the Float to Double conversion,
    // so values before are provided as doubles in the float case.
    ConversionTestFixture testFixture = new ConversionTestFixture(fixture.allocator(), outputSchema);
    testFixture.createConvertersFor(inputSchema);
    RowSet actual = testFixture.addRow(11, 12, 13, 14L, 15.5D, 16.25D).addRow(127, 32757, Integer.MAX_VALUE, Long.MAX_VALUE, 10E6D, 10E200D).build();
    // Build the expected vector without a type converter.
    final SingleRowSet expected = fixture.rowSetBuilder(outputSchema).addRow("11", "12", "13", "14", "15.5", "16.25").addRow("127", "32757", Integer.toString(Integer.MAX_VALUE), Long.toString(Long.MAX_VALUE), "1.0E7", "1.0E201").build();
    // Compare
    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) 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