本文整理汇总了Java中org.datavec.spark.transform.misc.WritablesToStringFunction类的典型用法代码示例。如果您正苦于以下问题:Java WritablesToStringFunction类的具体用法?Java WritablesToStringFunction怎么用?Java WritablesToStringFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WritablesToStringFunction类属于org.datavec.spark.transform.misc包,在下文中一共展示了WritablesToStringFunction类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exportCSVLocal
import org.datavec.spark.transform.misc.WritablesToStringFunction; //导入依赖的package包/类
public static void exportCSVLocal(String outputDir, String baseFileName, int numFiles, String delimiter,
String quote, JavaRDD<List<Writable>> data, int rngSeed) throws Exception {
JavaRDD<String> lines = data.map(new WritablesToStringFunction(delimiter, quote));
double[] split = new double[numFiles];
for (int i = 0; i < split.length; i++)
split[i] = 1.0 / numFiles;
JavaRDD<String>[] splitData = lines.randomSplit(split);
int count = 0;
Random r = new Random(rngSeed);
for (JavaRDD<String> subset : splitData) {
String path = FilenameUtils.concat(outputDir, baseFileName + (count++) + ".csv");
List<String> linesList = subset.collect();
if (!(linesList instanceof ArrayList))
linesList = new ArrayList<>(linesList);
Collections.shuffle(linesList, r);
FileUtils.writeLines(new File(path), linesList);
}
}
示例2: exportCSVSpark
import org.datavec.spark.transform.misc.WritablesToStringFunction; //导入依赖的package包/类
public static void exportCSVSpark(String directory, String delimiter, String quote, int outputSplits,
JavaRDD<List<Writable>> data) {
//NOTE: Order is probably not random here...
JavaRDD<String> lines = data.map(new WritablesToStringFunction(delimiter, quote));
lines.coalesce(outputSplits);
lines.saveAsTextFile(directory);
}
示例3: testWritablesToString
import org.datavec.spark.transform.misc.WritablesToStringFunction; //导入依赖的package包/类
@Test
public void testWritablesToString() throws Exception {
List<Writable> l = Arrays.<Writable>asList(new DoubleWritable(1.5), new Text("someValue"));
String expected = l.get(0).toString() + "," + l.get(1).toString();
assertEquals(expected, new WritablesToStringFunction(",").call(l));
}