Search in sources :

Example 51 with ScalarReader

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

the class TestScalarAccessors method testVarcharRW.

@Test
public void testVarcharRW() {
    TupleMetadata schema = new SchemaBuilder().add("col", MinorType.VARCHAR).buildSchema();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addRow("").addRow("fred").addRow("barney").build();
    assertEquals(3, 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("fred", colReader.getString());
    assertEquals("fred", colReader.getObject());
    assertEquals("\"fred\"", colReader.getAsString());
    assertTrue(reader.next());
    assertEquals("barney", colReader.getString());
    assertEquals("barney", colReader.getObject());
    assertEquals("\"barney\"", 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 52 with ScalarReader

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

the class TestResultSetLoaderMapArray method testDoubleNestedArray.

/**
 * Test a doubly-nested arrays of maps.
 */
@Test
public void testDoubleNestedArray() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addMapArray("m1").add("b", MinorType.INT).addMapArray("m2").add("c", MinorType.INT).addArray("d", MinorType.VARCHAR).resumeMap().resumeSchema().buildSchema();
    ResultSetLoaderImpl.ResultSetOptions options = new OptionBuilder().setSchema(schema).build();
    ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
    RowSetLoader rootWriter = rsLoader.writer();
    rsLoader.startBatch();
    ScalarWriter aWriter = rootWriter.scalar("a");
    ArrayWriter a1Writer = rootWriter.array("m1");
    TupleWriter m1Writer = a1Writer.tuple();
    ScalarWriter bWriter = m1Writer.scalar("b");
    ArrayWriter a2Writer = m1Writer.array("m2");
    TupleWriter m2Writer = a2Writer.tuple();
    ScalarWriter cWriter = m2Writer.scalar("c");
    ScalarWriter dWriter = m2Writer.array("d").scalar();
    for (int i = 0; i < 5; i++) {
        rootWriter.start();
        aWriter.setInt(i);
        for (int j = 0; j < 4; j++) {
            int a1Key = i + 10 + j;
            bWriter.setInt(a1Key);
            for (int k = 0; k < 3; k++) {
                int a2Key = a1Key * 10 + k;
                cWriter.setInt(a2Key);
                for (int l = 0; l < 2; l++) {
                    dWriter.setString("d-" + (a2Key * 10 + l));
                }
                a2Writer.save();
            }
            a1Writer.save();
        }
        rootWriter.save();
    }
    RowSet results = fixture.wrap(rsLoader.harvest());
    RowSetReader reader = results.reader();
    ScalarReader aReader = reader.scalar("a");
    ArrayReader a1Reader = reader.array("m1");
    TupleReader m1Reader = a1Reader.tuple();
    ScalarReader bReader = m1Reader.scalar("b");
    ArrayReader a2Reader = m1Reader.array("m2");
    TupleReader m2Reader = a2Reader.tuple();
    ScalarReader cReader = m2Reader.scalar("c");
    ScalarElementReader dReader = m2Reader.elements("d");
    for (int i = 0; i < 5; i++) {
        reader.next();
        assertEquals(i, aReader.getInt());
        for (int j = 0; j < 4; j++) {
            a1Reader.setPosn(j);
            int a1Key = i + 10 + j;
            assertEquals(a1Key, bReader.getInt());
            for (int k = 0; k < 3; k++) {
                a2Reader.setPosn(k);
                int a2Key = a1Key * 10 + k;
                assertEquals(a2Key, cReader.getInt());
                for (int l = 0; l < 2; l++) {
                    assertEquals("d-" + (a2Key * 10 + l), dReader.getString(l));
                }
            }
        }
    }
    rsLoader.close();
}
Also used : TupleReader(org.apache.drill.exec.vector.accessor.TupleReader) ScalarElementReader(org.apache.drill.exec.vector.accessor.ScalarElementReader) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.test.rowSet.RowSet) ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) ArrayReader(org.apache.drill.exec.vector.accessor.ArrayReader) ResultSetLoader(org.apache.drill.exec.physical.rowSet.ResultSetLoader) TupleWriter(org.apache.drill.exec.vector.accessor.TupleWriter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) RowSetLoader(org.apache.drill.exec.physical.rowSet.RowSetLoader) ArrayWriter(org.apache.drill.exec.vector.accessor.ArrayWriter) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 53 with ScalarReader

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

the class TestScalarAccessors method testNullableString.

@Test
public void testNullableString() {
    BatchSchema batchSchema = new SchemaBuilder().addNullable("col", MinorType.VARCHAR).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow("").addSingleCol(null).addRow("abcd").build();
    assertEquals(3, rs.rowCount());
    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 : 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 54 with ScalarReader

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

the class TestScalarAccessors method longRWTester.

private void longRWTester(MinorType type) {
    BatchSchema batchSchema = new SchemaBuilder().add("col", type).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).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());
    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.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 55 with ScalarReader

use of org.apache.drill.exec.vector.accessor.ScalarReader 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)

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