Adds the processed metrics. See {@link AddColumnsProcessedMetrics} for
more information.

@param DataTable $table
971288
public function filter($table)
    {
        // Add standard processed metrics
        parent::filter($table);

        $goals = $this->getGoalsInTable($table);
        if (!empty($this->goalsToProcess)) {
            $goals = array_unique(array_merge($goals, $this->goalsToProcess));
            sort($goals);
        }

        $idSite = DataTableFactory::getSiteIdFromMetadata($table);

        $extraProcessedMetrics = $table->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME);

        $extraProcessedMetrics[] = new RevenuePerVisit();
        if ($this->processOnlyIdGoal != self::GOALS_MINIMAL_REPORT) {
            foreach ($goals as $idGoal) {
                if (($this->processOnlyIdGoal > self::GOALS_FULL_TABLE
                        || $this->isEcommerce)
                    && $this->processOnlyIdGoal != $idGoal
                ) {
                    continue;
                }

                $extraProcessedMetrics[] = new ConversionRate($idSite, $idGoal); // PerGoal\ConversionRate

                // When the table is displayed by clicking on the flag icon, we only display the columns
                // Visits, Conversions, Per goal conversion rate, Revenue
                if ($this->processOnlyIdGoal == self::GOALS_OVERVIEW) {
                    continue;
                }

                $extraProcessedMetrics[] = new Conversions($idSite, $idGoal); // PerGoal\Conversions or GoalSpecific\
                $extraProcessedMetrics[] = new GoalSpecificRevenuePerVisit($idSite, $idGoal); // PerGoal\Revenue
                $extraProcessedMetrics[] = new Revenue($idSite, $idGoal); // PerGoal\Revenue

                if ($this->isEcommerce) {
                    $extraProcessedMetrics[] = new AverageOrderRevenue($idSite, $idGoal);
                    $extraProcessedMetrics[] = new ItemsCount($idSite, $idGoal);
                }
            }
        }

        $table->setMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME, $extraProcessedMetrics);
    }
975582
protected function processTables()
	{
		foreach ($this->tables as $table)
		{
			$this->table = $table;
			$this->processCurrentTable();
		}
	}
93866
public function onLoadDataContainer(string $table): void
    {
        if (!isset($GLOBALS['TL_DCA'][$table]['fields']) || !\is_array($GLOBALS['TL_DCA'][$table]['fields'])) {
            return;
        }

        $hasTagsFields = false;

        foreach ($GLOBALS['TL_DCA'][$table]['fields'] as $name => &$field) {
            if ('cfgTags' !== $field['inputType']) {
                continue;
            }

            $hasTagsFields = true;
            $manager = $this->registry->get($field['eval']['tagsManager']);

            if ($manager instanceof DcaAwareInterface) {
                $manager->updateDcaField($field);
            }
        }

        // Add assets for backend
        if (TL_MODE === 'BE' && $hasTagsFields) {
            $this->addAssets();
        }
    }
1168080
public function filter($table)
    {
        // set of all column names in the pivoted table mapped with the sum of all column
        // values. used later in truncating and ordering the pivoted table's columns.
        $columnSet = array();

        // if no pivot column was set, use the first one found in the row
        if (empty($this->pivotColumn)) {
            $this->pivotColumn = $this->getNameOfFirstNonLabelColumnInTable($table);
        }

        Log::debug("PivotByDimension::%s: pivoting table with pivot column = %s", __FUNCTION__, $this->pivotColumn);

        foreach ($table->getRows() as $row) {
            $row->setColumns(array('label' => $row->getColumn('label')));

            $associatedTable = $this->getIntersectedTable($table, $row);
            if (!empty($associatedTable)) {
                foreach ($associatedTable->getRows() as $columnRow) {
                    $pivotTableColumn = $columnRow->getColumn('label');

                    $columnValue = $this->getColumnValue($columnRow, $this->pivotColumn);

                    if (isset($columnSet[$pivotTableColumn])) {
                        $columnSet[$pivotTableColumn] += $columnValue;
                    } else {
                        $columnSet[$pivotTableColumn] = $columnValue;
                    }

                    $row->setColumn($pivotTableColumn, $columnValue);
                }

                Common::destroy($associatedTable);
                unset($associatedTable);
            }
        }

        Log::debug("PivotByDimension::%s: pivoted columns set: %s", __FUNCTION__, $columnSet);

        $others = Piwik::translate('General_Others');
        $defaultRow = $this->getPivotTableDefaultRowFromColumnSummary($columnSet, $others);

        Log::debug("PivotByDimension::%s: un-prepended default row: %s", __FUNCTION__, $defaultRow);

        // post process pivoted datatable
        foreach ($table->getRows() as $row) {
            // remove subtables from rows
            $row->removeSubtable();
            $row->deleteMetadata('idsubdatatable_in_db');

            // use default row to ensure column ordering and add missing columns/aggregate cut-off columns
            $orderedColumns = $defaultRow;
            foreach ($row->getColumns() as $name => $value) {
                if (isset($orderedColumns[$name])) {
                    $orderedColumns[$name] = $value;
                } else {
                    $orderedColumns[$others] += $value;
                }
            }
            $row->setColumns($orderedColumns);
        }

        $table->clearQueuedFilters(); // TODO: shouldn't clear queued filters, but we can't wait for them to be run
                                      //       since generic filters are run before them. remove after refactoring
                                      //       processed metrics.

        // prepend numerals to columns in a queued filter (this way, disable_queued_filters can be used
        // to get machine readable data from the API if needed)
        $prependedColumnNames = $this->getOrderedColumnsWithPrependedNumerals($defaultRow, $others);

        Log::debug("PivotByDimension::%s: prepended column name mapping: %s", __FUNCTION__, $prependedColumnNames);

        $table->queueFilter(function (DataTable $table) use ($prependedColumnNames) {
            foreach ($table->getRows() as $row) {
                $row->setColumns(array_combine($prependedColumnNames, $row->getColumns()));
            }
        });
    }
