Perl6 CRO - 2

In my first post about Perl6 and CRO I  mentioned I had problems take care of POST and GET messages at the same time.  The problem was a misspelled semi-colon

get -> 'greet', :%zname {
  say %zname:
 content 'text/plain',  'bye';
I wrote a colon instead of the correct semi-colon, you see it above say %zname: the result was

Cannot resolve caller say(Hash: DateTime); none of these signatures match:
   (Mu $: *%_)
 in block  at myfstserver.p6 line 26
 in code  at /home/tooljn/.rakudobrew/moar-nom/install/share/perl6/site/sources/1DC86B9F9A31CA5BEE35765E177159BAEDB91AAA (Cro::HTTP::Router) line 79
It took me some four hours to figure this out. If the error message had been a more helpful

%zname: is uninitialized or %zname: does not exist ...
I had probably spotted the problem instantly.

Now  my CRO server works beautifully. CRO seems amazing so far, a hell lot of functionality stuffed in there. Now I only have to learn Perl6. The language is truly great and CRO looks even greater and it is only the first beta version, really looking forward to the next version.


Object Orientation is not such a good idea

 I found this on youtube https://www.youtube.com/watch?v=QM1iUe6IofM
The speaker expresses much the same ideas and opinions I have about Object Oriented programming. Actually on programming  at large, the speaker offers an alternative the good old procedural style as a better alternative.
I have many times found myself in the same situation the speaker describs when you need to change OO programs.You end up with many classes and interfaces with small code bits scattered all over.

Perl6 CRO and Data Warehouse streaming services

What do you do when you do not have anything to do on a Sunday afternoon?

Why not implement Streaming services for a Data Warehouse? The company’s tool fleet can send performance stats over the net. I get questions about and  requests for Internet of Things, if not daily at least on a monthly basis. Often from apprehensive or perplexed persons asking for bongoDB or Big Data Hadraloop solutions. For some reason they all seem to think they need some new more or less esoteric software to gather and store data from net-connected gadgets. Sunday after lunch I stumbled on this presentation. I liked the idea about building a streaming service of stacked micro services so I had a go with Perl6 Cro. I sat up a streaming HTTP server using Cro, this server receives GET and POST calls and write them to disk as text files. Then there is another service ( a PHP program) picking up these textfiles and inserts them in a MySQL database.
The Data Warehouse streaming services

This is not by far an optimal performant or final solution, it is just a PoC, still my first test indicated it can easily handle 10 transactions a second (nothing in the chain seemed saturated), and it is a persistent solution, all incoming transactions are written to disk and not erased until they are safely stored in the database.
Not bad for a Sunday afternoon. I had some help from Andreas with POST messages and Postman for testing.

This solution is not without problems, CRO is in Beta stage, and I have problems to take care of POST and GET messages at the same time. I do not know Perl6, so I do not know if my Perl6 knowledge is too low, the CRO documentation is not correct or there are bugs in CRO first Beta version. But I’m confident my issues will be ironed out in near future. There are other more mature frameworks, but CRO looks both cool and promising, so I’ll try to stick to it.

I have said many times SQL databases can be used for so called Big Data applications, and I always eat my own dog food. If for some reason it shows SQL databases is not up to the task I switch to something else. The same goes for CRO, but it’s not fair to ditch a Beta software just because you do not understand it, and so far it looks great. (Andreas thinks I should go for a mature production ready alternative though.)


Web server and new glasses

Some years ago I wrote my first Node.js Hapi.js program. Now it was time to write the second, or rather extend the first with a new function. First I upgraded  Node and Hapi from releases 0.x.x something to node vs  8.4.0 and Hapi vs 16.5.2, it looked like a giant leap and I expected to rewrite all from scratch, but only a few simple adjustment was needed.
The first version run a Data Warehouse job in the background and at the end responded if it was a success or not. That was fine until some long running made the HTTP interface time out. After many futile attempts to fix the timeout, I called Andreas he told ‘you don’t do it that way, create one function that starts the job and immediately return the pid of the submitted job, and another function that replies if the pid is active or not. I should have figured out that myself, but I didn’t.
Anyway that should be simple and it actually was except for one detail, I have new glasses, text is a bit blurred with the new lenses.

var foo = spawn("/bin/ps", [' -p ' + pid]. {shell: true});
The invalid dot magnified, should be a comma.
I had by mistake written a . (dot) instead of a , (comma), but I did not see the dot to me it looked the same as the comma it should be. Spending an entire day on google trying to figure out what the problem was, I finally rewrote the spawn statement and it worked just fine. Sometimes programming is so frustrating, simple things can take forever.
Now I will rewrite this simple web server into a proper REST server. This should be easy, my program is more or less a REST server as it is, I just have to tweak the code a bit.
But as usual I’m confused with the never ending list of ever growing Node js frameworks. I am thinking adding TrailsJs to Hapi.js just for the hell of it. I have absolutely no clue what the implications of that is.

The new “PID active” function:

It remains to be seen if I have to set the spawned process as detached or not. According to the documentation ‘detached’ is for Windows only.


The growth of

The Data Warehouse still surprises me. After 16 years it still grows in terms of users, jobs, sql queries, reports etc. I had a look the other day at a Twitter published graph and saw jobs/month has increased from 58000 to 71000 during the last year, a staggering 22% that’s a lot.
Number of jobs or resource consumption are not a very good measures of the useful production of a Data Warehouse or any other application. It is very hard to measure the useful production of most computer apps. Number of jobs may indicate inefficiency or a stupid divide of logical tasks into too many jobs. Anyway it is a measure, assuming the Data Warehouse is not deteriorating the increase of jobs is an indication of increased use. As far as I can see the Data Warehouse is not deteriorating, if anything it is getting better.

Never in my wildest dream did I anticipated the phenomenal progress of the Data Warehouse when we started 2001 by solving one problem for one purchaser. And never did I expect the Data Warehouse be alive and kicking 16 years later. I'm not surprised however, useful applications have a tendency to live long. After my rewrite of the first version 2006, the Data Warehouse was superior to anything there was on the market. Some claim it still is, I don't know about that but it is certainly different from anything on the market.


Amazon delivery time

2017-07-07 I ordered a book in paper format from Amazon. I choose the most economic transport without looking at delivery times. When I looked a my order, to my astonishment I realized the delivery date was 2017-08-17!
My word, what kind of process can result in that delivery time for a book year 2017? Does Amazon send the paper book from USA? With a sailing ship to Holland? And from there with a horse coach to Stockholm, Sweden?
I thought Amazon was a rational modern company with a serious customer focus. Not in my wildest dreams could I imagine such a long delivery time. I get the feeling Amazon purposely extend the delivery time to ‘punish’ me for not choosing a more expensive delivery alternative.

It would be interesting to know where Amazon prints my copy of the book and the route Amazon sends the book to me.
Looking at the order I can see the book is on its way to me😈


Perl6, what's in a name

I occasionally follow Perl 6 development. Now when version 1 of Perl6 can be glimpsed at the horizon, a quibble of the name have arised. When I wrote version 1, I mean the first version the developers think is of such quality they can recommend it for professional production use, that is how most of us define a version 1 of any software be a language or not. But I’m not sure that goes for the Perl6 guys, they speak of version star, christmas instead of 1,2,3 etc. Normally you increase a software version number when you introduce non backward compatible code or new important features have been introduced. Now Perl6 is just not an upgrade of the old Perl which now seem to be called Perl5  (by the Perl6 developers), it’s a complete new language. The name Perl6 introduce some interesting questions. What should a new version of the old Perl be? Perl vs 6, or Perl vs 7, Perl5 vs 6?. And Perl6 itself Perl6 vs 1? To me it seems not very clever creating a software give it a name of an existing software just appending the name with the next version number. This is bound to lead to confusion and annoyance about both languages in future.
The reason for keeping Perl in the name is as I understand ‘positive connotations of the name Perl’. That was a valid argument the previous century, today Perl as a name of a computer language is on par with Cobol. There is nothing wrong (in general terms) with Cobol or Perl, but positive connotations, come on in an age where PHP is associated with old farts, the word Perl does not arouse the masses.
I have seen a suggestion to add a compiler name to the name ‘Rakudo Perl6’, that’s really daft. Perl6 is marketed as a language specification, adding a compiler name to it is really an odd suggestion.
‘Hey what language did you use for your last mobile app?’, ‘Rakudo Perl6 version 5’ that is a conversation you will never hear.
My suggestion is to rebrand the language as ‘PerlyGate’. It is a compromise name, that solves the most irritating problems with the name Perl6, but keeps the connotations whatever they are with Perl, and also links to the Christian mumbo jumbo and connotations the Perl community seems so fond of.

I write this because I care, I want a language like Perl6 to become a success. It is a programmers dream, let be it is too large for my liking, but still it is better by far than any other 3g language I have seen..


Why SAP BAPIs may be bad for you

Yesterday I got a call "the users are displeased with some  reports. The column 'project_definition' is defined as char(9) while it should be char(11), this makes many joins usesless or even invald. How can we fix this?'.
Since the most data coming from SAP into the Data Warehouse is automagically created by the import mechanism is not only redefine a definition from char(9) to char(11), it's correcting the import mechanism, that's why I was called.
I was puzzled, I was pretty sure the algorithm calculating column length in MySQL was right. It had worked untouched for ten years. Recently I done some minor changes in other parts of the Data Warehouse (first in about 5 years), ‘that could not possibly be the reason’ I said to myself, but as any experienced programmer knows when you say something as stupid as that it often is the very reason for the bug, it’s called bit rot, and it can do very awkward things, so I decided to take a look at the code, it was untouched and looked alright to me. Then I looked at the produced definition of ‘project_definition' it showed char(14) not char(11). That’s funny now I got three disparate definitions I decided to have a look at the definitions of 'project_definition' in the Data Warehouse.
Using the information_schema database in MySQL:

Project_definition showed up in 69 tables (including test and obsolete tables), here are a few:

Then I checked the length of project_definition:

Oh golly! now I had 5 lengths (including 11). What was going on here?
Then I remembered, I did this ‘SAP Project’ 9 year ago for a workshop in Nantes. Instead of extracting data directly from SAP tables, I decided to extract data via BAPI’s. I didn’t know the SAP projects subsystem and I had very little time, so I thought BAPIs would be a shortcut since SAP had prepared the data I needed, or so I thought.
I asked my Data Warehouse accomplice at the time, Ulf Davidsson, he told me ‘It’s an exceptionally bad idea, BAPIs never give you what you want, there is always data missing, you have to enhance the BAPI and then you have lost the advantage you are looking for, and it takes longer time than finding the data yourself, grab table data or write your own ABAP code, then you have control’.
In retroperspective Ulf was right, actually in more ways than he knew at the time. But I’m a stubborn son of a bitch, so I created the Projects database entirely of BAPIs. The first thing the users told me ‘we are missing X,Y,Z…’. I stupidly asked ‘is that really necessary?’. ‘Without X,Y,Z… this is useless’ was the reply, so I had to roll up my sleeves and start digging in the SAP database, fortunately it was not that much missing. The real problem for me if I recall this right, I did not have control of the data I just run the Bapis enforced it with some table data. I had to spend much time figuring out how to join the data, eventually I got it right and the users were happy. But due to the atomic nature of  BAPIs it is extremely time consuming to extract data via BAPIs. It took about an hour to extract the requested data, it was bad but the night is long. After a few years, there were many more projects, another workshop started to do projects and then a distribution center started to use projects and the night was not so long anymore. Grabbing purchase requisitions began to take ridicules long time. I did a quick fix by parallelize the extractions and cut the time down to about 3 hours. It was bad, but manageable.After a few years it was not manageable any more.  
I had to rewrite the worst performers into table extractions. This stabilized the performance it’s stable under the hour now, it’s bad but stable.It is a mess, a mix of BAPIs and tables, but apparently a useful mess, when the extraction is late or have failed, users start complaining early morning.
I have asked a number of coworkers to rewrite the projects app, but the reply is always ‘NO, that mess you have to clean up yourself, I will not touch it’. And to be honest neither will I. And now I have this length problem. I suspect the BAPIs do not have as strict and consistent definitions as the SAP tables. And that the BAPI definitions have changed over time. And this has gone unnoticed as long as project names were not longer than 9 chars. I can probably just delete the projects database and it will correctly rebuild itself, but I’m not sure, so I change the char(9) definitions into char(14) in MySql and wait and see what happens.

BAPIs or the BAPI concept is not bad. Mass extractions is clearly not the intended use of BAPIs, they are low volume schnittstellen into SAP, e.g. extract one Sales order and eventually update it is the intended use of BAPIs. Nor should you combine the output of BAPIs to create a reporting structure,.

For mass extraction of SAP data be cautious with BAPIs, use table extraction (RFC_READ_TABLE et al.) or own ABAP code you have control over.


Introduction to Perl6

I find this blog post http://perl6intro.com/ a well written introduction to Perl6.
Ever since I first read about Perl6 around 2001 I have been intrigued by the language and the meticulous construction process of the language. Now some sixteen years later Perl6 appears to be reaching production status! If nothing else the development team should have some recognition for endurance.
The blog post is worth reading even if you have no intention of using Perl6.


A small hack

“Hi can you help us? Everyone has gone home and we need the financial transactions for our new financial app, it is super many transactions. Is there any way we can get them to our Windows share with period number in the filename before tomorrow. We like to test the new app during the Midsummer.  Everyone is gone, you are the only one we could get hold of. Can you help? And yes we need the file to be tab separated.”

In Sweden we take Midsummer seriously, we basically close down the country to party. But this was just a five minute hack, so I promised to help out just for the hell of it. First a little detective work, where the f-k are the transactions after a short while I found them already being in a SQL table in the Data Warehouse, great! It’s just copy a job and adjust a bit. Five minutes later I could call back “You have your transactions in your WinShare.” “Thank you ever so much, you are fantastic!” Some times it is not easy to be humble, this is one of those times. I remember another midsummer when I was not so cocky.

Some years ago I rebuild the Linux system in the ETL server of the Data Warehouse on midsummer eve morning in an attempt to connect ODBC to Iseries DB2 systems. In the middle of this my siblings called me and told me they were waiting on me going out to the countryside. I stopped my rebuilding sure my tinkering could not possibly intervene with the normal operations of the ETL server. Of course it did, it killed all ETL jobs for the entire holiday. The guys responsible for the Data Warehouse had to work two days repair the damages, and they made me promise never to do ANYTHING  next midsummer eve or ever any midsummer eve after.

And now I just did it again! I hope noone ever finds out:) The job I just assembled and run:

