How to make multiple rows from one row in Talend? - talend

I have data that looks like this:
Name | Address | FormName
John | 123 Apple Drive | Form1 Form2 Form3
Dave| 133 Westchester Drive | Form1 Form2 Form3
How can I turn this into multiple rows based on that FormName column? So the result would be:
Name | Address | FormName
John | 123 Apple Drive | Form1
John | 123 Apple Drive | Form2
John | 123 Apple Drive | Form3
Dave| 133 Westchester Drive | Form1
Dave| 133 Westchester Drive | Form2
Dave| 133 Westchester Drive | Form3
So a row was created for each form for each person.
I tried using the tJavaFlex component but that seems too complicated for this simple task.

I found out that tNormalize does exactly this! I hooked up tNormalize to my tMap like this:
And in tNormalize component I specified what I wanted to separate on (spaces) and what column to normalize

One approach:
Loop for each row in the data set.
1.1. Put the name and address into a "current person" string.
1.2. When you get to the form "field", parse that.
1.2.1. For each form in the form field
1.2.2. Print (add to vector, etc.) the "current person" + "current form" - Concatenate.
It's a very basic, straight forward approach, so get that first, understand how it works, then consider other approaches - if any.

Related

How do I compare values across two different .csv files?

I have two .csv files, one is a dump from a third party application the other is a dump from Active Directory (using PowerShell).
The third party .csv looks something like this
e-mail address
Name
Title
Dept
john#work.com
John
Engineer
Office
mary#work.com
Mary
Supervisor
Factory
The AD .csv looks something like this
e-mail address
Name
Title
Dept
john#work.com
John
Engineer
Main Office
mary#work.com
Mary
Team Supervisor
Factory
Is there a way (ideally in PowerShell) that the two .csv files can be read and the differences highlighted and exported to third file.
e.g for the row containing john#work.con the Dept value is different, for the row containing mary#work.com the Title is different
The output would look something like this - where "Please update" has been entered into the required cell.
e-mail address
Name
Title
Dept
john#work.com
John
Engineer
Please update
mary#work.com
Mary
Please update
Factory
Regards
Philip
Here is one way you can do it, using Group-Object, using these CSVs as example:
$csv1 = #'
e-mail address,Name,Title,Dept
john#work.com,John,Engineer,Office
mary#work.com,Mary,Supervisor,Factory
guy#work.com,Guy,Supervisor,Factory
'# | ConvertFrom-Csv
$csv2 = #'
e-mail address,Name,Title,Dept
john#work.com,John,Engineer,Main Office
mary#work.com,Mary,Team Supervisor,Factory
otherguy#work.com,Other Guy,Team Supervisor,Factory
'# | ConvertFrom-Csv
Group both objects by their e-mail address property and then if the group count is equal to 1, skip that object since there is nothing to compare, else, compare each property against each other and update the property value of one of the objects (the object with index 0 in this case, which will be the one we return):
$csv1 + $csv2 | Group-Object 'e-mail address' | ForEach-Object {
if($_.Count -eq 1) { return }
# following assumes there will be no more than 2 elements!
# it also assumes both CSVs have the same column names!
foreach($prop in $_.Group[0].PSObject.Properties.Name) {
if($_.Group[0].$prop -ne $_.Group[1].$prop) {
$_.Group[0].$prop = 'Please Update'
}
}
$_.Group[0]
} | Format-Table
The result we can expect from above example, as you can see, guy and otherguy are not taken into consideration for the comparison:
e-mail address Name Title Dept
-------------- ---- ----- ----
john#work.com John Engineer Please Update
mary#work.com Mary Please Update Factory

How to translate a zend application

What's the best way to translate the database content of a zend application ?
I am thinking to add field to database tables
Or create others tables
What I do is to have two tables and a view.
Let's say we have "nouns". So, I create a table NOUN_R with only "IdLanguage" (and whatever needed), another table NOUN_TR (translation), with, "IdLanguage" , a Locale (EN, DE, ...), description and text.
So far:
NOUN_R
NOUN | IDlanguage
Yellow | 1
Red | 2
NOUN_TR
NOUN | IDlanguage | Language
Yellow | 1 | EN
Giallo | 1 | IT
Red | 2 | EN
Rosso | 2 | IT
Finally, you get a view which filters on Locale!
That's the way I'm using right now, not the "best solution" :)

How to select a column of a table in emacs org mode

