承接 cylab/php-spark 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cylab/php-spark

Composer 安装命令:

composer require cylab/php-spark

包简介

A wrapper around arrays that mimics the MapReduce methods of Apache Spark

README 文档

README

pipeline status coverage report

php-spark is a wrapper around arrays that mimics the MapReduce API of Apache Spark.

$data = new Dataset([1, 2, 3, 4]);
$result = $data
	->map(function ($v) {
		return 2 * $v;
	})
	->reduce(function ($v, $agg) {
		return $agg + $v;
	});

$result == 20;

php-spark is NOT a PHP driver for Apache Spark (and I wish this would exist).

Dataset

A dataset is an immutable array of data. It is the equivalent of Spark RDD (Resilient Distributed Dataset).

use Cylab\Spark\Dataset;

$d = new Dataset([1, 2, 3, 4]);
var_dump($d->collect());

Transformations

Transformations return another dataset.

MethodDescription
map(func)Return a new distributed dataset formed by passing each element of the source through a function func.
distinct()Return a new dataset that contains the distinct elements of the source dataset.
reduceByKey(func)When called on a dataset of (K, V) pairs, returns a dataset of (K, V) pairs where the values for each key are aggregated using the given reduce function func, which must be of type (V,V) => V.
groupByKey()When called on a dataset of (K, V) pairs, returns a dataset of (K, V[]) pairs.

Actions

Actions return other types of result.

MethodDescription
reduce(func)Aggregate the elements of the dataset using a function func (which takes two arguments and returns one).
collect()Return all the elements of the dataset as an array.
count()Return the number of elements in the dataset.
first()Return the first element of the dataset (similar to take(1)).
take(n)Return an array with the first n elements of the dataset.

Map

Map applies the provided function to all elements in the dataset and returns a new dataset containing the result of the map operation.

$d2 = $d->map(function ($v) { return 2 * $v; });

Reduce

The reduce function you provide must take two parameters: the current value and the aggregated value.

use Cylab\Spark\Dataset;

$d = new Dataset([1, 2, 3, 4]);
$result = $d->reduce(function ($v, $agg) {
	return $agg + $v;
});

$result == 10;

Tuple

Some methods expect the dataset to contain a list of <key, value> tuples.

use Cylab\Spark\Dataset;
use Cylab\Spark\Tuple;

$strings = ["foe", "bar", "foe"];
$d = new Dataset ($strings);
$d2 = $d->map(function($s) { return new Tuple($s, 1); });

ReduceByKey

For this method to work, the input dataset must be a list of <key, value> tuples. The reduce function is then applied to all elements with the same key.

$counts = $d2->reduceByKey(function ($count, $sum) {
	return $sum + $count;
});

First

Get the first element of a dataset.

// Tuple<"foe", 2>
var_dump($counts->first());

Future work

  • flatMap
  • sample
  • union
  • intersection
  • aggregateByKey
  • sortByKey
  • join
  • cartesian
  • takeSample
  • takeOrdered
  • countByKey
  • saveAsObjectFile
  • saveAsJsonFile

cylab/php-spark 适用场景与选型建议

cylab/php-spark 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 780 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 08 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 cylab/php-spark 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 cylab/php-spark 我们能提供哪些服务?
定制开发 / 二次开发

基于 cylab/php-spark 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 780
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-08-18