Showing posts with label first. Show all posts
Showing posts with label first. Show all posts

Wednesday, February 18, 2015

First C Program Hello World

We have gained lots of theoretical knowledge. Now its time to move on and write our first C program and understand it.


Hello World C Program

This is a program to print “Hello World”

#include<stdio.h>

void main()
{
printf("Hello World");
}


Output
Hello World

Now try to understand this program step by step.

1. #include<stdio.h>: First statement started with #, it is called pre-processor directive. We will learn about them thoroughly in later tutorials. #include<stdio.h> is used to include the stdio.h header file in our program. Header files contains the functions that we use in our program. Here we have used printf() function which is present in stdio.h header file.

2. void main(): Here main() is the function. A program always starts with the main() function and every program must have main(). Here void is the return type of this function. It means main() function will not return anything. The opening curly braces ({) and closing curly braces (}) shows the body of the function.

main() can also be called as a collection of statements.

3. printf(): Here printf() is another function. This is used to print the values on the screen. Its general form is

printf(“Statement you want to print on screen”);

4. Semicolon (;) is used for denoting the termination of statement. It is also called statement terminator in C Language.


How to compile and execute?

Here we are using TURBO C compiler. If you have not downloaded it yet than download it from here.

1. Open Turbo C and type the program.
2. After that press F2 to save the program with .c extension. Eg: program.c
3. Now Press ALT + F9 to compile and CTRL + F9 to run the program.
4. Press ALT + F5 to view the output.

Well this is the easiest C program. Now lets move on and try slightly complicated program of multiplication of two numbers.


C Program to multiply two numbers


#include<stdio.h>

void main()
{
int a, b, c;
a=3;
b=4;
c=a*b;
printf("Answer is %d",c);
}

Output
Answer is 12

Now lets try to understand this program.

1. First two statements are same as above program. In the third statement I have written

int a, b, c;

Here int is the keyword for integer and a, b and c are the integer variables. So they can only store integer values.

2. In the next two statements I have written

a=3;
b=4;

In these statements we are storing the values 3 and 4 in a and b variables respectively.

3. In the next statement 

c=a*b;

We are multiplying the values in a and b, and storing them in the variable c.

4. Now in the last statement we are printing the value which is in c. A new thing %d which we have used in this program. It is called format specifier. It usually tell the compiler that it has to print the integer value on screen which is present in a variable.

Some common format specifiers are given below

a. %d for integers
b. %c for characters
c. %f for floating point numbers or real numbers

A bit elaborated form of printf() is given below

printf(“string you want to print ”, variable);

Suppose we have to print the value in b so we will use the function.

printf(“%d”,b);


Things to keep in mind

1. Use semicolon at the end of each statement.
2. Type the statements in main program as the way you want them to be executed.
3. Never try to memorise any program. Just try to understand it.
4. Learning programming is all about practical. So start doing practical from now.
Read more »

Sunday, February 15, 2015

My first learning example in Kettle An example is reproduced from Pentaho Tutorials Topic Filtering Rows

Hi Guys,

Here is my first learning experience with Kettle Community ETL.

Download Kettle from :  Click Me

Sources to get start with Kettle :

1) http://wiki.pentaho.com/display/EAI/Getting+Started
2) http://localhost:8080/pentaho/docs/InformationMap.html
3) http://wiki.pentaho.com/display/EAI/Pentaho+Data+Integration+%28Kettle%29+Tutorial

You should have installed java in your local machine and path, java_home, jre_home set for it.

Below topic is a re-production of Kettle Transformation & Job example from Pentaho Tutorials and the description is slightly differ from the actual description.

Lets look at simple basics and then well jump into 1st example.


#  What is Transformation in Kettle ?
# What are jobs in Kettle ?
# Core difference b/w Transformation & Jobs in Kettle ? 
# Extensions for transformations & jobs in Kettle ?
# What are steps & hops ? 

1) What is the usage of Transformation ?

    Transformations are used to describe the data flows for ETL such as reading from a source, transforming data and
    loading it into a target location.

2) Jobs

Jobs are used to coordinate ETL activities such as

Defining the flow and dependencies for what order transformations should be run
Preparing for execution by checking conditions such as, "Is my source file available?," or "Does a table exist?"
Performing bulk load database operations
File Management such as posting or retrieving files using FTP, copying files and deleting files
Sending success or failure notifications through email


3)Whats the difference between transformations and jobs?

Transformations are about moving and transforming rows from source to target. Jobs are more about high level flow control: executing transformations, sending mails on failure, ftping files

4) Extensions for transformations & jobs in Kettle ?
Transformation : .ktr
Jobs : .kjb

5) What are steps & hops ?

  • A transformation is a network of logical tasks called steps.
  • Transformations are essentially data flows.
  • The transformation is, in essence, a directed graph of a logical set of data transformation configurations.
  • Steps are the building blocks of a transformation, 
  • for example a text file input or a table output. 
  • There are over 140 steps available in Pentaho Data Integration and they are grouped according to function; for example, input, output, scripting, and so on. 
  • Each step in a transformation is designed to perform a specific task, such as reading data from a flat file, filtering rows, and logging to a database 
  •  Steps can be configured to perform the tasks you require. 
  •  
  • Hops are data pathways that connect steps together and allow schema metadata to pass from one step to another. 
  •  Hops determine the flow of data through the steps not necessarily the sequence in which they run.
  •  When you run a transformation, each step starts up in its own thread and pushes and passes data. 
More info  at :  Click Me


TOPIC :
Load sales data into a database. Several of the customer records are missing postal codes(zip codes) that must be resolved before loading into the database.

You will be given two .csv files to load the data into database. 
The first file is : sales_data.csv and later one is Zipssortedbycitystate.csv

( Location of the files : /home/sada/softwares installed/Pentaho/data-integration/samples/transformations/files
)


In short , there is a column called "postalcode"  in sales_data.csv with missing postal codes(i.e., the values are null) and need to fill the missed the missed postal codes using "postalcode"  column of Zipsortedbycitystate.csv file. 


Explanation : 
The Final Transformation looks as shown in below :

The final job looks as shown in below(doing job is optional for this topic)


Transformation is divided into below sub tasks.
1) Retrieve Data From Flat File ( i.e., Retrieve Data From "sales_data.csv")
2) Filtering the records ( from the source file get only not null valued rows for "postal code").
3) Load to into Relational database ( Total Number of rows in this 2747)
4) Retrieve Data From your look-up file.
5) Resolve Missing zip information.


Download the example : Click Me

NOTE : While running the .ktr file (or .kjb file) in your environment you should specify the flat files(.csv files) location as per your folder structure.

#:  Ive taken postgresql as output table.

Thank you.

Sadakar
BI developer.
(Pentaho/Jasper/Talend/Kettle).

:-)







Read more »