use of org.apache.drill.exec.vector.accessor.ScalarElementReader in project drill by axbaretto.
the class TestScalarAccessors method testIntervalDayArray.
@Test
public void testIntervalDayArray() {
BatchSchema batchSchema = new SchemaBuilder().addArray("col", MinorType.INTERVALDAY).build();
Period p1 = Period.days(0);
Period p2 = Period.days(3).plusHours(4).plusMinutes(5).plusSeconds(23);
Period p3 = Period.days(999).plusHours(23).plusMinutes(59).plusSeconds(59);
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addSingleCol(new Period[] {}).addSingleCol(new Period[] { p1, p2, p3 }).build();
assertEquals(2, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarElementReader colReader = reader.elements(0);
assertEquals(ValueType.PERIOD, colReader.valueType());
assertTrue(reader.next());
assertEquals(0, colReader.size());
assertTrue(reader.next());
assertEquals(3, colReader.size());
assertEquals(p1, colReader.getPeriod(0).normalizedStandard());
assertEquals(p2, colReader.getPeriod(1).normalizedStandard());
assertEquals(p3.normalizedStandard(), colReader.getPeriod(2).normalizedStandard());
assertEquals(p2, ((Period) colReader.getObject(1)).normalizedStandard());
assertEquals(p2.toString(), colReader.getAsString(1));
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarElementReader in project drill by axbaretto.
the class TestScalarAccessors method testVarBinaryArray.
@Test
public void testVarBinaryArray() {
BatchSchema batchSchema = new SchemaBuilder().addArray("col", MinorType.VARBINARY).build();
byte[] v1 = new byte[] {};
byte[] v2 = new byte[] { (byte) 0x00, (byte) 0x7f, (byte) 0x80, (byte) 0xFF };
byte[] v3 = new byte[] { (byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xAF };
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addSingleCol(new byte[][] {}).addSingleCol(new byte[][] { v1, v2, v3 }).build();
assertEquals(2, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarElementReader colReader = reader.elements(0);
assertEquals(ValueType.BYTES, colReader.valueType());
assertTrue(reader.next());
assertEquals(0, colReader.size());
assertTrue(reader.next());
assertEquals(3, colReader.size());
assertTrue(Arrays.equals(v1, colReader.getBytes(0)));
assertTrue(Arrays.equals(v2, colReader.getBytes(1)));
assertTrue(Arrays.equals(v3, colReader.getBytes(2)));
assertTrue(Arrays.equals(v2, (byte[]) colReader.getObject(1)));
assertEquals("[00, 7f, 80, ff]", colReader.getAsString(1));
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarElementReader in project drill by axbaretto.
the class TestScalarAccessors method testIntervalYearArray.
@Test
public void testIntervalYearArray() {
BatchSchema batchSchema = new SchemaBuilder().addArray("col", MinorType.INTERVALYEAR).build();
Period p1 = Period.years(0);
Period p2 = Period.years(2).plusMonths(3);
Period p3 = Period.years(1234).plusMonths(11);
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addSingleCol(new Period[] {}).addSingleCol(new Period[] { p1, p2, p3 }).build();
assertEquals(2, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarElementReader colReader = reader.elements(0);
assertEquals(ValueType.PERIOD, colReader.valueType());
assertTrue(reader.next());
assertEquals(0, colReader.size());
assertTrue(reader.next());
assertEquals(3, colReader.size());
assertEquals(p1, colReader.getPeriod(0));
assertEquals(p2, colReader.getPeriod(1));
assertEquals(p3, colReader.getPeriod(2));
assertEquals(p2, colReader.getObject(1));
assertEquals(p2.toString(), colReader.getAsString(1));
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.exec.vector.accessor.ScalarElementReader 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.exec.vector.accessor.ScalarElementReader 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);
}
Aggregations