Examples of QueryPlan


Examples of org.apache.phoenix.compile.QueryPlan

            final int index = i;
            futures.add(executor.submit(new JobCallable<ServerCache>() {

                @Override
                public ServerCache call() throws Exception {
                    QueryPlan hashPlan = hashPlans[index];
                    ServerCache cache = hashClient.addHashCache(ranges, hashPlan.iterator(),
                            clientProjectors[index], hashPlan.getEstimatedSize(), hashExpressions[index], plan.getTableRef());
                    long endTime = System.currentTimeMillis();
                    boolean isSet = firstJobEndTime.compareAndSet(0, endTime);
                    if (!isSet && (endTime - firstJobEndTime.get()) > maxServerCacheTimeToLive) {
                        LOG.warn("Hash plan [" + index + "] execution seems too slow. Earlier hash cache(s) might have expired on servers.");
                    }
View Full Code Here

Examples of org.apache.phoenix.compile.QueryPlan

                params.set(i, null);
            }
        }
        try {
            // Just compile top level query without optimizing to get ResultSetMetaData
            QueryPlan plan = statement.compilePlan(this, Sequence.ValueOp.VALIDATE_SEQUENCE);
            return new PhoenixResultSetMetaData(this.getConnection(), plan.getProjector());
        } finally {
            int lastSetBit = 0;
            while ((lastSetBit = unsetParams.nextSetBit(lastSetBit)) != -1) {
                params.set(lastSetBit, BindManager.UNBOUND_PARAMETER);
                lastSetBit++;
View Full Code Here

Examples of org.apache.phoenix.compile.QueryPlan

        Connection connection = null;
        try {
            connection = this.phoenixConfiguration.getConnection();
            final Statement  statement = connection.createStatement();
            final PhoenixStatement pstmt = statement.unwrap(PhoenixStatement.class);
            final QueryPlan queryPlan = pstmt.compileQuery(selectStatement);
            isValidStatement(queryPlan);
            final String tableName = queryPlan.getTableRef().getTable().getName().getString();
            final List<? extends ColumnProjector> projectedColumns = queryPlan.getProjector().getColumnProjectors();
            final List<String> columns = Lists.transform(projectedColumns,
                                                            new Function<ColumnProjector,String>() {
                                                                @Override
                                                                public String apply(ColumnProjector column) {
                                                                    return column.getName();
View Full Code Here

Examples of org.apache.phoenix.compile.QueryPlan

    List<ColumnInfo> columnInfos = null;
        try {
            connection = this.phoenixConfiguration.getConnection();
            final Statement  statement = connection.createStatement();
            final PhoenixStatement pstmt = statement.unwrap(PhoenixStatement.class);
            final QueryPlan queryPlan = pstmt.compileQuery(sqlQuery);
            final List<? extends ColumnProjector> projectedColumns = queryPlan.getProjector().getColumnProjectors();
            columnInfos = Lists.newArrayListWithCapacity(projectedColumns.size());
            columnInfos = Lists.transform(projectedColumns, new Function<ColumnProjector,ColumnInfo>() {
              @Override
        public ColumnInfo apply(final ColumnProjector columnProjector) {
          return new ColumnInfo(columnProjector.getName(), columnProjector.getExpression().getDataType().getSqlType());
View Full Code Here

Examples of org.apache.phoenix.compile.QueryPlan

    @Override
    public RecordReader<NullWritable, PhoenixRecord> createRecordReader(InputSplit split, TaskAttemptContext context)
            throws IOException, InterruptedException {      
        setConf(context.getConfiguration());
        final QueryPlan queryPlan = getQueryPlan(context);
        try {
            return new PhoenixRecordReader(phoenixConfiguration,queryPlan);   
        }catch(SQLException sqle) {
            throw new IOException(sqle);
        }
View Full Code Here

Examples of org.apache.phoenix.compile.QueryPlan

    @Override
    public List<InputSplit> getSplits(JobContext context) throws IOException, InterruptedException {       
        List<InputSplit> splits = null;
        try{
            setConf(context.getConfiguration());
            final QueryPlan queryPlan = getQueryPlan(context);
            @SuppressWarnings("unused")
            final ResultIterator iterator = queryPlan.iterator();
            final List<KeyRange> allSplits = queryPlan.getSplits();
            splits = generateSplits(queryPlan,allSplits);
        } catch(SQLException sqlE) {
            LOG.error(String.format(" Error [%s] in getSplits of PhoenixInputFormat ", sqlE.getMessage()));
            Throwables.propagate(sqlE);
        }
View Full Code Here

Examples of org.apache.phoenix.compile.QueryPlan

            super(from, hint, isDistinct, select, where, groupBy, having, orderBy, limit, bindCount, isAggregate);
        }

        @Override
        public PhoenixResultSet executeQuery() throws SQLException {
            QueryPlan plan = optimizePlan();
            Scanner scanner = plan.getScanner();
            PhoenixResultSet rs = newResultSet(scanner);
            resultSets.add(rs);
            lastResultSet = rs;
            lastUpdateCount = NO_UPDATE;
            lastUpdateOperation = null;
View Full Code Here

Examples of org.apache.phoenix.compile.QueryPlan

       
        @Override
        public ResultSetMetaData getResultSetMetaData() throws SQLException {
            if (resultSetMetaData == null) {
                // Just compile top level query without optimizing to get ResultSetMetaData
                QueryPlan plan = new QueryCompiler(PhoenixStatement.this).compile(this);
                resultSetMetaData = new PhoenixResultSetMetaData(connection, plan.getProjector());
            }
            return resultSetMetaData;
        }
View Full Code Here

Examples of org.apache.phoenix.compile.QueryPlan

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

    public QueryPlan optimize(SelectStatement select, PhoenixStatement statement, List<? extends PDatum> targetColumns, ParallelIteratorFactory parallelIteratorFactory) throws SQLException {
        QueryCompiler compiler = new QueryCompiler(statement, targetColumns, parallelIteratorFactory);
        QueryPlan dataPlan = compiler.compile(select);
        if (!useIndexes) {
            return dataPlan;
        }
        // Get the statement as it's been normalized now
        // TODO: the recompile for the index tables could skip the normalize step
        select = (SelectStatement)dataPlan.getStatement();
        PTable dataTable = dataPlan.getTableRef().getTable();
        List<PTable>indexes = Lists.newArrayList(dataTable.getIndexes());
        if (indexes.isEmpty() || dataPlan.getTableRef().hasDynamicCols() || select.getHint().hasHint(Hint.NO_INDEX)) {
            return dataPlan;
        }
       
        // The targetColumns is set for UPSERT SELECT to ensure that the proper type conversion takes place.
        // For a SELECT, it is empty. In this case, we want to set the targetColumns to match the projection
        // from the dataPlan to ensure that the metadata for when an index is used matches the metadata for
        // when the data table is used.
        if (targetColumns.isEmpty()) {
            List<? extends ColumnProjector> projectors = dataPlan.getProjector().getColumnProjectors();
            List<PDatum> targetDatums = Lists.newArrayListWithExpectedSize(projectors.size());
            for (ColumnProjector projector : projectors) {
                targetDatums.add(projector.getExpression());
            }
            targetColumns = targetDatums;
        }
       
        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) {
            addPlan(statement, translatedIndexSelect, index, targetColumns, parallelIteratorFactory, plans);
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;
            }
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.