Skip to main content
Solved

start_count / workspace runner


vki
Contributor
Forum|alt.badge.img+7
  • Contributor
Hello

 

 

I want to transform tables and at the same time add unique ID-Fields to them with a counter-transformer. As identical tables are saved in different oracle users, I set up a workspace for one user, parameterized it and run it out of another workspace for all users, using the workspace runner.

 

My problem now is to get the start_count of the counter dynamically, so that at the second run of the workspace runner the counter continues with the last value of the first run.

 

I found this: http://fmepedia.safe.com/articles/How_To/Get-the-Start-Count-for-the-Counter-from-a-different-dataset, but what I have is not really a different dataset...Isn't there a possibility to save a value temporarily when using a workspace runner?

 

 

Thanks in advance

 

Vera

Best answer by fmelizard

Hi Vera,

 

 

Since a sequence is automatically created by oracle for each feature in a table is that not what you are looking for?

 

 

The ora message means you are trying to insert a null value to a non nullable column
View original
Did this help you find an answer to your question?
This post is closed to further activity.
It may be a question with a best answer, an implemented idea, or just a post needing no comment.
If you have a follow-up or related question, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

11 replies

takashi
Influencer
  • September 30, 2013
Hi Vera,

 

 

The WorkspaceRunner creates different fme process for each run, so I think the method described in the linked article cannot be applied in your case. One possible approach is to save the next start count value into an external file in the shutdown process, and to read it when the next process starts. Be aware that this approach works only when you specify "Yes" to "Wait for Job to Complete" parameter of the WorkspaceRunner.   Main workspace 1) Define a published parameter to fetch whether the current process is the first one or not. Name: IS_FIRST_RUN Type: Choice Configuration: Yes%No   2) Define a private scripted (Python) parameter named "COUNT_START" to return the start count read from an external file. ----- import os global g_path g_path = './counter.txt' if FME_MacroValues['IS_FIRST_RUN'] == 'No' and os.path.exists(g_path):     f = open(g_path, 'rb')     n = f.readline().strip()     f.close()     return n if n else 0 else:     return 0 ----- * You can also define the file path as another published parameter or a global variable in Startup Python Script etc..   3) Link the "Count Start" parameter of the Counter to the "COUNT_START" parameter above.   4) Insert a PythonCaller with this script after the Counter. When the translation is completed, g_count indicates the last count. ----- import fmeobjects def updateCount(feature):     global g_count     g_count = int(feature.getAttribute('_count')) -----   5) Define the Shutdown Python Script like this to save the next start count (last count + 1). ----- f = open(g_path, 'wb') f.write(str(g_count + 1)) f.close() -----   Workspace that calls the main workspace 6) When running for the first user, pass "Yes" to "IS_FIRST_RUN" parameter of the main workspace through the WorkspaceRunner. Otherwise pass "No".     It's a little complicated. Hope a more elegant solution will be provided.

 

Takashi

takashi
Influencer
  • September 30, 2013
Correction:

 

* You can also define the file path as another published parameter or a global variable in Startup Python Script etc..

 

 

Startup Python Script will be interpreted after scripted parameter, so the file path cannot be define in the startup process.

takashi
Influencer
  • September 30, 2013
Another approach.

 

If you can get the number of features to be written for each user before the WorkspaceRunner, you can calculate the start count beforehand and pass it to the main workspace as a parameter. user[0]: number = n[0], start[0] = 0 user[1]: number = n[1], start[1] = start[0] + n[0] user[2]: number = n[2], start[2] = start[1] + n[1] ... user[i]: number = n[i], start[i] = start[i - 1] + n[i - 1]   "Multiple Feature Attribute Support" option of the AttributeCreator can be used effectively to do this calculation.

fmelizard
Contributor
Forum|alt.badge.img+17
  • Contributor
  • September 30, 2013
Since you are writting to oracle why not use a SQL executor to read the last value from each users table and assign it to the counter?

 

 

A demo for something like this can br found if you create a new  workspace  Create Workspace wizard > FME Store > Database > read oracle sequence nextval

vki
Contributor
Forum|alt.badge.img+7
  • Author
  • Contributor
  • September 30, 2013
Thanks Takashi for your answers, I will try it out, especially the last one.

 

 

But first I'd like to try another possible solution, but I can't get it to work:

 

In my oracle DB I have an "admin"-user which has a public sequence that I could use to create all of my IDs.

 

I put an SQLExecuter-Transformer between origin- and the result-table and connected it to the "admin"-schema, then I wrote the SQL-Statement (...NEXTVAL...) and exposed the "ID"-Attribute. As I understood it, a value should be calculated for each feature that enters the transformer.  But I get an Oracle-error: ORA-01400: cannot insert NULL (ID)??

 

 

Thanks, Vera

fmelizard
Contributor
Forum|alt.badge.img+17
  • Contributor
  • Best Answer
  • September 30, 2013
Hi Vera,

 

 

Since a sequence is automatically created by oracle for each feature in a table is that not what you are looking for?

 

 

The ora message means you are trying to insert a null value to a non nullable column

vki
Contributor
Forum|alt.badge.img+7
  • Author
  • Contributor
  • September 30, 2013
Itay,

 

 

I didn't see your answer because was writing my last question. But that's exactly what I was looking for!

 

 

Many thanks

 

Vera

fmelizard
Contributor
Forum|alt.badge.img+17
  • Contributor
  • September 30, 2013
Glad to hear it :) python is not always the answer....

takashi
Influencer
  • September 30, 2013
I overlooked that the destination dataset is oracle database. I think Itay's suggestion is the best solution :-)

 


fmelizard
Contributor
Forum|alt.badge.img+17
  • Contributor
  • September 30, 2013
??? ????? Takashi

david_r
Evangelist
  • October 1, 2013
On more tip, for posterity: If you get error messages starting with "ORA" when reading or writing to Oracle, you can just google the error number directly, without the error text.

 

 

Example:

 

ORA-01400 -> http://www.google.com/search?q=ORA-01400

 

 

The beauty of this is that this works regardless of your current language or locale setting.

 

 

David

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings