use of org.apache.drill.test.rowSet.RowSet.SingleRowSet in project drill by axbaretto.
the class TestScalarAccessors method testIntervalRW.
@Test
public void testIntervalRW() {
BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.INTERVAL).build();
Period p1 = Period.days(0);
Period p2 = Period.years(7).plusMonths(8).plusDays(3).plusHours(4).plusMinutes(5).plusSeconds(23);
Period p3 = Period.years(9999).plusMonths(11).plusDays(365).plusHours(23).plusMinutes(59).plusSeconds(59);
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow(p1).addRow(p2).addRow(p3).build();
assertEquals(3, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertEquals(ValueType.PERIOD, colReader.valueType());
assertTrue(reader.next());
assertFalse(colReader.isNull());
// The normalizedStandard() call is a hack. See DRILL-5689.
assertEquals(p1, colReader.getPeriod().normalizedStandard());
assertTrue(reader.next());
assertEquals(p2, colReader.getPeriod().normalizedStandard());
assertEquals(p2, ((Period) colReader.getObject()).normalizedStandard());
assertEquals(p2.toString(), colReader.getAsString());
assertTrue(reader.next());
assertEquals(p3.normalizedStandard(), colReader.getPeriod().normalizedStandard());
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.test.rowSet.RowSet.SingleRowSet in project drill by axbaretto.
the class TestScalarAccessors method intArrayTester.
private void intArrayTester(MinorType type) {
BatchSchema batchSchema = new SchemaBuilder().addArray("col", type).build();
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addSingleCol(new int[] {}).addSingleCol(new int[] { 0, 20, 30 }).build();
assertEquals(2, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarElementReader colReader = reader.elements(0);
assertEquals(ValueType.INTEGER, colReader.valueType());
assertTrue(reader.next());
assertEquals(0, colReader.size());
assertTrue(reader.next());
assertEquals(3, colReader.size());
assertEquals(0, colReader.getInt(0));
assertEquals(20, colReader.getInt(1));
assertEquals(30, colReader.getInt(2));
assertEquals(0, colReader.getObject(0));
assertEquals(20, colReader.getObject(1));
assertEquals(30, colReader.getObject(2));
assertEquals("0", colReader.getAsString(0));
assertEquals("20", colReader.getAsString(1));
assertEquals("30", colReader.getAsString(2));
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.test.rowSet.RowSet.SingleRowSet in project drill by axbaretto.
the class RowSetTest method testTopFixedWidthArray.
/**
* Test an array of ints (as an example fixed-width type)
* at the top level of a schema.
*/
@Test
public void testTopFixedWidthArray() {
BatchSchema batchSchema = new SchemaBuilder().add("c", MinorType.INT).addArray("a", MinorType.INT).build();
ExtendableRowSet rs1 = fixture.rowSet(batchSchema);
RowSetWriter writer = rs1.writer();
writer.scalar(0).setInt(10);
ScalarWriter array = writer.array(1).scalar();
array.setInt(100);
array.setInt(110);
writer.save();
writer.scalar(0).setInt(20);
array.setInt(200);
array.setInt(120);
array.setInt(220);
writer.save();
writer.scalar(0).setInt(30);
writer.save();
SingleRowSet result = writer.done();
RowSetReader reader = result.reader();
assertTrue(reader.next());
assertEquals(10, reader.scalar(0).getInt());
ScalarElementReader arrayReader = reader.array(1).elements();
assertEquals(2, arrayReader.size());
assertEquals(100, arrayReader.getInt(0));
assertEquals(110, arrayReader.getInt(1));
assertTrue(reader.next());
assertEquals(20, reader.scalar(0).getInt());
assertEquals(3, arrayReader.size());
assertEquals(200, arrayReader.getInt(0));
assertEquals(120, arrayReader.getInt(1));
assertEquals(220, arrayReader.getInt(2));
assertTrue(reader.next());
assertEquals(30, reader.scalar(0).getInt());
assertEquals(0, arrayReader.size());
assertFalse(reader.next());
SingleRowSet rs2 = fixture.rowSetBuilder(batchSchema).addRow(10, intArray(100, 110)).addRow(20, intArray(200, 120, 220)).addRow(30, null).build();
new RowSetComparison(rs1).verifyAndClearAll(rs2);
}
use of org.apache.drill.test.rowSet.RowSet.SingleRowSet in project drill by axbaretto.
the class RowSetTest method testScalarStructure.
/**
* Test the simplest constructs: a row with top-level scalar
* columns.
* <p>
* The focus here is the structure of the readers and writers, along
* with the row set loader and verifier that use those constructs.
* That is, while this test uses the int vector, this test is not
* focused on that vector.
*/
@Test
public void testScalarStructure() {
TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).buildSchema();
ExtendableRowSet rowSet = fixture.rowSet(schema);
RowSetWriter writer = rowSet.writer();
// Required Int
// Verify the invariants of the "full" and "simple" access paths
assertEquals(ObjectType.SCALAR, writer.column("a").type());
assertSame(writer.column("a"), writer.column(0));
assertSame(writer.scalar("a"), writer.scalar(0));
assertSame(writer.column("a").scalar(), writer.scalar("a"));
assertSame(writer.column(0).scalar(), writer.scalar(0));
assertEquals(ValueType.INTEGER, writer.scalar(0).valueType());
try {
writer.column(0).array();
fail();
} catch (UnsupportedOperationException e) {
// Expected
}
try {
writer.column(0).tuple();
fail();
} catch (UnsupportedOperationException e) {
// Expected
}
// Test the various ways to get at the scalar writer.
writer.column("a").scalar().setInt(10);
writer.save();
writer.scalar("a").setInt(20);
writer.save();
writer.column(0).scalar().setInt(30);
writer.save();
writer.scalar(0).setInt(40);
writer.save();
// Finish the row set and get a reader.
SingleRowSet actual = writer.done();
RowSetReader reader = actual.reader();
// Verify invariants
assertEquals(ObjectType.SCALAR, reader.column(0).type());
assertSame(reader.column("a"), reader.column(0));
assertSame(reader.scalar("a"), reader.scalar(0));
assertSame(reader.column("a").scalar(), reader.scalar("a"));
assertSame(reader.column(0).scalar(), reader.scalar(0));
assertEquals(ValueType.INTEGER, reader.scalar(0).valueType());
// Test various accessors: full and simple
assertTrue(reader.next());
assertEquals(10, reader.column("a").scalar().getInt());
assertTrue(reader.next());
assertEquals(20, reader.scalar("a").getInt());
assertTrue(reader.next());
assertEquals(30, reader.column(0).scalar().getInt());
assertTrue(reader.next());
assertEquals(40, reader.scalar(0).getInt());
assertFalse(reader.next());
// Test the above again via the writer and reader
// utility classes.
SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(10).addRow(20).addRow(30).addRow(40).build();
new RowSetComparison(expected).verifyAndClearAll(actual);
}
use of org.apache.drill.test.rowSet.RowSet.SingleRowSet in project drill by axbaretto.
the class RowSetTest method testScalarArrayStructure.
/**
* Test a record with a top level array. The focus here is on the
* scalar array structure.
*
* @throws VectorOverflowException should never occur
*/
@Test
public void testScalarArrayStructure() {
TupleMetadata schema = new SchemaBuilder().addArray("a", MinorType.INT).buildSchema();
ExtendableRowSet rowSet = fixture.rowSet(schema);
RowSetWriter writer = rowSet.writer();
// Repeated Int
// Verify the invariants of the "full" and "simple" access paths
assertEquals(ObjectType.ARRAY, writer.column("a").type());
assertSame(writer.column("a"), writer.column(0));
assertSame(writer.array("a"), writer.array(0));
assertSame(writer.column("a").array(), writer.array("a"));
assertSame(writer.column(0).array(), writer.array(0));
assertEquals(ObjectType.SCALAR, writer.column("a").array().entry().type());
assertEquals(ObjectType.SCALAR, writer.column("a").array().entryType());
assertSame(writer.array(0).entry().scalar(), writer.array(0).scalar());
assertEquals(ValueType.INTEGER, writer.array(0).scalar().valueType());
try {
writer.column(0).scalar();
fail();
} catch (UnsupportedOperationException e) {
// Expected
}
try {
writer.column(0).tuple();
fail();
} catch (UnsupportedOperationException e) {
// Expected
}
// Write some data
ScalarWriter intWriter = writer.array("a").scalar();
intWriter.setInt(10);
intWriter.setInt(11);
writer.save();
intWriter.setInt(20);
intWriter.setInt(21);
intWriter.setInt(22);
writer.save();
intWriter.setInt(30);
writer.save();
intWriter.setInt(40);
intWriter.setInt(41);
writer.save();
// Finish the row set and get a reader.
SingleRowSet actual = writer.done();
RowSetReader reader = actual.reader();
// Verify the invariants of the "full" and "simple" access paths
assertEquals(ObjectType.ARRAY, writer.column("a").type());
assertSame(reader.column("a"), reader.column(0));
assertSame(reader.array("a"), reader.array(0));
assertSame(reader.column("a").array(), reader.array("a"));
assertSame(reader.column(0).array(), reader.array(0));
assertEquals(ObjectType.SCALAR, reader.column("a").array().entryType());
assertEquals(ValueType.INTEGER, reader.array(0).elements().valueType());
// Read and verify the rows
ScalarElementReader intReader = reader.array(0).elements();
assertTrue(reader.next());
assertEquals(2, intReader.size());
assertEquals(10, intReader.getInt(0));
assertEquals(11, intReader.getInt(1));
assertTrue(reader.next());
assertEquals(3, intReader.size());
assertEquals(20, intReader.getInt(0));
assertEquals(21, intReader.getInt(1));
assertEquals(22, intReader.getInt(2));
assertTrue(reader.next());
assertEquals(1, intReader.size());
assertEquals(30, intReader.getInt(0));
assertTrue(reader.next());
assertEquals(2, intReader.size());
assertEquals(40, intReader.getInt(0));
assertEquals(41, intReader.getInt(1));
assertFalse(reader.next());
// Test the above again via the writer and reader
// utility classes.
SingleRowSet expected = fixture.rowSetBuilder(schema).addSingleCol(intArray(10, 11)).addSingleCol(intArray(20, 21, 22)).addSingleCol(intArray(30)).addSingleCol(intArray(40, 41)).build();
new RowSetComparison(expected).verifyAndClearAll(actual);
}
Aggregations