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);
}
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);
}
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);
}
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);
}
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();
}
Aggregations