Tuesday, January 30, 2018

React for hard core Java Developers

React for hard core Java Developers

The world has changed. New equilibrium has formed. If you apply for a job called "Java Developer" you are expected to have some knowledge of JavaScript. Everybody talks about cross functional teams, everybody is full stack developer, so Java Developers write JavaScript apps and you should too.. to be precise you should write apps in ECMAScript version ES6 or version ES2015 which are essentially the very same version. Once again: ECMAScript is standard for JavaScript, ES6 is a former name of its version, ES2015 is the current name for ES6 version.

ECMAScript is actually pretty cool language... but but but.. browsers do not support it, they support only few of the new features. So you have to pass your code into source-to-source transpiler like Babel https://babeljs.io . The result of the process is pure old JavaScript. It does not matter if you do not like code-generation tools, because a transpiler basically is a code-generation tool, you are forced to use it because you want to use all the new features of the language and you need them to write better code.

Now you need to learn few words:
  • node - JavaScript runtime, lets say a JVM for JavaScript
  • npm - node package manager - it downloads dependencies (like ivy, maven, gradle)
  • react - library with the components
  • redux - you store state of the app in it
  • webpack - it takes your dependencies and turns them into common js for your browser
  • jsx - a syntax extension for JavaScript. It looks like html and it is used in that way
At the beginning you need some hello world fully functional mind blowing example otherwise you will feel that you got stuck. Because the whole react ecosystem is like a puzzle it is hard without a hand..

Before that you have to install git, node and npm. Please use Google, I am not going to describe this. Only small hint for Mac users, use brew, it is useful.

Redux-Minimal

There is a good option to start with react. It is Redux Minimal. It is a github repo, it is a template for you to start - https://redux-minimal.js.org/ . Take a look at the amount of packages lister in the readme file there, it does not seem to be minimal but it is actually perfect because you do not have to add the packages manually and now you have it out of the box.

If you use iTerm please turn on "Unlimited scrollback".

The readme page has a "Getting Started" section so read it and do it It is only few commands. It is very easy. Clone, install and start... Then read the output of the start command. There is an information where does the app runs locally (it is on localhost of course), so open the app. The app is a simple "User Manager".

Now take a look into the folder where you run the commands. What is there?
  • node_modules - all the modules are downloaded into this folder
  • package.json - the dependencies are described here in section dependencies and devDependencies. There are also presets for babel (a version of ECMA is specified; react preset for JSX extension; stage-3 actually adds few other features into the language also). The important is also the "scripts" section, here you can see what does npm do when you write "npm start" or "npm test" etc.
  • webpack configs - these files are loaded by webpack so it knows what to do with the packages....
  • test - contains all your tests for components, reducers, sagas
  • scr_users - source code for the demo application ("User Manager")
  • src - a folder that has been prepared for your application, if you want to start with one
  • public - a folder where you put images and static code
So take a look at public/index.html - you will see that it loads bootstrap library (html, css, js things) and there is a html div with id app. Now open src_users/index.js and now you should understand what is the entrypoint of the application. Now you have a very simple app running and you can start to play with it. Use reverse engineering and Google and youtube to find tutorials from now on and you will be able to create your own app.

Maybe I will post another post about React itself, redux and its reducers, middleware and other stuff.

Friday, August 28, 2015

Importing/Loading data from CSV files into SAP Hana

SAP Hana and loading of data from CSV files

Use case: There is one machine with CSV file and another machine with SAP Hana database. You want to import data from the CSV file into the SAP Hana table. That's it.

There are at least 4 options how to import CSV files into SAP Hana.

  1. Import using SAP Hana Studio
  2. Import using control file and import statement
  3. Parse the file on your own and insert values using JDBC driver
  4. Import using Smart Data Integration
Lets compare all listed methods.

SAP Hana Studio

Import using SAP Hana Studio is manual approach of loading CSV file into SAP Hana. It is very easy and straight forward. The file is on your local machine, the studio will transfer the data into Hana table. The biggest disadvantages are the speed of the process and the disability of triggering the load automatically.

Import statement and control files

This method seems to be the fastest and can be automatized but... your file has to reside on Hana server. That means that you have to transfer your data first. If you deal with big amount of data then your data file might have 20 GB or even 100+ times more. You can use FTP to transfer the data but you will waste disk resources on Hana server. Other option is to share file system and this option might not be the ideal for you.

JDBC Import

So you think that all previous options are bad and you want to import your data using JDBC which is standard and easy to use. You can read your CSV file and push/insert the data using multiple threads. You will use batches, that means you will commit after few thousands of inserts. You can disable persistent merge on the target table and the import will be much faster. There is always one problem with this approach and it is wasting of database resources - connections, transactions. Wasting of such resources might cause some problems for your enterprise application.

Smart Data Integration

Smart Data Integration is probably very good solution for loading any data into SAP Hana. Your source data can be stored in different types of databases or even in CSV file but.. You will have to run SDI Agent on the machine which will read your source CSV data. Your account has to be connected with license that is eligible to download the client:) as it is mentioned here in this post https://scn.sap.com/thread/3707101


Thursday, August 13, 2015

SAP Hana is missing MERGE INTO so let's use UPSERT

MERGE INTO is great. SAP HANA SPS 10 has no MERGE INTO... So, let's use UPSERT - it might be fine for certain use cases, especially when your target table has no PRIMARY KEY. You can create PRIMARY KEY and UPSERT will use it to determine if the row should be inserted or updated. This example will show you how to do it:
create table a (x int, y int, primary key (x));

create table b (x int, y int);

insert into a (x, y) values (1,1);
insert into a (x, y) values (2,2);
insert into a (x, y) values (3,3);
insert into a (x, y) values (4,4);
insert into a (x, y) values (5,5);

insert into b (x, y) values (1, 10);
insert into b (x, y) values (2, 20);
insert into b (x, y) values (3, 30);
insert into b (x, y) values (40, 40);
insert into b (x, y) values (50, 50);

upsert a select * from b;

select * from a;
The last select will result in:
X;Y
1;10
2;20
3;30
4;4
5;5
40;40
50;50
So records were updated if the key has been already there and new records were inserted.