rekalogika / analytics-core
Adds OLAP functionality to Doctrine entities
Fund package maintenance!
Requires
- php: ^8.2
- doctrine/collections: ^2.2 || ^3.0
- doctrine/dbal: ^3 || ^4
- doctrine/migrations: ^3.5
- doctrine/orm: ^2.20 || ^3.2
- doctrine/persistence: ^3.1 || ^4.0
- psr/clock: ^1.0
- psr/event-dispatcher: ^1.0
- psr/log: ^3.0
- rekalogika/doctrine-advanced-group-by: ^2.6 || ^3.6
- rekalogika/rekapager-contracts: ^1.0
- rekalogika/rekapager-doctrine-orm-adapter: ^1.0
- symfony/lock: ^6.4 || ^7.0 || ^8.0
- symfony/polyfill-intl-icu: ^1.31
- symfony/property-access: ^6.4 || ^7.0 || ^8.0
- symfony/service-contracts: ^3
- symfony/translation-contracts: ^3
- symfony/uid: ^6.4 || ^7.0 || ^8.0
Requires (Dev)
None
Suggests
- rekalogika/pivot-table: Transforms the result into a pivot table
Provides
None
Conflicts
None
Replaces
None
- dev-main
- v0.40.0
- v0.39.0
- v0.38.0
- v0.37.1
- v0.36.0
- v0.35.0
- v0.34.0
- v0.33.0
- v0.32.3
- v0.32.2
- v0.32.1
- v0.32.0
- v0.31.0
- v0.30.0
- v0.29.0
- v0.28.0
- v0.27.0
- v0.26.1
- v0.26.0
- v0.25.0
- v0.24.1
- v0.24.0
- v0.23.2
- v0.23.1
- v0.23.0
- v0.22.1
- v0.22.0
- v0.21.5
- v0.21.4
- v0.21.3
- v0.21.2
- v0.21.1
- v0.21.0
- v0.20.6
- v0.20.4
- v0.20.3
- v0.20.2
- v0.20.1
- v0.10.1
- v0.10.0
This package is auto-updated.
Last update: 2026-11-04 14:13:58 UTC
README
The core of Rekalogika Analytics. Creates and maintains pre-aggregated summary tables for Doctrine entities, and lets you query them as an OLAP data cube.
Warning
This package is still in development and not yet ready for production use. The API is subject to change.
What's Inside
- Metadata. Attributes for defining a summary entity:
Summary,Dimension,Measure, andPartition, inRekalogika\Analytics\Metadata\Attribute. - Value resolvers. Describe how a value is obtained from the source entity,
such as
PropertyValue,IdentifierValue,IntegerValue, andCustomExpression. - Aggregate functions.
Sum,Count,Min,Max,Average,Range,StdDev, andSumSquare. - Partitioning.
DefaultIntegerPartitionfor integer primary keys andUuidV7IntegerPartitionfor UUIDv7 primary keys. Partitions allow the summary table to be refreshed incrementally. - Time dimensions. Hierarchical time dimensions (Gregorian and ISO week calendars, from year down to hour) with source and summary time zone support.
- PostgreSQL extras. Approximate distinct count using the
hllextension. - Refresh engine. Tracks changes to the source entities and refreshes the affected partitions of the summary table.
- Query engine. The
SummaryManagerandQueryAPI, returning results as aCubeCellthat you can slice, dice, roll up, drill down, and pivot.
Requirements
- PHP 8.2 or later
- Doctrine ORM 2.20+ or 3.x
- PostgreSQL
Installation
This package is not meant to be used on its own. Only usage under Symfony is supported for now, so install the Symfony bundle instead, which pulls in this package:
composer require rekalogika/analytics-bundle
Usage
Define a summary entity for your source entity:
use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Rekalogika\Analytics\Core\AggregateFunction\Count; use Rekalogika\Analytics\Core\AggregateFunction\Sum; use Rekalogika\Analytics\Core\Entity\BaseSummary; use Rekalogika\Analytics\Core\Partition\DefaultIntegerPartition; use Rekalogika\Analytics\Core\ValueResolver\IdentifierValue; use Rekalogika\Analytics\Core\ValueResolver\IntegerValue; use Rekalogika\Analytics\Metadata\Attribute as Analytics; use Symfony\Component\Translation\TranslatableMessage; #[ORM\Entity()] #[Analytics\Summary( sourceClass: Order::class, label: new TranslatableMessage('Orders'), )] class OrderSummary extends BaseSummary { #[ORM\Embedded()] #[Analytics\Partition(new IntegerValue('id'))] private DefaultIntegerPartition $partition; #[ORM\ManyToOne()] #[ORM\JoinColumn(nullable: true)] #[Analytics\Dimension( source: new IdentifierValue('customer.country'), label: new TranslatableMessage('Customer country'), )] private ?Country $customerCountry = null; #[ORM\Column(type: Types::INTEGER)] #[Analytics\Measure( function: new Sum('item.price'), label: new TranslatableMessage('Price'), )] private ?int $price = null; #[ORM\Column(type: Types::INTEGER)] #[Analytics\Measure( function: new Count('id'), label: new TranslatableMessage('Count'), )] private ?int $count = null; // getters... }
The summary entity and its source entity must be managed by the same entity manager, because the summary table is refreshed with queries that read from the source table.
Then query it using the SummaryManager service:
use Rekalogika\Analytics\Contracts\SummaryManager; /** @var SummaryManager $summaryManager */ $result = $summaryManager ->createQuery() ->from(OrderSummary::class) ->withDimensions('customerCountry') ->getResult(); foreach ($result->drillDown('customerCountry') as $cell) { $country = $cell->getCoordinates()->get('customerCountry')?->getMember(); $count = $cell->getMeasures()->get('count')?->getValue(); }
Documentation
License
MIT
Contributing
This framework consists of multiple repositories split from a monorepo. Be
sure to submit issues and pull requests to the
rekalogika/analytics monorepo.