Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Custom Component Adding Output Columns

$
0
0

Hi,

I am building a custom component that has the following code:

public override void ProvideComponentProperties()
{
	base.RemoveAllInputsOutputsAndCustomProperties();

	IDTSInput100 input = ComponentMetaData.InputCollection.New();
	input.Name = "Input";

	IDTSOutput100 output = ComponentMetaData.OutputCollection.New();
	output.Name = "Detail Table";
	output.SynchronousInputID = input.ID;

	IDTSOutput100 errorOutput = ComponentMetaData.OutputCollection.New();
	errorOutput.Name = "Error";
	errorOutput.IsErrorOut = true;

	IDTSOutputColumn100 MyColumn = output.OutputColumnCollection.New();
	MyColumn.Name = "MyColumn1";
	MyColumn.SetDataTypeProperties(DataType.DT_STR, 20, 0, 0, 1252);
	IDTSOutputColumn100 MyColumn2 = output.OutputColumnCollection.New();
	MyColumn2.Name = "MyColumn2";
	MyColumn2.SetDataTypeProperties(DataType.DT_STR, 20, 0, 0, 1252);
	IDTSOutputColumn100 MyColumn3 = output.OutputColumnCollection.New();
	MyColumn3.Name = "MyColumn3";
	MyColumn3.SetDataTypeProperties(DataType.DT_STR, 20, 0, 0, 1252);
	IDTSOutputColumn100 MyColumn4 = output.OutputColumnCollection.New();
	MyColumn4.Name = "MyColumn4";
	MyColumn4.SetDataTypeProperties(DataType.DT_STR, 20, 0, 0, 1252);
	IDTSOutputColumn100 MyColumn5 = output.OutputColumnCollection.New();
	MyColumn5.Name = "MyColumn5";
	MyColumn5.SetDataTypeProperties(DataType.DT_STR, 20, 0, 0, 1252);
}

public override DTSValidationStatus Validate()
{
	bool pbCancel = false;

	// Validate that there is only one input.
	if (ComponentMetaData.InputCollection.Count != 1)
	{
		ComponentMetaData.FireError(0, ComponentMetaData.Name, "Incorrect number of inputs.", "", 0, out pbCancel);
		return DTSValidationStatus.VS_ISCORRUPT;
	}

	// Validate number of outputs.
	if (ComponentMetaData.OutputCollection.Count != 2)
	{
		ComponentMetaData.FireError(0, ComponentMetaData.Name, "Incorrect number of outputs.", "", 0, out pbCancel);
		return DTSValidationStatus.VS_ISCORRUPT;
	}

	// Determine whether the metadata needs refresh
	IDTSInput100 input = ComponentMetaData.InputCollection[0];
	IDTSVirtualInput100 vInput = input.GetVirtualInput();

	bool cancel = false;

	foreach (IDTSInputColumn100 column in input.InputColumnCollection)
	{
		try
		{
			IDTSVirtualInputColumn100 vColumn = vInput.VirtualInputColumnCollection.GetVirtualInputColumnByLineageID(column.LineageID);
		}
		catch
		{
			ComponentMetaData.FireError(0, ComponentMetaData.Name, "The input column " + column.IdentificationString + " does not match a column in the upstream component.", "", 0, out cancel);
			areInputColumnsValid = false;
			return DTSValidationStatus.VS_NEEDSNEWMETADATA;
		}
	}

	return DTSValidationStatus.VS_ISVALID;
}

public override void PreExecute()
{
	IDTSInput100 input = ComponentMetaData.InputCollection[0];
	inputBufferColumnIndex = new int[input.InputColumnCollection.Count];

	for (int x = 0; x < input.InputColumnCollection.Count; x++)
	{
		IDTSInputColumn100 column = input.InputColumnCollection[x];
		inputBufferColumnIndex[x] = BufferManager.FindColumnByLineageID(input.Buffer, column.LineageID);
	}

	IDTSOutput100 output = ComponentMetaData.OutputCollection[0];
	outputBufferColumnIndex = new int[output.OutputColumnCollection.Count];

	for (int x = 0; x < output.OutputColumnCollection.Count; x++)
	{
		IDTSOutputColumn100 outcol = output.OutputColumnCollection[x];
		outputBufferColumnIndex[x] = BufferManager.FindColumnByLineageID(input.Buffer, outcol.LineageID);
	}

}

And consider for a second the following ProcessInput Method that does nothing:

public override void ProcessInput(int inputID, PipelineBuffer buffer)
{
	if (!buffer.EndOfRowset)
	{
		while (buffer.NextRow())
		{

		}
	}

}

Now if I build a custom component with this code and run it in a SSIS package, the component will:

(a) Have an input with all the input columns, and an output with the 5 output columns: Mycolumn, Mycolumn1, ...., MyColumn5.

(b) At runtime, the component will send all the data from the input straight through to the output and the output will contain all the columns from the input (and the respective data) and the 5 columns created in the output with no data.

Given this, I have a number of questions I was hoping someone could help me with.

(1) In the advanced editor of the component under "Input and Output Properties", can I make the input columns appear in the defined output in addition to the 5 columns I declare in the component? 

(2) Lets say in the SSIS package there are 8 input columns: input1, input2, input3,..., input8 and these need to be mapped to the defined output columns as per the following: input1 + '_' + input2 to Mycolumn, input3 + '_' + input4  to Mycolumn2, input5 to Mycolumn3, input6 + '_' + input7 to MyColumn4, and input8 to MyColumn6. How should my ProcessInput method look so that only Mycolumn, mycolumn2,..., mycolumn5 are output and not the original input columns as well.

Thanks in advance for any help.


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>