I can't find my way around copying a column, or a series of them, from a table.
The only solution I found so far is to copy the whole table and then delete the columns I don't need.
I suppose there must be another easier way for this. Maybe I am just too tired to realize how to do it.
I think the easiest way would be to take advantage of emacs rectangles
To create your rectangle, put your cursor at one of the corners of the rectangle you want to create.
Use C-SPC, or whatever you have set-mark-command set to.
Place your cursor at the diagonal corner of your rectangle.
Use C-x r rr to copy the rectangle to the register named r
Use C-x r ir to insert the rectangle that is being held in the register named r.
Following this process will copy and insert the columns that you want. You may need to repeat this process if the columns are not adjacent.
NOTE
I am using a bolded r to denote that this is technically a name of the register, and not some special input.
If you specifically want to copy the column(s) into another org table (or indeed back into the original table), there's support for that.
See C-hf org-table-copy-region RET
It works much like the regular rectangle commands, so it's not a better interface for selecting the column; but the associated paste command is smart about what it does with the content.
I you are planning to use emacs rectangle command you avoid the use of registers by using the command copy-rectangle-as-kill bound C-xrM-w, execute the command after selecting a region this will copy the rectangle (see this for an example of how marking rectangles works). Then you can paste the copied retangle by doing C-xry.
UPDATE
The page org-mode hacks describes a way to copy columns using org-table formulas. You will need to name the table.
Here is an example of using table formulas to copy columns from another table
Suppose you have following table named FOO, it is necessary to name the table for referring it from table formulas.
#+TBLNAME: FOO
| 0 | 2 | 1 |
| 1 | 3 | 2 |
| 2 | 4 | 3 |
You want to copy the columns 1 and 3 from table FOO to column 1 and 3 of the following table (lets call it B)
| | 5 | |
| | 6 | |
| | 7 | |
The following formula will do the trick, you will need to copy the formula below the table B and move cursor on the formula and do C-cC-c
#+TBLFM: $1=remote(FOO,###$1)::$2=remote(FOO,###$3)
The table B will be converted to the following
| 0 | 5 | 1 |
| 1 | 6 | 2 |
| 2 | 7 | 3 |
You can read about the syntax of the org table formulas here, basically $N refers to Nth column, #N refers to Nth row. ## and $# can be used instead of N to refer the row and column where the current value goes. remote(table-name, #N$N) refers to the Nth row and Nth column of the table table-name. :: concats multiple formulas.
I too had trouble using the standard rectangle operations. When moving to the next column, all of all of the rows between the point and the mark were highlighted. When I tried copying columns by formula as described above and in the org mode hacks, org threw errors if the column's values were non-numeric with more than one word.
But a good hint about cutting and pasting revealed that the problem is the initial direction of motion of the cursor. Moving first rightward to the next column, then down highlights the correct region. Standard rectangle operations then work correctly.
The "native" way in org mode is already covered in the answer by user2053036; I just wanted to add that in the simpler context, "to copy a column within a table": Let's say you have this table
| hello | world |
| is | good |
And want to repeat column 2 in column 3.
Steps:
Place the cursor after the bottom right | of the table
Open a new column to the right using keys Alt-Shift-<right>
| hello | world | |
| is | good | |
Add the "row copy from" formula (for example by putting cursor to row 1 column 3 and typing =$1 C-c C-c; or just type the TBLFM below the table and jump to step 4)
| hello | world | hello |
| is | good | |
#+TBLFM: $3=$1
Place the cursor on the TBLFM and type C-c C-c
| hello | world | hello |
| is | good | is |
#+TBLFM: $3=$1
That will copy column 1 to column 3.

Multiple SQLite Queries on iOS

I have more than 3 views. My database looks like this:
Category:
CatID | CatTitle
----------------
1 | XYZ
2 | Sample
Content:
ItemID | ItemCatID | ItemText | ItemText2 | ItemText3 | ItemText4
-----------------------------------------------------------------
1 | 1 | Test | Bla | Sample | MoreContent
2 | 1 | Test2 | BlaBla | Sample2 | Other Content
3 | 2 | Test3 | BlaBla2 | Sample3 | Other Content2
I want a view where first page category, second page list (ItemText), third page detail.
I'm not sure how to go about accomplishing that. If I use JOIN should I define "sqlite3_stmt *compiledStatement" in triple?
I think it can be done with 'For', "get parent,child" (like a cursor in java)?
Any advice welcome.
I'm not sure what you want.
Can you be more specific?
I can give you two tips though, first SQLite does not support stored procedures and has a very limited support for PL/SQL:http://www.sqlite.org/whentouse.html
if you REALLY MUST use it I suggest looking at this, I never tried it but it may work:
http://chriswolf.heroku.com/articles/2011/01/26/adding-stored-procedures-to-sqlite
Second, you usually wanna use a Wrapper around SQLite c functions so you worry about the SQL itself more and less about the c functions, examples:
Best Cocoa/Objective-C Wrapper Library for SQLite on iPhone
Hope this helps

looping through a csv

just wondering if i could do this in powershell, or even a c#/vb.net command line program.
I have data that looks like this:
(source: kalleload.net)
I have a Teams Table. It looks like this:
| id | teamname | teamcity |
so for example, C2 has the value "Atlanta Braves". I need to split this up into "Atlanta" and "Braves". Data is consistent. for example "New York Mets" is actually "NewYork Mets".
So i need to go through column C and D and insert all the teams (no duplicates into the db).
One line of PowerShell will read in the CSV file and create a custom object for each home and away team listing (with a property for the city name and for the team name). The last command in the pipeline will eliminate the duplicates.
$TeamsAndCities = import-csv -path c:\mycsvfile.csv | foreach-object { $_.away, $_.home | select-object #{Name='City';Expression={$_.split(' ')[0]}}, #{Name='Team';Expression={$_.split(' ')[1]}} } | select-object -unique
You can do database access from PowerShell as well, but that might be suited to a new question with some more details about the database you are connecting to.
I rarely code in VBA/VB but...
Something like
Dim rngAwayTeam As Range, rngHomeTeam As Range
set rngAwayTeam = Worksheets("YourWorksheet").Range("C2")
set rngHomeTeam = Worksheets("YourWorksheet").Range("D2")
Dim rowOffset As Integer
rowOffset = 1
Do While (rngAwayTeam.Offset(rowOffset,1).Text <> "")
'Do something with rngAwayTeam.Offset(rowOffset,1).Text
'and rngHomeTeam.Offset(rowOffset,1).Text
rowOffset = rowOffset + 1
Loop
There are other ways I'm sure, but, here is what I would do.
Yes that is an excel macro. Again, I rarely use VBA or .Net, just trying to help you out the best I can. You could just use a C# COM object for the database side of things. (Still new, can't comment.)
You can do it in C# console application quite easily.
All you have to do is loop through each line in the file, adding it to an array using split on the comma (,).
Then you can use your array to display the values or retrieve a specific value on a row.