@Test public void testDealWithMappingForCube() throws IOException { CubeManager cubeManager = CubeManager.getInstance(getTestConfig()); CubeInstance cube = cubeManager.getCube("test_kylin_cube_with_slr_left_join_ready"); CubeInstance updated = TableSchemaUpdater.dealWithMappingForCube(cube, mappings); updated = reinit(updated, cubeManager.CUBE_SERIALIZER); try (DataInputStream bis = new DataInputStream( new FileInputStream(new File(mappingRootPath + CubeInstance.concatResourcePath(updated.getName()))))) { CubeInstance expected = cubeManager.CUBE_SERIALIZER.deserialize(bis); Assert.assertTrue(expected.equalsRaw(updated)); } catch (Exception e) { Assert.fail("CubeInstance is not updated correctly"); } }
public static CubeInstance dealWithMappingForCube(CubeInstance other, Map<String, TableSchemaUpdateMapping> mappings) { CubeInstance copy = CubeInstance.getCopyOf(other); copy.setLastModified(other.getLastModified()); if (other.getSnapshots() != null && !other.getSnapshots().isEmpty()) { Map<String, String> snapshotsCopy = replaceTableIdentityForTableSnapshots(other.getSnapshots(), mappings); copy.resetSnapshots(); copy.getSnapshots().putAll(snapshotsCopy); } if (other.getSegments() != null && !other.getSegments().isEmpty()) { Segments<CubeSegment> segmentsCopy = new Segments<>(); for (CubeSegment segment : other.getSegments()) { CubeSegment segmentCopy = CubeSegment.getCopyOf(segment); segmentCopy.setCubeInstance(copy); Map<String, String> snapshotsCopy = replaceTableIdentityForTableSnapshots(segment.getSnapshots(), mappings); segmentCopy.resetSnapshots(); segmentCopy.getSnapshots().putAll(snapshotsCopy); segmentsCopy.add(segmentCopy); } copy.setSegments(segmentsCopy); } return copy; }
TableSchemaUpdater { public static CubeInstance dealWithMappingForCube(CubeInstance other, Map<String, TableSchemaUpdateMapping> mappings) { CubeInstance copy = CubeInstance.getCopyOf(other); copy.setLastModified(other.getLastModified()); if (other.getSnapshots() != null && !other.getSnapshots().isEmpty()) { Map<String, String> snapshotsCopy = replaceTableIdentityForTableSnapshots(other.getSnapshots(), mappings); copy.resetSnapshots(); copy.getSnapshots().putAll(snapshotsCopy); } if (other.getSegments() != null && !other.getSegments().isEmpty()) { Segments<CubeSegment> segmentsCopy = new Segments<>(); for (CubeSegment segment : other.getSegments()) { CubeSegment segmentCopy = CubeSegment.getCopyOf(segment); segmentCopy.setCubeInstance(copy); Map<String, String> snapshotsCopy = replaceTableIdentityForTableSnapshots(segment.getSnapshots(), mappings); segmentCopy.resetSnapshots(); segmentCopy.getSnapshots().putAll(snapshotsCopy); segmentsCopy.add(segmentCopy); } copy.setSegments(segmentsCopy); } return copy; } }
TableSchemaUpdater { public static CubeInstance dealWithMappingForCube(CubeInstance other, Map<String, TableSchemaUpdateMapping> mappings) { CubeInstance copy = CubeInstance.getCopyOf(other); copy.setLastModified(other.getLastModified()); if (other.getSnapshots() != null && !other.getSnapshots().isEmpty()) { Map<String, String> snapshotsCopy = replaceTableIdentityForTableSnapshots(other.getSnapshots(), mappings); copy.resetSnapshots(); copy.getSnapshots().putAll(snapshotsCopy); } if (other.getSegments() != null && !other.getSegments().isEmpty()) { Segments<CubeSegment> segmentsCopy = new Segments<>(); for (CubeSegment segment : other.getSegments()) { CubeSegment segmentCopy = CubeSegment.getCopyOf(segment); segmentCopy.setCubeInstance(copy); Map<String, String> snapshotsCopy = replaceTableIdentityForTableSnapshots(segment.getSnapshots(), mappings); segmentCopy.resetSnapshots(); segmentCopy.getSnapshots().putAll(snapshotsCopy); segmentsCopy.add(segmentCopy); } copy.setSegments(segmentsCopy); } return copy; }  }
TableSchemaUpdater { public static CubeInstance dealWithMappingForCube(CubeInstance other, Map<String, TableSchemaUpdateMapping> mappings) { CubeInstance copy = CubeInstance.getCopyOf(other); copy.setLastModified(other.getLastModified()); if (other.getSnapshots() != null && !other.getSnapshots().isEmpty()) { Map<String, String> snapshotsCopy = replaceTableIdentityForTableSnapshots(other.getSnapshots(), mappings); copy.resetSnapshots(); copy.getSnapshots().putAll(snapshotsCopy); } if (other.getSegments() != null && !other.getSegments().isEmpty()) { Segments<CubeSegment> segmentsCopy = new Segments<>(); for (CubeSegment segment : other.getSegments()) { CubeSegment segmentCopy = CubeSegment.getCopyOf(segment); segmentCopy.setCubeInstance(copy); Map<String, String> snapshotsCopy = replaceTableIdentityForTableSnapshots(segment.getSnapshots(), mappings); segmentCopy.resetSnapshots(); segmentCopy.getSnapshots().putAll(snapshotsCopy); segmentsCopy.add(segmentCopy); } copy.setSegments(segmentsCopy); } 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 CubeInstance dealWithMappingForCube(CubeInstance other, Map<String, TableSchemaUpdateMapping> mappings) { CubeInstance copy = CubeInstance.getCopyOf(other); copy.setLastModified(other.getLastModified()); if (other.getSnapshots() != null && !other.getSnapshots().isEmpty()) { Map<String, String> snapshotsCopy = replaceTableIdentityForTableSnapshots(other.getSnapshots(), mappings); copy.resetSnapshots(); copy.getSnapshots().putAll(snapshotsCopy); } if (other.getSegments() != null && !other.getSegments().isEmpty()) { Segments<CubeSegment> segmentsCopy = new Segments<>(); for (CubeSegment segment : other.getSegments()) { CubeSegment segmentCopy = CubeSegment.getCopyOf(segment); segmentCopy.setCubeInstance(copy); Map<String, String> snapshotsCopy = replaceTableIdentityForTableSnapshots(segment.getSnapshots(), mappings); segmentCopy.resetSnapshots(); segmentCopy.getSnapshots().putAll(snapshotsCopy); segmentsCopy.add(segmentCopy); } copy.setSegments(segmentsCopy); } 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);  }