Search in sources :

Example 1 with AbstractTupleWriter

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

the class DummyWriterTest method testDummyMap.

/**
 * Test a dummy map or map array. A (non-enforced) rule is that such maps
 * contain only dummy writers. The writers act like "real" writers.
 */
@Test
public void testDummyMap() {
    TupleMetadata schema = new SchemaBuilder().addMap("m1").add("a", MinorType.INT).addArray("b", MinorType.VARCHAR).resumeSchema().addMapArray("m2").add("c", MinorType.INT).resumeSchema().buildSchema();
    List<AbstractObjectWriter> writers = new ArrayList<>();
    {
        schema.metadata("m1").setProjected(false);
        TupleMetadata mapSchema = schema.metadata("m1").mapSchema();
        List<AbstractObjectWriter> members = new ArrayList<>();
        members.add(ColumnWriterFactory.buildColumnWriter(mapSchema.metadata("a"), null));
        members.add(ColumnWriterFactory.buildColumnWriter(mapSchema.metadata("b"), null));
        writers.add(ColumnWriterFactory.buildMapWriter(schema.metadata("m1"), null, members));
    }
    {
        schema.metadata("m2").setProjected(false);
        TupleMetadata mapSchema = schema.metadata("m2").mapSchema();
        List<AbstractObjectWriter> members = new ArrayList<>();
        members.add(ColumnWriterFactory.buildColumnWriter(mapSchema.metadata("c"), null));
        writers.add(ColumnWriterFactory.buildMapWriter(schema.metadata("m2"), null, members));
    }
    AbstractTupleWriter rootWriter = new RootWriterFixture(schema, writers);
    // Events are ignored.
    rootWriter.startWrite();
    rootWriter.startRow();
    // Dummy columns seem real.
    rootWriter.tuple("m1").scalar("a").setInt(20);
    rootWriter.tuple(0).array("b").scalar().setString("foo");
    // Dummy array map seems real.
    rootWriter.array("m2").tuple().scalar("c").setInt(30);
    rootWriter.array("m2").save();
    rootWriter.array(1).tuple().scalar(0).setInt(40);
    rootWriter.array(1).save();
    // More ignored events.
    rootWriter.restartRow();
    rootWriter.saveRow();
    rootWriter.endWrite();
}
Also used : AbstractTupleWriter(org.apache.drill.exec.vector.accessor.writer.AbstractTupleWriter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 2 with AbstractTupleWriter

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

the class TestDummyWriter method testDummyDict.

@Test
public void testDummyDict() {
    final String dictName = "d";
    final String dictArrayName = "da";
    TupleMetadata schema = new SchemaBuilder().addDict(dictName, MinorType.INT).repeatedValue(MinorType.VARCHAR).resumeSchema().addDictArray(dictArrayName, MinorType.VARCHAR).value(MinorType.INT).resumeSchema().buildSchema();
    List<AbstractObjectWriter> writers = new ArrayList<>();
    final String keyFieldName = DictVector.FIELD_KEY_NAME;
    final String valueFieldName = DictVector.FIELD_VALUE_NAME;
    // Create key and value writers for dict
    ColumnMetadata dictMetadata = schema.metadata(dictName);
    TupleMetadata dictSchema = dictMetadata.tupleSchema();
    List<AbstractObjectWriter> dictFields = new ArrayList<>();
    dictFields.add(ColumnWriterFactory.buildColumnWriter(dictSchema.metadata(keyFieldName), null));
    dictFields.add(ColumnWriterFactory.buildColumnWriter(dictSchema.metadata(valueFieldName), null));
    writers.add(ObjectDictWriter.buildDict(dictMetadata, null, dictFields));
    // Create key and value writers for dict array
    ColumnMetadata dictArrayMetadata = schema.metadata(dictArrayName);
    TupleMetadata dictArraySchema = dictArrayMetadata.tupleSchema();
    List<AbstractObjectWriter> dictArrayFields = new ArrayList<>();
    dictArrayFields.add(ColumnWriterFactory.buildColumnWriter(dictArraySchema.metadata(keyFieldName), null));
    dictArrayFields.add(ColumnWriterFactory.buildColumnWriter(dictArraySchema.metadata(valueFieldName), null));
    writers.add(ObjectDictWriter.buildDictArray(dictArrayMetadata, null, dictArrayFields));
    AbstractTupleWriter rootWriter = new RootWriterFixture(schema, writers);
    // Events are ignored.
    rootWriter.startWrite();
    rootWriter.startRow();
    // Nothing is projected
    DictWriter dictWriter = rootWriter.dict(dictName);
    assertFalse(dictWriter.isProjected());
    assertFalse(dictWriter.keyWriter().isProjected());
    assertFalse(dictWriter.valueWriter().array().scalar().isProjected());
    DictWriter dictWriter1 = rootWriter.array(dictArrayName).dict();
    assertFalse(dictWriter1.isProjected());
    assertFalse(dictWriter1.keyWriter().isProjected());
    assertFalse(dictWriter1.valueWriter().scalar().isProjected());
    // Dummy columns seem real.
    rootWriter.dict(dictName).keyWriter().setInt(20);
    rootWriter.dict(0).valueWriter().array().scalar().setString("foo");
    // Dummy array dict seems real.
    rootWriter.array(dictArrayName).dict().keyWriter().setString("foo");
    rootWriter.array(dictArrayName).dict().valueWriter().scalar().setInt(30);
    rootWriter.array(dictArrayName).save();
    rootWriter.array(1).dict().keyWriter().setString("bar");
    rootWriter.array(1).dict().valueWriter().scalar().setInt(40);
    rootWriter.array(1).save();
    // More ignored events.
    rootWriter.restartRow();
    rootWriter.saveRow();
    rootWriter.endWrite();
}
Also used : AbstractTupleWriter(org.apache.drill.exec.vector.accessor.writer.AbstractTupleWriter) ObjectDictWriter(org.apache.drill.exec.vector.accessor.writer.ObjectDictWriter) DictWriter(org.apache.drill.exec.vector.accessor.DictWriter) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) ArrayList(java.util.ArrayList) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 3 with AbstractTupleWriter

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

