use of org.hsqldb_voltpatches.VoltXMLElement in project voltdb by VoltDB.
the class ParsedSelectStmt method parseDisplayColumns.
private void parseDisplayColumns(VoltXMLElement columnsNode, boolean isDistributed) {
try {
m_parsingInDisplayColumns = true;
int index = 0;
for (VoltXMLElement child : columnsNode.children) {
parseDisplayColumn(index, child, isDistributed);
++index;
}
} finally {
m_parsingInDisplayColumns = false;
}
}
use of org.hsqldb_voltpatches.VoltXMLElement in project voltdb by VoltDB.
the class ParsedUnionStmt method parse.
@Override
void parse(VoltXMLElement stmtNode) {
String type = stmtNode.attributes.get("uniontype");
// Set operation type
m_unionType = UnionType.valueOf(type);
int idx = 0;
VoltXMLElement limitElement = null, offsetElement = null, orderbyElement = null;
for (VoltXMLElement child : stmtNode.children) {
if (SELECT_NODE_NAME.equals(child.name) || UNION_NODE_NAME.equals(child.name)) {
assert (idx < m_children.size());
AbstractParsedStmt nextStmt = m_children.get(idx++);
nextStmt.parse(child);
} else if (child.name.equals("limit")) {
limitElement = child;
} else if (child.name.equals("offset")) {
offsetElement = child;
} else if (child.name.equals("ordercolumns")) {
orderbyElement = child;
}
}
// Parse LIMIT/OFFSET
ParsedSelectStmt.parseLimitAndOffset(limitElement, offsetElement, m_limitOffset);
// Parse ORDER BY
if (orderbyElement != null) {
parseOrderColumns(orderbyElement);
placeTVEsForOrderby();
}
// prepare the limit plan node if it needs one.
if (hasLimitOrOffset()) {
ParsedSelectStmt.prepareLimitPlanNode(this, m_limitOffset);
}
}
use of org.hsqldb_voltpatches.VoltXMLElement in project voltdb by VoltDB.
the class TestVoltXMLElement method makeNamedElement.
VoltXMLElement makeNamedElement(String elementName, String attName) {
VoltXMLElement e = new VoltXMLElement(elementName);
e.attributes.put("name", attName);
return e;
}
use of org.hsqldb_voltpatches.VoltXMLElement in project voltdb by VoltDB.
the class PartitionStatement method processPartitionTable.
private boolean processPartitionTable(String statement) throws VoltCompilerException {
// matches if it is PARTITION TABLE <table> ON COLUMN <column>
Matcher statementMatcher = SQLParser.matchPartitionTable(statement);
if (!statementMatcher.matches()) {
throw m_compiler.new VoltCompilerException(String.format("Invalid PARTITION statement: \"%s\", " + "expected syntax: PARTITION TABLE <table> ON COLUMN <column>", // remove trailing semicolon
statement.substring(0, statement.length() - 1)));
}
// group(1) -> table, group(2) -> column
String tableName = checkIdentifierStart(statementMatcher.group(1), statement);
String columnName = checkIdentifierStart(statementMatcher.group(2), statement);
VoltXMLElement tableXML = m_schema.findChild("table", tableName.toUpperCase());
if (tableXML != null) {
tableXML.attributes.put("partitioncolumn", columnName.toUpperCase());
// Column validity check done by VoltCompiler in post-processing
// 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 PARTITION statement: table %s does not exist", tableName));
}
return true;
}
use of org.hsqldb_voltpatches.VoltXMLElement in project voltdb by VoltDB.
the class MatViewFallbackQueryXMLGenerator method generateFallbackQueryXMLs.
private void generateFallbackQueryXMLs() {
/*********************************************************************************************************
* This function will turn the XML for materialized view definitions like:
* SELECT d1, d2, COUNT(*), MIN(abs(v1)) AS vmin, MAX(abs(v1)) AS vmax FROM ENG6511 GROUP BY d1, d2;
* into fallback query XMLs like:
* SELECT min(v1) FROM ENG6511 WHERE d1=? AND d2=? AND abs(v1)>=?;
* SELECT max(v1) FROM ENG6511 WHERE d1=? AND d2=? AND abs(v1)<=?;
********************************************************************************************************/
List<VoltXMLElement> columns = VoltXMLElementHelper.getFirstChild(m_xml, "columns").children;
List<VoltXMLElement> parameters = VoltXMLElementHelper.getFirstChild(m_xml, "parameters").children;
VoltXMLElement groupcolumnsElement = VoltXMLElementHelper.getFirstChild(m_xml, "groupcolumns");
List<VoltXMLElement> tablescans = VoltXMLElementHelper.getFirstChild(m_xml, "tablescans").children;
VoltXMLElement tablescanForJoinCond = tablescans.get(tablescans.size() - 1);
// Add the joincond to the last table scan element.
List<VoltXMLElement> joincondList = VoltXMLElementHelper.getFirstChild(tablescanForJoinCond, "joincond", true).children;
VoltXMLElement joincond = joincondList.size() == 0 ? null : joincondList.get(0);
joincondList.clear();
// 1. Turn groupby into joincond (WHERE) ================================================================
if (groupcolumnsElement != null) {
// If there is no group by clause, then nothing needs to be transformed.
List<VoltXMLElement> groupcolumns = groupcolumnsElement.children;
for (int i = 0; i < m_groupByColumnsParsedInfo.size(); ++i) {
String index = String.valueOf(i);
String valueType = m_groupByColumnsParsedInfo.get(i).expression.getValueType().getName();
VoltXMLElement column = groupcolumns.get(i);
// Add the column to the parameter list.
parameters.add(VoltXMLElementHelper.buildParamElement(nextElementId(), index, valueType));
// Put together the where conditions for the groupby columns.
//
// Note that due to ENG-11080 we need to use NOT DISTINCT for
// multi-table views, due to the possibility of GB columns being NULL.
// For single-table views, we can catch NULL GB columns at runtime and
// fall back to a manual scan.
String comparisonOp = m_isMultiTableView ? "notdistinct" : "equal";
VoltXMLElement columnParamJoincond = VoltXMLElementHelper.buildColumnParamJoincondElement(comparisonOp, column, lastElementId(), nextElementId());
joincond = VoltXMLElementHelper.mergeTwoElementsUsingOperator("and", nextElementId(), joincond, columnParamJoincond);
}
// Remove the group by columns, they are now in the form of where conditions.
m_xml.children.remove(groupcolumnsElement);
}
// 2. Process aggregation columns =====================================================================
List<VoltXMLElement> originalColumns = new ArrayList<>();
originalColumns.addAll(columns);
columns.clear();
// Parameter index for min/max column
String paramIndex = String.valueOf(m_groupByColumnsParsedInfo.size());
// Add one min/max columns at a time as a new fallback query XML.
for (int i = m_groupByColumnsParsedInfo.size() + 1; i < m_displayColumnsParsedInfo.size(); ++i) {
VoltXMLElement column = originalColumns.get(i);
String optype = column.attributes.get("optype");
if (optype.equals("min") || optype.equals("max")) {
columns.add(column);
VoltXMLElement aggArg = column.children.get(0);
String operator = optype.equals("min") ? "greaterthanorequalto" : "lessthanorequalto";
String valueType = m_displayColumnsParsedInfo.get(i).expression.getValueType().getName();
parameters.add(VoltXMLElementHelper.buildParamElement(nextElementId(), paramIndex, valueType));
VoltXMLElement aggArgJoincond = VoltXMLElementHelper.buildColumnParamJoincondElement(operator, aggArg, lastElementId(), nextElementId());
joincondList.add(VoltXMLElementHelper.mergeTwoElementsUsingOperator("and", nextElementId(), joincond, aggArgJoincond));
m_fallbackQueryXMLs.add(m_xml.duplicate());
// For debug:
// System.out.println(m_xml.toString());
columns.clear();
joincondList.clear();
parameters.remove(m_groupByColumnsParsedInfo.size());
}
}
}
Aggregations