public void saveRep(Repository rep, ObjectId id_transformation, ObjectId id_step) throws KettleException { rep.saveStepAttribute( id_transformation, id_step, "specification_method", specificationMethod == null ? null : specificationMethod.getCode()); rep.saveStepAttribute( id_transformation, id_step, "trans_object_id", transObjectId == null ? null : transObjectId.toString()); rep.saveStepAttribute(id_transformation, id_step, "filename", fileName); // $NON-NLS-1$ rep.saveStepAttribute(id_transformation, id_step, "trans_name", transName); // $NON-NLS-1$ rep.saveStepAttribute( id_transformation, id_step, "directory_path", directoryPath); // $NON-NLS-1$ for (int i = 0; i < inputMappings.size(); i++) { inputMappings.get(i).saveRep(rep, id_transformation, id_step, "input_", i); } for (int i = 0; i < outputMappings.size(); i++) { outputMappings.get(i).saveRep(rep, id_transformation, id_step, "output_", i); } // save the mapping parameters too // mappingParameters.saveRep(rep, id_transformation, id_step); rep.saveStepAttribute( id_transformation, id_step, 0, "allow_multiple_input", allowingMultipleInputs); rep.saveStepAttribute( id_transformation, id_step, 0, "allow_multiple_output", allowingMultipleOutputs); }
public void getFields( RowMetaInterface row, String origin, RowMetaInterface info[], StepMeta nextStep, VariableSpace space) throws KettleStepException { // First load some interesting data... // Then see which fields get added to the row. // TransMeta mappingTransMeta = null; try { mappingTransMeta = loadMappingMeta(this, repository, space); } catch (KettleException e) { throw new KettleStepException( BaseMessages.getString(PKG, "MappingMeta.Exception.UnableToLoadMappingTransformation"), e); } // The field structure may depend on the input parameters as well (think of parameter // replacements in MDX queries for instance) if (mappingParameters != null) { // See if we need to pass all variables from the parent or not... // if (mappingParameters.isInheritingAllVariables()) { mappingTransMeta.copyVariablesFrom(space); } // Just set the variables in the transformation statically. // This just means: set a number of variables or parameter values: // List<String> subParams = Arrays.asList(mappingTransMeta.listParameters()); for (int i = 0; i < mappingParameters.getVariable().length; i++) { String name = mappingParameters.getVariable()[i]; String value = space.environmentSubstitute(mappingParameters.getInputField()[i]); if (!Const.isEmpty(name) && !Const.isEmpty(value)) { if (subParams.contains(name)) { try { mappingTransMeta.setParameterValue(name, value); } catch (UnknownParamException e) { // this is explicitly checked for up front } } mappingTransMeta.setVariable(name, value); } } } // Keep track of all the fields that need renaming... // List<MappingValueRename> inputRenameList = new ArrayList<MappingValueRename>(); /* * Before we ask the mapping outputs anything, we should teach the mapping * input steps in the sub-transformation about the data coming in... */ for (MappingIODefinition definition : inputMappings) { RowMetaInterface inputRowMeta; if (definition.isMainDataPath() || Const.isEmpty(definition.getInputStepname())) { // The row metadata, what we pass to the mapping input step // definition.getOutputStep(), is "row" // However, we do need to re-map some fields... // inputRowMeta = row.clone(); if (!inputRowMeta.isEmpty()) { for (MappingValueRename valueRename : definition.getValueRenames()) { ValueMetaInterface valueMeta = inputRowMeta.searchValueMeta(valueRename.getSourceValueName()); if (valueMeta == null) { throw new KettleStepException( BaseMessages.getString( PKG, "MappingMeta.Exception.UnableToFindField", valueRename.getSourceValueName())); } valueMeta.setName(valueRename.getTargetValueName()); } } } else { // The row metadata that goes to the info mapping input comes from the // specified step // In fact, it's one of the info steps that is going to contain this // information... // String[] infoSteps = getInfoSteps(); int infoStepIndex = Const.indexOfString(definition.getInputStepname(), infoSteps); if (infoStepIndex < 0) { throw new KettleStepException( BaseMessages.getString( PKG, "MappingMeta.Exception.UnableToFindMetadataInfo", definition.getInputStepname())); } if (info[infoStepIndex] != null) { inputRowMeta = info[infoStepIndex].clone(); } else { inputRowMeta = null; } } // What is this mapping input step? // StepMeta mappingInputStep = mappingTransMeta.findMappingInputStep(definition.getOutputStepname()); // We're certain it's a MappingInput step... // MappingInputMeta mappingInputMeta = (MappingInputMeta) mappingInputStep.getStepMetaInterface(); // Inform the mapping input step about what it's going to receive... // mappingInputMeta.setInputRowMeta(inputRowMeta); // What values are we changing names for? // mappingInputMeta.setValueRenames(definition.getValueRenames()); // Keep a list of the input rename values that need to be changed back at // the output // if (definition.isRenamingOnOutput()) Mapping.addInputRenames(inputRenameList, definition.getValueRenames()); } // All the mapping steps now know what they will be receiving. // That also means that the sub-transformation / mapping has everything it // needs. // So that means that the MappingOutput steps know exactly what the output // is going to be. // That could basically be anything. // It also could have absolutely no resemblance to what came in on the // input. // The relative old approach is therefore no longer suited. // // OK, but what we *can* do is have the MappingOutput step rename the // appropriate fields. // The mapping step will tell this step how it's done. // // Let's look for the mapping output step that is relevant for this actual // call... // MappingIODefinition mappingOutputDefinition = null; if (nextStep == null) { // This is the main step we read from... // Look up the main step to write to. // This is the output mapping definition with "main path" enabled. // for (MappingIODefinition definition : outputMappings) { if (definition.isMainDataPath() || Const.isEmpty(definition.getOutputStepname())) { // This is the definition to use... // mappingOutputDefinition = definition; } } } else { // Is there an output mapping definition for this step? // If so, we can look up the Mapping output step to see what has changed. // for (MappingIODefinition definition : outputMappings) { if (nextStep.getName().equals(definition.getOutputStepname()) || definition.isMainDataPath() || Const.isEmpty(definition.getOutputStepname())) { mappingOutputDefinition = definition; } } } if (mappingOutputDefinition == null) { throw new KettleStepException( BaseMessages.getString(PKG, "MappingMeta.Exception.UnableToFindMappingDefinition")); } // OK, now find the mapping output step in the mapping... // This method in TransMeta takes into account a number of things, such as // the step not specified, etc. // The method never returns null but throws an exception. // StepMeta mappingOutputStep = mappingTransMeta.findMappingOutputStep(mappingOutputDefinition.getInputStepname()); // We know it's a mapping output step... MappingOutputMeta mappingOutputMeta = (MappingOutputMeta) mappingOutputStep.getStepMetaInterface(); // Change a few columns. mappingOutputMeta.setOutputValueRenames(mappingOutputDefinition.getValueRenames()); // Perhaps we need to change a few input columns back to the original? // mappingOutputMeta.setInputValueRenames(inputRenameList); // Now we know wat's going to come out of there... // This is going to be the full row, including all the remapping, etc. // RowMetaInterface mappingOutputRowMeta = mappingTransMeta.getStepFields(mappingOutputStep); row.clear(); row.addRowMeta(mappingOutputRowMeta); }
public String getXML() { StringBuffer retval = new StringBuffer(300); retval .append(" ") .append( XMLHandler.addTagValue( "specification_method", specificationMethod == null ? null : specificationMethod.getCode())); retval .append(" ") .append( XMLHandler.addTagValue( "trans_object_id", transObjectId == null ? null : transObjectId.toString())); // Export a little bit of extra information regarding the reference since it doesn't really // matter outside the same repository. // if (repository != null && transObjectId != null) { try { RepositoryObject objectInformation = repository.getObjectInformation(transObjectId, RepositoryObjectType.TRANSFORMATION); if (objectInformation != null) { transName = objectInformation.getName(); directoryPath = objectInformation.getRepositoryDirectory().getPath(); } } catch (KettleException e) { // Ignore object reference problems. It simply means that the reference is no longer valid. } } retval.append(" ").append(XMLHandler.addTagValue("trans_name", transName)); // $NON-NLS-1$ retval.append(" ").append(XMLHandler.addTagValue("filename", fileName)); // $NON-NLS-1$ retval .append(" ") .append(XMLHandler.addTagValue("directory_path", directoryPath)); // $NON-NLS-1$ retval .append(" ") .append(XMLHandler.openTag("mappings")) .append(Const.CR); // $NON-NLS-1$ $NON-NLS-2$ retval .append(" ") .append(XMLHandler.openTag("input")) .append(Const.CR); // $NON-NLS-1$ $NON-NLS-2$ for (int i = 0; i < inputMappings.size(); i++) { retval.append(inputMappings.get(i).getXML()); } retval .append(" ") .append(XMLHandler.closeTag("input")) .append(Const.CR); // $NON-NLS-1$ $NON-NLS-2$ retval .append(" ") .append(XMLHandler.openTag("output")) .append(Const.CR); // $NON-NLS-1$ $NON-NLS-2$ for (int i = 0; i < outputMappings.size(); i++) { retval.append(outputMappings.get(i).getXML()); } retval .append(" ") .append(XMLHandler.closeTag("output")) .append(Const.CR); // $NON-NLS-1$ $NON-NLS-2$ // Add the mapping parameters too // retval.append(" ").append(mappingParameters.getXML()).append(Const.CR); // $NON-NLS-1$ retval .append(" ") .append(XMLHandler.closeTag("mappings")) .append(Const.CR); // $NON-NLS-1$ $NON-NLS-2$ retval .append(" ") .append( XMLHandler.addTagValue("allow_multiple_input", allowingMultipleInputs)); // $NON-NLS-1$ retval .append(" ") .append( XMLHandler.addTagValue( "allow_multiple_output", allowingMultipleOutputs)); // $NON-NLS-1$ return retval.toString(); }