Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
自定义分区&;Scala在Spark中的排序_Scala_Apache Spark_Apache Spark Sql - Fatal编程技术网

自定义分区&;Scala在Spark中的排序

自定义分区&;Scala在Spark中的排序,scala,apache-spark,apache-spark-sql,Scala,Apache Spark,Apache Spark Sql,我需要在Spark数据帧上应用自定义分区和排序。[据我目前所知,不经过RDD是不可能的,RDD和Dataframe之间的转换是有代价的]。我的计划是在PairRDD上使用repartitionAndSortWithinPartitions方法。有没有更好的办法 在尝试使用“重新分区和SortWithinPartitions”时,我面临的问题如下: 我的数据框是 val df = dataset.select(AbstractRecordProvider .getKeyUDF(spar

我需要在Spark数据帧上应用自定义分区和排序。[据我目前所知,不经过RDD是不可能的,RDD和Dataframe之间的转换是有代价的]。我的计划是在PairRDD上使用repartitionAndSortWithinPartitions方法。有没有更好的办法

在尝试使用“重新分区和SortWithinPartitions”时,我面临的问题如下:

我的数据框是

val df = dataset.select(AbstractRecordProvider
      .getKeyUDF(sparkArguments.getDatasetArguments)
        (col(hashKeyName), lit(null)).as("key"), to_json(struct(dataset.columns.map(col): _*)).as("value"))
getKeyUDF返回'Byte[Array]&to_json返回'String',因此基本上df的模式如下

root
 |-- key: binary (nullable = true)
 |-- value: string (nullable = true)
我的自定义顺序定义为::

类词典编纂规则扩展了排序[数组[字节]]

我有一个自定义分区器,定义为::

class XXHashRangeBasedPartitioner(partitions:Int)扩展了分区器

我将自定义排序设置为数组[Byte]的隐式排序

隐式val排序:排序[Array[Byte]]=new-LexicographicalOrdering

我面临的挑战是如何应用“”。我知道重新分区和SortWithinPartition只能应用于PairRDD。但是,

val pairRDD = df.rdd.map(record => (record.get(0),record.get(1))).repartitionAndSortWithinPartitions(new XXHashRangeBasedPartitioner(10))
导致错误

错误:value-repartitionAndSortWithinPartitions不是org.apache.spark.rdd.rdd[(任何,任何)]的成员。

我想我应该让RDD的类型为RDD[(数组[Byte],String)],而不是RDD[(Any,Any)],因为“提到”它们将与作用域中具有隐式排序[K]的任何键类型K一起工作。我有一个隐式排序[Array[Byte]]

如何将RDD[(Any,Any)]转换为RDD[Array[Byte],String]或首先从现有的数据帧中获取RDD[Array[Byte],String]

==编辑==

我可以使用“asInstanceOf”进行打字

val partitionedDf = df.rdd.map(record => (record.get(0).asInstanceOf[Array[Byte]],record.get(1).asInstanceOf[String])).repartitionAndSortWithinPartitions(new XXHashRangeBasedPartitioner(sparkArguments.getPartitionConfigurationArguments.getNumberOfPartitions))
有没有比我上面所做的更好或更有效的方法来实现“自定义分区和排序”