the class TestDummyWriter method testDummyScalar.

/**
 * Test dummy column writers for scalars and arrays of
 * scalars.
 */
@Test
public void testDummyScalar() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addArray("b", MinorType.VARCHAR).buildSchema();
    List<AbstractObjectWriter> writers = new ArrayList<>();
    // We provide no vector. Factory should build us "dummy" writers.
    writers.add(ColumnWriterFactory.buildColumnWriter(schema.metadata("a"), null));
    writers.add(ColumnWriterFactory.buildColumnWriter(schema.metadata("b"), null));
    AbstractTupleWriter rootWriter = new RootWriterFixture(schema, writers);
    // Events are ignored.
    rootWriter.startWrite();
    rootWriter.startRow();
    // At present, dummy writers report no type (because they don't have one.)
    assertEquals(ValueType.NULL, rootWriter.scalar(0).valueType());
    // First column. Set int value.
    rootWriter.scalar(0).setInt(10);
    // Dummy writer does not do type checking. Write "wrong" type.
    // Should be allowed.
    rootWriter.scalar("a").setString("foo");
    // Column is required, but writer does no checking. Can set
    // a null value.
    rootWriter.column(0).scalar().setNull();
    // Second column: is an array.
    rootWriter.array(1).scalar().setString("bar");
    rootWriter.array(1).scalar().setString("mumble");
    // Again, type is not checked.
    rootWriter.array("b").scalar().setInt(200);
    // More ignored events.
    rootWriter.restartRow();
    rootWriter.saveRow();
    rootWriter.endWrite();
}
Also used : AbstractTupleWriter(org.apache.drill.exec.vector.accessor.writer.AbstractTupleWriter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) ArrayList(java.util.ArrayList) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 4 with AbstractTupleWriter

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

the class TestDummyWriter method testDummyMap.

/**
 * Test a dummy map or map array. A (non-enforced) rule is that such maps
 * contain only dummy writers. The writers act like "real" writers.
 */