A mini app!

Yesterday a consultant called me “Hey Lars I’m building a new app feeding a new financial app with master data from SAP. They need the the data in tab separated files exported to a windows share. Do you have standard functions for that in the Data Warehouse or do I have to code that myself?”
“Funny you mention this, I created a similar app  the day before yesterday.”
“First the tab separation.    
You do this by adding a delimiter to the sqlconverter_CSV.php”:
“Next export to a Windows share. The Data warehouse supports the CIFS file system, just do a CIFS mount and copy the data to the windows share.”
“Okay” the consultant replied.
Later at the the end of the day on my way home I passed the consultant. I asked the consultant if he had any more problems. “No I’m done. Six feeds from SAP exported to this new application, tested and put into a daily production schedule ”:
“And a button on an Excel sheet, so the finance manager can fire off the export at will..”
“Why in Excel” I asked
“Why not” the consultant replied.
“It looks you made a nice little mini app today.”
The consultant looked at me and said “Miniapp?!? Do you realise how long time this would have taken any other place?”
“Yes I know” I replied, “but here it’s a nice miniapp”.

Actually it was a hell of a job done by the consultant, no matter where.


ITL - awful syntax awesome functionality

Last week I was asked If I could help design the integration between ERP systems and a Jira application, the idea was to deploy a new SQL server instance and an application server to create a “funnel” application of some sort. The ERP data should be massaged into an access friendly  format for the Jira app.
I like agile development so I created a crude prototype for testing and then  iteratively refine the prototype together with users, the first thing I did was to create a process map:
For the prototype I suggested the Data Warehouse since it is up and running and is designed for this type of applications. For this first prototype we decided to use a few handmade MS Excels as data, these Excels were FTPed over to the DW FTP landing zone, and then I created an ITL script:
If you look carefully  you can see I added support for an XML and a cvs format as well.
The I run the script:
And the result:

