@Test public void testDealWithMappingForModel() throws IOException { DataModelManager dataModelManager = DataModelManager.getInstance(getTestConfig()); DataModelDesc model = dataModelManager.getDataModelDesc("ci_inner_join_model"); DataModelDesc updated = TableSchemaUpdater.dealWithMappingForModel(model, mappings); updated = reinit(updated, dataModelManager.getDataModelSerializer()); try (DataInputStream bis = new DataInputStream( new FileInputStream(new File(mappingRootPath + DataModelDesc.concatResourcePath(updated.getName()))))) { DataModelDesc expected = dataModelManager.getDataModelSerializer().deserialize(bis); Assert.assertTrue(expected.equalsRaw(updated)); } catch (Exception e) { Assert.fail("Model is not updated correctly"); } }
public static DataModelDesc dealWithMappingForModel(DataModelDesc other, Map<String, TableSchemaUpdateMapping> mappings) { if (!Strings.isNullOrEmpty(other.getFilterCondition())) { throw new UnsupportedOperationException("Cannot deal with filter condition " + other.getFilterCondition()); } DataModelDesc copy = DataModelDesc.getCopyOf(other); copy.setLastModified(other.getLastModified()); TableSchemaUpdateMapping rootMapping = getTableSchemaUpdateMapping(mappings, other.getRootFactTableName()); if (rootMapping != null) { TableDesc rootFactTable = other.getRootFactTable().getTableDesc(); copy.setRootFactTableName( rootMapping.getTableIdentity(rootFactTable.getDatabase(), rootFactTable.getName())); } JoinTableDesc[] joinTables = other.getJoinTables(); JoinTableDesc[] joinTablesCopy = new JoinTableDesc[joinTables.length]; for (int i = 0; i < joinTables.length; i++) { JoinTableDesc joinTable = joinTables[i]; joinTablesCopy[i] = JoinTableDesc.getCopyOf(joinTable); String tableIdentity = joinTable.getTable(); TableSchemaUpdateMapping mapping = getTableSchemaUpdateMapping(mappings, tableIdentity); if (mapping != null && mapping.isTableIdentityChanged()) { joinTablesCopy[i].setTable(mapping.getTableIdentity(tableIdentity)); } } copy.setJoinTables(joinTablesCopy); PartitionDesc partDesc = other.getPartitionDesc(); PartitionDesc partCopy = PartitionDesc.getCopyOf(partDesc); if (partDesc.getPartitionDateColumnRef() != null) { partCopy.setPartitionDateColumn( replacePartitionCol(partDesc.getPartitionDateColumnRef().getCanonicalName(), mappings)); } if (partDesc.getPartitionTimeColumnRef() != null) { partCopy.setPartitionTimeColumn( replacePartitionCol(partDesc.getPartitionTimeColumnRef().getCanonicalName(), mappings)); } copy.setPartitionDesc(partCopy); return copy; }
TableSchemaUpdater { public static DataModelDesc dealWithMappingForModel(DataModelDesc other, Map<String, TableSchemaUpdateMapping> mappings) { if (!Strings.isNullOrEmpty(other.getFilterCondition())) { throw new UnsupportedOperationException("Cannot deal with filter condition " + other.getFilterCondition()); } DataModelDesc copy = DataModelDesc.getCopyOf(other); copy.setLastModified(other.getLastModified()); TableSchemaUpdateMapping rootMapping = getTableSchemaUpdateMapping(mappings, other.getRootFactTableName()); if (rootMapping != null) { TableDesc rootFactTable = other.getRootFactTable().getTableDesc(); copy.setRootFactTableName( rootMapping.getTableIdentity(rootFactTable.getDatabase(), rootFactTable.getName())); } JoinTableDesc[] joinTables = other.getJoinTables(); JoinTableDesc[] joinTablesCopy = new JoinTableDesc[joinTables.length]; for (int i = 0; i < joinTables.length; i++) { JoinTableDesc joinTable = joinTables[i]; joinTablesCopy[i] = JoinTableDesc.getCopyOf(joinTable); String tableIdentity = joinTable.getTable(); TableSchemaUpdateMapping mapping = getTableSchemaUpdateMapping(mappings, tableIdentity); if (mapping != null && mapping.isTableIdentityChanged()) { joinTablesCopy[i].setTable(mapping.getTableIdentity(tableIdentity)); } } copy.setJoinTables(joinTablesCopy); PartitionDesc partDesc = other.getPartitionDesc(); PartitionDesc partCopy = PartitionDesc.getCopyOf(partDesc); if (partDesc.getPartitionDateColumnRef() != null) { partCopy.setPartitionDateColumn( replacePartitionCol(partDesc.getPartitionDateColumnRef().getCanonicalName(), mappings)); } if (partDesc.getPartitionTimeColumnRef() != null) { partCopy.setPartitionTimeColumn( replacePartitionCol(partDesc.getPartitionTimeColumnRef().getCanonicalName(), mappings)); } copy.setPartitionDesc(partCopy); return copy; } }
TableSchemaUpdater { public static DataModelDesc dealWithMappingForModel(DataModelDesc other, Map<String, TableSchemaUpdateMapping> mappings) { if (!Strings.isNullOrEmpty(other.getFilterCondition())) { throw new UnsupportedOperationException("Cannot deal with filter condition " + other.getFilterCondition()); } DataModelDesc copy = DataModelDesc.getCopyOf(other); copy.setLastModified(other.getLastModified()); TableSchemaUpdateMapping rootMapping = getTableSchemaUpdateMapping(mappings, other.getRootFactTableName()); if (rootMapping != null) { TableDesc rootFactTable = other.getRootFactTable().getTableDesc(); copy.setRootFactTableName( rootMapping.getTableIdentity(rootFactTable.getDatabase(), rootFactTable.getName())); } JoinTableDesc[] joinTables = other.getJoinTables(); JoinTableDesc[] joinTablesCopy = new JoinTableDesc[joinTables.length]; for (int i = 0; i < joinTables.length; i++) { JoinTableDesc joinTable = joinTables[i]; joinTablesCopy[i] = JoinTableDesc.getCopyOf(joinTable); String tableIdentity = joinTable.getTable(); TableSchemaUpdateMapping mapping = getTableSchemaUpdateMapping(mappings, tableIdentity); if (mapping != null && mapping.isTableIdentityChanged()) { joinTablesCopy[i].setTable(mapping.getTableIdentity(tableIdentity)); } } copy.setJoinTables(joinTablesCopy); PartitionDesc partDesc = other.getPartitionDesc(); PartitionDesc partCopy = PartitionDesc.getCopyOf(partDesc); if (partDesc.getPartitionDateColumnRef() != null) { partCopy.setPartitionDateColumn( replacePartitionCol(partDesc.getPartitionDateColumnRef().getCanonicalName(), mappings)); } if (partDesc.getPartitionTimeColumnRef() != null) { partCopy.setPartitionTimeColumn( replacePartitionCol(partDesc.getPartitionTimeColumnRef().getCanonicalName(), mappings)); } copy.setPartitionDesc(partCopy); return copy; }  }
TableSchemaUpdater { public static DataModelDesc dealWithMappingForModel(DataModelDesc other, Map<String, TableSchemaUpdateMapping> mappings) { if (!Strings.isNullOrEmpty(other.getFilterCondition())) { throw new UnsupportedOperationException("Cannot deal with filter condition " + other.getFilterCondition()); } DataModelDesc copy = DataModelDesc.getCopyOf(other); copy.setLastModified(other.getLastModified()); TableSchemaUpdateMapping rootMapping = getTableSchemaUpdateMapping(mappings, other.getRootFactTableName()); if (rootMapping != null) { TableDesc rootFactTable = other.getRootFactTable().getTableDesc(); copy.setRootFactTableName( rootMapping.getTableIdentity(rootFactTable.getDatabase(), rootFactTable.getName())); } JoinTableDesc[] joinTables = other.getJoinTables(); JoinTableDesc[] joinTablesCopy = new JoinTableDesc[joinTables.length]; for (int i = 0; i < joinTables.length; i++) { JoinTableDesc joinTable = joinTables[i]; joinTablesCopy[i] = JoinTableDesc.getCopyOf(joinTable); String tableIdentity = joinTable.getTable(); TableSchemaUpdateMapping mapping = getTableSchemaUpdateMapping(mappings, tableIdentity); if (mapping != null && mapping.isTableIdentityChanged()) { joinTablesCopy[i].setTable(mapping.getTableIdentity(tableIdentity)); } } copy.setJoinTables(joinTablesCopy); PartitionDesc partDesc = other.getPartitionDesc(); PartitionDesc partCopy = PartitionDesc.getCopyOf(partDesc); if (partDesc.getPartitionDateColumnRef() != null) { partCopy.setPartitionDateColumn( replacePartitionCol(partDesc.getPartitionDateColumnRef().getCanonicalName(), mappings)); } if (partDesc.getPartitionTimeColumnRef() != null) { partCopy.setPartitionTimeColumn( replacePartitionCol(partDesc.getPartitionTimeColumnRef().getCanonicalName(), mappings)); } copy.setPartitionDesc(partCopy); return copy; }  static TableDesc dealWithMappingForTable(TableDesc other, Map<String, TableSchemaUpdateMapping> mappings); static DataModelDesc dealWithMappingForModel(DataModelDesc other,
            Map<String, TableSchemaUpdateMapping> mappings); static CubeDesc dealWithMappingForCubeDesc(CubeDesc other, Map<String, TableSchemaUpdateMapping> mappings); static CubeInstance dealWithMappingForCube(CubeInstance other,
            Map<String, TableSchemaUpdateMapping> mappings); static TableSchemaUpdateMapping getTableSchemaUpdateMapping(Map<String, TableSchemaUpdateMapping> mappings,
            String key); }
