Hitachi Vantara Pentaho Community Forums
Results 1 to 1 of 1

Thread: Pentaho delete records with HBase

  1. #1
    Join Date
    Oct 2013
    Posts
    216

    Post Pentaho delete records with HBase

    Hi ,

    I have created one transformation in which I want to delete records from HBase table.

    I have used User Defined Java Step.

    When I run ETL , this java step is not finishing.

    I have attached my java code written for this step, in which at line "HTable table = new HTable(HBconf, "my_table");" process not going forward.

    Does anyone know , how I can delete records in Hbase ? Any other way to achieve this ?

    Thanks in Advance.

    Code :-

    import java.io.IOException;
    import java.util.*;
    import org.pentaho.di.core.database.*;

    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.hbase.HBaseConfiguration;
    import org.apache.hadoop.hbase.client.*;
    import org.apache.hadoop.hbase.util.Bytes;
    import org.apache.hadoop.hbase.HTableDescriptor;
    import org.apache.hadoop.hbase.client.Delete;
    import org.apache.hadoop.hbase.client.HTable;

    public String LinkField;

    public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
    {

    Object[] r = getRow();

    if (r == null) {
    setOutputDone();
    return false;
    }
    if (first) {
    first=false;
    }

    LinkField = get(Fields.In, "DOC_VPK_DOCUMENT_NBR").getString(r);

    logBasic("Logging input field "+LinkField);
    Configuration HBconf = HBaseConfiguration.create();
    System.out.println("Stage0");
    logBasic("Stage1");

    String tableName = getInputRowMeta().getString(r, getParameter("TABLEFIELD"), null );
    logBasic("Stage table"+tableName);


    try{
    HTable table = new HTable(HBconf, "my_table");
    Scan s =new Scan();
    logBasic("Stage2");


    logBasic("Logging input field2"+LinkField);
    Instantiating HBaseAdmin class
    HBaseAdmin admin = new HBaseAdmin(HBconf);
    logBasic("Stage3");

    Getting all the list of tables using HBaseAdmin object
    HTableDescriptor[] tableDescriptor = admin.listTables();
    logBasic("Stage4");

    printing all the table names.
    for(int i=0; i<tableDescriptor.length;i++ ){
    System.out.println(tableDescriptor[i].getNameAsString());
    }

    ResultScanner rs = table.getScanner(s);


    for (org.apache.hadoop.hbase.client.Result r1 = rs.next(); r1 != null; r1 = rs.next())
    {
    String key = Bytes.toString(r1.getRow());
    // logBasic("Scan: "+r1);
    // logBasic("Scan: "+key);
    // logBasic("==========" + key.equals(LinkField));

    if(key.equals(LinkField)){
    Delete delete = new Delete(Bytes.toBytes(key));
    table.delete(delete);
    logBasic("Deleted.......................");
    }
    else{
    logBasic("Why are you in else............?");
    }
    }
    logBasic("Logging input field3"+LinkField);
    table.close();
    }

    catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    //throw new KettleException(e);
    }

    return true;
    }
    Last edited by nitin_pipalia; 12-30-2016 at 06:37 AM.
    -- NITIN --

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.