697380
public function addTable($table, $after=null) {

        // Calculate the previous and next tables
        $prevtable = null;
        $nexttable = null;

        if (!$after) {
            if ($this->tables) {
                end($this->tables);
                $prevtable = $this->tables[key($this->tables)];
            }
        } else {
            $prevtable = $this->getTable($after);
        }
        if ($prevtable && $prevtable->getNext()) {
            $nexttable = $this->getTable($prevtable->getNext());
        }

        // Set current table previous and next attributes
        if ($prevtable) {
            $table->setPrevious($prevtable->getName());
            $prevtable->setNext($table->getName());
        }
        if ($nexttable) {
            $table->setNext($nexttable->getName());
            $nexttable->setPrevious($table->getName());
        }
        // Some more attributes
        $table->setLoaded(true);
        $table->setChanged(true);
        // Add the new table
        $this->tables[] = $table;
        // Reorder the whole structure
        $this->orderTables($this->tables);
        // Recalculate the hash
        $this->calculateHash(true);
        // We have one new table, so the structure has changed
        $this->setVersion(userdate(time(), '%Y%m%d', 99, false));
        $this->setChanged(true);
    }
773342
protected function loadMetadataForTable(Table $table)
    {
        $tblName = $table->getName();

        if (isset($this->defaultAliases[$tblName])) {
            $className = $this->defaultAliases[$tblName];
        } else {
            $className = $tblName;
            $this->unmapped[] = $tblName;
        }

        $contentKey = $this->getContentTypeFromAlias($table->getOption('alias'));
        $this->metadata[$className] = [];
        $this->metadata[$className]['identifier'] = $table->getPrimaryKey();
        $this->metadata[$className]['table'] = $table->getName();
        $this->metadata[$className]['boltname'] = $contentKey;
        if (isset($this->contenttypes[$contentKey]['class'])) {
            $this->metadata[$className]['class'] = $this->contenttypes[$contentKey]['class'];
        }
        foreach ($table->getColumns() as $colName => $column) {
            $mapping = [
                'fieldname'        => $column->getName(),
                'attribute'        => $this->camelize($column->getName()),
                'type'             => $column->getType()->getName(),
                'fieldtype'        => $this->getFieldTypeFor($contentKey, $column),
                'length'           => $column->getLength(),
                'nullable'         => !$column->getNotnull(),
                'platformOptions'  => $column->getPlatformOptions(),
                'precision'        => $column->getPrecision(),
                'scale'            => $column->getScale(),
                'default'          => $column->getDefault(),
                'columnDefinition' => $column->getColumnDefinition(),
                'autoincrement'    => $column->getAutoincrement(),
            ];

            $this->metadata[$className]['fields'][$colName] = $mapping;

            if (isset($this->contenttypes[$contentKey]['fields'][$colName])) {
                $this->metadata[$className]['fields'][$colName]['data'] = $this->contenttypes[$contentKey]['fields'][$colName];
            }
        }

        // This loop checks the contenttypes definition for any non-db fields and adds them.
        if ($contentKey && isset($this->contenttypes[$contentKey])) {
            $this->setRelations($contentKey, $className);
            $this->setIncomingRelations($contentKey, $className);
            $this->setTaxonomies($contentKey, $className);
            $this->setTemplatefields($contentKey, $className);
            $this->setRepeaters($contentKey, $className);
        }

        foreach ($this->getAliases() as $alias => $tablename) {
            if (array_key_exists($tablename, $this->metadata)) {
                $this->metadata[$alias] = $this->metadata[$tablename];
            } elseif (
                array_key_exists($tablename, $this->defaultAliases) &&
                array_key_exists($this->defaultAliases[$tablename], $this->metadata)
            ) {
                $this->metadata[$alias] = $this->metadata[$this->defaultAliases[$tablename]];
            }
        }
    }
