// Looks at all tables involved in all the mappings in the definition and returns a list of output keys that will be created. It will also deal with mapped // outputs. The outputs from each mapping will only be included if it passes the inclusion/exclusion criteria based on the context. If the schema has StagingOutputs // defined, then the calulated output list is exactly the same as the schema output list. // @param schema a StagingSchema // @param context a context of values used to to check mapping inclusion/exclusion // @return a Set of unique output keys public HashSet <String> getOutputs(StagingSchema schema, Dictionary <String, String> context) { HashSet <String> outputs = new HashSet <String>(); // if outputs are defined in the schema, then there is no reason to look any further into the mappings; the output defines exactly what keys will // be returned and it doesn't matter what context is passed in that case if (schema.getOutputMap() != null) { foreach (KeyValuePair <String, IOutput> entry in schema.getOutputMap()) { outputs.Add(entry.Key); } return(outputs); } // if outputs were not defined, then the tables involved in the mappings will be used to determine the possible outputs if (schema.getMappings() != null) { foreach (StagingMapping mapping in schema.getMappings()) { outputs.UnionWith(getOutputs(mapping, context)); } } // if valid outputs are defined on the schema level, only return outputs that defined; this removed "temporary" outputs that may be defined during the // staging process if (schema.getOutputMap() != null) { outputs.RemoveWhere(entry => !schema.getOutputMap().ContainsKey(entry)); } return(outputs); }
public void testMappingIdUniqueness() { HashSet <String> errors = new HashSet <String>(); foreach (String schemaId in _STAGING.getSchemaIds()) { StagingSchema schema = _STAGING.getSchema(schemaId); // build a list of input tables that should be excluded HashSet <String> ids = new HashSet <String>(); List <IMapping> mappings = schema.getMappings(); if (mappings != null) { foreach (StagingMapping mapping in mappings) { if (ids.Contains(mapping.getId())) { errors.Add("The mapping id " + schemaId + ":" + mapping.getId() + " is duplicated. This should never happen"); } ids.Add(mapping.getId()); } } } assertNoErrors(errors, "input values and their assocated validation tables"); }
// Looks at all tables involved in all the mappings in the definition and returns a list of input keys that could be used. It will also deal with mapped // inputs. The inputs from each mapping will only be included if it passes the inclusion/exclusion criteria based on the context. Note that if an input // to a table was not a supplied input (i.e. it was created as an output of a previous table) it will not be included in the list of inputs. The inputs will // also include any used in schema selection. All inputs returned from this method should be in the schema input list otherwise there is a problem with the // schema. // @param schema a StagingSchema // @param context a context of values used to to check mapping inclusion/exclusion // @return a Set of unique input keys public HashSet <String> getInputs(StagingSchema schema, Dictionary <String, String> context) { HashSet <String> inputs = new HashSet <String>(); // add schema selection fields if (schema.getSchemaSelectionTable() != null) { StagingTable table = getTable(schema.getSchemaSelectionTable()); if (table != null) { foreach (StagingColumnDefinition def in table.getColumnDefinitions()) { if (ColumnType.INPUT == def.getType()) { inputs.Add(def.getKey()); } } } } // process all mappings if (schema.getMappings() != null) { HashSet <String> excludedInputs = new HashSet <String>(); HashSet <String> thisInput = null; foreach (StagingMapping mapping in schema.getMappings()) { thisInput = getInputs(mapping, context, excludedInputs); inputs.UnionWith(thisInput); } } // always remove all context variables since they are never needed to be supplied inputs.ExceptWith(CONTEXT_KEYS); return(inputs); }
// Initialize a schema. // @param schema schema entity // @return initialized schema entity public static StagingSchema initSchema(StagingSchema schema) { // parse the schema selection ranges if (schema.getSchemaSelectionTable() == null) { throw new System.InvalidOperationException("Schemas must have a schema selection table."); } // store the inputs in a Map that can searched more efficiently if (schema.getInputs() != null) { Dictionary <String, IInput> parsedInputMap = new Dictionary <String, IInput>(); foreach (StagingSchemaInput input in schema.getInputs()) { // verify that all inputs contain a key if (input.getKey() == null) { throw new System.InvalidOperationException("All input definitions must have a 'key' defined."); } parsedInputMap[input.getKey()] = input; } schema.setInputMap(parsedInputMap); } // store the outputs in a Map that can searched more efficiently if (schema.getOutputs() != null) { Dictionary <String, IOutput> parsedOutputMap = new Dictionary <String, IOutput>(); foreach (StagingSchemaOutput output in schema.getOutputs()) { // verify that all inputs contain a key if (output.getKey() == null) { throw new System.InvalidOperationException("All output definitions must have a 'key' defined."); } parsedOutputMap[output.getKey()] = output; } schema.setOutputMap(parsedOutputMap); } // make sure that the mapping initial context does not set a value for an input field if (schema.getMappings() != null) { foreach (StagingMapping mapping in schema.getMappings()) { if (mapping.getInitialContext() != null) { foreach (StagingKeyValue kv in mapping.getInitialContext()) { if (schema.getInputMap().ContainsKey(kv.getKey())) { throw new System.InvalidOperationException("The key '" + kv.getKey() + "' is defined in an initial context, but that is not allowed since it is also defined as an input."); } } } } } return(schema); }