Showing posts with label iterate. Show all posts
Showing posts with label iterate. Show all posts

Tuesday, March 20, 2012

Script Question inside a DataFlow

Is it possible to iterate over all of the fields of the Row collection inside of the Script Component of a data flow. Basically, want I want to is to check every incoming column (all are strings) for a particular character sequence, and if found, change it to something else. I am current accessing each field as Row.Field1, Row.Field2, etc. and just thought there must be a better way to do something like:

For each col in Row

if row.col = XXX then do something.

End For

Thanks in advance for your help

gsell wrote:

Is it possible to iterate over all of the fields of the Row collection inside of the Script Component of a data flow. Basically, want I want to is to check every incoming column (all are strings) for a particular character sequence, and if found, change it to something else. I am current accessing each field as Row.Field1, Row.Field2, etc. and just thought there must be a better way to do something like:

For each col in Row

if row.col = XXX then do something.

End For

Thanks in advance for your help

Well, you COULD do that but, trust me, it would be much much slower than what you are already doing. To loop over the data this would need to be an asynchronous (sometimes called a blocking) component and these are slow.

The correct way to do this is what you are already doing.

-Jamie

Wednesday, March 7, 2012

Script component - column iteration within

I have a synchronous script component and have added 5 fields to the output (field1, field2... field5). Can I iterate those fields?

In sudo language, I'd like to do:

Code Snippet

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
dim i as integer = 1
while i < 6
row.field[i] = "somevalue: " + i.ToString
end while
end sub

Somehow, I'd like to be able to do that without specifying each field individually:

row.field1 = "somevalue: " + "1"
row.field2 = "somevalue: " + "2"
...

Phil Brammer wrote:

I have a synchronous script component and have added 5 fields to the output (field1, field2... field5). Can I iterate those fields?

In sudo language, I'd like to do:

Code Snippet

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
dim i as integer = 1
while i < 6
row.field[i] = "somevalue: " + i.ToString
end while
end sub

Somehow, I'd like to be able to do that without specifying each field individually:

row.field1 = "somevalue: " + "1"
row.field2 = "somevalue: " + "2"
...

Phil,

This should put you on the right path:

Code Snippet

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

Dim col As IDTSOutputColumn90

For Each col In Me.ComponentMetaData.OutputCollection(0).OutputColumnCollection

MsgBox(col.Name)

Next

End Sub

-Jamie

P.S. How did you get all the code indented in your post?

|||

Question. Why on earth do you want to do this? Smile

|||

Jamie Thomson wrote:

Question. Why on earth do you want to do this?

I'm trying to build an example for a poster from last night...

So the above works great for iterating the columns, now I need to assign a value to the output columns by iterating them.

Code Snippet

While counter < maxSegments
For Each col In Me.ComponentMetaData.OutputCollection(0).OutputColumnCollection

If col.Name.Contains("Segment" + (counter + 1).ToString) Then
' Below I need to take the current "column name" and assign a value to it in the output collection
Row.(col.Name) = myStringArray(counter)
Exit For
End If

Next
counter = counter + 1
End While


I just cut and paste with the indentions and it just works for me!|||

Jamie Thomson wrote:


Code Snippet

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

Dim col As IDTSOutputColumn90

For Each col In Me.ComponentMetaData.OutputCollection(0).OutputColumnCollection

MsgBox(col.Name)

Next

End Sub

-Jamie

P.S. How did you get all the code indented in your post?

How do you get color?

|||

JayH wrote:

How do you get color?

Let me guess, Jamie: Internet Explorer?|||

Phil Brammer wrote:

JayH wrote:

How do you get color?

Let me guess, Jamie: Internet Explorer?

I just copy and paste as well Smile

I get colour but no indents. Phil gets indents but no colour. Weird.

I'm on Vista and IE7.

-Jamie

P.S. color not colour. Whoops - better not get into that!!! Smile

|||

Phil Brammer wrote:


Let me guess, Jamie: Internet Explorer?

I think I tried IE, but it didn't do it either.

While I'm asking questions, how do users mark questions as "answered". I only see "Was this post helpful?" with Yes/No buttons. Is that it? I just assumed that only the OP had permission to mark the question as answered, and since I never start threads I just wasn't seeing it.
|||

JayH wrote:

Phil Brammer wrote:


Let me guess, Jamie: Internet Explorer?

I think I tried IE, but it didn't do it either.

While I'm asking questions, how do users mark questions as "answered". I only see "Was this post helpful?" with Yes/No buttons. Is that it? I just assumed that only the OP had permission to mark the question as answered, and since I never start threads I just wasn't seeing it.

That's correct. Only the OP and moderators can mark threads as answered.|||

Phil Brammer wrote:

JayH wrote:

Phil Brammer wrote:


Let me guess, Jamie: Internet Explorer?

I think I tried IE, but it didn't do it either.

While I'm asking questions, how do users mark questions as "answered". I only see "Was this post helpful?" with Yes/No buttons. Is that it? I just assumed that only the OP had permission to mark the question as answered, and since I never start threads I just wasn't seeing it.

That's correct. Only the OP and moderators can mark threads as answered.

really? dang. I didn't know that.

|||

Jamie Thomson wrote:

really? dang. I didn't know that.

What do you mean? aren't you a moderator? If so, you will see 'Mark as answer' buttom on each post

|||

Rafael Salas wrote:

Jamie Thomson wrote:

really? dang. I didn't know that.

What do you mean? aren't you a moderator? If so, you will see 'Mark as answer' buttom on each post

Yes, I'm a moderator. Hence I have the ability to 'mark as answered'. Hence I didn't know that none-moderators do not have the ability to do this.

-Jamie

|||jaegd has a wonderful example of a script component that does what I'm looking at:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=864401&SiteID=1