Search in sources :

Example 1 with GenericRow

use of org.apache.spark.sql.catalyst.expressions.GenericRow in project zeppelin by apache.

the class Spark2Shims method getAsDataFrame.

@Override
public Dataset<Row> getAsDataFrame(String value) {
    String[] lines = value.split("\\n");
    String head = lines[0];
    String[] columns = head.split("\t");
    StructType schema = new StructType();
    for (String column : columns) {
        schema = schema.add(column, "String");
    }
    List<Row> rows = new ArrayList<>();
    for (int i = 1; i < lines.length; ++i) {
        String[] tokens = lines[i].split("\t");
        Row row = new GenericRow(tokens);
        rows.add(row);
    }
    return sparkSession.createDataFrame(rows, schema);
}
Also used : GenericRow(org.apache.spark.sql.catalyst.expressions.GenericRow) StructType(org.apache.spark.sql.types.StructType) ArrayList(java.util.ArrayList) GenericRow(org.apache.spark.sql.catalyst.expressions.GenericRow) Row(org.apache.spark.sql.Row)

Example 2 with GenericRow

use of org.apache.spark.sql.catalyst.expressions.GenericRow in project zeppelin by apache.

the class Spark3Shims method getAsDataFrame.

@Override
public Dataset<Row> getAsDataFrame(String value) {
    String[] lines = value.split("\\n");
    String head = lines[0];
    String[] columns = head.split("\t");
    StructType schema = new StructType();
    for (String column : columns) {
        schema = schema.add(column, "String");
    }
    List<Row> rows = new ArrayList<>();
    for (int i = 1; i < lines.length; ++i) {
        String[] tokens = lines[i].split("\t");
        Row row = new GenericRow(tokens);
        rows.add(row);
    }
    return sparkSession.createDataFrame(rows, schema);
}
Also used : GenericRow(org.apache.spark.sql.catalyst.expressions.GenericRow) StructType(org.apache.spark.sql.types.StructType) ArrayList(java.util.ArrayList) GenericRow(org.apache.spark.sql.catalyst.expressions.GenericRow) Row(org.apache.spark.sql.Row)

Aggregations

ArrayList (java.util.ArrayList)2 Row (org.apache.spark.sql.Row)2 GenericRow (org.apache.spark.sql.catalyst.expressions.GenericRow)2 StructType (org.apache.spark.sql.types.StructType)2