Now we have to wait wait for the Jira guys to tell if this table is OK for them or if we have to modify our prototype.
As you can see there are some functionality cramped into the script. Look at the <forevery>  line, intersect=FTP, means this list is sifted by the actual FTP directory, removing lines which have no corresponding file in the FTP directory, which makes the script simpler since we do not have to think about ‘file does not exists’ conditions.

FTP is not something used for anything else than truly public data these days, but it is easily to setup and for the prototype with test data it works well.


PHP at Bloomberg's - 4

Part four, requesting data (this post)

In the last post (which I hoped to be the last) in the series PHP at Bloomberg’s I described how you fetch a result with a responseId after you have requested information from Bloomberg’s.
Having shown the ‘retrieve app’ for the business owner I was asked “Can’t you request an information set in one shot mode, and then retrieve the result”. “Why do you want to do that? We schedule a request periodically at Bloomberg and then we just retrieve the result when time is due and have ever green data. Schedule once fetch fresh data forever” I responded. “Schedule periodically at Bloomberg has contractual implications. We like to be able to schedule ourselves. We like the abillity to request "one shot" or “ad hoc” reports then fetch the result, and schedule this daily. We know this is more cumbersome, but can you have try?”  
Easy I thought, first I create a job to send the request to Bloomberg and then wait for the report to be produced:
Then I had to modify the PHP code from the previous post a bit. In the original code I create the parameter list directly in the PHP code as it is just a one liner:

But here the parameter list is hundreds of lines. I decided to specify the list as plain XML text following Bloomberg SOAP standard, (you see it above in the <soaprequest> tag). And add code to convert it to an array:

I added a <top> node making the XML well formed and via JSON encode/decode created a perfect array for the soap request.
Then I just run the job and after a few tries it worked. This was easy, unfortunately it turned out to not be as easy with the scheduling. Right now I’m thinking about how to solve the scheduling, but there are some twists to it that I don’t get my head around. When the scheduling is done I might write yet another post about PHP at Bloomberg’s.


Den Bock zum gärtner machen

Some while ago the company decided to make the goat the gardener, so they put me in charge of group codes, not only the application managing the codes (which I agreed to), but also the codes themselves. I told all and everyone I’m not qualified to do that and all and everyone agreed. The codes are serious business e.g. we have a number of codes to classify our products to keep track of what we sell and analysing marketing trends etc. We have number ranges for parts. If these codes are messed up the consequences may be dire. I take the codes dead serious, that’s why I said “I’m not qualified” in the first place. Some may think it is easy to hand out and keep track of codes you only have to be careful, accurate and meticulous. It’s easy to say, but if you are the antithesis of those traits it is very very hard to keep accurate records of things. If you add to that inability to correctly repeat manual tasks and periods of indolence, it is difficult. (That’s why I became a programmer not a keeper of records.)