141892
private function sumTable($table)
    {
        $metadata = $table->getMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME);
        $enableCopyMetadata = false;

        foreach ($table->getRowsWithoutSummaryRow() as $row) {
            $this->sumRow($row, $enableCopyMetadata, $metadata);
        }

        $summaryRow = $table->getRowFromId(DataTable::ID_SUMMARY_ROW);

        if ($summaryRow) {
            $this->sumRow($summaryRow, $enableCopyMetadata, $metadata);
        }
    }
1001041
public function filter($table)
    {
        if ($this->truncateAfter < 0) {
            return;
        }

        $this->addSummaryRow($table);
        $table->queueFilter('ReplaceSummaryRowLabel', array($this->labelSummaryRow));

        if ($this->filterRecursive) {
            foreach ($table->getRowsWithoutSummaryRow() as $row) {
                if ($row->isSubtableLoaded()) {
                    $this->filter($row->getSubtable());
                }
            }
        }
    }
1282307
protected function whitelistTable($table) {
        if(is_array($table)) {
            foreach ($table as $t) {
                $this->query->addToTableWhitelist($t);
            }
        }
        else {
            $this->query->addToTableWhitelist($table);
        }
    }
734572
protected function _loadBehavior(Table $table)
    {
        $behaviors = $table->behaviors();
        if (!Arr::in('Process', $behaviors->loaded())) {
            $behaviors->load('Core.Process');
        }
    }
1239550
public function getColumnListing($table)
    {
        $results = $this->connection->selectFromWriteConnection($this->grammar->compileColumnListing(
            $this->connection->getTablePrefix().$table
        ));

        return $this->connection->getPostProcessor()->processColumnListing($results);
    }
584276
protected function storeTable($table)
    {
        $fh = fopen($this->dataFile($table), 'w');

        fputcsv($fh, $this->keys[$table]);

        foreach ($this->rows[$table] as $row) {
            fputcsv($fh, $this->sanitiseRow($table, $row));
        }

        fclose($fh);
    }
846197
@Override
  public void onTableProcessBegin(Table table, long tableProcessTime) {

    Preconditions.checkNotNull(table);

    if (!this.expectedHighWatermarks.hasPartitionWatermarks(tableKey(table))) {
      this.expectedHighWatermarks.setPartitionWatermarks(tableKey(table), Maps.<String, Long> newHashMap());
    }
  }
138941
public void addMetric(Metric metric)
    {
        if(this.metrics == null)
            this.metrics = new ArrayList<Metric>();
        this.metrics.add(metric);
    }
541417
protected function addIndexes(Table $table)
    {
        $dataFetcher = $this->dbh->query("sp_indexes_rowset '" . $table->getName() . "'");
        $dataFetcher->setStyle(\PDO::FETCH_ASSOC);

        $indexes = [];
        foreach ($dataFetcher as $row) {
            $colName = $this->cleanDelimitedIdentifiers($row['COLUMN_NAME']);
            $name = $this->cleanDelimitedIdentifiers($row['INDEX_NAME']);

            $isPk = $this->cleanDelimitedIdentifiers($row['PRIMARY_KEY']);
            $isUnique = $this->cleanDelimitedIdentifiers($row['UNIQUE']);

            $localColumn   = $table->getColumn($colName);

            // ignore PRIMARY index
            if ($isPk) {
                continue;
            }

            if (!isset($indexes[$name])) {
                if ($isUnique) {
                    $indexes[$name] = new Unique($name);
                } else {
                    $indexes[$name] = new Index($name);
                }
                $indexes[$name]->setTable($table);
            }

            $indexes[$name]->addColumn($localColumn);
        }

        foreach ($indexes as $index) {
            if ($index instanceof Unique) {
                $table->addUnique($index);
            } else {
                $table->addIndex($index);
            }
        }
    }
788873
protected function addIndexes(Table $table)
    {
        $stmt = $this->dbh->query("PRAGMA index_list('" . $table->getName() . "')");

        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {

            $name = $row['name'];
            $index = new Index($name);

            $stmt2 = $this->dbh->query("PRAGMA index_info('" . $name . "')");
            while ($row2 = $stmt2->fetch(PDO::FETCH_ASSOC)) {
                $colname = $row2['name'];
                $index->addColumn($table->getColumn($colname));
            }

            $table->addIndex($index);
        }
    }
232796
public static function deleteInvalidSummedColumnsFromDataTable($dataTable)
    {
        foreach ($dataTable->getRows() as $id => $row) {
            if (($idSubtable = $row->getIdSubDataTable()) !== null
                || $id === DataTable::ID_SUMMARY_ROW
            ) {
                $subTable = $row->getSubtable();
                if ($subTable) {
                    self::deleteInvalidSummedColumnsFromDataTable($subTable);
                }

                if ($row instanceof DataTableSummaryRow) {
                    $row->recalculate();
                }

                foreach (Metrics::$columnsToDeleteAfterAggregation as $name) {
                    $row->deleteColumn($name);
                }
            }
        }

        // And this as well
        ArchivingHelper::removeEmptyColumns($dataTable);
    }