Search in sources :

Example 31 with ScalarWriter

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

the class HDF5BatchReader method writeIntListColumn.

/**
 * Helper function to write a 2D int list
 * @param rowWriter the row to which the data will be written
 * @param name the name of the outer list
 * @param list the list of data
 */
private void writeIntListColumn(TupleWriter rowWriter, String name, int[] list) {
    int index = rowWriter.tupleSchema().index(name);
    if (index == -1) {
        ColumnMetadata colSchema = MetadataUtils.newScalar(name, TypeProtos.MinorType.INT, TypeProtos.DataMode.REPEATED);
        index = rowWriter.addColumn(colSchema);
    }
    ScalarWriter arrayWriter = rowWriter.column(index).array().scalar();
    int maxElements = Math.min(list.length, PREVIEW_ROW_LIMIT);
    for (int i = 0; i < maxElements; i++) {
        arrayWriter.setInt(list[i]);
    }
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter)

Example 32 with ScalarWriter

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

the class HDF5BatchReader method writeByteColumn.

/**
 * Helper function to write a 1D byte column
 *
 * @param rowWriter The row to which the data will be written
 * @param name The column name
 * @param value The value to be written
 */
private void writeByteColumn(TupleWriter rowWriter, String name, byte value) {
    ScalarWriter colWriter = getColWriter(rowWriter, name, MinorType.TINYINT);
    colWriter.setInt(value);
}
Also used : ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter)

Example 33 with ScalarWriter

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

the class HDF5BatchReader method writeFloat8ListColumn.

private void writeFloat8ListColumn(TupleWriter rowWriter, String name, double[] list) {
    int index = rowWriter.tupleSchema().index(name);
    if (index == -1) {
        ColumnMetadata colSchema = MetadataUtils.newScalar(name, TypeProtos.MinorType.FLOAT8, TypeProtos.DataMode.REPEATED);
        index = rowWriter.addColumn(colSchema);
    }
    ScalarWriter arrayWriter = rowWriter.column(index).array().scalar();
    int maxElements = Math.min(list.length, PREVIEW_ROW_LIMIT);
    for (int i = 0; i < maxElements; i++) {
        arrayWriter.setDouble(list[i]);
    }
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter)

Example 34 with ScalarWriter

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

the class HDF5BatchReader method doubleMatrixHelper.

private void doubleMatrixHelper(double[][] colData, int cols, int rows, RowSetLoader rowWriter) {
    // This is the case where a dataset is projected in a metadata query.  The result should be a list of lists
    TupleMetadata nestedSchema = new SchemaBuilder().addRepeatedList(DOUBLE_COLUMN_NAME).addArray(TypeProtos.MinorType.FLOAT8).resumeSchema().buildSchema();
    int index = rowWriter.tupleSchema().index(DOUBLE_COLUMN_NAME);
    if (index == -1) {
        index = rowWriter.addColumn(nestedSchema.column(DOUBLE_COLUMN_NAME));
    }
    // The outer array
    ArrayWriter listWriter = rowWriter.column(index).array();
    // The inner array
    ArrayWriter innerWriter = listWriter.array();
    // The strings within the inner array
    ScalarWriter floatWriter = innerWriter.scalar();
    int maxElements = Math.min(colData.length, PREVIEW_ROW_LIMIT);
    int maxCols = Math.min(colData[0].length, PREVIEW_COL_LIMIT);
    for (int i = 0; i < maxElements; i++) {
        for (int k = 0; k < maxCols; k++) {
            floatWriter.setDouble(colData[i][k]);
        }
        listWriter.save();
    }
}
Also used : TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) ArrayWriter(org.apache.drill.exec.vector.accessor.ArrayWriter) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter)

Example 35 with ScalarWriter

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

the class ShpBatchReader method writeStringColumn.

private void writeStringColumn(TupleWriter rowWriter, String name, String value) {
    int index = rowWriter.tupleSchema().index(name);
    if (index == -1) {
        ColumnMetadata colSchema = MetadataUtils.newScalar(name, TypeProtos.MinorType.VARCHAR, TypeProtos.DataMode.OPTIONAL);
        index = rowWriter.addColumn(colSchema);
    }
    ScalarWriter colWriter = rowWriter.scalar(index);
    colWriter.setString(value);
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter)

Aggregations

ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)120 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)69 SubOperatorTest (org.apache.drill.test.SubOperatorTest)68 Test (org.junit.Test)68 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)51 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)44 ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)31 ArrayWriter (org.apache.drill.exec.vector.accessor.ArrayWriter)26 RowSetLoader (org.apache.drill.exec.physical.resultSet.RowSetLoader)25 ResultSetLoader (org.apache.drill.exec.physical.resultSet.ResultSetLoader)24 TupleWriter (org.apache.drill.exec.vector.accessor.TupleWriter)23 ArrayReader (org.apache.drill.exec.vector.accessor.ArrayReader)22 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)21 ExtendableRowSet (org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet)19 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)18 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)17 TupleReader (org.apache.drill.exec.vector.accessor.TupleReader)17 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)14 RowSetReader (org.apache.drill.test.rowSet.RowSetReader)14 ResultSetLoader (org.apache.drill.exec.physical.rowSet.ResultSetLoader)13