Search in sources :

Example 76 with SingleRowSet

use of org.apache.drill.test.rowSet.RowSet.SingleRowSet 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();
}
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 77 with SingleRowSet

use of org.apache.drill.test.rowSet.RowSet.SingleRowSet 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();
}
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 78 with SingleRowSet

use of org.apache.drill.test.rowSet.RowSet.SingleRowSet 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 79 with SingleRowSet

use of org.apache.drill.test.rowSet.RowSet.SingleRowSet 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 80 with SingleRowSet

use of org.apache.drill.test.rowSet.RowSet.SingleRowSet 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)

Aggregations

SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)93 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)78 Test (org.junit.Test)74 BatchSchema (org.apache.drill.exec.record.BatchSchema)64 SubOperatorTest (org.apache.drill.test.SubOperatorTest)57 RowSetReader (org.apache.drill.test.rowSet.RowSetReader)38 RowSet (org.apache.drill.test.rowSet.RowSet)27 ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)25 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)25 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)22 RowSetLoader (org.apache.drill.exec.physical.rowSet.RowSetLoader)17 ResultSetLoader (org.apache.drill.exec.physical.rowSet.ResultSetLoader)16 ValueVector (org.apache.drill.exec.vector.ValueVector)13 ScalarElementReader (org.apache.drill.exec.vector.accessor.ScalarElementReader)13 RowSetBuilder (org.apache.drill.test.rowSet.RowSetBuilder)13 ColumnSize (org.apache.drill.exec.record.RecordBatchSizer.ColumnSize)10 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)10 TupleWriter (org.apache.drill.exec.vector.accessor.TupleWriter)10 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)9 RepeatedValueVector (org.apache.drill.exec.vector.complex.RepeatedValueVector)9