Search in sources :

Example 71 with ScalarReader

use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.

the class TestScalarAccessors method longRWTester.

private void longRWTester(MinorType type) {
    TupleMetadata schema = new SchemaBuilder().add("col", type).buildSchema();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(0L).addRow(Long.MAX_VALUE).addRow(Long.MIN_VALUE).build();
    assertEquals(3, rs.rowCount());
    RowSetReader reader = rs.reader();
    ScalarReader colReader = reader.scalar(0);
    assertEquals(ValueType.LONG, colReader.valueType());
    assertTrue(reader.next());
    assertFalse(colReader.isNull());
    assertEquals(0, colReader.getLong());
    assertTrue(reader.next());
    assertEquals(Long.MAX_VALUE, colReader.getLong());
    if (colReader.extendedType() == ValueType.LONG) {
        assertEquals(Long.MAX_VALUE, colReader.getObject());
        assertEquals(Long.toString(Long.MAX_VALUE), colReader.getAsString());
    }
    assertTrue(reader.next());
    assertEquals(Long.MIN_VALUE, colReader.getLong());
    assertFalse(reader.next());
    rs.clear();
}
Also used : ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder)

Example 72 with ScalarReader

use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.

the class TestScalarAccessors method testDecimal18RW.

@Test
public void testDecimal18RW() {
    MajorType type = MajorType.newBuilder().setMinorType(MinorType.DECIMAL18).setScale(3).setPrecision(9).setMode(DataMode.REQUIRED).build();
    TupleMetadata schema = new SchemaBuilder().add("col", type).buildSchema();
    BigDecimal v1 = BigDecimal.ZERO;
    BigDecimal v2 = BigDecimal.valueOf(123_456_789_123_456_789L, 3);
    BigDecimal v3 = BigDecimal.valueOf(999_999_999_999_999_999L, 3);
    SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(v1).addRow(v2).addRow(v3).build();
    assertEquals(3, rs.rowCount());
    RowSetReader reader = rs.reader();
    ScalarReader colReader = reader.scalar(0);
    assertEquals(ValueType.DECIMAL, colReader.valueType());
    assertTrue(reader.next());
    assertFalse(colReader.isNull());
    assertEquals(0, v1.compareTo(colReader.getDecimal()));
    assertTrue(reader.next());
    assertEquals(0, v2.compareTo(colReader.getDecimal()));
    assertEquals(0, v2.compareTo((BigDecimal) colReader.getObject()));
    assertEquals(v2.toString(), colReader.getAsString());
    assertTrue(reader.next());
    assertEquals(0, v3.compareTo(colReader.getDecimal()));
    assertFalse(reader.next());
    rs.clear();
}
Also used : ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BigDecimal(java.math.BigDecimal) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 73 with ScalarReader

use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.

the class TestScalarAccessors method testNullableDouble.

@Test
public void testNullableDouble() {
    TupleMetadata schema = new SchemaBuilder().addNullable("col", MinorType.FLOAT8).buildSchema();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(10D).addSingleCol(null).addRow(30D).build();
    assertEquals(3, rs.rowCount());
    RowSetReader reader = rs.reader();
    ScalarReader colReader = reader.scalar(0);
    assertTrue(reader.next());
    assertFalse(colReader.isNull());
    assertEquals(10, colReader.getDouble(), 0.000001);
    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.getDouble(), 0.000001);
    assertFalse(reader.next());
    rs.clear();
}
Also used : ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 74 with ScalarReader

use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.

the class TestScalarAccessors method testBitResize.

/**
 * The bit reader/writer are special and use the BitVector directly.
 * Ensure that resize works in this special case.
 */
@Test
public void testBitResize() {
    TupleMetadata schema = new SchemaBuilder().add("col", MinorType.BIT).buildSchema();
    RowSetBuilder rsb = new RowSetBuilder(fixture.allocator(), schema, 100);
    ScalarWriter bitWriter = rsb.writer().scalar(0);
    for (int i = 0; i < ValueVector.MAX_ROW_COUNT; i++) {
        bitWriter.setBoolean((i % 5) == 0);
        rsb.writer().save();
    }
    SingleRowSet rs = rsb.build();
    RowSetReader reader = rs.reader();
    ScalarReader bitReader = reader.scalar(0);
    for (int i = 0; i < ValueVector.MAX_ROW_COUNT; i++) {
        reader.next();
        assertEquals((i % 5) == 0, bitReader.getBoolean());
    }
    rs.clear();
}
Also used : ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 75 with ScalarReader

use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.

the class TestScalarAccessors method testTimeStampObjectRW.

@Test
public void testTimeStampObjectRW() {
    TupleMetadata schema = new SchemaBuilder().add("col", MinorType.TIMESTAMP).buildSchema();
    LocalDate dt = LocalDate.of(2019, 3, 24);
    LocalTime lt = LocalTime.of(12, 13, 14);
    Instant v1 = LocalDateTime.of(dt, lt).toInstant(ZoneOffset.UTC);
    SingleRowSet rs = fixture.rowSetBuilder(schema).addSingleCol(v1).build();
    assertEquals(1, rs.rowCount());
    RowSetReader reader = rs.reader();
    ScalarReader colReader = reader.scalar(0);
    assertEquals(ValueType.TIMESTAMP, colReader.extendedType());
    assertTrue(reader.next());
    assertEquals(v1, colReader.getTimestamp());
    assertFalse(reader.next());
    rs.clear();
}
Also used : ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) LocalTime(java.time.LocalTime) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) Instant(java.time.Instant) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) LocalDate(java.time.LocalDate) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)97 SubOperatorTest (org.apache.drill.test.SubOperatorTest)78 Test (org.junit.Test)78 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)72 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)68 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)65 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)31 ArrayReader (org.apache.drill.exec.vector.accessor.ArrayReader)29 RowSetReader (org.apache.drill.test.rowSet.RowSetReader)27 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)26 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)26 BatchSchema (org.apache.drill.exec.record.BatchSchema)22 ExtendableRowSet (org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet)19 Period (org.joda.time.Period)15 ArrayWriter (org.apache.drill.exec.vector.accessor.ArrayWriter)13 TupleReader (org.apache.drill.exec.vector.accessor.TupleReader)10 TupleWriter (org.apache.drill.exec.vector.accessor.TupleWriter)10 VectorContainer (org.apache.drill.exec.record.VectorContainer)9 BigDecimal (java.math.BigDecimal)7 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)7