Skip to content

Commit

Permalink
#1681 name after W.DS not I.DS
Browse files Browse the repository at this point in the history
  • Loading branch information
joohokim1 committed Mar 22, 2019
1 parent ba676f8 commit b62ee5b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public ResponseEntity<?> deleteChain(

if (autoCreate) {
for (String newId : newIds) {
PrepTransformResponse response = this.transformService.create(newId, dataflow.getDfId(), true);
PrepTransformResponse response = this.transformService.create(newId, dataflow.getDfId(), null);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void afterCreate(PrDataflow dataflow) throws PrepException {
}
}
for(PrDataset dataset : importedDatasets) {
PrepTransformResponse response = this.transformService.create(dataset.getDsId(), dataflow.getDfId(), true);
PrepTransformResponse response = this.transformService.create(dataset.getDsId(), dataflow.getDfId(), null);
}
} catch (Exception e) {
LOGGER.error("afterCreate(): caught an exception: ", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class PrepTransformController {
LOGGER.trace("create(): start");

try {
response = transformService.create(importedDsId, request.getDfId(), true);
response = transformService.create(importedDsId, request.getDfId(), null);
} catch (Exception e) {
LOGGER.error("create(): caught an exception: ", e);
throw PrepException.create(PrepErrorCodes.PREP_TRANSFORM_ERROR_CODE, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ public List<String> getUpstreamDsIds(String dsId) throws IOException, CannotSeri

// create stage0 (POST)
@Transactional(rollbackFor = Exception.class)
public PrepTransformResponse create(String importedDsId, String dfId, boolean needAutoTyping) throws Exception {
public PrepTransformResponse create(String importedDsId, String dfId, String cloningDsName) throws Exception {
LOGGER.trace("create(): start");

PrDataset importedDataset = datasetRepository.findRealOne(datasetRepository.findOne(importedDsId));
PrDataflow dataflow = dataflowRepository.findOne(dfId);
assert importedDataset.getDsType() == IMPORTED : importedDataset.getDsType();

PrDataset wrangledDataset = makeWrangledDataset(importedDataset, dataflow, dfId);
PrDataset wrangledDataset = makeWrangledDataset(importedDataset, dataflow, dfId, cloningDsName);
datasetRepository.save(wrangledDataset);

// We need to save into the repository to get an ID.
Expand All @@ -289,8 +289,8 @@ public PrepTransformResponse create(String importedDsId, String dfId, boolean ne
response.setWrangledDsId(wrangledDsId);
this.putAddedInfo(response, wrangledDataset);

// Auto type detection and conversion
if (needAutoTyping && prepProperties.isAutoTypingEnabled()) {
// Auto type detection and conversion (except cloning case)
if (cloningDsName == null && prepProperties.isAutoTypingEnabled()) {
switch (importedDataset.getImportType()) {
case UPLOAD:
case URI:
Expand Down Expand Up @@ -322,7 +322,7 @@ public PrepTransformResponse clone(String wrangledDsId) throws Exception {
PrDataset wrangledDataset = datasetRepository.findRealOne(datasetRepository.findOne(wrangledDsId));
String upstreamDsId = getFirstUpstreamDsId(wrangledDsId);

PrepTransformResponse response = create(upstreamDsId, wrangledDataset.getCreatorDfId(), false);
PrepTransformResponse response = create(upstreamDsId, wrangledDataset.getCreatorDfId(), wrangledDataset.getDsName());
String cloneDsId = response.getWrangledDsId();

List<PrTransformRule> transformRules = getRulesInOrder(wrangledDsId);
Expand Down Expand Up @@ -1154,12 +1154,31 @@ public PrepTransformResponse fetch_internal(String dsId, Integer stageIdx) {
return response;
}

private static PrDataset makeWrangledDataset(PrDataset importedDataset, PrDataflow dataflow, String dfId) {
private static String getNewDsName(PrDataset importedDataset, PrDataflow dataflow, String dfId, String cloningDsName) {
if (cloningDsName == null) {
return importedDataset.getDsName().replaceFirst(" \\((EXCEL|CSV|JSON|STAGING|MYSQL|ORACLE|TIBERO|HIVE|POSTGRESQL|MSSQL|PRESTO)\\)$","");
}

List<String> dsNames = new ArrayList();
for (PrDataset dataset : dataflow.getDatasets()) {
dsNames.add(dataset.getDsName());
}

for (int i = 1; /* NOP */; i++) {
String newDsName = String.format("%s (%d)", cloningDsName, i);

if (!dsNames.contains(newDsName)) {
return newDsName;
}

assert i < 100000 : String.format("Too much duplication: cloningDsName=%s" + cloningDsName);
}
}

private static PrDataset makeWrangledDataset(PrDataset importedDataset, PrDataflow dataflow, String dfId, String cloningDsName) {
PrDataset wrangledDataset = new PrDataset();

//wrangledDataset.setDsName(importedDataset.getDsName() + " [W]");
String dsName = importedDataset.getDsName();
String newDsName = dsName.replaceFirst(" \\((EXCEL|CSV|JSON|STAGING|MYSQL|ORACLE|TIBERO|HIVE|POSTGRESQL|MSSQL|PRESTO)\\)$","");
String newDsName = getNewDsName(importedDataset, dataflow, dfId, cloningDsName);
wrangledDataset.setDsName(newDsName);
wrangledDataset.setDsType(WRANGLED);
wrangledDataset.setCreatorDfId(dfId);
Expand Down

0 comments on commit b62ee5b

Please sign in to comment.