Ok, I am writing an avro file using SSIS script component as a destination. Since AVRO needs a schema as well, I need to define the schema. It works fine when I define the schema manually. But I have 10-12 data flow tasks and I do not want to write the schema explicitly. I am trying to see if I can use the BufferWrapper which is auto generated to see if I can read from there but I can't and it always returns blank.
I have tried the solution posted here and also read up this . But everything returns blank.
I have also come across this . Could that be the reason and if that explanation in the answer posted there is correct, isn't this possible?
So, in my public override void PreExecute(), I have something like this:
Schema = @"{
""type"":""record"",
""name"":""Microsoft.Hadoop.Avro.Specifications.Counterparts"",
""fields"":
[
{ ""name"":""CounterpartID"", ""type"":""int"" },
{ ""name"":""CounterpartFirstDepositDate"", ""type"":[""string"",""null""] },
{ ""name"":""CounterpartFirstTradeDate"",""type"":[""string"",""null""] },
{ ""name"":""ClientSegmentReportingID"",""type"":[""int"",""null""] },
{ ""name"":""ClientSegmentReportingName"", ""type"":[""string"",""null""] },
{ ""name"":""ContractID"", ""type"":[""int"",""null""] },
{ ""name"":""ContractFirstDepositDate"", ""type"":[""string"",""null""] },
{ ""name"":""ContractFirstTradeDate"",""type"":[""string"",""null""] },
{ ""name"":""ContractClosingOffice"",""type"":[""string"",""null""] },
{ ""name"":""LeadCreationDate"", ""type"":[""string"",""null""] },
{ ""name"":""ContractCountryOfResidence"", ""type"":[""string"",""null""] }
]
}";
}
Instead of manually defining all this schema, I am checking if I could generate it out of the BufferWrapper but this returns blank:
var fields = typeof(Input0Buffer).GetFields().Select(m => new
{
Name = m.Name,
Type = m.FieldType
}).ToList();
Also, if I just do this, that also returns blank
Type myType = typeof(Input0Buffer);
// Get the fields of the specified class.
FieldInfo[] myField = myType.GetFields();
Earlier I was putting these new methods in Pre-Execute but then thought, maybe the buffer isn't initialized by then , so I moved that to Input0_ProcessInputRow method and making sure that it is triggered only once using a counter variable and making this code run only when counter=0, but even that returns blank.
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
if (counter == 0)
{
Type myType = typeof(Input0Buffer);
// Get the fields of the specified class.
FieldInfo[] myField = myType.GetFields();
}
//Processing logic
}
Isn't it possible because of this ?
As it talks about it being protected and also not accessible from outside that autogenerated class.
I have finally found the answer here: https://waheedrous.wordpress.com/2014/02/24/ssis-global-replace-for-all-columns-using-a-script-component/
I can finally get the list of columns and datatypes from within the script component. I will only run it the first time (using a counter variable).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.