我在Scala中使用spark库.我已经创建了一个DataFrame
val searchArr = Array(
StructField("log",IntegerType,true),
StructField("user", StructType(Array(
StructField("date",StringType,true),
StructField("ua",StringType,true),
StructField("ui",LongType,true))),true),
StructField("what",StructType(Array(
StructField("q1",ArrayType(IntegerType, true),true),
StructField("q2",ArrayType(IntegerType, true),true),
StructField("sid",StringType,true),
StructField("url",StringType,true))),true),
StructField("where",StructType(Array(
StructField("o1",IntegerType,true),
StructField("o2",IntegerType,true))),true)
)
val searchSt = new StructType(searchArr)
val searchData = sqlContext.jsonFile(searchPath, searchSt)
Run Code Online (Sandbox Code Playgroud)
我现在要爆炸什么东西what.q1,它应该包含一个整数数组,但文档是有限的:http://spark.apache.org/docs/1.4.0/api/java/org/apache/ 火花/ SQL/DataFrame.html#爆炸(java.lang.String中,%20java.lang.String,%20scala.Function1,%20scala.reflect.api.TypeTags.TypeTag)
到目前为止,我尝试了一些没有太多运气的东西
val searchSplit = searchData.explode("q1", "rb")(q1 => q1.getList[Int](0).toArray())
Run Code Online (Sandbox Code Playgroud)
有关如何使用爆炸的任何想法/示例?
我试图在ArrayList对象中排序日期.为此,我使用sort其中dateList是我的ArrayList对象:
Collections.sort(dateList, new DateComparator());
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下Comparator类执行此操作:
class DateComparator implements Comparator {
int compare(Object a, Object b) {
Date x = (Date) a;
Date y = (Date) b;
if (x > y) {
return 1;}
else if (x == y) {
return 0;}
else if (x < y) {
return 1;
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这给了我以下错误:
1)无法实现比较(T,T) - 尝试分配较弱的访问权限; 是公共的,其中T扩展Object在接口Comparator中声明
2)二元运算符'>'的坏操作数类型:if(x> y){first type:Date second type:Date
3)二元运算符'<'的坏操作数类型:else if(x
什么是错的任何想法?
干杯