Search in sources :

Example 36 with SingleRowSet

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

the class TestScalarAccessors method testStringArray.

@Test
public void testStringArray() {
    BatchSchema batchSchema = new SchemaBuilder().addArray("col", MinorType.VARCHAR).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addSingleCol(new String[] {}).addSingleCol(new String[] { "fred", "", "wilma" }).build();
    assertEquals(2, rs.rowCount());
    RowSetReader reader = rs.reader();
    ScalarElementReader colReader = reader.elements(0);
    assertEquals(ValueType.STRING, colReader.valueType());
    assertTrue(reader.next());
    assertEquals(0, colReader.size());
    assertTrue(reader.next());
    assertEquals(3, colReader.size());
    assertEquals("fred", colReader.getString(0));
    assertEquals("", colReader.getString(1));
    assertEquals("wilma", colReader.getString(2));
    assertEquals("fred", colReader.getObject(0));
    assertEquals("", colReader.getObject(1));
    assertEquals("wilma", colReader.getObject(2));
    assertEquals("\"fred\"", colReader.getAsString(0));
    assertEquals("\"\"", colReader.getAsString(1));
    assertEquals("\"wilma\"", colReader.getAsString(2));
    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) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 37 with SingleRowSet

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

the class TestScalarAccessors method testDoubleRW.

@Test
public void testDoubleRW() {
    BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.FLOAT8).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).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.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 38 with SingleRowSet

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

the class TestScalarAccessors method testDecimal18RW.

@Test
public void testDecimal18RW() {
    MajorType type = MajorType.newBuilder().setMinorType(MinorType.DECIMAL18).setScale(3).setPrecision(9).setMode(DataMode.REQUIRED).build();
    BatchSchema batchSchema = new SchemaBuilder().add("col", type).build();
    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(batchSchema).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.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) BigDecimal(java.math.BigDecimal) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 39 with SingleRowSet

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

the class TestScalarAccessors method nullableIntTester.

private void nullableIntTester(MinorType type) {
    BatchSchema batchSchema = new SchemaBuilder().addNullable("col", type).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow(10).addSingleCol(null).addRow(30).build();
    assertEquals(3, rs.rowCount());
    RowSetReader reader = rs.reader();
    ScalarReader colReader = reader.scalar(0);
    assertTrue(reader.next());
    assertFalse(colReader.isNull());
    assertEquals(10, colReader.getInt());
    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.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)

Example 40 with SingleRowSet

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

the class TestScalarAccessors method doubleArrayTester.

private void doubleArrayTester(MinorType type) {
    BatchSchema batchSchema = new SchemaBuilder().addArray("col", type).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addSingleCol(new double[] {}).addSingleCol(new double[] { 0, 20.5, 30.0 }).build();
    assertEquals(2, rs.rowCount());
    RowSetReader reader = rs.reader();
    ScalarElementReader colReader = reader.elements(0);
    assertEquals(ValueType.DOUBLE, colReader.valueType());
    assertTrue(reader.next());
    assertEquals(0, colReader.size());
    assertTrue(reader.next());
    assertEquals(3, colReader.size());
    assertEquals(0, colReader.getDouble(0), 0.00001);
    assertEquals(20.5, colReader.getDouble(1), 0.00001);
    assertEquals(30.0, colReader.getDouble(2), 0.00001);
    assertEquals(0, (double) colReader.getObject(0), 0.00001);
    assertEquals(20.5, (double) colReader.getObject(1), 0.00001);
    assertEquals(30.0, (double) colReader.getObject(2), 0.00001);
    assertEquals("0.0", colReader.getAsString(0));
    assertEquals("20.5", colReader.getAsString(1));
    assertEquals("30.0", colReader.getAsString(2));
    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) RowSetReader(org.apache.drill.test.rowSet.RowSetReader)

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