// Looks at all tables involved in the mapping and returns a list of output keys that could be created. This also includes the output keys // used in the inclusion and exclusion tables if any. The outputs from each mapping will only be included if it passes the inclusion/exclusion // criteria based on the context. // @param mapping a StagingMapping // @param context a context of values used to to check mapping inclusion/exclusion // @return a Set of unique output keys public HashSet <String> getOutputs(StagingMapping mapping, Dictionary <String, String> context) { HashSet <String> outputs = new HashSet <String>(); if (mapping.getTablePaths() != null) { if (context == null || _engine.isMappingInvolved(mapping, context)) { outputs.UnionWith(_engine.getOutputs(mapping)); } } return(outputs); }
// Looks at all tables involved in the mapping and returns a list of input keys that could be used. This always includes the input keys // used in the inclusion and exclusion tables if any. The inputs from each table path will only be included if it passes the inclusion/exclusion // criteria based on the context. // @param mapping a StagingMapping // @param context a context of values used to to check mapping inclusion/exclusion // @param excludedInputs a list of input keys to not consider as inputs // @return a Set of unique input keys public HashSet <String> getInputs(StagingMapping mapping, Dictionary <String, String> context, HashSet <String> excludedInputs) { HashSet <String> inputs = new HashSet <String>(); // the inclusion tables are always evaluated so any inputs there should be added always if (mapping.getInclusionTables() != null) { foreach (StagingTablePath path in mapping.getInclusionTables()) { inputs.UnionWith(getInputs(path, excludedInputs)); } } // the exclusion tables are always evaluated so any inputs there should be added always if (mapping.getExclusionTables() != null) { foreach (StagingTablePath path in mapping.getExclusionTables()) { inputs.UnionWith(getInputs(path, excludedInputs)); } } // if there are tables paths and if the mapping is involved, add the inputs if (mapping.getTablePaths() != null) { if (context == null || _engine.isMappingInvolved(mapping, context)) { inputs.UnionWith(_engine.getInputs(mapping, excludedInputs)); } } // always remove all context variables since they are never needed to be supplied inputs.ExceptWith(CONTEXT_KEYS); return(inputs); }
public void testInvalidContext() { InMemoryDataProvider provider = new InMemoryDataProvider("test", "1.0"); StagingTable table = new StagingTable(); table.setId("table_input1"); StagingColumnDefinition def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 1"); def1.setType(ColumnType.INPUT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "1" }); table.getRawRows().Add(new List <String>() { "2" }); provider.addTable(table); table = new StagingTable(); table.setId("table_selection"); def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 1"); def1.setType(ColumnType.INPUT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "*" }); provider.addTable(table); table = new StagingTable(); table.setId("table_mapping"); def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 1"); def1.setType(ColumnType.INPUT); StagingColumnDefinition def2 = new StagingColumnDefinition(); def2.setKey("final_output"); def2.setName("Output"); def2.setType(ColumnType.ENDPOINT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1, def2 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "*", "VALUE:ABC" }); provider.addTable(table); StagingSchema schema = new StagingSchema(); schema.setId("schema_test"); schema.setSchemaSelectionTable("table_selection"); List <StagingSchemaInput> inputs = new List <StagingSchemaInput>(); inputs.Add(new StagingSchemaInput("input1", "Input 1", "table_input1")); schema.setInputs(inputs); List <StagingSchemaOutput> outputs = new List <StagingSchemaOutput>(); outputs.Add(new StagingSchemaOutput("final_output", "Final Output")); schema.setOutputs(outputs); StagingMapping mapping = new StagingMapping(); mapping.setId("m1"); List <IKeyValue> mapInitialContext = new List <IKeyValue>(); mapInitialContext.Add(new StagingKeyValue("input1", "XXX")); mapping.setInitialContext(mapInitialContext); StagingTablePath path = new StagingTablePath(); path.setId("table_mapping"); HashSet <String> pathInputs = new HashSet <String>(); pathInputs.Add("input1"); path.setInputs(pathInputs); HashSet <String> pathOutputs = new HashSet <String>(); pathOutputs.Add("final_output"); path.setOutputs(pathOutputs); List <ITablePath> mapTablePaths = new List <ITablePath>(); mapTablePaths.Add(path); mapping.setTablePaths(mapTablePaths); List <IMapping> schemaMappings = new List <IMapping>(); schemaMappings.Add(mapping); schema.setMappings(schemaMappings); try { provider.addSchema(schema); Assert.Fail("Add Schema should have thrown an exception."); } catch (System.InvalidOperationException e) { Assert.IsTrue(e.Message.Contains("not allowed since it is also defined as an input")); } }
public void testGetInputsWithContext() { InMemoryDataProvider provider = new InMemoryDataProvider("test", "1.0"); StagingTable table = new StagingTable(); table.setId("table_input1"); StagingColumnDefinition def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 1"); def1.setType(ColumnType.INPUT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "1" }); table.getRawRows().Add(new List <String>() { "2" }); provider.addTable(table); table = new StagingTable(); table.setId("table_input2"); def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 2"); def1.setType(ColumnType.INPUT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "" }); table.getRawRows().Add(new List <String>() { "A" }); table.getRawRows().Add(new List <String>() { "B" }); provider.addTable(table); table = new StagingTable(); table.setId("table_selection"); def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 1"); def1.setType(ColumnType.INPUT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "*" }); provider.addTable(table); table = new StagingTable(); table.setId("table_mapping"); def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 1"); def1.setType(ColumnType.INPUT); StagingColumnDefinition def2 = new StagingColumnDefinition(); def2.setKey("input2"); def2.setName("Input 2"); def2.setType(ColumnType.INPUT); StagingColumnDefinition def3 = new StagingColumnDefinition(); def3.setKey("mapped_field"); def3.setName("Temp value"); def3.setType(ColumnType.INPUT); StagingColumnDefinition def4 = new StagingColumnDefinition(); def4.setKey("final_output"); def4.setName("Output"); def4.setType(ColumnType.ENDPOINT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1, def2, def3, def4 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "*", "*", "*", "VALUE:ABC" }); provider.addTable(table); StagingSchema schema = new StagingSchema(); schema.setId("schema_test"); schema.setSchemaSelectionTable("table_selection"); List <StagingSchemaInput> inputs = new List <StagingSchemaInput>(); inputs.Add(new StagingSchemaInput("input1", "Input 1", "table_input1")); inputs.Add(new StagingSchemaInput("input2", "Input 2", "table_input2")); schema.setInputs(inputs); List <StagingSchemaOutput> outputs = new List <StagingSchemaOutput>(); outputs.Add(new StagingSchemaOutput("final_output", "Final Output")); schema.setOutputs(outputs); StagingMapping mapping = new StagingMapping(); mapping.setId("m1"); List <IKeyValue> mapInitialContext = new List <IKeyValue>(); mapInitialContext.Add(new StagingKeyValue("tmp_field", null)); mapping.setInitialContext(mapInitialContext); StagingTablePath path = new StagingTablePath(); path.setId("table_mapping"); HashSet <IKeyMapping> pathInputMap = new HashSet <IKeyMapping>(); pathInputMap.Add(new StagingKeyMapping("tmp_field", "mapped_field")); path.setInputMapping(pathInputMap); HashSet <String> pathInputs = new HashSet <String>(); pathInputs.Add("input1"); pathInputs.Add("input2"); pathInputs.Add("tmp_field"); path.setInputs(pathInputs); HashSet <String> pathOutputs = new HashSet <String>(); pathOutputs.Add("final_output"); path.setOutputs(pathOutputs); List <ITablePath> mapTablePaths = new List <ITablePath>(); mapTablePaths.Add(path); mapping.setTablePaths(mapTablePaths); List <IMapping> schemaMappings = new List <IMapping>(); schemaMappings.Add(mapping); schema.setMappings(schemaMappings); provider.addSchema(schema); TNMStagingCSharp.Src.Staging.Staging staging = TNMStagingCSharp.Src.Staging.Staging.getInstance(provider); HashSet <String> testSet1 = staging.getInputs(staging.getSchema("schema_test")); HashSet <String> testSet2 = new HashSet <String>(); testSet2.Add("input1"); testSet2.Add("input2"); // should only return the "real" inputs and not the temp field set in initial context Assert.IsTrue(testSet1.SetEquals(testSet2)); }
// Looks at all tables involved in the mapping and returns a list of output keys that could be created. This also includes the output keys // used in the inclusion and exclusion tables if any. // @param mapping a StagingMapping // @return a Set of unique output keys public HashSet <String> getOutputs(StagingMapping mapping) { return(getOutputs(mapping, null)); }
// Looks at all tables involved in the mapping and returns a list of input keys that could be used. This also includes the input keys // used in the inclusion and exclusion tables if any. // @param mapping a StagingMapping // @return a Set of unique input keys public HashSet <String> getInputs(StagingMapping mapping) { return(getInputs(mapping, null, new HashSet <String>())); }