package org.datavec.spark.transform;

import org.datavec.api.transform.TransformProcess;
import org.datavec.api.transform.schema.Schema;
import org.datavec.api.writable.DoubleWritable;
import org.datavec.api.writable.Text;
import org.datavec.api.writable.Writable;
import org.datavec.spark.transform.model.Base64NDArrayBody;
import org.datavec.spark.transform.model.CSVRecord;
import org.junit.Test;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.serde.base64.Nd4jBase64;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by agibsonccc on 12/24/16.
 */
public class CSVSparkTransformerTest {
    @Test
    public void testTransformer() throws Exception {
        List<Writable> input = new ArrayList<>();
        input.add(new DoubleWritable(1.0));
        input.add(new DoubleWritable(2.0));

        Schema schema = new Schema.Builder()
                .addColumnDouble("1.0").addColumnDouble("2.0").build();
        List<Writable> output = new ArrayList<>();
        output.add(new Text("1.0"));
        output.add(new Text("2.0"));

        TransformProcess transformProcess = new TransformProcess.Builder(schema).convertToString("1.0").convertToString("2.0").build();
        CSVSparkTransform csvSparkTransform = new CSVSparkTransform(transformProcess);
        String[] values = new String[] {"1.0","2.0"};
        CSVRecord record = csvSparkTransform.transform(new CSVRecord(values));
        Base64NDArrayBody body = csvSparkTransform.toArray(new CSVRecord(values));
        INDArray fromBase64 = Nd4jBase64.fromBase64(body.getNdarray());
        System.out.println("Base 64ed array " + fromBase64);

    }

}

@@ -318,16 +318,70 @@
 ayBody;%0A
+import org.datavec.spark.transform.model.BatchRecord;%0A
 import o
@@ -416,32 +416,32 @@
 odel.CSVRecord;%0A
-
 import org.junit
@@ -586,16 +586,60 @@
 .List;%0A%0A
+import static org.junit.Assert.assertTrue;%0A%0A
 /**%0A * C
@@ -1667,24 +1667,67 @@
 Ndarray());%0A
+        assertTrue(fromBase64.isVector());%0A
         Syst
@@ -1780,13 +1780,1280 @@
 );%0A%0A
-
     %7D%0A%0A
+    @Test%0A    public void testTransformerBatch() throws Exception %7B%0A        List%3CWritable%3E input = new ArrayList%3C%3E();%0A        input.add(new DoubleWritable(1.0));%0A        input.add(new DoubleWritable(2.0));%0A%0A        Schema schema = new Schema.Builder()%0A                .addColumnDouble(%221.0%22).addColumnDouble(%222.0%22).build();%0A        List%3CWritable%3E output = new ArrayList%3C%3E();%0A        output.add(new Text(%221.0%22));%0A        output.add(new Text(%222.0%22));%0A%0A        TransformProcess transformProcess = new TransformProcess.Builder(schema).convertToString(%221.0%22).convertToString(%222.0%22).build();%0A        CSVSparkTransform csvSparkTransform = new CSVSparkTransform(transformProcess);%0A        String%5B%5D values = new String%5B%5D %7B%221.0%22,%222.0%22%7D;%0A        CSVRecord record = csvSparkTransform.transform(new CSVRecord(values));%0A        BatchRecord batchRecord = new BatchRecord();%0A        for(int i = 0; i %3C 3; i++)%0A            batchRecord.add(record);%0A        BatchRecord batchRecord1 = csvSparkTransform.transform(batchRecord);%0A        Base64NDArrayBody body = csvSparkTransform.toArray(batchRecord1);%0A        INDArray fromBase64 = Nd4jBase64.fromBase64(body.getNdarray());%0A        assertTrue(fromBase64.isMatrix());%0A        System.out.println(%22Base 64ed array %22 + fromBase64);%0A%0A    %7D%0A%0A%0A
 %7D%0A

add test