Search in sources :

Example 1 with VoltXMLElement

use of org.hsqldb_voltpatches.VoltXMLElement in project voltdb by VoltDB.

the class ReplicateTable method processStatement.

@Override
protected boolean processStatement(DDLStatement ddlStatement, Database db, DdlProceduresToLoad whichProcs) throws VoltCompilerException {
    // matches if it is REPLICATE TABLE <table-name>
    Matcher statementMatcher = SQLParser.matchReplicateTable(ddlStatement.statement);
    if (!statementMatcher.matches()) {
        return false;
    }
    // group(1) -> table
    String tableName = checkIdentifierStart(statementMatcher.group(1), ddlStatement.statement);
    VoltXMLElement tableXML = m_schema.findChild("table", tableName.toUpperCase());
    if (tableXML != null) {
        tableXML.attributes.remove("partitioncolumn");
        // mark the table as dirty for the purposes of caching sql statements
        m_compiler.markTableAsDirty(tableName);
    } else {
        throw m_compiler.new VoltCompilerException(String.format("Invalid REPLICATE statement: table %s does not exist", tableName));
    }
    return true;
}
Also used : Matcher(java.util.regex.Matcher) VoltXMLElement(org.hsqldb_voltpatches.VoltXMLElement) VoltCompilerException(org.voltdb.compiler.VoltCompiler.VoltCompilerException)

Example 2 with VoltXMLElement

use of org.hsqldb_voltpatches.VoltXMLElement in project voltdb by VoltDB.

the class AbstractParsedStmt method parseParameters.

/**
     * Populate the statement's paramList from the "parameters" element. Each
     * parameter has an id and an index, both of which are numeric. It also has
     * a type and an indication of whether it's a vector parameter. For each
     * parameter, we create a ParameterValueExpression, named pve, which holds
     * the type and vector parameter indication. We add the pve to two maps,
     * m_paramsById and m_paramsByIndex.
     *
     * We also set a counter, MAX_PARAMETER_ID, to the largest id in the
     * expression. This helps give ids to references to correlated expressions
     * of subqueries.
     *
     * @param paramsNode
     */
protected void parseParameters(VoltXMLElement root) {
    VoltXMLElement paramsNode = null;
    for (VoltXMLElement node : root.children) {
        if (node.name.equalsIgnoreCase("parameters")) {
            paramsNode = node;
            break;
        }
    }
    if (paramsNode == null) {
        return;
    }
    long max_parameter_id = -1;
    for (VoltXMLElement node : paramsNode.children) {
        if (node.name.equalsIgnoreCase("parameter")) {
            long id = Long.parseLong(node.attributes.get("id"));
            int index = Integer.parseInt(node.attributes.get("index"));
            if (index > max_parameter_id) {
                max_parameter_id = index;
            }
            String typeName = node.attributes.get("valuetype");
            String isVectorParam = node.attributes.get("isvector");
            VoltType type = VoltType.typeFromString(typeName);
            ParameterValueExpression pve = new ParameterValueExpression();
            pve.setParameterIndex(index);
            pve.setValueType(type);
            if (isVectorParam != null && isVectorParam.equalsIgnoreCase("true")) {
                pve.setParamIsVector();
            }
            m_paramsById.put(id, pve);
            m_paramsByIndex.put(index, pve);
        }
    }
    if (max_parameter_id >= NEXT_PARAMETER_ID) {
        NEXT_PARAMETER_ID = (int) max_parameter_id + 1;
    }
}
Also used : VoltType(org.voltdb.VoltType) VoltXMLElement(org.hsqldb_voltpatches.VoltXMLElement) ParameterValueExpression(org.voltdb.expressions.ParameterValueExpression) Constraint(org.voltdb.catalog.Constraint)

Example 3 with VoltXMLElement

use of org.hsqldb_voltpatches.VoltXMLElement in project voltdb by VoltDB.

the class AbstractParsedStmt method limitPlanNodeFromXml.

/**
     * Produce a LimitPlanNode from the given XML
     * @param limitXml    Volt XML for limit
     * @param offsetXml   Volt XML for offset
     * @return An instance of LimitPlanNode for the given XML
     */
