Category Archives: Uncategorized

Building Hadoop – download and build

    Before you build Hadoop, you need to download the version that you require.
    You can explore the SVN tree here:
    http://svn.apache.org/repos/asf/hadoop/common/

    Since I was interested in the branch: “branch-20-append”, that is what I used in the following command:
    svn co http://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20-append/ hadoop-0.20-append

    Once it is downloaded, you need to create a build.properties file (if you want control over the naming of the archives that would be generated as a consequence of this exercise):
    cd hadoop-0.20-append/
    vi build.properties

    Insert the following:

    version=0.20-append

    Save the file and then run:
    ant mvn-install

    This will generate the required file. You can search for these files with:
    find ~/.m2 -name "hadoop-*.jar"

    References:

    http://wiki.apache.org/hadoop/HowToContribute

    http://wiki.apache.org/hadoop/HowToSetupYourDevelopmentEnvironment

    http://www.michael-noll.com/blog/2011/04/14/building-an-hadoop-0-20-x-version-for-hbase-0-90-2/

Oracle Case versus Decode function

There is an equivalent Oracle function for the ANSI CASE function – it is called DECODE in Oracle. Both of them operate on data that has been retrieved from the database and consequently there is a need to reduce the number of rows that are to be retrieved with the help of the WHERE clause. As for any post-processing action, this would add cycles to any SQL query where either one of these statements are used in.

The other difference between the two is that CASE is an ANSI SQL standard and is portable across the different database vendors.

The following are equivalent examples of the CASE and DECODE functions based on the Oracle sample HR schema.

CASE:

SELECT country_name, CASE region_id WHEN 1 THEN ‘EUROPE’ WHEN 2 THEN ‘SOUTH AMERICA’ WHEN 3 THEN ‘AUSTRALIA’ ELSE ‘UNKNOWN’ END CONTINENT
FROM   countries; 

DECODE:

SELECT country_name, Decode(region_id, 1,’EUROPE’, 2,’SOUTH AMERICA’, 3,’AUSTRALIA’, ‘OTHER’) CONTINENT
FROM   countries;

Credit Cards and Luhn’s algorithm

Credit Card numbers – for most of the major players in the field – can be validated by the Luhn  algorithm. So when you enter a dummy credit card number for testing such as 4111111111111111 for VISA, suffice to say it can be validated by an implementation of Luhn Algorithm. Consequently before the credit card number is sent across the network for validation, it can be validated locally as well reducing expenses and latency.

For more information and sample implementations of Luhn Algorithm in various languages, please refer to the wiki page on Credit Card numbers.

netstat on linux

Coming from BSD, it so seemed that netstat -a would do the trick. However when I was running Active MQ, the console told me that port 8161 was being used but somehow netstat was not confirming that.

 Scratched my head, did a "man netstat" and it so figures that if the address cannot be resolved then that entry was not displayed. The answer is to perform;

netstat -anp =>that will take care of displaying 8161.

Write a program to do merge sort recursively

Write a program to do merge sort recursively

The following program does the trick. Please evaluate the order of complexity (Big O) and space requirements as well.

package mergesort;

public class MergeSortRecursive {

    public static void main(String[] args)
    {
        int[] array =
            { 1, 2, 333, 44, 24, 5, 66, 73, 75, 664, 64, 4, 122 };

        (new MergeSortRecursive()).mergeSort(array);
        printArray(array);

    }

    void mergeSort(int[] array)
    {

        if (array.length > 1)
        {
            int mid = array.length / 2;
           
            int[] left = getSubArray(array, 0, mid – 1);
            int[] right = getSubArray(array, mid, array.length -1);
            mergeSort(left);
            mergeSort(right);
            merge(array, left, right);
        }
        return;

    }

    private void merge(int[] array, int[] left, int[] right)
    {
        int l1 = 0;
        int r1 = 0;

        for (int i = 0; i < array.length; i++)
        {
            if (left[l1] <= right[r1])
            {
                array[i] = left[l1];
                if (++l1 == left.length)
                {
                    // copy from other array
                    while (++i < array.length && r1 < right.length)
                    {
                        array[i] = right[r1++];
                    }
                    break;
                }
            }
            else
            {
                array[i] = right[r1];
                if (++r1 == right.length)
                {
                    // copy from other array
                    while (++i < array.length && l1 < left.length)
                    {
                        array[i] = left[l1++];
                    }

                    break;
                }
            }

        }

    }

    private int[] getSubArray(int[] array, int low, int high)
    {
        int[] retArray = new int[high – low + 1];
        for (int i = low; i <= high; i++)
        {
            retArray[i – low] = array[i];
        }
        return retArray;
    }
   
    private static void printArray(int[] array)
    {
        for (int i : array)
        {
            System.out.print(i+"\t");
        }
       
    }

}