本文整理汇总了Python中pyspark.SparkContext.binaryRecords方法的典型用法代码示例。如果您正苦于以下问题:Python SparkContext.binaryRecords方法的具体用法?Python SparkContext.binaryRecords怎么用?Python SparkContext.binaryRecords使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyspark.SparkContext
的用法示例。
在下文中一共展示了SparkContext.binaryRecords方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SparkContext
# 需要导入模块: from pyspark import SparkContext [as 别名]
# 或者: from pyspark.SparkContext import binaryRecords [as 别名]
from pyspark import SparkConf, SparkContext
conf = (SparkConf()
.setMaster("local[4]")
.setAppName("MyApp")
.set("spark.executor.memory", "1g")
.set('spark.local.dir', './target/tmp'))
sc = SparkContext(conf = conf)
def test(a):
print 'a', a
words = sc.binaryRecords("./gen/data/nums", 3)
words = words.map(test)
words.saveAsTextFile('./target/result3')
sc.stop()
示例2: len
# 需要导入模块: from pyspark import SparkContext [as 别名]
# 或者: from pyspark.SparkContext import binaryRecords [as 别名]
outfilename=basedir+"/reducemap_binary_output-"+str(idx).zfill(2)+".bin"
outfile=open(outfilename,'w')
for x in iterator:
outfile.write(str(x[1].data))
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: simple_reducemap <fileA> <fileB>", file=sys.stderr)
exit(-1)
sc = SparkContext(appName="SimpleReduceMap")
#todo: https://spark.apache.org/docs/latest/configuration.html#spark-properties
# conf.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
linesA = sc.binaryRecords(sys.argv[1],24)
A = linesA.mapPartitionsWithIndex(parseVectorFunctor(linesA.getNumPartitions()),True).cache()
A.getStorageLevel()
print(A.getStorageLevel())
linesB = sc.binaryRecords(sys.argv[2],24)
B = linesB.mapPartitionsWithIndex(parseVectorFunctor(linesB.getNumPartitions()),True).cache()
C = A.union(B).cache()
D = C.reduceByKey(dot_vec3).cache()
print("numPartitions(%d,%s): %d"%(D.id(),D.name(),D.getNumPartitions()))
#D.foreach(lambda v: print(str(v)))
D.getStorageLevel()
print(D.getStorageLevel())
示例3: add_vec3
# 需要导入模块: from pyspark import SparkContext [as 别名]
# 或者: from pyspark.SparkContext import binaryRecords [as 别名]
return lambda p: add_vec3(p,shift)
def savebin(iterator):
basedir='/tmp' #'/mnt'
idx=len(glob(basedir+'/binary_output*.bin'))
outfilename=basedir+"/binary_output-"+str(idx).zfill(2)+".bin"
outfile=open(outfilename,'w')
for x in iterator:
outfile.write(x.data)
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: simple_map <file>", file=sys.stderr)
exit(-1)
sc = SparkContext(appName="SimpleMap")
lines = sc.binaryRecords(sys.argv[1],24) #three doubles per vector (record)
A = lines.map(parseVector) # is .cache() this causing unnecessary/redundant processing when memory is overflowed? At least for this case, cache isn't needed anyway. Basically, I'm afraid that calling cache with insufficient memory performs computation to create the cache entry, which then pushes previous entries out. In the end, when the data is actually used it needs to be computed again. As my pappy always told me, "be careful with cache!"
print("numPartitions(%d,%s): %d"%(A.id(),A.name(),A.getNumPartitions()))
shift=np.array([25.25,-12.125,6.333],dtype=np.float64)
B = A.map(construct_apply_shift(shift))
print("numPartitions(%d,%s): %d"%(B.id(),B.name(),B.getNumPartitions()))
B.foreachPartition(savebin)
sc.stop()