Search in sources :

Example 36 with ScalarReader

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

the class TestScalarAccessors method testDoubleRW.

@Test
public void testDoubleRW() {
    TupleMetadata schema = new SchemaBuilder().add("col", MinorType.FLOAT8).buildSchema();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(0D).addRow(Double.MAX_VALUE).addRow(Double.MIN_VALUE).addRow(100D).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(Double.MAX_VALUE, colReader.getDouble(), 0.000001);
    assertEquals(Double.MAX_VALUE, (double) colReader.getObject(), 0.000001);
    assertTrue(reader.next());
    assertEquals(Double.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.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 37 with ScalarReader

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

the class TestScalarAccessors method longArrayTester.

private void longArrayTester(MinorType type) {
    TupleMetadata schema = new SchemaBuilder().addArray("col", type).buildSchema();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addSingleCol(new long[] {}).addSingleCol(new long[] { 0, 20, 30 }).build();
    assertEquals(2, rs.rowCount());
    RowSetReader reader = rs.reader();
    ArrayReader arrayReader = reader.array(0);
    ScalarReader colReader = arrayReader.scalar();
    assertEquals(ValueType.LONG, colReader.valueType());
    assertTrue(reader.next());
    assertEquals(0, arrayReader.size());
    assertTrue(reader.next());
    assertEquals(3, arrayReader.size());
    assertTrue(arrayReader.next());
    assertEquals(0, colReader.getLong());
    if (colReader.extendedType() == ValueType.LONG) {
        assertEquals(0L, colReader.getObject());
        assertEquals("0", colReader.getAsString());
    }
    assertTrue(arrayReader.next());
    assertEquals(20, colReader.getLong());
    if (colReader.extendedType() == ValueType.LONG) {
        assertEquals(20L, colReader.getObject());
        assertEquals("20", colReader.getAsString());
    }
    assertTrue(arrayReader.next());
    assertEquals(30, colReader.getLong());
    if (colReader.extendedType() == ValueType.LONG) {
        assertEquals(30L, colReader.getObject());
        assertEquals("30", colReader.getAsString());
    }
    assertFalse(arrayReader.next());
    if (colReader.extendedType() == ValueType.LONG) {
        assertEquals("[0, 20, 30]", arrayReader.getAsString());
        assertEquals(Arrays.asList(0L, 20L, 30L), arrayReader.getObject());
    }
    assertFalse(reader.next());
    rs.clear();
}
Also used : ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) ArrayReader(org.apache.drill.exec.vector.accessor.ArrayReader) 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 38 with ScalarReader

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

the class TestScalarAccessors method testDecimal9RW.

@Test
public void testDecimal9RW() {
    MajorType type = MajorType.newBuilder().setMinorType(MinorType.DECIMAL9).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, 3);
    BigDecimal v3 = BigDecimal.valueOf(999_999_999, 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 39 with ScalarReader

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

the class TestScalarAccessors method testNullableVarchar.

@Test
public void testNullableVarchar() {
    TupleMetadata schema = new SchemaBuilder().addNullable("col", MinorType.VARCHAR).buildSchema();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addRow("").addSingleCol(null).addRow("abcd").build();
    assertEquals(3, rs.rowCount());
    // Verify vector state
    VectorContainer container = rs.container();
    assertEquals(1, container.getNumberOfColumns());
    ValueVector v = container.getValueVector(0).getValueVector();
    assertTrue(v instanceof NullableVarCharVector);
    NullableVarCharVector nvcv = (NullableVarCharVector) v;
    assertEquals(3, nvcv.getAccessor().getValueCount());
    assertEquals(2, nvcv.getMutator().getLastSet());
    // Data vector: 3 values written above.
    VarCharVector vv = nvcv.getValuesVector();
    assertEquals(3, vv.getAccessor().getValueCount());
    // Offsets vector: one more than row count
    UInt4Vector ov = vv.getOffsetVector();
    assertEquals(4, ov.getAccessor().getValueCount());
    assertEquals(4 * 4, ov.getBuffer().writerIndex());
    // Last offset and bytes buf length must agree
    int lastIndex = ov.getAccessor().get(3);
    assertEquals(lastIndex, vv.getBuffer().writerIndex());
    // Verify using the reader
    RowSetReader reader = rs.reader();
    ScalarReader colReader = reader.scalar(0);
    assertTrue(reader.next());
    assertFalse(colReader.isNull());
    assertEquals("", colReader.getString());
    assertTrue(reader.next());
    assertTrue(colReader.isNull());
    assertNull(colReader.getObject());
    assertEquals("null", colReader.getAsString());
    assertTrue(reader.next());
    assertEquals("abcd", colReader.getString());
    assertEquals("abcd", colReader.getObject());
    assertEquals("\"abcd\"", colReader.getAsString());
    assertFalse(reader.next());
    rs.clear();
}
Also used : RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) BaseDataValueVector(org.apache.drill.exec.vector.BaseDataValueVector) ValueVector(org.apache.drill.exec.vector.ValueVector) ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) RepeatedVarCharVector(org.apache.drill.exec.vector.RepeatedVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) VectorContainer(org.apache.drill.exec.record.VectorContainer) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 40 with ScalarReader

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

the class TestScalarAccessors method testNullableInterval.

@Test
public void testNullableInterval() {
    TupleMetadata schema = new SchemaBuilder().addNullable("col", MinorType.INTERVAL).buildSchema();
    Period p1 = Period.years(0);
    Period p2 = Period.years(7).plusMonths(8).plusDays(3).plusHours(4).plusMinutes(5).plusSeconds(23);
    SingleRowSet rs = fixture.rowSetBuilder(schema).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.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.exec.physical.rowSet.RowSet.SingleRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Period(org.joda.time.Period) 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