I was assured “You do not have to keep track of the codes, the responsibility sits in the business. This is a self service application.” And sure as hell the first thing happend “Hi Lars, I’m Riccardo responsible for new spareparts at the Milano Factory, I need new spare part numbers, can you help?”
“Well you know, you are supposed to do that yourself, frankly I do not know how to do it” I responded.
“I’m told you are the expert and this is a matter of urgency we need those numbers now, please”.
After an hour I had figured out how to assign spare part numbers to Riccardo.
Riccardo was just the first, almost every day I get new requests which I forget about or put at the bottom of my pile of tasks to do. It takes me hours to do these tasks, which in the hands of a capable keeper of records would have been expedited in minutes, what they do swiftly with confidence, I have to check, cross check and check again, as I said I take this seriously this must be correct the first time.     
The other day I was cced a mail conversation about MAC addresses. I did not look at it, but these mails just kept coming, I opened the fifth MAC address  mail, to my astonishment I realised I was responsible for handing out MAC addresses, not only within the company but to sub suppliers too.
In this last mail a purchaser begged for more MAC addresses, a supplier had just stopped production of a component the Tierp Factory was in short supply of. I take codes serious, but that’s nothing compared with production stop in a factory. I take great pride in helping the factories improving their processes by better IT systems, Reading about halted production really got me going, in no time minutes that is I produced the required MAC addresses, later it took almost half an hour for me to check I done it right.

Riccardo does not exists, but I get similar urgent requests almost daily.


Find an item in SharePoint

I got a request from user “Can you help me find number series owned by ‘AFS’, it seems I cannot search myself”. Sure this easy - SharePoint to the rescue:

Easy peasy I thought, but Oh no the dreaded 5000 limit again:

I tried the search window, but no SharePoint is relentless:

No! Search cannot be done in SharePoint. Why am I not surprised?
Ok, Excel to the rescue:
Export the SharePoint list to Excel. First I get a friendly reminder:
Yes MS Excel is compatible.
Then I get another friendly security notification:
This I’m not sure what it is about but let’s go crazy, Rock’n’Roll I press ‘Enable’.

And voila here is Excel with its working search function, working in no time on super large datasets (5000 items and even larger than that):

And the result:  

Can it be simpler? Thank you SharePoint for superior search functionality😀