Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDI/kettle importer improvements, minor google sheets input fix #3303 #3315 #3316

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,22 @@ public class KettleConst {
// ExcelWriter
{"extention", "extension"},
// Formula
{"formula_string", "formula"}
{"formula_string", "formula"},
// XML Join
{"targetXMLstep", "targetXMLTransform"},
{"sourceXMLstep", "sourceXMLTransform"},
// Multiway Merge Join, 0-9 for simplicity
{"step0", "transform0"},
// step1 and step2 are already covered earlier in the mapping. left in comments here for clarity.
//{"step1", "transform1"},
//{"step2", "transform2"},
{"step3", "transform3"},
{"step4", "transform4"},
{"step5", "transform5"},
{"step6", "transform6"},
{"step7", "transform7"},
{"step8", "transform8"},
{"step9", "transform9"},
})
.collect(Collectors.toMap(data -> (String) data[0], data -> (String) data[1]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ private enum EntryType {
START,
DUMMY,
FORMULA,
GOOGLE_SHEETS_INPUT,
SIMPLE_MAPPING,
OTHER
};

Expand Down Expand Up @@ -510,7 +512,8 @@ private void processNode(Document doc, Node node, EntryType entryType, int depth
for (int j = 0; j < node.getChildNodes().getLength(); j++) {
Node childNode = node.getChildNodes().item(j);
if (childNode.getNodeName().equals("jobname")
|| childNode.getNodeName().equals("transname")) {
|| childNode.getNodeName().equals("transname")
|| childNode.getNodeName().equals("trans_name")) {
if (!StringUtil.isEmpty(childNode.getTextContent())) {
nodeToProcess = processRepositoryNode(node);
}
Expand Down Expand Up @@ -571,6 +574,14 @@ private void processNode(Document doc, Node node, EntryType entryType, int depth
&& childNode.getChildNodes().item(0).getNodeValue().equals("Formula")) {
entryType = EntryType.FORMULA;
}
if (childNode.getNodeName().equals("type")
&& childNode.getChildNodes().item(0).getNodeValue().equals("PentahoGoogleSheetsPluginInputMeta")){
entryType = EntryType.GOOGLE_SHEETS_INPUT;
}
if (childNode.getNodeName().equals("type")
&& childNode.getChildNodes().item(0).getNodeValue().equals("Mapping")) {
entryType = EntryType.SIMPLE_MAPPING;
}
}
}
}
Expand Down Expand Up @@ -678,6 +689,114 @@ else if (entryType == EntryType.TRANS)
}
}
}

if(entryType == EntryType.SIMPLE_MAPPING
&& currentNode.getNodeName().equals("transform")){

Node filenameNode = null;
String transName = "";
String directoryPath = "";
// get trans name, file name, path, set correct filename when needed.
for(int j=0; j <currentNode.getChildNodes().getLength(); j++){
if(currentNode.getChildNodes().item(j).getNodeName().equals("directory_path")){
directoryPath = currentNode.getChildNodes().item(j).getTextContent();
currentNode.removeChild(currentNode.getChildNodes().item(j));
}
if(currentNode.getChildNodes().item(j).getNodeName().equals("trans_name")){
transName = currentNode.getChildNodes().item(j).getTextContent();
currentNode.removeChild(currentNode.getChildNodes().item(j));
}
if(currentNode.getChildNodes().item(j).getNodeName().equals("filename")){
filenameNode = currentNode.getChildNodes().item(j);
}
}

// if we have a trans name and directory path, use it to update the mapping pipeline filename.
if(!StringUtils.isEmpty(transName) && !StringUtils.isEmpty(directoryPath)){
filenameNode.setTextContent("${PROJECT_HOME}" + directoryPath + "/" + transName + ".hpl");
}

// add the default pipeline run configuration.
Element runConfigElement = doc.createElement("runConfiguration");
runConfigElement.appendChild(doc.createTextNode(defaultPipelineRunConfiguration));
currentNode.appendChild(runConfigElement);
}

if(entryType == EntryType.GOOGLE_SHEETS_INPUT
&& currentNode.getNodeName().equals("jsonCredentialPath")){
String jsonCredentialKeyPath = currentNode.getTextContent();
currentNode.setTextContent(jsonCredentialKeyPath.replace('\\', '/'));
}
if(entryType == EntryType.GOOGLE_SHEETS_INPUT
&& currentNode.getNodeName().equals("field")){

// get the second (1) child node to replace data types
for(int j=0; j < currentNode.getChildNodes().getLength(); j++){
Node childNode = currentNode.getChildNodes().item(j);
if(childNode.getNodeName().equals("type")){
String typeNodeValue = childNode.getTextContent();
switch(typeNodeValue){
case "Avro Record":
childNode.setTextContent("20");
break;
case "BigNumber":
childNode.setTextContent("6");
break;
case "Binary":
childNode.setTextContent("8");
break;
case "Boolean":
childNode.setTextContent("4");
break;
case "Date":
childNode.setTextContent("3");
break;
case "Integer":
childNode.setTextContent("5");
break;
case "Internet Address":
childNode.setTextContent("10");
break;
case "Number":
childNode.setTextContent("1");
break;
case "Serializable":
childNode.setTextContent("7");
break;
case "String":
childNode.setTextContent("2");
break;
case "Timestamp":
childNode.setTextContent("9");
break;
// default to String
default:
childNode.setTextContent("2");
break;
}
}if(childNode.getNodeName().equals("trim_type")){
String trimTypeNode = childNode.getTextContent();
switch(trimTypeNode){
case "none":
childNode.setTextContent("0");
break;
case "left":
childNode.setTextContent("1");
break;
case "right":
childNode.setTextContent("2");
break;
case "both":
childNode.setTextContent("3");
break;
// don't trim if not known
default:
childNode.setTextContent("0");
break;
}
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public GoogleSheetsInputMeta() {
inputFields = new ArrayList<>();
}

@HopMetadataProperty(key="jsonCrendentialPath", injectionGroupKey = "SHEET")
@HopMetadataProperty(key="jsonCredentialPath", injectionGroupKey = "SHEET")
private String jsonCredentialPath;

@HopMetadataProperty(key="spreadsheetKey", injectionGroupKey = "SHEET")
Expand Down Expand Up @@ -91,8 +91,8 @@ public String getJsonCredentialPath() {
return this.jsonCredentialPath == null ? "" : this.jsonCredentialPath;
}

public void setJsonCredentialPath(String key) {
this.jsonCredentialPath = key;
public void setJsonCredentialPath(String jsonCredentialPath) {
this.jsonCredentialPath = jsonCredentialPath;
}

public List<GoogleSheetsInputField> getInputFields() {
Expand Down
Loading