use of org.apache.drill.test.rowSet.RowSetReader in project drill by axbaretto.
the class TestScalarAccessors method testNullableVarBinary.
@Test
public void testNullableVarBinary() {
BatchSchema batchSchema = new SchemaBuilder().addNullable("col", MinorType.VARBINARY).build();
byte[] v1 = new byte[] {};
byte[] v2 = new byte[] { (byte) 0x00, (byte) 0x7f, (byte) 0x80, (byte) 0xFF };
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow(v1).addSingleCol(null).addRow(v2).build();
assertEquals(3, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertEquals(ValueType.BYTES, colReader.valueType());
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertTrue(Arrays.equals(v1, colReader.getBytes()));
assertTrue(reader.next());
assertTrue(colReader.isNull());
assertNull(colReader.getObject());
assertEquals("null", colReader.getAsString());
assertTrue(reader.next());
assertTrue(Arrays.equals(v2, colReader.getBytes()));
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.test.rowSet.RowSetReader in project drill by axbaretto.
the class TestScalarAccessors method testSmallIntRW.
@Test
public void testSmallIntRW() {
BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.SMALLINT).build();
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow(0).addRow(Short.MAX_VALUE).addRow(Short.MIN_VALUE).build();
assertEquals(3, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertEquals(ValueType.INTEGER, colReader.valueType());
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertEquals(0, colReader.getInt());
assertTrue(reader.next());
assertEquals(Short.MAX_VALUE, colReader.getInt());
assertEquals((int) Short.MAX_VALUE, colReader.getObject());
assertEquals(Short.toString(Short.MAX_VALUE), colReader.getAsString());
assertTrue(reader.next());
assertEquals(Short.MIN_VALUE, colReader.getInt());
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.test.rowSet.RowSetReader 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.test.rowSet.RowSetReader in project drill by axbaretto.
the class TestScalarAccessors method testFloatRW.
@Test
public void testFloatRW() {
BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.FLOAT4).build();
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow(0F).addRow(Float.MAX_VALUE).addRow(Float.MIN_VALUE).addRow(100F).build();
assertEquals(4, rs.rowCount());
RowSetReader reader = rs.reader();
ScalarReader colReader = reader.scalar(0);
assertEquals(ValueType.DOUBLE, colReader.valueType());
assertTrue(reader.next());
assertFalse(colReader.isNull());
assertEquals(0, colReader.getDouble(), 0.000001);
assertTrue(reader.next());
assertEquals(Float.MAX_VALUE, colReader.getDouble(), 0.000001);
assertEquals((double) Float.MAX_VALUE, (double) colReader.getObject(), 0.000001);
assertTrue(reader.next());
assertEquals(Float.MIN_VALUE, colReader.getDouble(), 0.000001);
assertTrue(reader.next());
assertEquals(100, colReader.getDouble(), 0.000001);
assertEquals("100.0", colReader.getAsString());
assertFalse(reader.next());
rs.clear();
}
use of org.apache.drill.test.rowSet.RowSetReader 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();
}
Aggregations