Monday, April 15, 2013

Ubuntu: Reinstall or Recover Ubuntu GRUB

This is post will explain how to reinstall the Ubuntu GRUB.

Initially I had Windows 7 and Ubuntu as dual boot. Later I installed CentOS and it changed the GRUB. On boot, Ubuntu was not showing in the boot selection list. Then I tried several ways for updating GRUB with Ubuntu and I didn't get. After many searches in Google I found a tool which solves the GRUB problem.

First boot with Ubuntu Live CD, open terminal (shortcut: Ctrl+Alt+t). Execute below command.


First add the boot-repair repository:

sudo add-apt-repository ppa:yannubuntu/boot-repair

Update your repository:

sudo apt-get update

Now install boot repair:

sudo apt-get install -y boot-repair

Open the boot-repair tool from terminal:

boot-repair

 Wait for few minutes it will scan your machine. Then click Recommended repair button





Then restart the machine on successful repair.

Now you dual or triple OS list in boot list.


For more option on repairing, click Advanced options, this will several customization options.



Monday, February 13, 2012

Hive: Custom User Defined Function (UDF)

Apache Hive has many functions to manipulate the data. Here below given the custom hive function for converting the Unix timestamp value to actual readable date value. This custom method is like adding a functionality to a job processing a query in Hadoop MapReduce.
Here it is enough to extend UDF class.

package com.hive.example.util;

import java.util.Date;
import java.text.DateFormat;

import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;

public class UnixtimeToDate extends UDF{
    public Text evaluate(Text text) {
        if(text == null) return null;
        long timestamp = Long.parseLong(text.toString());
        return new Text(toDate(timestamp));
    }
    
    private String toDate(long timestamp) {
        Date date = new Date (timestamp * 1000);
        return DateFormat.getInstance().format(date).toString();
    }
}

Pack this class file into a jar: 
$jar -cvf convert.jar com.hive.example.util.UnixtimeToDate

Verify jar using command : $jar -tvf convert.jar

add this jar in hive prompt
hive>create temporary function userdate as 'com.hive.example.util.UnixtimeToDate';

Example:
Normally without the function query:
hive>select id, unixtime from table;
12     879959583

 Then use function 'userdate' in sql command
hive>select id, userdate(unixtime) from table;
12     19/11/97 10:43 PM