Search in sources :

Example 1 with NON_DETERMINISTIC

use of com.facebook.presto.verifier.framework.LimitQueryDeterminismAnalysis.NON_DETERMINISTIC in project presto by prestodb.

the class LimitQueryDeterminismAnalyzer method analyzeLimitNoOrderBy.

private LimitQueryDeterminismAnalysis analyzeLimitNoOrderBy(Query newLimitQuery, long limit) {
    Query rowCountQuery = simpleQuery(new Select(false, ImmutableList.of(new SingleColumn(new FunctionCall(QualifiedName.of("count"), ImmutableList.of(new LongLiteral("1")))))), new TableSubquery(newLimitQuery));
    QueryResult<Long> result = callAndConsume(() -> prestoAction.execute(rowCountQuery, DETERMINISM_ANALYSIS_MAIN, resultSet -> Optional.of(resultSet.getLong(1))), stats -> stats.getQueryStats().map(QueryStats::getQueryId).ifPresent(determinismAnalysisDetails::setLimitQueryAnalysisQueryId));
    long rowCountHigherLimit = getOnlyElement(result.getResults());
    if (rowCountHigherLimit == rowCount) {
        return DETERMINISTIC;
    }
    if (rowCountHigherLimit > rowCount) {
        return NON_DETERMINISTIC;
    }
    return FAILED_DATA_CHANGED;
}
Also used : QualifiedName(com.facebook.presto.sql.tree.QualifiedName) NOT_RUN(com.facebook.presto.verifier.framework.LimitQueryDeterminismAnalysis.NOT_RUN) SingleColumn(com.facebook.presto.sql.tree.SingleColumn) ArrayList(java.util.ArrayList) VerifierUtil.callAndConsume(com.facebook.presto.verifier.framework.VerifierUtil.callAndConsume) Identifier(com.facebook.presto.sql.tree.Identifier) SQLException(java.sql.SQLException) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) ResultSet(java.sql.ResultSet) SelectItem(com.facebook.presto.sql.tree.SelectItem) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) QueryStats(com.facebook.presto.jdbc.QueryStats) TableSubquery(com.facebook.presto.sql.tree.TableSubquery) DETERMINISTIC(com.facebook.presto.verifier.framework.LimitQueryDeterminismAnalysis.DETERMINISTIC) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Math.toIntExact(java.lang.Math.toIntExact) NON_DETERMINISTIC(com.facebook.presto.verifier.framework.LimitQueryDeterminismAnalysis.NON_DETERMINISTIC) ENGLISH(java.util.Locale.ENGLISH) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) CreateTableAsSelect(com.facebook.presto.sql.tree.CreateTableAsSelect) OrderBy(com.facebook.presto.sql.tree.OrderBy) Query(com.facebook.presto.sql.tree.Query) QuerySpecification(com.facebook.presto.sql.tree.QuerySpecification) With(com.facebook.presto.sql.tree.With) Set(java.util.Set) VerifierUtil.getColumnIndices(com.facebook.presto.verifier.framework.VerifierUtil.getColumnIndices) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) ResultSetConverter(com.facebook.presto.verifier.prestoaction.PrestoAction.ResultSetConverter) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Insert(com.facebook.presto.sql.tree.Insert) Objects(java.util.Objects) DeterminismAnalysisDetails(com.facebook.presto.verifier.event.DeterminismAnalysisDetails) List(java.util.List) Expression(com.facebook.presto.sql.tree.Expression) FAILED_DATA_CHANGED(com.facebook.presto.verifier.framework.LimitQueryDeterminismAnalysis.FAILED_DATA_CHANGED) FAILED_QUERY_FAILURE(com.facebook.presto.verifier.framework.LimitQueryDeterminismAnalysis.FAILED_QUERY_FAILURE) PrestoAction(com.facebook.presto.verifier.prestoaction.PrestoAction) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) Optional(java.util.Optional) VerifierUtil.delimitedIdentifier(com.facebook.presto.verifier.framework.VerifierUtil.delimitedIdentifier) Select(com.facebook.presto.sql.tree.Select) Long.parseLong(java.lang.Long.parseLong) DETERMINISM_ANALYSIS_MAIN(com.facebook.presto.verifier.framework.QueryStage.DETERMINISM_ANALYSIS_MAIN) Statement(com.facebook.presto.sql.tree.Statement) QueryUtil.simpleQuery(com.facebook.presto.sql.QueryUtil.simpleQuery) Query(com.facebook.presto.sql.tree.Query) QueryUtil.simpleQuery(com.facebook.presto.sql.QueryUtil.simpleQuery) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) QueryStats(com.facebook.presto.jdbc.QueryStats) CreateTableAsSelect(com.facebook.presto.sql.tree.CreateTableAsSelect) Select(com.facebook.presto.sql.tree.Select) Long.parseLong(java.lang.Long.parseLong) SingleColumn(com.facebook.presto.sql.tree.SingleColumn) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) TableSubquery(com.facebook.presto.sql.tree.TableSubquery)

Aggregations

QueryStats (com.facebook.presto.jdbc.QueryStats)1 QueryUtil.simpleQuery (com.facebook.presto.sql.QueryUtil.simpleQuery)1 CreateTableAsSelect (com.facebook.presto.sql.tree.CreateTableAsSelect)1 Expression (com.facebook.presto.sql.tree.Expression)1 FunctionCall (com.facebook.presto.sql.tree.FunctionCall)1 Identifier (com.facebook.presto.sql.tree.Identifier)1 Insert (com.facebook.presto.sql.tree.Insert)1 LongLiteral (com.facebook.presto.sql.tree.LongLiteral)1 OrderBy (com.facebook.presto.sql.tree.OrderBy)1 QualifiedName (com.facebook.presto.sql.tree.QualifiedName)1 Query (com.facebook.presto.sql.tree.Query)1 QuerySpecification (com.facebook.presto.sql.tree.QuerySpecification)1 Select (com.facebook.presto.sql.tree.Select)1 SelectItem (com.facebook.presto.sql.tree.SelectItem)1 SingleColumn (com.facebook.presto.sql.tree.SingleColumn)1 Statement (com.facebook.presto.sql.tree.Statement)1 TableSubquery (com.facebook.presto.sql.tree.TableSubquery)1 With (com.facebook.presto.sql.tree.With)1 DeterminismAnalysisDetails (com.facebook.presto.verifier.event.DeterminismAnalysisDetails)1 DETERMINISTIC (com.facebook.presto.verifier.framework.LimitQueryDeterminismAnalysis.DETERMINISTIC)1