Search in sources :

Example 16 with VoltXMLElement

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

the class QueryPlanner method forgeVoltXMLForSwapTables.

// Generate a Volt XML tree for a hypothetical SWAP TABLE statement.
// This can take any form that makes it easy for the planner to turn
// it into an AbstractParsedStmt and then an AbstractPlanNode (tree).
private VoltXMLElement forgeVoltXMLForSwapTables(String theTable, String otherTable) {
    if (theTable.equalsIgnoreCase(otherTable)) {
        throw new PlanningErrorException("Can not swap table \"" + theTable + "\" with itself.");
    }
    VoltXMLElement result = new VoltXMLElement("swap");
    result.attributes.put("thetable", theTable.toUpperCase());
    result.attributes.put("othertable", otherTable.toUpperCase());
    return result;
}
Also used : VoltXMLElement(org.hsqldb_voltpatches.VoltXMLElement)

Example 17 with VoltXMLElement

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

the class ParsedUpdateStmt method parse.

@Override
void parse(VoltXMLElement stmtNode) {
    assert (m_tableList.size() == 1);
    Table table = m_tableList.get(0);
    // Need to add the table to the cache. It may be required to resolve the
    // correlated TVE in case of WHERE clause contains IN subquery
    addTableToStmtCache(table, table.getTypeName());
    for (VoltXMLElement child : stmtNode.children) {
        if (child.name.equalsIgnoreCase("columns")) {
            parseTargetColumns(child, table, columns);
        }
    }
}
Also used : Table(org.voltdb.catalog.Table) VoltXMLElement(org.hsqldb_voltpatches.VoltXMLElement)

Example 18 with VoltXMLElement

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

the class TestVoltXMLElement method testDupeChild.

public void testDupeChild() {
    VoltXMLElement first = makeNamedElement("element", "element");
    VoltXMLElement child1 = new VoltXMLElement("child");
    child1.attributes.put("value", "3");
    first.children.add(child1);
    // Same element name, no attribute "name"
    VoltXMLElement child2 = new VoltXMLElement("child");
    child2.attributes.put("value", "4");
    first.children.add(child2);
    VoltXMLElement second = makeNamedElement("element", "element");
    VoltXMLElement child1s = new VoltXMLElement("child");
    child1s.attributes.put("value", "5");
    second.children.add(child1s);
    // Same element name, no attribute "name"
    VoltXMLElement child2s = new VoltXMLElement("child");
    child2s.attributes.put("value", "6");
    second.children.add(child2s);
    VoltXMLDiff diff = VoltXMLElement.computeDiff(first, second);
    System.out.println("diff: " + diff.toString());
    VoltXMLElement third = first.duplicate();
    third.applyDiff(diff);
    System.out.println(first.toMinString());
    System.out.println(second.toMinString());
    System.out.println(third.toMinString());
    assertEquals(second.toMinString(), third.toMinString());
}
Also used : VoltXMLDiff(org.hsqldb_voltpatches.VoltXMLElement.VoltXMLDiff) VoltXMLElement(org.hsqldb_voltpatches.VoltXMLElement)

Example 19 with VoltXMLElement

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

the class TestVoltXMLElement method testDiff.

