Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
S
stats-facil
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneur
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
facil
stats-facil
Validations
7f5b9f35
Valider
7f5b9f35
rédigé
11 years ago
par
diosmosis
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Refs #4200, tweaked RankingQuery docs.
parent
4a573d0c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
core/RankingQuery.php
+54
-44
54 ajouts, 44 suppressions
core/RankingQuery.php
avec
54 ajouts
et
44 suppressions
core/RankingQuery.php
+
54
−
44
Voir le fichier @
7f5b9f35
...
@@ -21,26 +21,26 @@ use Exception;
...
@@ -21,26 +21,26 @@ use Exception;
*
*
* The general use case looks like this:
* The general use case looks like this:
*
*
* // limit to 500 rows + "Others"
* // limit to 500 rows + "Others"
* $rankingQuery = new RankingQuery(500);
* $rankingQuery = new RankingQuery();
* $rankingQuery->setLimit(500);
*
*
* // idaction_url will be "Others" in the row that contains the aggregated rest
*
// idaction_url will be "Others" in the row that contains the aggregated rest
* $rankingQuery->addLabelColumn('idaction_url');
*
$rankingQuery->addLabelColumn('idaction_url');
*
*
* // the actual query. it's important to sort it before the limit is applied
* // the actual query. it's important to sort it before the limit is applied
* $sql = 'SELECT idaction_url, COUNT(*) AS nb_hits
* $sql = 'SELECT idaction_url, COUNT(*) AS nb_hits
* FROM log_link_visit_action
* FROM log_link_visit_action
* GROUP BY idaction_url
* GROUP BY idaction_url
* ORDER BY nb_hits DESC';
* ORDER BY nb_hits DESC';
*
* // execute the query
* $rankingQuery->execute($sql);
*
*
* // execute the query
* $rankingQuery->execute($sql);
*
*
* For more examples, see RankingQueryTest.php
* For more examples, see RankingQueryTest.php
*
*
*
* @package Piwik
* @package Piwik
* @api
*/
*/
class
RankingQuery
class
RankingQuery
{
{
...
@@ -90,8 +90,9 @@ class RankingQuery
...
@@ -90,8 +90,9 @@ class RankingQuery
private
$othersLabelValue
=
'Others'
;
private
$othersLabelValue
=
'Others'
;
/**
/**
* The constructor.
* Constructor.
* Can be used as a shortcut for setLimit()
*
* @param int|false $limit The result row limit. See [setLimit](#setLimit).
*/
*/
public
function
__construct
(
$limit
=
false
)
public
function
__construct
(
$limit
=
false
)
{
{
...
@@ -101,9 +102,9 @@ class RankingQuery
...
@@ -101,9 +102,9 @@ class RankingQuery
}
}
/**
/**
* Set the limit after which everything is grouped to "Others"
* Set the limit after which everything is grouped to "Others"
.
*
*
* @param $limit
int
* @param
int
$limit
*/
*/
public
function
setLimit
(
$limit
)
public
function
setLimit
(
$limit
)
{
{
...
@@ -113,7 +114,7 @@ class RankingQuery
...
@@ -113,7 +114,7 @@ class RankingQuery
/**
/**
* Set the value to use for the label in the 'Others' row.
* Set the value to use for the label in the 'Others' row.
*
*
* @param
$value string
* @param
string $value
*/
*/
public
function
setOthersLabel
(
$value
)
public
function
setOthersLabel
(
$value
)
{
{
...
@@ -124,7 +125,7 @@ class RankingQuery
...
@@ -124,7 +125,7 @@ class RankingQuery
* Add a label column.
* Add a label column.
* Labels are the columns that are replaced with "Others" after the limit.
* Labels are the columns that are replaced with "Others" after the limit.
*
*
* @param
$labelColumn string|array
* @param
string|array $labelColumn
*/
*/
public
function
addLabelColumn
(
$labelColumn
)
public
function
addLabelColumn
(
$labelColumn
)
{
{
...
@@ -141,8 +142,8 @@ class RankingQuery
...
@@ -141,8 +142,8 @@ class RankingQuery
* Add a column that has be added to the outer queries.
* Add a column that has be added to the outer queries.
*
*
* @param $column
* @param $column
* @param string|bool $aggregationFunction
string
* @param string|bool $aggregationFunction
If set, this function is used to aggregate the values of "Others",
*
If set, this function is used to aggregate the values of "Others"
*
eg, `'min'`, `'max'` or `'sum'`.
*/
*/
public
function
addColumn
(
$column
,
$aggregationFunction
=
false
)
public
function
addColumn
(
$column
,
$aggregationFunction
=
false
)
{
{
...
@@ -156,13 +157,13 @@ class RankingQuery
...
@@ -156,13 +157,13 @@ class RankingQuery
}
}
/**
/**
*
The inner query can have a column that marks the rows that shall be excluded from limiting
.
*
Sets a column that will be used to filter the result into two categories
.
*
If
th
e
column
contains 0, rows are handled as usual. For values greater than 0, separate
*
Rows where
th
is
column
has a value > 0 will be removed from the result and put
*
groups are made. If this method is used, generate() returns both the regul
ar re
sult an
d
*
into another array. Both the result and the array of excluded rows
ar
e
re
turne
d
*
the excluded columns separately
.
*
by [execute](#execute)
.
*
*
* @param $column string
n
ame of the column
* @param $column string
N
ame of the column
.
* @throws Exception
when
method is used more than once
* @throws Exception
if
method is used more than once
.
*/
*/
public
function
setColumnToMarkExcludedRows
(
$column
)
public
function
setColumnToMarkExcludedRows
(
$column
)
{
{
...
@@ -175,16 +176,21 @@ class RankingQuery
...
@@ -175,16 +176,21 @@ class RankingQuery
}
}
/**
/**
* This method can be used to get multiple groups in one go. For example, one might query
* This method can be used to parition the result based on the possible values of one
* the top following pages, outlinks and downloads in one go by using log_action.type as
* table column. This means the query will split the result set into other sets of rows
* the partition column and [TYPE_ACTION_URL, TYPE_OUTLINK, TYPE_DOWNLOAD] as the possible
* for each possible value you provide (where the rows of each set have a column value
* values.
* that equals a possible value). Each of these new sets of rows will be individually
* When this method has been used, generate() returns as array that contains one array
* limited resulting in several limited result sets.
* per group of data.
*
* For example, you can run a query aggregating some data on the log_action table and
* partition by log_action.type with the possible values of [TYPE_ACTION_URL](#),
* [TYPE_OUTLINK](#), [TYPE_DOWNLOAD](#). The result will be three separate result sets
* that are aggregated the same ways, but for rows where `log_action.type = TYPE_OUTLINK`,
* for rows where `log_action.type = TYPE_ACTION_URL` and for rows `log_action.type = TYPE_DOWNLOAD`.
*
*
* @param $partitionColumn string
* @param $partitionColumn string
The column name to partion by.
* @param $possibleValues
a
rray of
integers
* @param $possibleValues
A
rray of
possible column values.
* @throws Exception
when
method is used more than once
* @throws Exception
if
method is used more than once
.
*/
*/
public
function
partitionResultIntoMultipleGroups
(
$partitionColumn
,
$possibleValues
)
public
function
partitionResultIntoMultipleGroups
(
$partitionColumn
,
$possibleValues
)
{
{
...
@@ -198,13 +204,15 @@ class RankingQuery
...
@@ -198,13 +204,15 @@ class RankingQuery
}
}
/**
/**
* Execute the query.
* Execute
s
the query.
* The object has to be configured first using the other methods.
* The object has to be configured first using the other methods.
*
*
* @param $innerQuery string The "payload" query. The result has be sorted as desired.
* @param $innerQuery string The "payload" query that does the actual data aggregation. The ordering
* has to be specified in this query. [RankingQuery](#) cannot apply ordering
* itself.
* @param $bind array Bindings for the inner query.
* @param $bind array Bindings for the inner query.
* @return array The format depends on which methods have been used
* @return array The format depends on which methods have been used
* to configure the ranking query
* to configure the ranking query
.
*/
*/
public
function
execute
(
$innerQuery
,
$bind
=
array
())
public
function
execute
(
$innerQuery
,
$bind
=
array
())
{
{
...
@@ -254,11 +262,13 @@ class RankingQuery
...
@@ -254,11 +262,13 @@ class RankingQuery
/**
/**
* Generate the SQL code that does the magic.
* Generate the SQL code that does the magic.
* If you want to get the result, use execute() instead. If you
're interested in
* If you want to get the result, use execute() instead. If you
want to run the query
*
the generated SQL code (e.g. for debugging)
, use this method.
*
yourself
, use this method.
*
*
* @param $innerQuery string SQL of the actual query
* @param $innerQuery string The "payload" query that does the actual data aggregation. The ordering
* @return string entire ranking query SQL
* has to be specified in this query. [RankingQuery](#) cannot apply ordering
* itself.
* @return string The entire ranking query SQL.
*/
*/
public
function
generateQuery
(
$innerQuery
)
public
function
generateQuery
(
$innerQuery
)
{
{
...
@@ -362,4 +372,4 @@ class RankingQuery
...
@@ -362,4 +372,4 @@ class RankingQuery
END
END
"
;
"
;
}
}
}
}
\ No newline at end of file
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter