Skip to content

Commit

Permalink
Deep copy segment when duplicate cube instance
Browse files Browse the repository at this point in the history
(cherry picked from commit 4d5cf906fbe4cd840e2daf7333be8c52c7ccfb29)
  • Loading branch information
eventd authored and liyang-kylin committed Jan 26, 2018
1 parent ce1775a commit 73554fa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ public CubeSegment getOriginalSegmentToOptimize(CubeSegment optimizedSegment) {
}

public CubeDesc getDescriptor() {
if (config == null) {
return null;
}
return CubeDescManager.getInstance(config).getCubeDesc(descName);
}

Expand Down Expand Up @@ -297,6 +300,10 @@ public void setDisplayName(String displayName) {

@Override
public int getCost() {
if (getDescriptor() == null) {
//in case not initialized
return 0;
}
int countedDimensionNum = getRowKeyColumnCount();
int c = countedDimensionNum * COST_WEIGHT_DIMENSION + getMeasures().size() * COST_WEIGHT_MEASURE;
DataModelDesc model = getModel();
Expand Down Expand Up @@ -348,7 +355,7 @@ public CubeSegment getSegment(String name, SegmentStatusEnum status) {
}

public void setSegments(Segments segments) {
this.segments = segments;
this.segments = new Segments<>(segments);
}

public CubeSegment getSegmentById(String segmentId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@

package org.apache.kylin.cube;

import static org.junit.Assert.assertNotNull;

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.kylin.common.persistence.JsonSerializer;
import org.apache.kylin.cube.cuboid.TreeCuboidScheduler;
import org.apache.kylin.metadata.model.SegmentStatusEnum;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -56,6 +57,21 @@ public void getTreeCuboidSchedulerTest() {
for (Long cuboid : cuboids) {
System.out.println(cuboid + ":" + cuboidsWithRowCnt.get(cuboid));
}
assertNotNull(cuboidsWithRowCnt.get(255L));
Assert.assertNotNull(cuboidsWithRowCnt.get(255L));
}

@Test
public void copyCubeSegmentTest() {
int origSegCount = cubeInstance.getSegments().size();
CubeInstance newCubeInstance = CubeInstance.getCopyOf(cubeInstance);

CubeSegment mockSeg = new CubeSegment();
mockSeg.setUuid(UUID.randomUUID().toString());
mockSeg.setStorageLocationIdentifier(UUID.randomUUID().toString());
mockSeg.setStatus(SegmentStatusEnum.READY);
newCubeInstance.getSegments().add(mockSeg);

Assert.assertEquals(origSegCount, cubeInstance.getSegments().size());
Assert.assertEquals(origSegCount + 1, newCubeInstance.getSegments().size());
}
}

0 comments on commit 73554fa

Please sign in to comment.