Search in sources :

Example 56 with TupleMetadata

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

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

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

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

Example 60 with TupleMetadata

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

the class TestConstantColumnLoader method testConstantColumnLoader.

/**
 * Test the static column loader using one column of each type.
 * The null column is of type int, but the associated value is of
 * type string. This is a bit odd, but works out because we detect that
 * the string value is null and call setNull on the writer, and avoid
 * using the actual data.
 */
@Test
public void testConstantColumnLoader() {
    final MajorType aType = MajorType.newBuilder().setMinorType(MinorType.VARCHAR).setMode(DataMode.REQUIRED).build();
    final MajorType bType = MajorType.newBuilder().setMinorType(MinorType.VARCHAR).setMode(DataMode.OPTIONAL).build();
    final List<ConstantColumnSpec> defns = new ArrayList<>();
    defns.add(new DummyColumn("a", aType, "a-value"));
    defns.add(new DummyColumn("b", bType, "b-value"));
    final ResultVectorCacheImpl cache = new ResultVectorCacheImpl(fixture.allocator());
    final ConstantColumnLoader staticLoader = new ConstantColumnLoader(cache, defns);
    // Create a batch
    staticLoader.load(2);
    // Verify
    final TupleMetadata expectedSchema = new SchemaBuilder().add("a", aType).add("b", bType).buildSchema();
    final SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow("a-value", "b-value").addRow("a-value", "b-value").build();
    new RowSetComparison(expected).verifyAndClearAll(fixture.wrap(staticLoader.load(2)));
    staticLoader.close();
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) ConstantColumnSpec(org.apache.drill.exec.physical.impl.scan.project.ConstantColumnLoader.ConstantColumnSpec) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) ArrayList(java.util.ArrayList) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) ResultVectorCacheImpl(org.apache.drill.exec.physical.resultSet.impl.ResultVectorCacheImpl) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)1235 Test (org.junit.Test)1126 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)1008 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)598 SubOperatorTest (org.apache.drill.test.SubOperatorTest)460 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)293 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)264 ClusterTest (org.apache.drill.test.ClusterTest)261 EvfTest (org.apache.drill.categories.EvfTest)230 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)211 ResultSetLoader (org.apache.drill.exec.physical.resultSet.ResultSetLoader)111 JsonTest (org.apache.drill.categories.JsonTest)110 DirectRowSet (org.apache.drill.exec.physical.rowSet.DirectRowSet)109 BaseTest (org.apache.drill.test.BaseTest)106 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)100 RowSetLoader (org.apache.drill.exec.physical.resultSet.RowSetLoader)89 ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)72 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)69 UserException (org.apache.drill.common.exceptions.UserException)67 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)65