Monday, December 14, 2015

Getting started with Oracle Stored Procedure and parse clob xml data and cursor



This Post will having the details to create stored procedure in oracle and parsing the clob data through stored procedure.
employee.xml
-------------


  siva
  32
  M

Above xml will be stored as clob data in Person table

Person table Schema -

Id NUMBER,
Name Varchar2(50),
employee_details clob

Above xml will be stored as clob data in Person table
create table PERSON (Id NUMBER, Name varchar2(50), employee_details clob);
  create table EMPLOYEE (Name varchar2(50), age NUMBER ,sex varchar2(10));
We need to parse the clob data using oracle procedure

create or replace PROCEDURE SP_PARSE_CLOB (person_id NUMBER) AS
  PERSION_ID Person.id%type;
  PERSON_NAME Person.name%type;
  EMPLOYEE_DETAILS Person.employee_details%type;
  name varchar2(50);
  age varchar2(50);
  sex varchar2(50);
  EMPLOYEE_exc EXCEPTION;
  -- Create a cursor
 cursor personDataCursor IS SELECT id, Name,employee_details from PERSON;
 BEGIN
   OPEN personDataCursor;
 LOOP
 FETCH personDataCursor into PERSION_ID,PERSON_NAME,EMPLOYEE_DETAILS;
 EXIT WHEN personDataCursor%notfound;
 IF XMLTYPE(EMPLOYEE_DETAILS).existSNode('/Employee/name/text()') > 0 THEN
   name := XMLTYPE(EMPLOYEE_DETAILS).extract('/Employee/name/text()').getStringVal();
 END IF;
 IF XMLTYPE(EMPLOYEE_DETAILS).existSNode('/Employee/age/text()') > 0 THEN
  age := XMLTYPE(EMPLOYEE_DETAILS).extract('/Employee/age/text()').getStringVal();
 END IF;
 IF XMLTYPE(EMPLOYEE_DETAILS).existSNode('/Employee/sex/text()') > 0 THEN
  sex := XMLTYPE(EMPLOYEE_DETAILS).extract('/Employee/sex/text()').getStringVal();
 END IF;
 dbms_output.put_line('Name:'|| name|| ' ' || 'Age:' || ' ' ||age || ' ' || 'Sex:' || ' ' || sex);
 -- Inset into another table
BEGIN
  insert into EMPLOYEE(name,age,sex) values(name,age,sex);
 EXCEPTION
    WHEN OTHERS
   THEN
    RAISE EMPLOYEE_exc;
  END;
  commit;
  END LOOP;

EXCEPTION
    WHEN EMPLOYEE_exc
      THEN
        rollback;
     -- Do what ever you want like insert log details in any another table
    commit;
    DBMS_OUTPUT.PUT_LINE ('Insertion failed in EMPLOYEE : '|| '' || name);
    END;

Monday, December 7, 2015

ArithmeticOperations Example using Python

Arithmetic operation using python in windows.
In my previous post , I have written how to install python in windows and add plugin into eclipse.


In this post I am going to explain simple arithmetic operations.

Step 1: Open eclipse - File - New - PyDev Project - arithmeticoperation_test
Step 2: Right click on the - src - New- PyDevModule- ArithmeticOperation
Step 3:Paste below code into ArithmeticOperation.py file.


