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