How can accumulate a column, only if the column really exists?
In my setup() I want to create following datastore:
$this->src("warehouse_datasource")
->query("
SELECT dim.tDate.DateMonthNameDE, COUNT(fact.tJob.JobID) AS amount, dim.tDate.DateYear, dim.tDate.DateMonth
FROM fact.tJob INNER JOIN
dim.tDate ON fact.tJob.JobCreatedDateID = dim.tDate.DateID
WHERE (fact.tJob.JobCompanyID = :CompanySiteCompanyID
AND (:JobCompanySiteID = -1 OR fact.tJob.JobCompanySiteID = :JobCompanySiteID)
AND (:JobOwnerAccountID = -1 OR fact.tJob.JobOwnerAccountID = :JobOwnerAccountID)
AND (:JobTypeID = 255 OR fact.tJob.JobTypeID = :JobTypeID)
AND (:JobPositionID = 255 OR fact.tJob.JobPositionID = :JobPositionID)
AND (:JobEducationID = 255 OR fact.tJob.JobEducationID = :JobEducationID)
AND ( dim.tDate.DateYear >= :YearMin AND dim.tDate.DateYear <= :YearMax)
)
GROUP BY dim.tDate.DateYear, dim.tDate.DateMonthNameDE, dim.tDate.DateMonth
ORDER BY dim.tDate.DateYear, dim.tDate.DateMonthNameDE
")
->params(array(
":CompanySiteCompanyID"=>$this->params["CompanySiteCompanyID"],
":JobCompanySiteID" =>$this->params["JobCompanySiteID"],
":JobOwnerAccountID"=>$this->params["JobOwnerAccountID"],
":JobTypeID" =>$this->params["JobTypeID"],
":JobPositionID" =>$this->params["JobPositionID"],
":JobEducationID" =>$this->params["JobEducationID"],
":YearMin" =>$this->params["YearRange"][0],
":YearMax" =>$this->params["YearRange"][1],
))
->pipe(new AccumulativeColumn(array(
"running_amount"=>"amount"
)))
->pipe($this->dataStore('time_jobs_created'));
In my query I have some conditions. Thats why there are sometimes no data available. Therefore, the column "amount" will not always be created for counting the row.
After the query i use AccumulativeColumn to accumulate the amount of the counted columns. But when there is no amount column the AccumulativeColumn.php throws a: 'Undefined array key "amount"' exception.
I already tried to use the ->pipeIf() method, but I don't know how I can check if a column exists or not. How could I do that?