Search in sources :

Example 6 with VoltXMLDiff

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

the class TestVoltXMLElement method testNoDiff.

public void testNoDiff() {
    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();
    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 7 with VoltXMLDiff

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

the class DDLCompiler method applyDiff.

private void applyDiff(VoltXMLDiff stmtDiff) {
    // record which tables changed
    for (String tableName : stmtDiff.getChangedNodes().keySet()) {
        assert (tableName.startsWith("table"));
        tableName = tableName.substring("table".length());
        m_compiler.markTableAsDirty(tableName);
    }
    for (VoltXMLElement tableXML : stmtDiff.getRemovedNodes()) {
        String tableName = tableXML.attributes.get("name");
        assert (tableName != null);
        m_compiler.markTableAsDirty(tableName);
    }
    for (VoltXMLElement tableXML : stmtDiff.getAddedNodes()) {
        String tableName = tableXML.attributes.get("name");
        assert (tableName != null);
        m_compiler.markTableAsDirty(tableName);
    }
    m_schema.applyDiff(stmtDiff);
    // the changed nodes
    if (stmtDiff.getChangedNodes().isEmpty()) {
        return;
    }
    assert (stmtDiff.getChangedNodes().size() == 1);
    Entry<String, VoltXMLDiff> tableEntry = stmtDiff.getChangedNodes().entrySet().iterator().next();
    VoltXMLDiff tableDiff = tableEntry.getValue();
    // need columns to be changed
    if (tableDiff.getChangedNodes().isEmpty() || !tableDiff.getChangedNodes().containsKey("columnscolumns")) {
        return;
    }
    VoltXMLDiff columnsDiff = tableDiff.getChangedNodes().get("columnscolumns");
    assert (columnsDiff != null);
    // Need to have deleted columns
    if (columnsDiff.getRemovedNodes().isEmpty()) {
        return;
    }
    // Okay, get a list of deleted column names
    Set<String> removedColumns = new HashSet<>();
    for (VoltXMLElement e : columnsDiff.getRemovedNodes()) {
        assert (e.attributes.get("name") != null);
        removedColumns.add(e.attributes.get("name"));
    }
    // go back and get our table name.  Use the uniquename ("table" + name) to get the element
    // from the schema
    VoltXMLElement tableElement = m_schema.findChild(tableEntry.getKey());
    assert (tableElement != null);
    String partitionCol = tableElement.attributes.get("partitioncolumn");
    // if we removed the partition column, then remove the attribute from the schema
    if (partitionCol != null && removedColumns.contains(partitionCol)) {
        m_compiler.addWarn(String.format("Partition column %s was dropped from table %s.  Attempting to change table to replicated.", partitionCol, tableElement.attributes.get("name")));
        tableElement.attributes.remove("partitioncolumn");
    }
}
Also used : VoltXMLDiff(org.hsqldb_voltpatches.VoltXMLElement.VoltXMLDiff) VoltXMLElement(org.hsqldb_voltpatches.VoltXMLElement) HashSet(java.util.HashSet)

Aggregations

VoltXMLDiff (org.hsqldb_voltpatches.VoltXMLElement.VoltXMLDiff)7 VoltXMLElement (org.hsqldb_voltpatches.VoltXMLElement)5 HashSet (java.util.HashSet)1 HSQLDDLInfo (org.hsqldb_voltpatches.HSQLDDLInfo)1 HSQLParseException (org.hsqldb_voltpatches.HSQLInterface.HSQLParseException)1 VoltCompilerException (org.voltdb.compiler.VoltCompiler.VoltCompilerException)1