Search in sources :

Example 56 with SchemaBuilder

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

the class TestScalarAccessors method testIntervalArray.

@Test
public void testIntervalArray() {
    BatchSchema batchSchema = new SchemaBuilder().addArray("col", MinorType.INTERVAL).build();
    Period p1 = Period.days(0);
    Period p2 = Period.years(7).plusMonths(8).plusDays(3).plusHours(4).plusMinutes(5).plusSeconds(23);
    Period p3 = Period.years(9999).plusMonths(11).plusDays(365).plusHours(23).plusMinutes(59).plusSeconds(59);
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addSingleCol(new Period[] {}).addSingleCol(new Period[] { p1, p2, p3 }).build();
    assertEquals(2, rs.rowCount());
    RowSetReader reader = rs.reader();
    ScalarElementReader colReader = reader.elements(0);
    assertEquals(ValueType.PERIOD, colReader.valueType());
    assertTrue(reader.next());
    assertEquals(0, colReader.size());
    assertTrue(reader.next());
    assertEquals(3, colReader.size());
    assertEquals(p1, colReader.getPeriod(0).normalizedStandard());
    assertEquals(p2, colReader.getPeriod(1).normalizedStandard());
    assertEquals(p3.normalizedStandard(), colReader.getPeriod(2).normalizedStandard());
    assertEquals(p2, ((Period) colReader.getObject(1)).normalizedStandard());
    assertEquals(p2.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) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) Period(org.joda.time.Period) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 57 with SchemaBuilder

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

the class TestScalarAccessors method testNullableIntervalYear.

@Test
public void testNullableIntervalYear() {
    BatchSchema batchSchema = new SchemaBuilder().addNullable("col", MinorType.INTERVALYEAR).build();
    Period p1 = Period.years(0);
    Period p2 = Period.years(2).plusMonths(3);
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).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());
    assertTrue(reader.next());
    assertTrue(colReader.isNull());
    assertNull(colReader.getPeriod());
    assertNull(colReader.getObject());
    assertEquals("null", colReader.getAsString());
    assertTrue(reader.next());
    assertEquals(p2, colReader.getPeriod());
    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) Period(org.joda.time.Period) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 58 with SchemaBuilder

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

the class TestScalarAccessors method testIntRW.

@Test
public void testIntRW() {
    BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.INT).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).addRow(0).addRow(Integer.MAX_VALUE).addRow(Integer.MIN_VALUE).build();
    assertEquals(3, rs.rowCount());
    RowSetReader reader = rs.reader();
    ScalarReader colReader = reader.scalar(0);
    assertEquals(ValueType.INTEGER, colReader.valueType());
    assertTrue(reader.next());
    assertFalse(colReader.isNull());
    assertEquals(0, reader.scalar(0).getInt());
    assertTrue(reader.next());
    assertEquals(Integer.MAX_VALUE, colReader.getInt());
    assertEquals(Integer.MAX_VALUE, colReader.getObject());
    assertEquals(Integer.toString(Integer.MAX_VALUE), colReader.getAsString());
    assertTrue(reader.next());
    assertEquals(Integer.MIN_VALUE, 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) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 59 with SchemaBuilder

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

the class TestScalarAccessors method testNullableIntervalDay.

@Test
public void testNullableIntervalDay() {
    BatchSchema batchSchema = new SchemaBuilder().addNullable("col", MinorType.INTERVALDAY).build();
    Period p1 = Period.years(0);
    Period p2 = Period.days(3).plusHours(4).plusMinutes(5).plusSeconds(23);
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).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.getPeriod());
    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.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) Period(org.joda.time.Period) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 60 with SchemaBuilder

use of org.apache.drill.test.rowSet.schema.SchemaBuilder 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)

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