LimitPlanNode limitPlanNodeFromXml(VoltXMLElement limitXml, VoltXMLElement offsetXml) {
    if (limitXml == null && offsetXml == null) {
        return null;
    }
    String node;
    long limitParameterId = -1;
    long offsetParameterId = -1;
    long limit = -1;
    long offset = 0;
    if (limitXml != null) {
        // Parse limit
        if ((node = limitXml.attributes.get("limit_paramid")) != null) {
            limitParameterId = Long.parseLong(node);
        } else {
            assert (limitXml.children.size() == 1);
            VoltXMLElement valueNode = limitXml.children.get(0);
            String isParam = valueNode.attributes.get("isparam");
            if ((isParam != null) && (isParam.equalsIgnoreCase("true"))) {
                limitParameterId = Long.parseLong(valueNode.attributes.get("id"));
            } else {
                node = limitXml.attributes.get("limit");
                assert (node != null);
                limit = Long.parseLong(node);
            }
        }
    }
    if (offsetXml != null) {
        // Parse offset
        if ((node = offsetXml.attributes.get("offset_paramid")) != null) {
            offsetParameterId = Long.parseLong(node);
        } else {
            if (offsetXml.children.size() == 1) {
                VoltXMLElement valueNode = offsetXml.children.get(0);
                String isParam = valueNode.attributes.get("isparam");
                if ((isParam != null) && (isParam.equalsIgnoreCase("true"))) {
                    offsetParameterId = Long.parseLong(valueNode.attributes.get("id"));
                } else {
                    node = offsetXml.attributes.get("offset");
                    assert (node != null);
                    offset = Long.parseLong(node);
                }
            }
        }
    }
    // limit and offset can't have both value and parameter
    if (limit != -1)
        assert limitParameterId == -1 : "Parsed value and param. limit.";
    if (offset != 0)
        assert offsetParameterId == -1 : "Parsed value and param. offset.";
    LimitPlanNode limitPlanNode = new LimitPlanNode();
    limitPlanNode.setLimit((int) limit);
    limitPlanNode.setOffset((int) offset);
    limitPlanNode.setLimitParameterIndex(parameterCountIndexById(limitParameterId));
    limitPlanNode.setOffsetParameterIndex(parameterCountIndexById(offsetParameterId));
    return limitPlanNode;
}
Also used : LimitPlanNode(org.voltdb.plannodes.LimitPlanNode) VoltXMLElement(org.hsqldb_voltpatches.VoltXMLElement)

Example 4 with VoltXMLElement

use of org.hsqldb_voltpatches.VoltXMLElement in project voltdb by VoltDB.

the class AbstractParsedStmt method parseTableCondition.

/** Parse a where or join clause. This behavior is common to all kinds of statements.
     */
private AbstractExpression parseTableCondition(VoltXMLElement tableScan, String joinOrWhere) {
    AbstractExpression condExpr = null;
    for (VoltXMLElement childNode : tableScan.children) {
        if (!childNode.name.equalsIgnoreCase(joinOrWhere)) {
            continue;
        }
        assert (childNode.children.size() == 1);
        assert (condExpr == null);
        condExpr = parseConditionTree(childNode.children.get(0));
        assert (condExpr != null);
        ExpressionUtil.finalizeValueTypes(condExpr);
        condExpr = ExpressionUtil.evaluateExpression(condExpr);
        // If the condition is a trivial CVE(TRUE) (after the evaluation) simply drop it
        if (ConstantValueExpression.isBooleanTrue(condExpr)) {
            condExpr = null;
        }
    }
    return condExpr;
}
Also used : AbstractExpression(org.voltdb.expressions.AbstractExpression) VoltXMLElement(org.hsqldb_voltpatches.VoltXMLElement)

Example 5 with VoltXMLElement

use of org.hsqldb_voltpatches.VoltXMLElement in project voltdb by VoltDB.

the class AbstractParsedStmt method parseRowExpression.

/**
     *
     * @param exprNode
     * @return
     */
private AbstractExpression parseRowExpression(List<VoltXMLElement> exprNodes) {
    // Parse individual columnref expressions from the IN output schema
    List<AbstractExpression> exprs = new ArrayList<>();
    for (VoltXMLElement exprNode : exprNodes) {
        AbstractExpression expr = parseExpressionNode(exprNode);
        exprs.add(expr);
    }
    return new RowSubqueryExpression(exprs);
}
Also used : AbstractExpression(org.voltdb.expressions.AbstractExpression) RowSubqueryExpression(org.voltdb.expressions.RowSubqueryExpression) ArrayList(java.util.ArrayList) VoltXMLElement(org.hsqldb_voltpatches.VoltXMLElement)

Aggregations

VoltXMLElement (org.hsqldb_voltpatches.VoltXMLElement)62 AbstractExpression (org.voltdb.expressions.AbstractExpression)14 Constraint (org.voltdb.catalog.Constraint)13 VoltCompilerException (org.voltdb.compiler.VoltCompiler.VoltCompilerException)10 ArrayList (java.util.ArrayList)9 VoltType (org.voltdb.VoltType)7 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)6 HSQLInterface (org.hsqldb_voltpatches.HSQLInterface)5 VoltXMLDiff (org.hsqldb_voltpatches.VoltXMLElement.VoltXMLDiff)5 Column (org.voltdb.catalog.Column)5 Table (org.voltdb.catalog.Table)5 Matcher (java.util.regex.Matcher)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 HSQLParseException (org.hsqldb_voltpatches.HSQLInterface.HSQLParseException)3 JSONException (org.json_voltpatches.JSONException)3 Index (org.voltdb.catalog.Index)3 Statement (org.voltdb.catalog.Statement)3 StmtSubqueryScan (org.voltdb.planner.parseinfo.StmtSubqueryScan)3 ExpressionType (org.voltdb.types.ExpressionType)3