Showing posts with label Scripting. Show all posts
Showing posts with label Scripting. Show all posts

Monday, August 26, 2013

PowerDesigner: Generate automatic incrementing index name and code

Would you like to have index names and code generated with something other than Index_1, Index_2, etc.?

Here's how to do that. (Thanks for guidance from Robert Adlington, SAP/Sybase Technical Publications Manager).

  1. Open the XDB file (Oracle used in this case)
  2. Navigate to root:Profile\Index.
  3. Right click Index in the navigation column and select New->Event Handler.
  4. Select Initialize from the drop-down list
  5. In the Event Handler Script tab, enter your custom code:  I use:
    obj.SetNameAndCode obj.parent.name + " Index", Left(obj.parent.code, 24) + "_IDX"
After doing the above, in a table's property sheet on the Indexes tab, create a new index.  It should use the text from the table's Name attribute plus the word "Index" for the index's name and the first 24 characters of the table's Code attribute plus the _IDX extension for the index's code value.

The first index will have suffix _IDX and the second will have _IDX2, with the number incrementing for each additional index.  

The SetNameAndCode method applies any naming conventions and also verifies uniqueness - hence the incrementing suffix. I can’t make the first index end in 1, but you may be able to enhance the script to do so if it is important to you. [Rober Adlington]

If you use name to code conversions, the abbreviations from your conversion table will be picked up automatically in the index's code.  However, if you use a different abbreviation for Index than IDX, you will need to change the code entered into the Event Handler Script tab to use that instead.

Unfortunately, I don't know how to get the conversion table's abbreviations to be picked up automatically in that script (yet!)  If someone knows how to do that, please let all of us know with your added comment.

Friday, September 28, 2012

PowerDesigner: How to determine "create" and "modify" timestamps in XDB files

Have you ever wondered who made a change to a PowerDesigner XDB file and when the change was made?  Here's how to figure that out.

Open an XDB file in a text editor.  Search for CreationDate or ModificationDate.  Following these XML tags you will find Creator or Modifier tags; these will give the logon id (OS user) of the person who created or modified the attribute.

To get the date of creation or modification, create an Excel spreadsheet similar to the one shown below.  In the "Seconds" column, insert the number found in the XDB file such as:

<a:ModificationDate>1348840976</a:ModificationDate> (Column A4.)

Divide this number by 86,400, the number of seconds in a day ("Days", B column).
  • B column formula: =A4/86400
PowerDesigner counts the number of seconds from Midnight on January 1, 1970 UTC.  In Excel, add the number of fractional days to this date to get the calculated date in the UTC time zone.

To calculate the local time, add or subtract your time zone offset.  For me in the U.S. Central time zone, during daylight savings time, I need to subtract 5 hours, or 5/24 of a day.  The formula I use is below.
  • D column formula: =(C4+B4)-(5/24)
Of course, the formulas above would have their rows changed in each row, but you should get the idea.  You would also have to use a "custom" cell format to get the dates to display as shown below.  I use "m/d/yyyy h:mm:ss" as a custom format for dates in columns C and D.

A B C D
1 Seconds Days Starting Date UTC CDT
2 1325765647 15344.5098 1/1/1970 0:00:00 1/5/2012 7:14:07
3 1330036842 15393.9449 1/1/1970 0:00:00 2/23/2012 17:40:42
4 1348840976 15611.5854 1/1/1970 0:00:00 9/28/2012 9:02:56
5 1348842034 15611.5976 1/1/1970 0:00:00 9/28/2012 9:20:34

Hope you find this useful.

Friday, July 1, 2011

Testing data warehouse - Toolbox for IT Groups

Testing data warehouse - Toolbox for IT Groups

My response to the posted question concerning QA testing of Data Warehouse ETL is:


More than just using independently developed SQL statements, I recommend writing separate ETL programs using another programming / scripting language such as Perl to mimic what the ETL programs are supposed to be doing.

Since the same effort will be needed by both the ETL development team and the QA development team, QA cannot be left to the end as, in many projects, a "necessary evil" at the last minute. Both development teams will need to be working independently to, hopefully, achieve the same results.

For example, I had a QA lead project where the ETL programs were written in Pro-C++ moving data from a mainframe DB2 extracted file set to an Oracle UNIX-based enterprise database. Using the same design specifications that the Pro-C developers used, I wrote Perl scripts to create UNIX-based "tables" (file stores) that were to mimic the Oracle target tables.

A complete set of data extract files were created from the DB2 source. Using the same DB2 extract files, the developers ran their programs to load the target tables and I ran mine to load the UNIX files. Then I extracted the data loaded from the Oracle tables and saved the extract to another set of UNIX files in the same format as my extract files. Using UNIX diff command, I compared the two sets of files.

By doing this, I revealed two glaring errors that the developers said would not have been caught using just a small sample set of data extracts:

First, the Pro-C programs were doing batch commits every 2,000 rows, but the program was not resetting the counter in the FOR loop. Thus, only the first 2,000 rows were getting written to the Oracle tables. If the source-to-target mapping predicted a million rows, the resulting 2,000 rows was a big problem!

After this was fixed, the next glaring error my Perl scripts caught was that the variable array in Pro-C was not being cleared properly between rows. Therefore, some fields from the previous row were not cleared and were duplicated for subsequent rows. Thus some customers records that did not supply certain fields, say an email address, got the data in those fields from the previous customer record.

Since these programs were written using the same design specifications, but independently, one of the checks was to give the code used to each other, so I checked their Pro-C code and they checked my Perl code to see where the problem was.

Simply sending a few hundred rows of mocked-up test data to the Oracle target and checking that it matched expectations was not adequate testing and would not have revealed these serious bugs.

Monday, December 13, 2010

Programming using Scripting Languages

It might seem like I'm digressing from my "data-centric" focus, but, really, I don't think so.  I have had to write  scripts to automate many "data-centric" tasks over the years; most of these scripts contained embedded SQL for data manipulation (DML).  Many of these scripts were automated by using UNIX cron, Windows AT, or some other scheduler. For example:

  • Transfer data files from one location to another
  • Load data files directly into database staging tables
  • Extract data to create data files to be sent to clients or vendors using FTP
  • Create reports
  • Data migration from mainframe to regional client/server databases.
Granted, these tasks were done before modern CASE tools took over many of these tasks, but you still might need to do some tasks like these on an impromptu, urgent basis.  Or maybe the client doesn't have one of the CASE tools and doesn't want to spend the money to get one - just do it!

On UNIX systems, I suggest learning Korn Shell (ksh).  You will be surprised at how robust a programming language this is.  Now I know some people will say it is not a "programming" language because it isn't compiled, but the skills needed to write good scripts are the same as those needed to write good compiled programs.  Compiling a program is done to make it run faster and there are programs that will compile ksh scripts, such as shc.

Another favorite of mine is Perl.  It can be written for both UNIX and Windows systems (as well as many others) with little change needed between systems so it is quite portable.  Perl scripts can be compiled, too, using commercial programs such as Perl2EXE.