Search in sources :

Example 26 with ExpressionType

use of org.voltdb.types.ExpressionType in project voltdb by VoltDB.

the class AggregatePlanNode method setAggregatePlanNode.

private static AggregatePlanNode setAggregatePlanNode(AggregatePlanNode origin, AggregatePlanNode destination) {
    destination.m_isCoordinatingAggregator = origin.m_isCoordinatingAggregator;
    destination.m_prePredicate = origin.m_prePredicate;
    destination.m_postPredicate = origin.m_postPredicate;
    for (AbstractExpression expr : origin.m_groupByExpressions) {
        destination.addGroupByExpression(expr);
    }
    List<ExpressionType> aggregateTypes = origin.m_aggregateTypes;
    List<Integer> aggregateDistinct = origin.m_aggregateDistinct;
    List<Integer> aggregateOutputColumns = origin.m_aggregateOutputColumns;
    List<AbstractExpression> aggregateExpressions = origin.m_aggregateExpressions;
    for (int i = 0; i < origin.getAggregateTypesSize(); i++) {
        destination.addAggregate(aggregateTypes.get(i), aggregateDistinct.get(i) == 1 ? true : false, aggregateOutputColumns.get(i), aggregateExpressions.get(i));
    }
    destination.setOutputSchema(origin.getOutputSchema());
    return destination;
}
Also used : AbstractExpression(org.voltdb.expressions.AbstractExpression) ExpressionType(org.voltdb.types.ExpressionType)

Example 27 with ExpressionType

use of org.voltdb.types.ExpressionType in project voltdb by VoltDB.

the class ViewExplainer method explain.

public static ArrayList<String[]> explain(Table viewTable) throws Exception {
    String viewName = viewTable.getTypeName();
    MaterializedViewHandlerInfo mvHandlerInfo = viewTable.getMvhandlerinfo().get("mvHandlerInfo");
    MaterializedViewInfo mvInfo = null;
    CatalogMap<Statement> fallBackQueryStmts;
    List<Column> destColumnArray = CatalogUtil.getSortedCatalogItems(viewTable.getColumns(), "index");
    ArrayList<String[]> retval = new ArrayList<String[]>();
    // Is this view single-table?
    if (mvHandlerInfo == null) {
        // (Legacy code for single table view uses a different model and code path)
        if (viewTable.getMaterializer() == null) {
            // If we cannot find view metadata from both locations, this table is not a materialized view.
            throw new Exception("Table " + viewName + " is not a view.");
        }
        mvInfo = viewTable.getMaterializer().getViews().get(viewName);
        fallBackQueryStmts = mvInfo.getFallbackquerystmts();
    } else {
        // For multi-table views we need to show the query plan for evaluating joins.
        Statement createQuery = mvHandlerInfo.getCreatequery().get("createQuery");
        retval.add(new String[] { "Join Evaluation", Encoder.hexDecodeToString(createQuery.getExplainplan()) });
        fallBackQueryStmts = mvHandlerInfo.getFallbackquerystmts();
    }
    // For each min/max column find out if an execution plan is used.
    int minMaxAggIdx = 0;
    for (int j = 0; j < destColumnArray.size(); j++) {
        Column destColumn = destColumnArray.get(j);
        ExpressionType aggType = ExpressionType.get(destColumn.getAggregatetype());
        if (aggType == ExpressionType.AGGREGATE_MIN || aggType == ExpressionType.AGGREGATE_MAX) {
            Statement fallBackQueryStmt = fallBackQueryStmts.get(String.valueOf(minMaxAggIdx));
            // How this min/max will be refreshed?
            String plan = "";
            //   * execution plan
            if (mvHandlerInfo == null) {
                CatalogMap<IndexRef> hardCodedIndicesForSingleTableView = mvInfo.getIndexforminmax();
                String hardCodedIndexName = hardCodedIndicesForSingleTableView.get(String.valueOf(minMaxAggIdx)).getName();
                String indexNameUsedInStatement = getIndexNameUsedInStatement(fallBackQueryStmt);
                if (!indexNameUsedInStatement.equalsIgnoreCase(hardCodedIndexName)) {
                    plan = Encoder.hexDecodeToString(fallBackQueryStmt.getExplainplan());
                }
                // If we do not use execution plan, see which built-in method is used.
                if (plan.equals("")) {
                    if (hardCodedIndexName.equals("")) {
                        plan = "Built-in sequential scan.";
                    } else {
                        plan = "Built-in index scan \"" + hardCodedIndexName + "\".";
                    }
                }
            } else {
                plan = Encoder.hexDecodeToString(fallBackQueryStmt.getExplainplan());
            }
            retval.add(new String[] { "Refresh " + (aggType == ExpressionType.AGGREGATE_MIN ? "MIN" : "MAX") + " column \"" + destColumn.getName() + "\"", plan });
            minMaxAggIdx++;
        }
    }
    return retval;
}
Also used : MaterializedViewInfo(org.voltdb.catalog.MaterializedViewInfo) Statement(org.voltdb.catalog.Statement) ArrayList(java.util.ArrayList) IndexRef(org.voltdb.catalog.IndexRef) Column(org.voltdb.catalog.Column) MaterializedViewHandlerInfo(org.voltdb.catalog.MaterializedViewHandlerInfo) ExpressionType(org.voltdb.types.ExpressionType)

