Examples of QueryPlan


Examples of org.apache.phoenix.compile.QueryPlan

        }
        return -1;
    }
   
    private static boolean addPlan(PhoenixStatement statement, SelectStatement select, PTable index, List<? extends PDatum> targetColumns, ParallelIteratorFactory parallelIteratorFactory, List<QueryPlan> plans) throws SQLException {
        QueryPlan dataPlan = plans.get(0);
        int nColumns = dataPlan.getProjector().getColumnCount();
        String alias = '"' + dataPlan.getTableRef().getTableAlias() + '"'; // double quote in case it's case sensitive
        String schemaName = dataPlan.getTableRef().getTable().getSchemaName().getString();
        schemaName = schemaName.length() == 0 ? null '"' + schemaName + '"';

        String tableName = '"' + index.getTableName().getString() + '"';
        List<? extends TableNode> tables = Collections.singletonList(FACTORY.namedTable(alias, FACTORY.table(schemaName, tableName)));
        try {
            SelectStatement indexSelect = FACTORY.select(select, tables);           
            QueryCompiler compiler = new QueryCompiler(statement, targetColumns, parallelIteratorFactory);
            QueryPlan plan = compiler.compile(indexSelect);
            // Checking the index status and number of columns handles the wildcard cases correctly
            // We can't check the status earlier, because the index table may be out-of-date.
            if (plan.getTableRef().getTable().getIndexState() == PIndexState.ACTIVE && plan.getProjector().getColumnCount() == nColumns) {
                plans.add(plan);
                return true;
            }
        } catch (ColumnNotFoundException e) {
            /* Means that a column is being used that's not in our index.
View Full Code Here

Examples of org.apache.phoenix.compile.QueryPlan

     *    c) the data table plan
     * @param plans the list of candidate plans
     * @return
     */
    private QueryPlan chooseBestPlan(SelectStatement select, List<QueryPlan> plans) {
        QueryPlan firstPlan = plans.get(0);
        if (plans.size() == 1) {
            return firstPlan;
        }
       
        /**
 
View Full Code Here

Examples of org.apache.phoenix.compile.QueryPlan

        return optimize(statement, select, FromCompiler.getResolverForQuery(select, statement.getConnection()), Collections.<PColumn>emptyList(), null);
    }

    public QueryPlan optimize(PhoenixStatement statement, SelectStatement select, ColumnResolver resolver, List<? extends PDatum> targetColumns, ParallelIteratorFactory parallelIteratorFactory) throws SQLException {
        QueryCompiler compiler = new QueryCompiler(statement, select, resolver, targetColumns, parallelIteratorFactory);
        QueryPlan dataPlan = compiler.compile();
        return optimize(dataPlan, statement, targetColumns, parallelIteratorFactory);
    }
View Full Code Here

Examples of org.apache.phoenix.compile.QueryPlan

        }
       
        SelectStatement translatedIndexSelect = IndexStatementRewriter.translate(select, dataPlan.getContext().getResolver());
        List<QueryPlan> plans = Lists.newArrayListWithExpectedSize(1 + indexes.size());
        plans.add(dataPlan);
        QueryPlan hintedPlan = getHintedQueryPlan(statement, translatedIndexSelect, indexes, targetColumns, parallelIteratorFactory, plans);
        if (hintedPlan != null) {
            return hintedPlan;
        }
        for (PTable index : indexes) {
            QueryPlan plan = addPlan(statement, translatedIndexSelect, index, targetColumns, parallelIteratorFactory, dataPlan);
            if (plan != null) {
                // Query can't possibly return anything so just return this plan.
                if (plan.isDegenerate()) {
                    return plan;
                }
                plans.add(plan);
            }
        }
View Full Code Here

Examples of org.apache.phoenix.compile.QueryPlan

       
        return chooseBestPlan(select, plans);
    }
   
    private static QueryPlan getHintedQueryPlan(PhoenixStatement statement, SelectStatement select, List<PTable> indexes, List<? extends PDatum> targetColumns, ParallelIteratorFactory parallelIteratorFactory, List<QueryPlan> plans) throws SQLException {
        QueryPlan dataPlan = plans.get(0);
        String indexHint = select.getHint().getHint(Hint.INDEX);
        if (indexHint == null) {
            return null;
        }
        int startIndex = 0;
        String alias = dataPlan.getTableRef().getTableAlias();
        String prefix = HintNode.PREFIX + (alias == null ? dataPlan.getTableRef().getTable().getName().getString() : alias) + HintNode.SEPARATOR;
        while (startIndex < indexHint.length()) {
            startIndex = indexHint.indexOf(prefix, startIndex);
            if (startIndex < 0) {
                return null;
            }
            startIndex += prefix.length();
            boolean done = false; // true when SUFFIX found
            while (startIndex < indexHint.length() && !done) {
                int endIndex;
                int endIndex1 = indexHint.indexOf(HintNode.SEPARATOR, startIndex);
                int endIndex2 = indexHint.indexOf(HintNode.SUFFIX, startIndex);
                if (endIndex1 < 0 && endIndex2 < 0) { // Missing SUFFIX shouldn't happen
                    endIndex = indexHint.length();
                } else if (endIndex1 < 0) {
                    done = true;
                    endIndex = endIndex2;
                } else if (endIndex2 < 0) {
                    endIndex = endIndex1;
                } else {
                    endIndex = Math.min(endIndex1, endIndex2);
                    done = endIndex2 == endIndex;
                }
                String indexName = indexHint.substring(startIndex, endIndex);
                int indexPos = getIndexPosition(indexes, indexName);
                if (indexPos >= 0) {
                    // Hinted index is applicable, so return it. It'll be the plan at position 1, after the data plan
                    QueryPlan plan = addPlan(statement, select, indexes.get(indexPos), targetColumns, parallelIteratorFactory, dataPlan);
                    if (plan != null) {
                        return plan;
                    }
                    indexes.remove(indexPos);
                }
View Full Code Here

Examples of org.apache.phoenix.compile.QueryPlan

            SelectStatement indexSelect = FACTORY.select(select, tables);
            ColumnResolver resolver = FromCompiler.getResolverForQuery(indexSelect, statement.getConnection());
            // Check index state of now potentially updated index table to make sure it's active
            if (PIndexState.ACTIVE.equals(resolver.getTables().get(0).getTable().getIndexState())) {
                QueryCompiler compiler = new QueryCompiler(statement, indexSelect, resolver, targetColumns, parallelIteratorFactory);
                QueryPlan plan = compiler.compile();
                // Checking number of columns handles the wildcard cases correctly, as in that case the index
                // must contain all columns from the data table to be able to be used.
                if (plan.getTableRef().getTable().getIndexState() == PIndexState.ACTIVE && plan.getProjector().getColumnCount() == nColumns) {
                    return plan;
                }
            }
        } catch (ColumnNotFoundException e) {
            /* Means that a column is being used that's not in our index.
View Full Code Here

Examples of org.apache.phoenix.compile.QueryPlan

     *    c) the data table plan
     * @param plans the list of candidate plans
     * @return
     */
    private QueryPlan chooseBestPlan(SelectStatement select, List<QueryPlan> plans) {
        final QueryPlan dataPlan = plans.get(0);
        if (plans.size() == 1) {
            return dataPlan;
        }
       
        /**
         * If we have a plan(s) that are just point lookups (i.e. fully qualified row
         * keys), then favor those first.
         */
        List<QueryPlan> candidates = Lists.newArrayListWithExpectedSize(plans.size());
        for (QueryPlan plan : plans) {
            if (plan.getContext().getScanRanges().isPointLookup()) {
                candidates.add(plan);
            }
        }
        /**
         * If we have a plan(s) that removes the order by, choose from among these,
         * as this is typically the most expensive operation. Once we have stats, if
         * there's a limit on the query, we might choose a different plan. For example
         * if the limit was a very large number and the combination of applying other
         * filters on the row key are estimated to choose fewer rows, we'd choose that
         * one.
         */
        List<QueryPlan> stillCandidates = plans;
        List<QueryPlan> bestCandidates = candidates;
        if (!candidates.isEmpty()) {
            stillCandidates = candidates;
            bestCandidates = Lists.<QueryPlan>newArrayListWithExpectedSize(candidates.size());
        }
        for (QueryPlan plan : stillCandidates) {
            // If ORDER BY optimized out (or not present at all)
            if (plan.getOrderBy().getOrderByExpressions().isEmpty()) {
                bestCandidates.add(plan);
            }
        }
        if (bestCandidates.isEmpty()) {
            bestCandidates.addAll(stillCandidates);
        }
       
        int nViewConstants = 0;
        PTable dataTable = dataPlan.getTableRef().getTable();
        if (dataTable.getType() == PTableType.VIEW) {
            for (PColumn column : dataTable.getColumns()) {
                if (column.getViewConstant() != null) {
                    nViewConstants++;
                }
View Full Code Here

Examples of org.apache.phoenix.compile.QueryPlan

            // region observer to generate the index rows based on the data rows as we scan
            if (index.getIndexType() == IndexType.LOCAL) {
                final PhoenixStatement statement = new PhoenixStatement(connection);
                String tableName = getFullTableName(dataTableRef);
                String query = "SELECT count(*) FROM " + tableName;
                QueryPlan plan = statement.compileQuery(query);
                TableRef tableRef = plan.getContext().getResolver().getTables().get(0);
                // Set attribute on scan that UngroupedAggregateRegionObserver will switch on.
                // We'll detect that this attribute was set the server-side and write the index
                // rows per region as a result. The value of the attribute will be our persisted
                // index maintainers.
                // Define the LOCAL_INDEX_BUILD as a new static in BaseScannerRegionObserver
                Scan scan = plan.getContext().getScan();
                try {
                    scan.setTimeRange(dataTableRef.getLowerBoundTimeStamp(), Long.MAX_VALUE);
                } catch (IOException e) {
                    throw new SQLException(e);
                }
                ImmutableBytesWritable ptr = new ImmutableBytesWritable();
                PTable dataTable = tableRef.getTable();
                List<PTable> indexes = Lists.newArrayListWithExpectedSize(1);
                // Only build newly created index.
                indexes.add(index);
                IndexMaintainer.serialize(dataTable, ptr, indexes);
                scan.setAttribute(BaseScannerRegionObserver.LOCAL_INDEX_BUILD, ByteUtil.copyKeyBytesIfNecessary(ptr));
                // By default, we'd use a FirstKeyOnly filter as nothing else needs to be projected for count(*).
                // However, in this case, we need to project all of the data columns that contribute to the index.
                IndexMaintainer indexMaintainer = index.getIndexMaintainer(dataTable);
                for (ColumnReference columnRef : indexMaintainer.getAllColumns()) {
                    scan.addColumn(columnRef.getFamily(), columnRef.getQualifier());
                }
                Cell kv = plan.iterator().next().getValue(0);
                ImmutableBytesWritable tmpPtr = new ImmutableBytesWritable(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength());
                // A single Cell will be returned with the count(*) - we decode that here
                long rowCount = PDataType.LONG.getCodec().decodeLong(tmpPtr, SortOrder.getDefault());
                // The contract is to return a MutationState that contains the number of rows modified. In this
                // case, it's the number of rows in the data table which corresponds to the number of index
                // rows that were added.
                state = new MutationState(0, connection, rowCount);
            } else {
                PostIndexDDLCompiler compiler = new PostIndexDDLCompiler(connection, dataTableRef);
                MutationPlan plan = compiler.compile(index);
                try {
                    plan.getContext().setScanTimeRange(new TimeRange(dataTableRef.getLowerBoundTimeStamp(), Long.MAX_VALUE));
                } catch (IOException e) {
                    throw new SQLException(e);
                }
                state = connection.getQueryServices().updateData(plan);
            }           
View Full Code Here

Examples of plan_runner.query_plans.QueryPlan

    final String queryName = SystemParameters.getString(conf, "DIP_QUERY_NAME");
    // if "/" is the last character, adding one more is not a problem
    final String dataPath = SystemParameters.getString(conf, "DIP_DATA_PATH") + "/";
    final String extension = SystemParameters.getString(conf, "DIP_EXTENSION");

    QueryPlan queryPlan = null;

    // change between this and ...
    if (queryName.equalsIgnoreCase("rst"))
      queryPlan = new RSTPlan(dataPath, extension, conf).getQueryPlan();
    else if (queryName.equalsIgnoreCase("hyracks"))
View Full Code Here

Examples of plan_runner.query_plans.QueryPlan

  }

  public Main(String[] args) {
    final String confPath = args[0];
    final Config conf = SystemParameters.fileToStormConfig(confPath);
    final QueryPlan queryPlan = chooseQueryPlan(conf);

    addVariablesToMap(conf, confPath);
    putBatchSizes(queryPlan, conf);
    final TopologyBuilder builder = createTopology(queryPlan, conf);
    StormWrapper.submitTopology(conf, builder);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.