Search in sources :

Example 46 with RowSetReader

use of org.apache.drill.test.rowSet.RowSetReader in project drill by axbaretto.

the class TestScalarAccessors method testNullableInterval.

@Test
public void testNullableInterval() {
    BatchSchema batchSchema = new SchemaBuilder().addNullable("col", MinorType.INTERVAL).build();
    Period p1 = Period.years(0);
    Period p2 = Period.years(7).plusMonths(8).plusDays(3).plusHours(4).plusMinutes(5).plusSeconds(23);
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow(p1).addSingleCol(null).addRow(p2).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());
    assertEquals(p1, colReader.getPeriod().normalizedStandard());
    assertTrue(reader.next());
    assertTrue(colReader.isNull());
    assertNull(colReader.getPeriod());
    assertNull(colReader.getObject());
    assertEquals("null", colReader.getAsString());
    assertTrue(reader.next());
    assertEquals(p2, colReader.getPeriod().normalizedStandard());
    assertFalse(reader.next());
    rs.clear();
}
Also used : ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) Period(org.joda.time.Period) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 47 with RowSetReader

use of org.apache.drill.test.rowSet.RowSetReader in project drill by axbaretto.

the class TestScalarAccessors method testVarBinaryRW.

@Test
public void testVarBinaryRW() {
    BatchSchema batchSchema = new SchemaBuilder().add("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).addRow(v2).build();
    assertEquals(2, 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(Arrays.equals(v2, colReader.getBytes()));
    assertTrue(Arrays.equals(v2, (byte[]) colReader.getObject()));
    assertEquals("[00, 7f, 80, ff]", colReader.getAsString());
    assertFalse(reader.next());
    rs.clear();
}
Also used : ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 48 with RowSetReader

use of org.apache.drill.test.rowSet.RowSetReader in project drill by axbaretto.

the class TestScalarAccessors method testIntervalYearRW.

@Test
public void testIntervalYearRW() {
    BatchSchema batchSchema = new SchemaBuilder().add("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).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());
    assertEquals(p1, colReader.getPeriod());
    assertTrue(reader.next());
    assertEquals(p2, colReader.getPeriod());
    assertEquals(p2, colReader.getObject());
    assertEquals(p2.toString(), colReader.getAsString());
    assertTrue(reader.next());
    assertEquals(p3, colReader.getPeriod());
    assertFalse(reader.next());
    rs.clear();
}
Also used : ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) Period(org.joda.time.Period) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 49 with RowSetReader

use of org.apache.drill.test.rowSet.RowSetReader 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();
}
Also used : ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) Period(org.joda.time.Period) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 50 with RowSetReader

use of org.apache.drill.test.rowSet.RowSetReader 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();
}
Also used : SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) ScalarElementReader(org.apache.drill.exec.vector.accessor.ScalarElementReader) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) RowSetReader(org.apache.drill.test.rowSet.RowSetReader)

Aggregations

RowSetReader (org.apache.drill.test.rowSet.RowSetReader)55 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)50 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)46 SubOperatorTest (org.apache.drill.test.SubOperatorTest)39 Test (org.junit.Test)39 BatchSchema (org.apache.drill.exec.record.BatchSchema)34 ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)27 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)17 ScalarElementReader (org.apache.drill.exec.vector.accessor.ScalarElementReader)17 RowSet (org.apache.drill.test.rowSet.RowSet)16 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)14 ResultSetLoader (org.apache.drill.exec.physical.rowSet.ResultSetLoader)12 RowSetLoader (org.apache.drill.exec.physical.rowSet.RowSetLoader)12 Period (org.joda.time.Period)9 TupleReader (org.apache.drill.exec.vector.accessor.TupleReader)7 TupleWriter (org.apache.drill.exec.vector.accessor.TupleWriter)7 ExtendableRowSet (org.apache.drill.test.rowSet.RowSet.ExtendableRowSet)7 RowSetWriter (org.apache.drill.test.rowSet.RowSetWriter)7 ResultSetOptions (org.apache.drill.exec.physical.rowSet.impl.ResultSetLoaderImpl.ResultSetOptions)5 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)5