public void testDiff() {
    VoltXMLElement first = makeNamedElement("element", "element");
    VoltXMLElement changedChild1 = makeNamedElement("child", "changedchild1");
    first.children.add(changedChild1);
    changedChild1.attributes.put("deleteme", "noreally");
    VoltXMLElement changedChild2 = makeNamedElement("child", "changedchild2");
    first.children.add(changedChild2);
    VoltXMLElement changedGrandchild = makeNamedElement("child", "changedgrandchild");
    changedChild2.children.add(changedGrandchild);
    changedGrandchild.children.add(makeNamedElement("child", "doomeddescendent"));
    first.attributes.put("deleted", "doesntmatter");
    first.attributes.put("remains", "doesntmatter");
    first.attributes.put("changes", "oldvalue");
    first.children.add(makeNamedElement("child", "deletedchild"));
    first.children.add(makeNamedElement("child", "unchangedchild"));
    VoltXMLElement second = first.duplicate();
    second.attributes.remove("deleted");
    second.attributes.put("added", "addedval");
    second.attributes.put("changes", "newvalue");
    second.children.add(makeNamedElement("child", "addedchild"));
    second.children.remove(second.findChild("child", "deletedchild"));
    second.findChild("child", "changedchild1").attributes.remove("deleteme");
    VoltXMLElement temp = second.findChild("child", "changedchild2").findChild("child", "changedgrandchild");
    temp.children.remove(temp.findChild("child", "doomeddescendent"));
    VoltXMLDiff diff = VoltXMLElement.computeDiff(first, second);
    Map<String, String> addedAtt = diff.getAddedAttributes();
    assertEquals(1, addedAtt.size());
    assertTrue(addedAtt.keySet().contains("added"));
    assertEquals("addedval", addedAtt.get("added"));
    Map<String, String> changedAtt = diff.getChangedAttributes();
    assertEquals(1, changedAtt.size());
    assertTrue(changedAtt.keySet().contains("changes"));
    assertEquals("newvalue", changedAtt.get("changes"));
    Set<String> removedAtt = diff.getRemovedAttributes();
    assertEquals(1, removedAtt.size());
    assertTrue(removedAtt.contains("deleted"));
    List<VoltXMLElement> added = diff.getAddedNodes();
    assertEquals(1, added.size());
    assertTrue(findNamedNode(added, "addedchild") != null);
    List<VoltXMLElement> removed = diff.getRemovedNodes();
    assertEquals(1, removed.size());
    assertTrue(findNamedNode(removed, "deletedchild") != null);
    Map<String, VoltXMLDiff> changed = diff.getChangedNodes();
    assertEquals(2, changed.size());
    assertTrue(changed.containsKey("childchangedchild1"));
    VoltXMLDiff child1 = changed.get("childchangedchild1");
    assertTrue(child1.getRemovedAttributes().contains("deleteme"));
    assertTrue(changed.containsKey("childchangedchild2"));
    VoltXMLDiff child2 = changed.get("childchangedchild2");
    assertTrue(child2.getChangedNodes().containsKey("childchangedgrandchild"));
    VoltXMLDiff grandchild = child2.getChangedNodes().get("childchangedgrandchild");
    assertTrue(findNamedNode(grandchild.getRemovedNodes(), "doomeddescendent") != null);
    VoltXMLElement third = first.duplicate();
    third.applyDiff(diff);
    System.out.println(first.toMinString());
    System.out.println(second.toMinString());
    System.out.println(third.toMinString());
    assertEquals(second.toMinString(), third.toMinString());
}
Also used : VoltXMLDiff(org.hsqldb_voltpatches.VoltXMLElement.VoltXMLDiff) VoltXMLElement(org.hsqldb_voltpatches.VoltXMLElement)

Example 20 with VoltXMLElement

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

the class TestVoltXMLElement method testOrderFail.

public void testOrderFail() {
    VoltXMLElement first = makeNamedElement("element", "element");
    first.children.add(makeNamedElement("first", "first"));
    first.children.add(makeNamedElement("third", "third"));
    first.children.add(makeNamedElement("fourth", "fourth"));
    VoltXMLElement second = makeNamedElement("element", "element");
    second.children.add(makeNamedElement("first", "first"));
    second.children.add(makeNamedElement("second", "second"));
    second.children.add(makeNamedElement("third", "third"));
    second.children.add(makeNamedElement("fourth", "fourth"));
    VoltXMLDiff diff = VoltXMLElement.computeDiff(first, second);
    System.out.println("diff: " + diff.toString());
    VoltXMLElement third = first.duplicate();
    third.applyDiff(diff);
    System.out.println(first.toMinString());
    System.out.println(second.toMinString());
    System.out.println(third.toMinString());
    assertEquals(second.toMinString(), third.toMinString());
}
Also used : VoltXMLDiff(org.hsqldb_voltpatches.VoltXMLElement.VoltXMLDiff) 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