TableSchemaUpdater { public static DataModelDesc dealWithMappingForModel(DataModelDesc other, Map<String, TableSchemaUpdateMapping> mappings) { if (!Strings.isNullOrEmpty(other.getFilterCondition())) { throw new UnsupportedOperationException("Cannot deal with filter condition " + other.getFilterCondition()); } DataModelDesc copy = DataModelDesc.getCopyOf(other); copy.setLastModified(other.getLastModified()); TableSchemaUpdateMapping rootMapping = getTableSchemaUpdateMapping(mappings, other.getRootFactTableName()); if (rootMapping != null) { TableDesc rootFactTable = other.getRootFactTable().getTableDesc(); copy.setRootFactTableName( rootMapping.getTableIdentity(rootFactTable.getDatabase(), rootFactTable.getName())); } JoinTableDesc[] joinTables = other.getJoinTables(); JoinTableDesc[] joinTablesCopy = new JoinTableDesc[joinTables.length]; for (int i = 0; i < joinTables.length; i++) { JoinTableDesc joinTable = joinTables[i]; joinTablesCopy[i] = JoinTableDesc.getCopyOf(joinTable); String tableIdentity = joinTable.getTable(); TableSchemaUpdateMapping mapping = getTableSchemaUpdateMapping(mappings, tableIdentity); if (mapping != null && mapping.isTableIdentityChanged()) { joinTablesCopy[i].setTable(mapping.getTableIdentity(tableIdentity)); } } copy.setJoinTables(joinTablesCopy); PartitionDesc partDesc = other.getPartitionDesc(); PartitionDesc partCopy = PartitionDesc.getCopyOf(partDesc); if (partDesc.getPartitionDateColumnRef() != null) { partCopy.setPartitionDateColumn( replacePartitionCol(partDesc.getPartitionDateColumnRef().getCanonicalName(), mappings)); } if (partDesc.getPartitionTimeColumnRef() != null) { partCopy.setPartitionTimeColumn( replacePartitionCol(partDesc.getPartitionTimeColumnRef().getCanonicalName(), mappings)); } copy.setPartitionDesc(partCopy); return copy; }  static TableDesc dealWithMappingForTable(TableDesc other, Map<String, TableSchemaUpdateMapping> mappings); static DataModelDesc dealWithMappingForModel(DataModelDesc other,
            Map<String, TableSchemaUpdateMapping> mappings); static CubeDesc dealWithMappingForCubeDesc(CubeDesc other, Map<String, TableSchemaUpdateMapping> mappings); static CubeInstance dealWithMappingForCube(CubeInstance other,
            Map<String, TableSchemaUpdateMapping> mappings); static TableSchemaUpdateMapping getTableSchemaUpdateMapping(Map<String, TableSchemaUpdateMapping> mappings,
            String key);  }