Skip to content

Commit 10337be

Browse files
authored
Merge branch 'xdmod10.5' into support_jobarrays
2 parents e00a2a6 + 364b19e commit 10337be

File tree

10 files changed

+1326
-70
lines changed

10 files changed

+1326
-70
lines changed

classes/DataWarehouse/Data/BatchDataset.php

+58-6
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,35 @@ class BatchDataset extends Loggable implements Iterator
7070
private $hashCache = [];
7171

7272
/**
73-
* @param mixed $name Description.
74-
* @param \XDUser $user
73+
* Maximum number of rows to return.
74+
*
75+
* @var int
76+
*/
77+
private $limit;
78+
79+
/**
80+
* Starting row index.
81+
*
82+
* @var int
83+
*/
84+
private $offset;
85+
86+
/**
87+
* @param RawQuery $query
88+
* @param XDUser $user
7589
* @param LoggerInterface $logger
90+
* @param array|null $fieldAliases
91+
* @param int|null $limit
92+
* @param int $offset
7693
*/
77-
public function __construct(RawQuery $query, XDUser $user, LoggerInterface $logger = null)
78-
{
94+
public function __construct(
95+
RawQuery $query,
96+
XDUser $user,
97+
LoggerInterface $logger = null,
98+
$fieldAliases = null,
99+
$limit = null,
100+
$offset = 0
101+
) {
79102
parent::__construct($logger);
80103

81104
$this->query = $query;
@@ -91,7 +114,36 @@ public function __construct(RawQuery $query, XDUser $user, LoggerInterface $logg
91114
}
92115

93116
$rawStatsConfig = RawStatisticsConfiguration::factory();
94-
$this->fields = $rawStatsConfig->getBatchExportFieldDefinitions($query->getRealmName());
117+
$this->fields = $rawStatsConfig->getBatchExportFieldDefinitions(
118+
$query->getRealmName()
119+
);
120+
// If an array of field aliases has been provided,
121+
if (is_array($fieldAliases)) {
122+
// Validate the provided field aliases.
123+
$validFieldAliases = array_column($this->fields, 'alias');
124+
$invalidFieldAliases = array_diff(
125+
$fieldAliases,
126+
$validFieldAliases
127+
);
128+
if (count($invalidFieldAliases) > 0) {
129+
throw new Exception(
130+
"Invalid fields specified: '"
131+
. join("', '", $invalidFieldAliases)
132+
. "'."
133+
);
134+
}
135+
// Filter out the fields whose aliases were not provided.
136+
$this->fields = array_filter(
137+
$this->fields,
138+
function ($field) use ($fieldAliases) {
139+
return in_array($field['alias'], $fieldAliases);
140+
}
141+
);
142+
// Renumber the indexes.
143+
$this->fields = array_values($this->fields);
144+
}
145+
$this->limit = $limit;
146+
$this->offset = $offset;
95147
}
96148

97149
/**
@@ -148,7 +200,7 @@ public function next()
148200
public function rewind()
149201
{
150202
$this->logger->debug('Executing query');
151-
$this->sth = $this->query->getRawStatement();
203+
$this->sth = $this->query->getRawStatement($this->limit, $this->offset);
152204
$this->logger->debug(sprintf(
153205
'Raw query string: %s',
154206
$this->sth->queryString

0 commit comments

Comments
 (0)