spark-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Dang <nam...@gmail.com>
Subject Converting an InternalRow to a Row
Date Wed, 04 Jan 2017 19:27:15 GMT
Hi all,
(cc-ing dev since I've hit some developer API corner)

What's the best way to convert an InternalRow to a Row if I've got an
InternalRow and the corresponding Schema.

Code snippet:
    @Test
    public void foo() throws Exception {
        Row row = RowFactory.create(1);
        StructType struct = new StructType().add("id",
DataTypes.IntegerType);
        ExpressionEncoder<Row> enconder = RowEncoder.apply(struct);
        InternalRow internalRow = enconder.toRow(row);
        System.out.println("Internal row size: " + internalRow.numFields());
        Row roundTrip = enconder.fromRow(internalRow);
        System.out.println("Round trip: " + roundTrip.size());
    }

The code fails at the line encoder.fromRow() with the exception:
> Caused by: java.lang.UnsupportedOperationException: Cannot evaluate
expression: getcolumnbyordinal(0, IntegerType)

-------
Regards,
Andy

Mime
View raw message