当前位置: 首页>>代码示例>>PHP>>正文


PHP Statement::merge方法代码示例

本文整理汇总了PHP中Statement::merge方法的典型用法代码示例。如果您正苦于以下问题:PHP Statement::merge方法的具体用法?PHP Statement::merge怎么用?PHP Statement::merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Statement的用法示例。


在下文中一共展示了Statement::merge方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: queryCube

 public function queryCube(DataControllerCallContext $callcontext, CubeQueryRequest $request, ResultFormatter $resultFormatter)
 {
     $cubeName = $request->getCubeName();
     LogHelper::log_notice(t('Querying SQL-based cube: @cubeName', array('@cubeName' => $cubeName)));
     $environment_metamodel = data_controller_get_environment_metamodel();
     $metamodel = data_controller_get_metamodel();
     $callcontext->columnMapping = NULL;
     $cube = $metamodel->getCube($cubeName);
     LogHelper::log_debug($cube);
     $cubeDatasetName = $cube->sourceDatasetName;
     $cubeDataset = $metamodel->getDataset($cubeDatasetName);
     $datasource = $environment_metamodel->getDataSource($cubeDataset->datasourceName);
     // aliases for tables
     $TABLE_ALIAS__JOIN = 'j';
     $tableJoinIndex = 0;
     // preparing statement which aggregates data
     $aggrStatement = $this->prepareCubeQueryStatement($callcontext, $request);
     list($isSubqueryRequired, $assembledAggregationSections) = $aggrStatement->prepareSections(NULL);
     // assembling porting of SQL which is responsible for aggregation
     if (isset($request->referencedRequests)) {
         $joinStatement = $aggrStatement;
         // changing alias of first table. This new alias is expected the following code to join with lookup tables
         $joinStatement->updateTableAlias($joinStatement->tables[0]->alias, $TABLE_ALIAS__JOIN);
     } else {
         $joinStatement = new Statement();
         $aggregationTableSection = new SubquerySection(Statement::assemble($isSubqueryRequired, NULL, $assembledAggregationSections, Statement::$INDENT_SUBQUERY, FALSE), $TABLE_ALIAS__JOIN);
         $joinStatement->tables[] = $aggregationTableSection;
     }
     // adding support for dimension level properties
     if (isset($request->dimensions)) {
         foreach ($request->dimensions as $requestDimension) {
             $dimensionName = $requestDimension->dimensionName;
             $dimension = $cube->getDimension($dimensionName);
             $levelName = $requestDimension->levelName;
             // we do not need to map the column. It was done in prepareCubeQueryStatement()
             $levelDatabaseColumnName = ParameterHelper::assembleDatabaseColumnName($this->getMaximumEntityNameLength(), $dimensionName, $levelName);
             // adding support for level root column
             $levelRootColumn = new ColumnSection($levelDatabaseColumnName);
             $levelRootColumn->requestColumnIndex = $requestDimension->requestColumnIndex;
             $levelRootColumn->visible = isset($requestDimension->requestColumnIndex);
             $aggregationTableSection->columns[] = $levelRootColumn;
             if (!isset($requestDimension->properties)) {
                 continue;
             }
             $tableJoinIndex++;
             $levelTableAlias = $TABLE_ALIAS__JOIN . $tableJoinIndex;
             $level = $dimension->getLevel($levelName);
             $levelDataset = $metamodel->getDataset($level->datasetName);
             // preparing list of columns which are accessed by this dataset
             $usedColumnNames = NULL;
             $levelColumnAliasMapping = NULL;
             foreach ($requestDimension->properties as $property) {
                 $propertyName = $property->name;
                 $responseColumnName = ParameterHelper::assembleParameterName($dimensionName, $levelName, $propertyName);
                 $databaseColumnName = ParameterHelper::assembleDatabaseColumnName($this->getMaximumEntityNameLength(), $dimensionName, $levelName, $propertyName);
                 $callcontext->columnMapping[$databaseColumnName] = $responseColumnName;
                 ArrayHelper::addUniqueValue($usedColumnNames, $propertyName);
                 $levelColumnAliasMapping[$propertyName] = $databaseColumnName;
             }
             $isLevelKeyColumnAdded = ArrayHelper::addUniqueValue($usedColumnNames, $level->key);
             $levelStatement = $this->prepareDatasetSourceStatement($callcontext, $levelDataset, $usedColumnNames);
             // updating level statement table aliases
             $levelStatement->addTableAliasPrefix($levelTableAlias);
             foreach ($levelStatement->tables as $table) {
                 if (!isset($table->columns)) {
                     $table->columns = array();
                     // We do not need any columns
                 }
             }
             // updating level statement column aliases
             foreach ($requestDimension->properties as $property) {
                 $oldColumnAlias = $property->name;
                 $newColumnAlias = $levelColumnAliasMapping[$oldColumnAlias];
                 $levelTableSection = $levelStatement->getColumnTable($oldColumnAlias, TRUE);
                 $levelColumnSection = $levelTableSection->findColumnByAlias($oldColumnAlias);
                 if (isset($levelColumnSection)) {
                     $levelColumnSection->alias = $newColumnAlias;
                 } else {
                     $levelColumnSection = new ColumnSection($oldColumnAlias, $newColumnAlias);
                     $levelTableSection->columns[] = $levelColumnSection;
                 }
                 $levelColumnSection->requestColumnIndex = $property->requestColumnIndex;
             }
             // adding condition to join with 'main' statement
             $levelKeyTableSection = $levelStatement->getColumnTable($level->key);
             $levelKeyTableSection->conditions[] = new JoinConditionSection($level->key, new TableColumnConditionSectionValue($TABLE_ALIAS__JOIN, $levelDatabaseColumnName));
             // merging with 'main' statement
             $joinStatement->merge($levelStatement);
             // we do not need to return level key column
             if ($isLevelKeyColumnAdded && isset($levelKeyTableSection)) {
                 // FIXME this code does not work in the following case:
                 //   - our lookup dataset is fact dataset
                 //   - we need to work with project_id column from that dataset
                 //   - the column is present in *_facts and contains numeric value
                 //   - the column is present in *_c_project_id table and contains numeric value
                 //   - column 'value' in *_c_project_id table assigned an alias project_id
                 //   - more about implementation is in ReferenceDimensionDatasetAssembler
                 //   - the code is partially fixed by using $visibleOnly parameter
                 $tableSection = $levelStatement->getColumnTable($level->key, TRUE);
                 $keyColumn = $tableSection->findColumnByAlias($level->key);
//.........这里部分代码省略.........
开发者ID:ecs-hk,项目名称:Checkbook,代码行数:101,代码来源:AbstractSQLDataSourceQueryHandler.php

示例2: assemble

    public function assemble(AbstractSQLDataSourceQueryHandler $datasourceHandler, AbstractQueryRequest $request, DatasetMetaData $dataset, array $columnNames = NULL) {
        $statement = new Statement();

        $TABLE_ALIAS__FACTS = 'dsf';
        $TABLE_ALIAS__COLUMN_JOIN = 'cj';

        $metamodel = data_controller_get_metamodel();

        $cubeName = $dataset->name;
        $cube = $metamodel->getCube($cubeName);

        $factsDataset = $metamodel->getDataset($cube->factsDatasetName);

        self::$TABLE_ALIAS_SUFFIX__SEQUENCE++;
        $factsTable = new DatasetSection($factsDataset, $TABLE_ALIAS__FACTS . self::$TABLE_ALIAS_SUFFIX__SEQUENCE);
        $statement->tables[] = $factsTable;

        foreach ($dataset->getColumns() as $column) {
            $columnName = $column->name;

            $columnDefaultAlias = NULL;
            if (isset($columnNames)) {
                $columnDefaultAlias = array_search($columnName, $columnNames);
                if ($columnDefaultAlias === FALSE) {
                    continue;
                }

                // fixing the alias if the list of columns is not associative array
                if (is_int($columnDefaultAlias)) {
                    $columnDefaultAlias = NULL;
                }
            }

            // FIXME the following code does not work in the following situation:
            //   1) we need to query a dataset which is defined in GovDashboard using file upload
            //   2) column names are not provided
            //   3) for columns which are references to lookup, value from the primary key from lookup table is returned
            //      even if in definition of the dataset we have columns with the following application type: name@lookup, code @lookup and etc

            $isReferenceUsed = FALSE;
            $handler = DimensionLookupFactory::getInstance()->findHandler($column->type->getLogicalApplicationType());
            if (isset($handler)) {
                // FIXME remove this implementation when we implement 'Executable Tree' functionality
                list($connectedDatasetName, $connectedColumnName) = $handler->adjustReferencePointColumn($metamodel, $factsDataset->name, $columnName);
                if (($connectedDatasetName != $factsDataset->name) || ($connectedColumnName != $columnName)) {
                    self::$TABLE_ALIAS_SUFFIX__SEQUENCE++;
                    $columnJoinAliasPrefix = $TABLE_ALIAS__COLUMN_JOIN . self::$TABLE_ALIAS_SUFFIX__SEQUENCE;

                    $connectedDataset = $metamodel->getDataset($connectedDatasetName);
                    $connectedDatasetKeyColumnName = $connectedDataset->getKeyColumn()->name;

                    // preparing list of columns we want to get from connected dataset
                    $connectedDatasetColumnNames = NULL;
                    ArrayHelper::addUniqueValue($connectedDatasetColumnNames, $connectedDatasetKeyColumnName);
                    ArrayHelper::addUniqueValue($connectedDatasetColumnNames, $connectedColumnName);

                    $connectedStatement = $datasourceHandler->assembleDatasetSourceStatement($request, $connectedDataset, $connectedDatasetColumnNames);
                    $connectedStatement->addTableAliasPrefix($columnJoinAliasPrefix);

                    $connectedTable = $connectedStatement->getColumnTable($connectedColumnName);
                    // registering the column for facts table
                    $factsTableColumn = new ColumnSection($columnName, 'fact_' . $columnName);
                    $factsTableColumn->visible = FALSE;
                    $factsTable->columns[] = $factsTableColumn;
                    // adjusting key column from lookup
                    $connectedDatasetKeyColumn = $connectedTable->getColumn($connectedDatasetKeyColumnName);
                    $connectedDatasetKeyColumn->alias = 'lookup_' . $connectedDatasetKeyColumnName;
                    $connectedDatasetKeyColumn->visible = FALSE;
                    // adjusting value column from lookup
                    $connectedDatasetValueColumn = $connectedTable->getColumn($connectedColumnName);
                    $connectedDatasetValueColumn->alias = $columnName;
                    // the key column could be the same as value column
                    $connectedDatasetValueColumn->visible = TRUE;
                    // new value column which uses composite name as column alias
                    if (isset($columnDefaultAlias)) {
                        $connectedDatasetValueColumn2 = new ColumnSection(
                            $connectedColumnName,
                            DataSourceColumnNameHelper::generateFromParameterElements($datasourceHandler->getMaximumEntityNameLength(), $columnDefaultAlias));
                        $connectedDatasetValueColumn2->visible = FALSE;
                        $connectedTable->columns[] = $connectedDatasetValueColumn2;
                    }

                    // linking the lookup table with the facts table
                    $connectedTable->conditions[] = new JoinConditionSection(
                        $connectedDatasetKeyColumn->alias, new TableColumnConditionSectionValue($factsTable->alias, $columnName));

                    $statement->merge($connectedStatement);

                    $isReferenceUsed = TRUE;
                }
            }

            if (!$isReferenceUsed) {
                $factsTable->columns[] = new ColumnSection($columnName);
            }
        }

        return $statement;
    }
开发者ID:reisystems-india,项目名称:GovDashboard-Community,代码行数:99,代码来源:ReferenceDimensionDatasetAssembler.php

示例3: queryCube


//.........这里部分代码省略.........
                    $dimensionStatement = $this->prepareDatasetSourceStatement($callcontext, $request, $dimensionDataset, $usedColumnNames);

                    // updating dimension statement table aliases
                    $dimensionStatement->addTableAliasPrefix($dimensionTableAlias);

                    foreach ($dimensionStatement->tables as $table) {
                        if (!isset($table->columns)) {
                            $table->columns = array(); // We do not need any columns
                        }
                    }

                    // updating dimension statement column aliases
                    foreach ($requestDimension->columns as $requestColumn) {
                        $oldColumnAlias = $requestColumn->name;
                        $newColumnAlias = $dimensionColumnAliasMapping[$oldColumnAlias];

                        $dimensionTableSection = $dimensionStatement->getColumnTable($oldColumnAlias, TRUE);
                        $dimensionColumnSection = $dimensionTableSection->findColumnByAlias($oldColumnAlias);
                        if (isset($dimensionColumnSection)) {
                            $dimensionColumnSection->alias = $newColumnAlias;
                        }
                        else {
                            $dimensionColumnSection = new ColumnSection($oldColumnAlias, $newColumnAlias);
                            $dimensionTableSection->columns[] = $dimensionColumnSection;
                        }
                        $dimensionColumnSection->requestColumnIndex = $requestColumn->requestColumnIndex;
                    }

                    // adding condition to join with 'main' statement
                    $dimensionKeyTableSection = $dimensionStatement->getColumnTable($dimension->key);
                    $dimensionKeyTableSection->conditions[] = new JoinConditionSection(
                        $dimension->key, new TableColumnConditionSectionValue($TABLE_ALIAS__JOIN, $dimensionDatabaseColumnName));
                    // merging with 'main' statement
                    $joinStatement->merge($dimensionStatement);

                    // we do not need to return dimension key column
                    if ($isDimensionKeyColumnAdded && isset($dimensionKeyTableSection)) {
                        // FIXME this code does not work in the following case:
                        //   - our lookup dataset is fact dataset
                        //   - we need to work with project_id column from that dataset
                        //   - the column is present in *_facts and contains numeric value
                        //   - the column is present in *_c_project_id table and contains numeric value
                        //   - column 'value' in *_c_project_id table assigned an alias project_id
                        //   - more about implementation is in ReferenceDimensionDatasetAssembler
                        //   - the code is partially fixed by using $visibleOnly parameter
                        $tableSection = $dimensionStatement->getColumnTable($dimension->key, TRUE);
                        $keyColumn = $tableSection->findColumnByAlias($dimension->key);
                        if (isset($keyColumn)) {
                            $keyColumn->visible = FALSE;
                        }
                    }
                }
                else {
                    foreach ($requestDimension->columns as $requestColumn) {
                        $oldColumnAlias = $requestColumn->name;
                        $newColumnAlias = $dimensionColumnAliasMapping[$oldColumnAlias];

                        $column = new ColumnSection($newColumnAlias);
                        $column->requestColumnIndex = $requestColumn->requestColumnIndex;

                        $aggregationTableSection->columns[] = $column;
                    }
                }
            }
        }
开发者ID:reisystems-india,项目名称:GovDashboard-Community,代码行数:66,代码来源:AbstractSQLDataSourceQueryHandler.php

示例4: prepareReferencedCubeQueryStatement


//.........这里部分代码省略.........
                    }

                    foreach ($columnNames as $columnName) {
                        $parentDatabaseColumnName = DataSourceColumnNameHelper::generateFromParameterElements(
                            $datasourceHandler->getMaximumEntityNameLength(),
                            ($parentRequest->referenced ? ReferencePathHelper::assembleReference($parentCube->factsDatasetName, $parentDimension->name) : $parentDimension->name),
                            $columnName);

                        $referencedDatabaseColumnName = DataSourceColumnNameHelper::generateFromParameterElements(
                            $datasourceHandler->getMaximumEntityNameLength(),
                            ReferencePathHelper::assembleReference($referencedCube->factsDatasetName, $referencedDimension->name),
                            $columnName);

                        $joinConditions[] = new JoinConditionSection(
                            $referencedDatabaseColumnName, new TableColumnConditionSectionValue(self::$TABLE_ALIAS__REFERENCED . $link->linkId, $parentDatabaseColumnName));
                    }
                }
                if (!isset($joinConditions)) {
                    throw new IllegalArgumentException(t(
                        'There is no common columns to join %datasetNameA and %datasetNameB datasets',
                        array('%datasetNameA' => $parentCube->publicName, '%datasetNameB' => $referencedCube->publicName)));
                }

                // preparing aggregation statement for referenced cube
                $referencedAggregationStatement = $this->prepareSelectedCubeQueryStatement($datasourceHandler, $callcontext, $referencedRequest);
                list($isSubqueryRequired, $assembledReferencedCubeSections) = $referencedAggregationStatement->prepareSections(NULL);
                $referencedCubeSubquerySection = new SubquerySection(
                    Statement::assemble($isSubqueryRequired, NULL, $assembledReferencedCubeSections, SelectStatementPrint::INDENT__LEFT_OUTER_JOIN__SUBQUERY, FALSE),
                    self::$TABLE_ALIAS__REFERENCED . $referencedLink->linkId);

                // preparing columns which are returned by referenced aggregation
                foreach ($referencedAggregationStatement->tables as $table) {
                    if (!isset($table->columns)) {
                        continue;
                    }

                    foreach ($table->columns as $column) {
                        if (!$column->visible) {
                            continue;
                        }

                        $referencedCubeSubquerySection->columns[] = new ColumnSection($column->alias);
                    }
                }

                // linking with parent cube
                foreach ($joinConditions as $joinCondition) {
                    // we do not need to return columns which are used to join with parent cube
                    $referencedCubeSubquerySection->getColumn($joinCondition->subjectColumnName)->visible = FALSE;

                    $referencedCubeSubquerySection->conditions[] = $joinCondition;
                }

                // adding to resulting statement
                $combinedStatement->tables[] = $referencedCubeSubquerySection;

                // applying referenced cubes measure conditions on resulting statement as well
                $measureQueries = $referencedRequest->findMeasureQueries();
                if (isset($measureQueries)) {
                    foreach ($measureQueries as $measureQuery) {
                        $measureName = ReferencePathHelper::assembleReference($referencedCube->factsDatasetName, $measureQuery->name);
                        $measureDatabaseColumnName = DataSourceColumnNameHelper::generateFromParameterElements(
                            $datasourceHandler->getMaximumEntityNameLength(), $measureName);

                        foreach ($measureQuery->values as $value) {
                            $combinedStatement->conditions[] = new WhereConditionSection(
                                self::$TABLE_ALIAS__REFERENCED . $referencedLink->linkId,
                                $measureDatabaseColumnName,
                                    new ExactConditionSectionValue(
                                        $datasourceHandler->formatOperatorValue($callcontext, $referencedRequest, $referencedCube->factsDatasetName, NULL, $value)));
                        }
                    }
                }
            }
            else {
                throw new UnsupportedOperationException(t('Cube joins using intermediate dataset is not supported yet'));

                // preparing statement for intermediate dataset
                $requiredColumnNames = $referencedLink->columnNames;
                $referencedIntermediateDatasetStatement = $datasourceHandler->prepareDatasetSourceStatement($callcontext, NULL, $referencedLink->dataset, $requiredColumnNames);

                // adding condition to join with parent statement
                $referencedIntermediateDatasetTableSection = $referencedIntermediateDatasetStatement->tables[0];
                foreach ($referencedLink->columnNames as $columnIndex => $referencedColumnName) {
                    $referencedDatabaseColumnName = $referencedColumnName;

                    $parentColumnName = $referencedLink->parentColumnNames[$columnIndex];
                    $parentDatabaseColumnName = $parentColumnName;

                    $referencedIntermediateDatasetTableSection->conditions[] = new JoinConditionSection(
                        $referencedDatabaseColumnName, new TableColumnConditionSectionValue(self::$TABLE_ALIAS__REFERENCED . $link->linkId, $parentDatabaseColumnName));
                }

                $combinedStatement->merge($referencedIntermediateDatasetStatement);
            }

            // recursively check nested levels
            $this->prepareReferencedCubeQueryStatement($datasourceHandler, $callcontext, $combinedStatement, $datasetMappedCubeRequests, $referencedLink);
        }
    }
开发者ID:reisystems-india,项目名称:GovDashboard-Community,代码行数:101,代码来源:DefaultQueryEngine.php


注:本文中的Statement::merge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。