Skip to content

Commit

Permalink
Merge pull request #13 from smgallo/etl/test-multihost-aggregation
Browse files Browse the repository at this point in the history
Fixes/enhancements found when testing multihost aggregation
  • Loading branch information
smgallo authored Jan 17, 2017
2 parents 8118806 + de9d888 commit 415c17d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
9 changes: 6 additions & 3 deletions classes/ETL/Aggregator/pdoAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,9 @@ protected function getDirtyAggregationPeriods($aggregationUnit)

if ( null !== $startDate ) {
$ranges[] = "$startDate <= d.${aggregationUnit}_end";
} else if ( null !== $endDate ) {
}

if ( null !== $endDate ) {
$ranges[] = "$endDate >= d.${aggregationUnit}_start";
}

Expand Down Expand Up @@ -848,7 +850,7 @@ protected function _execute($aggregationUnit)
$discoveredBindParams['insert'] = $matches[0];

$this->logger->debug("Aggregation select query ($aggregationUnit)\n" . $this->selectSql);
$this->logger->debug("Aggregation insert query ($aggregationUnit)\n" . $this->$insertSql);
$this->logger->debug("Aggregation insert query ($aggregationUnit)\n" . $this->insertSql);

} // else ($optimize)

Expand Down Expand Up @@ -1114,8 +1116,9 @@ protected function processAggregationPeriods(

// Perform aggregation on this aggregation period

if ( $optimize ) {
$this->logger->debug("Aggregating $aggregationUnit $period_id");

if ( $optimize ) {

try {
if ( ! $this->etlOverseerOptions->isDryrun() ) {
Expand Down
37 changes: 26 additions & 11 deletions classes/ETL/DbEntity/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function __construct($config, $systemQuoteChar = null, Log $logger = null

if ( ! is_object($config) && is_string($config) ) {
$config = $this->parseJsonFile($config, "Query Definition");
} else if ( ! $config instanceof stdClass) {
} elseif ( ! $config instanceof stdClass) {
$msg = __CLASS__ . ": Argument is not a filename or object";
$this->logAndThrowException($msg);
}
Expand Down Expand Up @@ -158,22 +158,22 @@ protected function initialize(stdClass $config, $force = false)

if ( ! isset($config->records) ) {
$errorMsg[] = "records property not found";
} else if ( ! is_object($config->records) ) {
} elseif ( ! is_object($config->records) ) {
$errorMsg[] = "records property must be an object";
}

if ( ! isset($config->joins) ) {
$errorMsg[] = "joins property not found";
} else if ( ! is_array($config->joins) ) {
} elseif ( ! is_array($config->joins) ) {
$errorMsg[] = "joins property must be an array";
} else if ( 0 == count($config->joins) ) {
} elseif ( 0 == count($config->joins) ) {
$errorMsg[] = "joins property must include as least one element";
}

if ( isset($config->groupby) ) {
if ( ! is_array($config->groupby) ) {
$errorMsg[] = "groupby property must be an array";
} else if ( 0 == count($config->groupby) ) {
} elseif ( 0 == count($config->groupby) ) {
$errorMsg[] = "groupby property must include as least one element";
}
}
Expand Down Expand Up @@ -269,7 +269,7 @@ public function addRecord($columnName, $formula)
if ( null === $formula || "" === $formula ) {
$msg = "Empty formula for column '$columnName' '$formula'";
$this->logAndThrowException($msg);
} else if ( array_key_exists($columnName, $this->records) ) {
} elseif ( array_key_exists($columnName, $this->records) ) {
$msg = "Column '$columnName' already has a formula specified";
$this->logAndThrowException($msg);
}
Expand Down Expand Up @@ -577,7 +577,7 @@ public function addOverseerRestriction($restriction, $template)
if ( ! is_string($restriction) || "" == $restriction ) {
$msg = "Overseer restriction key must be a non-empty string";
$this->logAndThrowException($msg);
} else if ( ! is_string($template) || "" == $template ) {
} elseif ( ! is_string($template) || "" == $template ) {
$msg = "Overseer restriction template must be a non-empty string";
$this->logAndThrowException($msg);
}
Expand Down Expand Up @@ -633,7 +633,7 @@ public function addOverseerRestrictionValue($restriction, $value)
if ( ! is_string($restriction) || "" == $restriction ) {
$msg = "Overseer restriction key must be a non-empty string";
$this->logAndThrowException($msg);
} else if ( ! is_string($value) || "" == $value ) {
} elseif ( ! is_string($value) || "" == $value ) {
$msg = "Overseer restriction template must be a non-empty string";
$this->logAndThrowException($msg);
}
Expand Down Expand Up @@ -704,9 +704,24 @@ public function getSelectSql($includeSchema = true)
if ( null === $this->joins[$i]->getOn() ) {
$msg = "Join clause for table '" . $this->joins[$i]->getName() . "' does not provide ON condition";
}

// When we move to explictly marking the FROM clause this functionality may be moved
// into the Join class

$joinType = $this->joins[$i]->getType();
$joinList[] = ( null !== $joinType ? "$joinType " : "" ) . "JOIN " . $this->joins[$i]->getCreateSql($includeSchema);
}

// Handle various join types. STRAIGHT_JOIN is a mysql enhancement.

$joinStr = "JOIN";

if ( "STRAIGHT" == $joinType ) {
$joinStr = "STRAIGHT_JOIN";
} elseif (null !== $joinType) {
$joinStr = $joinType . " JOIN";
}

$joinList[] = $joinStr . " " . $this->joins[$i]->getCreateSql($includeSchema);
} // for ( $i = 1; $i < count($this->joins); $i++ )

// Construct the SELECT statement

Expand All @@ -722,7 +737,7 @@ public function getSelectSql($includeSchema = true)
// If any macros have been defined, process those macros now. Since macros can contain variables
// themselves, we will process the variables later.

if ( count($this->macros) > 0 ) {
if (count($this->macros) > 0) {
foreach ( $this->macros as $macro ) {
$sql = Utilities::processMacro($sql, $macro);
}
Expand Down

0 comments on commit 415c17d

Please sign in to comment.