@Test
public void testDummyMap() {
    TupleMetadata schema = new SchemaBuilder().addMap("m1").add("a", MinorType.INT).addArray("b", MinorType.VARCHAR).resumeSchema().addMapArray("m2").add("c", MinorType.INT).resumeSchema().buildSchema();
    List<AbstractObjectWriter> writers = new ArrayList<>();
    // Create the writers
    {
        TupleMetadata mapSchema = schema.metadata("m1").tupleSchema();
        List<AbstractObjectWriter> members = new ArrayList<>();
        members.add(ColumnWriterFactory.buildColumnWriter(mapSchema.metadata("a"), null));
        members.add(ColumnWriterFactory.buildColumnWriter(mapSchema.metadata("b"), null));
        writers.add(MapWriter.buildMapWriter(schema.metadata("m1"), null, members));
    }
    {
        TupleMetadata mapSchema = schema.metadata("m2").tupleSchema();
        List<AbstractObjectWriter> members = new ArrayList<>();
        members.add(ColumnWriterFactory.buildColumnWriter(mapSchema.metadata("c"), null));
        writers.add(MapWriter.buildMapWriter(schema.metadata("m2"), null, members));
    }
    AbstractTupleWriter rootWriter = new RootWriterFixture(schema, writers);
    // Events are ignored.
    rootWriter.startWrite();
    rootWriter.startRow();
    // Nothing is projected
    assertFalse(rootWriter.tuple("m1").isProjected());
    assertFalse(rootWriter.tuple("m1").scalar("a").isProjected());
    assertFalse(rootWriter.tuple("m1").array("b").isProjected());
    assertFalse(rootWriter.array("m2").isProjected());
    assertFalse(rootWriter.array("m2").tuple().isProjected());
    assertFalse(rootWriter.array("m2").tuple().scalar("c").isProjected());
    // Dummy columns seem real.
    rootWriter.tuple("m1").scalar("a").setInt(20);
    rootWriter.tuple(0).array("b").scalar().setString("foo");
    // Dummy array map seems real.
    rootWriter.array("m2").tuple().scalar("c").setInt(30);
    rootWriter.array("m2").save();
    rootWriter.array(1).tuple().scalar(0).setInt(40);
    rootWriter.array(1).save();
    // More ignored events.
    rootWriter.restartRow();
    rootWriter.saveRow();
    rootWriter.endWrite();
}
Also used : AbstractTupleWriter(org.apache.drill.exec.vector.accessor.writer.AbstractTupleWriter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 5 with AbstractTupleWriter

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

the class DummyWriterTest method testDummyScalar.

/**
 * Test dummy column writers for scalars and arrays of
 * scalars.
 */
@Test
public void testDummyScalar() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addArray("b", MinorType.VARCHAR).buildSchema();
    List<AbstractObjectWriter> writers = new ArrayList<>();
    // We provide no vector. Factory should build us "dummy" writers.
    writers.add(ColumnWriterFactory.buildColumnWriter(schema.metadata("a"), null));
    writers.add(ColumnWriterFactory.buildColumnWriter(schema.metadata("b"), null));
    AbstractTupleWriter rootWriter = new RootWriterFixture(schema, writers);
    // Events are ignored.
    rootWriter.startWrite();
    rootWriter.startRow();
    // At present, dummy writers report no type (because they don't have one.)
    assertNull(rootWriter.scalar(0).valueType());
    // First column. Set int value.
    rootWriter.scalar(0).setInt(10);
    // Dummy writer does not do type checking. Write "wrong" type.
    // Should be allowed.
    rootWriter.scalar("a").setString("foo");
    // Column is required, but writer does no checking. Can set
    // a null value.
    rootWriter.column(0).scalar().setNull();
    // Second column: is an array.
    rootWriter.array(1).scalar().setString("bar");
    rootWriter.array(1).scalar().setString("mumble");
    // Again, type is not checked.
    rootWriter.array("b").scalar().setInt(200);
    // More ignored events.
    rootWriter.restartRow();
    rootWriter.saveRow();
    rootWriter.endWrite();
}
Also used : AbstractTupleWriter(org.apache.drill.exec.vector.accessor.writer.AbstractTupleWriter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) ArrayList(java.util.ArrayList) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)5 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)5 AbstractObjectWriter (org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter)5 AbstractTupleWriter (org.apache.drill.exec.vector.accessor.writer.AbstractTupleWriter)5 SubOperatorTest (org.apache.drill.test.SubOperatorTest)5 Test (org.junit.Test)5 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)3 List (java.util.List)2 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)2 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)1 DictWriter (org.apache.drill.exec.vector.accessor.DictWriter)1 ObjectDictWriter (org.apache.drill.exec.vector.accessor.writer.ObjectDictWriter)1