Search in sources :

Example 36 with RowSetReader

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

the class TestScalarAccessors method testStringRW.

@Test
public void testStringRW() {
    BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.VARCHAR).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow("").addRow("abcd").build();
    assertEquals(2, rs.rowCount());
    RowSetReader reader = rs.reader();
    ScalarReader colReader = reader.scalar(0);
    assertEquals(ValueType.STRING, colReader.valueType());
    assertTrue(reader.next());
    assertFalse(colReader.isNull());
    assertEquals("", colReader.getString());
    assertTrue(reader.next());
    assertEquals("abcd", colReader.getString());
    assertEquals("abcd", colReader.getObject());
    assertEquals("\"abcd\"", 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 37 with RowSetReader

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

the class TestScalarAccessors method nullableLongTester.

private void nullableLongTester(MinorType type) {
    BatchSchema batchSchema = new SchemaBuilder().addNullable("col", type).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow(10L).addSingleCol(null).addRow(30L).build();
    assertEquals(3, rs.rowCount());
    RowSetReader reader = rs.reader();
    ScalarReader colReader = reader.scalar(0);
    assertTrue(reader.next());
    assertFalse(colReader.isNull());
    assertEquals(10, colReader.getLong());
    assertTrue(reader.next());
    assertTrue(colReader.isNull());
    assertNull(colReader.getObject());
    assertEquals("null", colReader.getAsString());
    // Data value is undefined, may be garbage
    assertTrue(reader.next());
    assertEquals(30, colReader.getLong());
    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)

Example 38 with RowSetReader

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

the class TestScalarAccessors method testIntervalDayRW.

@Test
public void testIntervalDayRW() {
    BatchSchema batchSchema = new SchemaBuilder().add("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).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 39 with RowSetReader

use of org.apache.drill.test.rowSet.RowSetReader 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();
}
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) Period(org.joda.time.Period) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 40 with RowSetReader

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

the class TestScalarAccessors method testTinyIntRW.

@Test
public void testTinyIntRW() {
    BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.TINYINT).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow(0).addRow(Byte.MAX_VALUE).addRow(Byte.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(Byte.MAX_VALUE, colReader.getInt());
    assertEquals((int) Byte.MAX_VALUE, colReader.getObject());
    assertEquals(Byte.toString(Byte.MAX_VALUE), colReader.getAsString());
    assertTrue(reader.next());
    assertEquals(Byte.MIN_VALUE, colReader.getInt());
    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)

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