0
創建JavaPairrRDD我有數據如下格式問題,而使用火花
Product1
somelines...
Iteam1
Iteam2
Product1
somelines....
Iteam1
Iteam3
我需要對作爲
(Product1:Item1,Item2)
(Product1:Item1,Item3)
我試着用下面的Java代碼中創建它(更新了更多的理解)
public static void main(String[] args) {
SparkConf sparkConf = new SparkConf().setAppName("Analyzer").setMaster("local[2]").set("sparkexecutor","1g");
JavaSparkContext ctx = new JavaSparkContext(sparkConf);
JavaPairRDD<String,String> lines = fetchProductData(ctx);
static JavaPairRDD<String, String> fetchProductData(JavaSparkContext ctx) {
JavaRDD<String> productLines = ctx.textFile("C:\\Service.log", 1);
System.out.println("called" + productLines);
JavaRDD<String[]> productLineMap = productLines.map(new Function<String, String[]>() {
String productname = "";
@Override
public String[] call(String s) throws Exception {
System.out.println("test"+s);
Matcher m = PRODUCTREGEX.matcher(s);
if(m.find()){
productname = m.group(1);
System.out.println("productname"+productname);
}
return s.split("\t");
}
});
JavaPairRDD<String, String> productMapKey = productLineMap.mapToPair(new PairFunction<String[], String, String>() {
@Override
public Tuple2<String, String> call(String[] strings) throws Exception {
String[] dataArray = strings[0].split(",");
String date_s = dataArray[5];
return new Tuple2<String, String>(dataArray[4], "product");
}
});
return productMapKey;
}
}
但是我即使是在代碼這種說法是不執行
System.out.println("test"+s);
任何機構可以幫助我在創造對。我正在使用java
你可以把這段代碼放在完整的上下文中('main'方法)嗎? – zero323
@ zero323我更新了代碼。 – sangita