'''
Created on 07-Dec-2015


@author: rajusiva

'''
a = input("Enter a value:")
b = input("Enter b value:")
print("Addition of 2 values is[",int(a)+int(b),"]")
print("subtract of 2 values is[",int(a)-int(b),"]")
print("Multiply of 2 values is[",int(a)*int(b),"]")
print("Division of 2 values is[",int(a)/int(b),"]")
print("Exponent of 2 values is[",int(a)**int(b),"]")
print("Modules of 2 values is[",int(a)%int(b),"]")
print("Floor Division of 2 values is[",int(a)//int(b),"]")

Step 4: Right click on the program-Run As- Python Run
Step 5: output as follows


Enter a value:25
Enter b value:10
Addition of 2 values is[ 35 ]
subtract of 2 values is[ 15 ]
Multiply of 2 values is[ 250 ]
Division of 2 values is[ 2.5 ]
Exponent of 2 values is[ 95367431640625 ]
Modules of 2 values is[ 5 ]
Floor Division of 2 values is[ 2 ]

Sunday, December 6, 2015

Getting started with python using eclipse

Getting started with Python using eclipse

Step1: Download latest Python from the python site.
                 https://www.python.org/downloads/


Step2:  Click on the downloaded exe file. Then it will open like below screen

           

Step 3: While installing , you need to  check the both check box.

Step 4: Click the Customize installation, .



Step 5: Click on the Next button,

Step 6: Change the Customize install location(C:\Python32), you can give any location where ever
                  you need python to be install. Then click finish

Step 7:  Python installed successfully on your machine.

Step 8: Now we need to download eclipse latest version for windows from this link.
                    http://www.eclipse.org/downloads/
Step 9 : unzip the downloaded eclipse.
Step 10:  open eclipse and select workspace
Step 11:   Click on help – Install New Software

Step 12: Provide   http://pydev.org/updates as mentioned below screenshot select all checkboxes, then click finish.
Step 13 :Select the checkboxes to install the python plugin in eclipse


Step 14: Need to configure python in eclipse.
  Go to eclipse – Windows- preferences-


Step 15: Check for PyDev or python – Python Interpreter – Click on the new button
Add the Interpreter Name and Interpreter Executable – where ever your python installed location
Python plugin has been configured in your eclipse successfully.
Step 16 : create PyDev project- Give any project name (helloworld_python)
    In eclipse- File- New - PyDev project


Provide name as  - helloworld_python then click finish, But make sure – Create src folder and add it to the PYTHONPATH- radio button selected


Step 17: Now python project created. Need to create Python Module in order to start the coding.
              Right click on the src folder of the python project- >new -> pyDevModule


Step 18: Click finish

Copy below code into your program

def hello(userInput):
    return "Hello World:"+userInput
userInput= input("Please type your name:")
print(hello(userInput))



Step 19: How to run the python program – Right click on the program
  Run As – Python Run

Input - Please type your name: siva
Output- Hello World: siva

Saturday, November 21, 2015

Hadoop Oozie Framework


Oozie  -  Framework

Oozie is a workflow/coordination system that you can use to manage Apache Hadoop jobs.

Oozie server a web application that runs in java servlet container(the standard Oozie distribution is using Tomcat).

This server supports reading and executing Workflows. Coordinators and Bundles definitions.

Oozie is a framework which is used to handle to run the Hadoop jobs.
It is same like Autosys,Cron jobs, ContolM  Scheduling tools

HPDF – Hadoop process definition language – defining the job details, start node , stop node ,input directory ,output directory etc.. details.
Main features:
Execute and Monitor workflows in Hadoop
Periodic scheduling of workflows
Trigger execution of data availability
HTTP and command line interface and webconsole
Oozie work flow start
Go to installation directory of oozie
Ex: cd /usr/lib/oozie-4.0.0/
:  ./bin/oozie-start.sh
Once it’s started then click the below URL to check whether Oozie started or not.
localhost:11000/oozie

In Oozie webconsole, you can see the job information (logs,configuration,etc..)

Oozie Workflow:

PREP: when a workflow job is first created it will be PREP state. Job is defined but not running.

RUNNING: When a CREATED workflow job is started.it goes into RUNNING state, it will remain in RUNNING state while it does not reach it’s end state, ends in error or it is suspended.

SUSPENDED: A RUNNING workflow job can be suspended, it will remain in SUSPENDED state until the workflow job is resumed or it’s killed.

                   
                                   




Scheduling with Oozie


Coordinator to Map Reduce  ->   Launch MR jobs at Regular intervals

Map Reduce to HDFS -> Write Files
         


Oozie – workflow.xml

The workflow definition language is  XML based and it is called HPDL- Hadoop Process Definiton language).

Workflow.xml minimum details we need to mention like name, starting point and ending point.

Ex:
                                   Name=”WorkFlowRunnerTest”>
        
        

Flow control nodes: Provides a way to control the workflow execution path
Start node start : This specifies a starting point of an Oozie Workflow
End node end: This specifies an end point for an Oozie Workflow.
To this we need to add action , and within that we will specify the map-reduce parameters.

   
      localhost:8032
      hdfs://localhost:9000 
    
   
       
           mapred.input.dir
           {inputDir}
      
       
           mapred.output.dir
           (outputDir)
        
action requires and tags to direct the next action on success or failure.

Job.properties file needs to mention details like input dir, output dir.
Job.properties file no need to move to HDFS.


Running a Oozie Application

1. Create a directory for Oozie Job(WordCountTest)
2. Write a application and create a jar (ex:Mapreduce jar). Move this jar to lib folder in WordCountTest directory.
3. Job.properties and workflow.xml inside WordCountTest directory
4. Move this directory to HDFS
5. Running the application
oozie job  -oozie http://localhost:11000/oozie  - config  job.properties –run
    (job.properties should be from local path)

Workflow Job Status command
oozie job –info job_123
Workflow Job Log
oozie job  –log  job_123
 Workflow Job definition
  oozie job  –definition job_123
   Oozie version
   oozie admin –oozie http://localhost:11000/oozie -version

Oozie Coordinator

The Oozie Coordinator supports the automated starting of Oozie workflow process.

It is typically used for the design and execution of recurring invocations of Workflow processed triggered by time and/or data availability.




  
      
         hdfs://bar:9000/app/logs/${YEAR}/${MONTH}/${DAY}/${HOUR}
        
      
       
            
                       ${current(0)}
            
            
            
              
                      
                              hdfs://localhost:9000/WordCountTest_TimeBased
                              
              inputData
              ${data(‘inputLogs’)}
                    
                  
              
          


Oozie commands

Checking the multiple workflow jobs

oozie jobs –oozie http://localhost:11000/oozie -localtime -len -filter status=RUNNING

Checking the status of the multiple coordinator jobs

oozie  jobs –oozie  http://localhost:11000/oozie -jobtype coordinator

Killing a workflow , Coordinator or Bundle Job

oozie  job –oozie  http://localhost:11000/oozie -kill

Checking the Status of a workflow , Coordinator or Bundle Job or a Coordinator Action

oozie job –oozie  http://localhost:11000/oozie –info


Hope this will guide you how to work with Oozie framework.


AddToAny

Contact Form

Name

Email *

Message *