Example 28 with ExpressionType

use of org.voltdb.types.ExpressionType in project voltdb by VoltDB.

the class AbstractExpression method fromJSONObject.

private static AbstractExpression fromJSONObject(JSONObject obj, StmtTableScan tableScan) throws JSONException {
    ExpressionType type = ExpressionType.get(obj.getInt(Members.TYPE));
    AbstractExpression expr;
    try {
        expr = type.getExpressionClass().newInstance();
    } catch (InstantiationException e) {
        e.printStackTrace();
        return null;
    } catch (IllegalAccessException e) {
        e.printStackTrace();
        return null;
    }
    expr.m_type = type;
    expr.m_valueType = VoltType.get((byte) obj.getInt(Members.VALUE_TYPE));
    if (obj.has(Members.VALUE_SIZE)) {
        expr.m_valueSize = obj.getInt(Members.VALUE_SIZE);
    } else {
        expr.m_valueSize = expr.m_valueType.getLengthInBytesForFixedTypes();
    }
    expr.m_left = fromJSONChild(obj, Members.LEFT, tableScan);
    expr.m_right = fromJSONChild(obj, Members.RIGHT, tableScan);
    if (!obj.isNull(Members.ARGS)) {
        JSONArray jarray = obj.getJSONArray(Members.ARGS);
        ArrayList<AbstractExpression> arguments = new ArrayList<>();
        loadFromJSONArray(arguments, jarray, tableScan);
        expr.setArgs(arguments);
    }
    expr.loadFromJSONObject(obj, tableScan);
    return expr;
}
Also used : JSONArray(org.json_voltpatches.JSONArray) ArrayList(java.util.ArrayList) ExpressionType(org.voltdb.types.ExpressionType)

Example 29 with ExpressionType

use of org.voltdb.types.ExpressionType in project voltdb by VoltDB.

the class OperatorExpression method refineOperandType.

@Override
public void refineOperandType(VoltType columnType) {
    if ((m_valueType != null) && (m_valueType != VoltType.NUMERIC)) {
        return;
    }
    ExpressionType type = getExpressionType();
    if (type == ExpressionType.OPERATOR_IS_NULL || type == ExpressionType.OPERATOR_NOT) {
        m_valueType = VoltType.BOOLEAN;
        m_valueSize = m_valueType.getLengthInBytesForFixedTypes();
        return;
    }
    m_left.refineOperandType(columnType);
    //XXX Not sure how unary minus (and unary plus?) are handled (possibly via an implicit zero left argument?)
    m_right.refineOperandType(columnType);
    VoltType cast_type = VoltTypeUtil.determineImplicitCasting(m_left.getValueType(), m_right.getValueType());
    if (cast_type == VoltType.INVALID) {
        throw new RuntimeException("ERROR: Invalid output value type for Expression '" + this + "'");
    }
    m_valueType = cast_type;
    m_valueSize = cast_type.getLengthInBytesForFixedTypes();
}
Also used : VoltType(org.voltdb.VoltType) ExpressionType(org.voltdb.types.ExpressionType)

Example 30 with ExpressionType

use of org.voltdb.types.ExpressionType in project voltdb by VoltDB.

the class TestPlansApproxCountDistinct method assertAggPlanNodeContainsFunctions.

private void assertAggPlanNodeContainsFunctions(AggregatePlanNode node, ExpressionType[] expectedAggFns) {
    List<ExpressionType> actualAggFns = node.getAggregateTypes();
    assertEquals("Wrong number of aggregate functions in plan", expectedAggFns.length, actualAggFns.size());
    int i = 0;
    for (ExpressionType expectedAggFn : expectedAggFns) {
        assertEquals("Found unexpected agg function", expectedAggFn, actualAggFns.get(i));
        ++i;
    }
}
Also used : ExpressionType(org.voltdb.types.ExpressionType)

Aggregations

ExpressionType (org.voltdb.types.ExpressionType)30 AbstractExpression (org.voltdb.expressions.AbstractExpression)16 ArrayList (java.util.ArrayList)6 ComparisonExpression (org.voltdb.expressions.ComparisonExpression)6 JSONException (org.json_voltpatches.JSONException)5 VoltType (org.voltdb.VoltType)5 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)5 Constraint (org.voltdb.catalog.Constraint)4 VoltXMLElement (org.hsqldb_voltpatches.VoltXMLElement)3 Column (org.voltdb.catalog.Column)3 AggregateExpression (org.voltdb.expressions.AggregateExpression)3 ColumnRef (org.voltdb.catalog.ColumnRef)2 MaterializedViewHandlerInfo (org.voltdb.catalog.MaterializedViewHandlerInfo)2 MaterializedViewInfo (org.voltdb.catalog.MaterializedViewInfo)2 OperatorExpression (org.voltdb.expressions.OperatorExpression)2 SelectSubqueryExpression (org.voltdb.expressions.SelectSubqueryExpression)2 WindowFunctionExpression (org.voltdb.expressions.WindowFunctionExpression)2 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)2 AggregatePlanNode (org.voltdb.plannodes.AggregatePlanNode)2 HashAggregatePlanNode (org.voltdb.plannodes.HashAggregatePlanNode)2