<jupyter_start><jupyter_text>sparkinactionhw05使用combineByKey，分别将mapSideCombine设置为true和false，并验证mapSideCombine为true时，确实发生了map端combine，而当其为false时，无map端combine。提示：mapSideCombine为true时，map端发生createCombiner，并可能发生mergeValues(如果同一个key有多个值)，reduce端做mergeCombiner。而当mapSideCombine为false时，map端只负责分组数据，reduce端负责createCombiner和mergeValues，无mergeCombiner操作。老师，python的api中：`combineByKey(createCombiner, mergeValue, mergeCombiners, numPartitions=None, partitionFunc=)`没有mapSideCombine这个参数。有点尴尬了。。。故，在这次作业中，我只是做了一个combineByKey的应用实例。望老师见谅！<jupyter_code>import pyspark
from pyspark.sql import SparkSession
#生成SparkSession实例
spark = SparkSession.builder \
     .master("local[*]") \
     .appName("combinebykeytest") \
     .config("spark.some.config.option", "some-value") \
     .getOrCreate()
sc = spark.sparkContext#通过sparkSession获取上下文
x = sc.parallelize([("a", 1), ("b", 1), ("a", 2)])
def to_list(a):
    return [a]

def append(a, b):
    a.append(b)
    return a

def extend(a, b):
    a.extend(b)
    return a

sorted(x.combineByKey(to_list, append, extend).collect())<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12695492180312787, 'fraction_numerical': 0.004599816007359705, 'mean_word_length': 8.379310344827585, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '615001', 'license': 'Apache-2.0', 'n_tokens_mistral': 481, 'n_tokens_neox': 495, 'n_words': 46, 'path': 'pyspark/sparkinaction/sparkinactionhw05.ipynb', 'repo_name': 'mayi140611/mayiexamples', 'size': '1087'}