Search in sources :

Example 51 with SchemaBuilder

use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.

the class TestCsv method testValidCsvHeaders.

@Test
public void testValidCsvHeaders() throws IOException {
    String fileName = "case2.csv";
    buildFile(fileName, validHeaders);
    RowSet actual = client.queryBuilder().sql(makeStatement(fileName)).rowSet();
    BatchSchema expectedSchema = new SchemaBuilder().add("a", MinorType.VARCHAR).add("b", MinorType.VARCHAR).add("c", MinorType.VARCHAR).build();
    RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow("10", "foo", "bar").build();
    new RowSetComparison(expected).verifyAndClearAll(actual);
}
Also used : RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) BatchSchema(org.apache.drill.exec.record.BatchSchema) RowSet(org.apache.drill.test.rowSet.RowSet) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Example 52 with SchemaBuilder

use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.

the class TestScalarAccessors method decimalArrayTester.

private void decimalArrayTester(MinorType type, int precision) {
    MajorType majorType = MajorType.newBuilder().setMinorType(type).setScale(3).setPrecision(precision).setMode(DataMode.REPEATED).build();
    BatchSchema batchSchema = new SchemaBuilder().add("col", majorType).build();
    BigDecimal v1 = BigDecimal.ZERO;
    BigDecimal v2 = BigDecimal.valueOf(123_456_789, 3);
    BigDecimal v3 = BigDecimal.TEN;
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addSingleCol(new BigDecimal[] {}).addSingleCol(new BigDecimal[] { v1, v2, v3 }).build();
    assertEquals(2, rs.rowCount());
    RowSetReader reader = rs.reader();
    ScalarElementReader colReader = reader.elements(0);
    assertEquals(ValueType.DECIMAL, colReader.valueType());
    assertTrue(reader.next());
    assertEquals(0, colReader.size());
    assertTrue(reader.next());
    assertEquals(3, colReader.size());
    assertEquals(0, v1.compareTo(colReader.getDecimal(0)));
    assertEquals(0, v2.compareTo(colReader.getDecimal(1)));
    assertEquals(0, v3.compareTo(colReader.getDecimal(2)));
    assertEquals(0, v2.compareTo((BigDecimal) colReader.getObject(1)));
    assertEquals(v2.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) 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)

Example 53 with SchemaBuilder

use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.

the class TestScalarAccessors method longArrayTester.

private void longArrayTester(MinorType type) {
    BatchSchema batchSchema = new SchemaBuilder().addArray("col", type).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addSingleCol(new long[] {}).addSingleCol(new long[] { 0, 20, 30 }).build();
    assertEquals(2, rs.rowCount());
    RowSetReader reader = rs.reader();
    ScalarElementReader colReader = reader.elements(0);
    assertEquals(ValueType.LONG, colReader.valueType());
    assertTrue(reader.next());
    assertEquals(0, colReader.size());
    assertTrue(reader.next());
    assertEquals(3, colReader.size());
    assertEquals(0, colReader.getLong(0));
    assertEquals(20, colReader.getLong(1));
    assertEquals(30, colReader.getLong(2));
    assertEquals(0L, colReader.getObject(0));
    assertEquals(20L, colReader.getObject(1));
    assertEquals(30L, colReader.getObject(2));
    assertEquals("0", colReader.getAsString(0));
    assertEquals("20", colReader.getAsString(1));
    assertEquals("30", 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)

Example 54 with SchemaBuilder

use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.

the class TestScalarAccessors method nullableDecimalTester.

private void nullableDecimalTester(MinorType type, int precision) {
    MajorType majorType = MajorType.newBuilder().setMinorType(type).setScale(3).setPrecision(precision).setMode(DataMode.OPTIONAL).build();
    BatchSchema batchSchema = new SchemaBuilder().add("col", majorType).build();
    BigDecimal v1 = BigDecimal.ZERO;
    BigDecimal v2 = BigDecimal.valueOf(123_456_789, 3);
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow(v1).addSingleCol(null).addRow(v2).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());
    assertTrue(colReader.isNull());
    assertNull(colReader.getObject());
    assertEquals("null", colReader.getAsString());
    assertTrue(reader.next());
    assertEquals(0, v2.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)

Example 55 with SchemaBuilder

use of org.apache.drill.test.rowSet.schema.SchemaBuilder in project drill by axbaretto.

the class TestScalarAccessors method nullableDoubleTester.

private void nullableDoubleTester(MinorType type) {
    BatchSchema batchSchema = new SchemaBuilder().addNullable("col", type).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow(10F).addSingleCol(null).addRow(30F).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.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)

Aggregations

SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)175 Test (org.junit.Test)154 BatchSchema (org.apache.drill.exec.record.BatchSchema)102 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)91 SubOperatorTest (org.apache.drill.test.SubOperatorTest)86 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)65 RowSet (org.apache.drill.test.rowSet.RowSet)52 RowSetReader (org.apache.drill.test.rowSet.RowSetReader)50 ResultSetLoader (org.apache.drill.exec.physical.rowSet.ResultSetLoader)38 RowSetLoader (org.apache.drill.exec.physical.rowSet.RowSetLoader)38 ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)26 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)25 DrillTest (org.apache.drill.test.DrillTest)21 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)20 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)18 RowSetBuilder (org.apache.drill.test.rowSet.RowSetBuilder)18 ScalarElementReader (org.apache.drill.exec.vector.accessor.ScalarElementReader)17 AbstractColumnMetadata (org.apache.drill.exec.record.metadata.AbstractColumnMetadata)16 TupleWriter (org.apache.drill.exec.vector.accessor.TupleWriter)16 RecordBatch (org.apache.drill.exec.record.RecordBatch)14