Top level Union is not supported currently; use a subquery for the union : Error

August 1, 2013
select c1, c2 from cert.tset1 tset1 union all select c1, c2 from cert.tset2 
tset2


vs 

select * from ( select c1, c2 from cert.tset1 tset1 union all select c1, c2 
from cert.tset2 tset2 ) T 

 

Advertisements

Difference between HBase and HDFS ?

April 30, 2013

HDFS is a distributed file system and has the following properties:
1. It is optimized for streaming access of large files. You would typically store files that are in the 100s of MB upwards on HDFS and access them through MapReduce to process them in batch mode.
2. HDFS is optimized for use cases where you write once and read many times like in the case of production logs. You can append to files in some of the recent versions but that is not a feature that is very commonly used. There is no concept of random writes.
3. HDFS doesn’t do random reads very well.

HBase on the other hand is a distributed column oriented database. The filesystem of choice typically is HDFS owing to the tight integration between HBase and HDFS. Having said that, it doesn’t mean that HBase can’t work on any other filesystem. It’s just not proven in production and at scale to work with anything except HDFS.
HBase provides you with the following:
1. It gives you the ability to do random read/writes on your data which HDFS doesnt allow you to.
2. HBase stores data in the form of key value pairs in a columnar fashion. HBase provides a flexible data model.
3. Fast scans across tables.
4. Scale in terms of writes as well as total volume of data.

An analogous comparison would be between MySQL and Ext4.


Dynamic Programming : ZigZag : TCCC03 Semi Final 3 level 1

December 31, 2012
	public int longestZigZag(int[] sequence){
		if(sequence.length == 1) return 1;
		int[] L = new int[sequence.length];
		int[] diff = new int[sequence.length-1];
		int maxLength = 1;
		boolean maxValue;
		
		for(int j =0; j<(sequence.length - 1);j++){
			diff[j] = sequence[j+1] - sequence[j];
		}
		if(diff[0] >= 0) maxValue = true;
		else maxValue = false;
		
		for(int j = 1; j< diff.length;j++){
			boolean curValue= maxValue;
			if(diff[j] > 0 ) curValue = true;
			else if(diff[j]<0) curValue = false;
			if(curValue != maxValue){
				maxLength++;
				maxValue = curValue;
			}
		}
		
		return maxLength+1;
	}

Learning and Mastering Java

December 25, 2012

Here is my target list for the enxt year. I have read all these books in some bits and pieces, but this year I want to be thorough with my knowledge.

1) SUN Certified Java programmer for  Java 6 exam

2) A programmer’s guide to SCJP Certification

3) Effective Java

4) Java Concurrency in Parctice

5) Head First Design Patterns

6) Java Puzzlers

7) Java Generics and Collections


SRM 208 Div 1 : TallPeople

December 25, 2012

public int[] getPeople(String[] people) {
int[] ret = new int[2];
int R=people.length,C=people[0].split(" ").length;
int[][] arr = new int[R][C];

for(int i = 0;i<R;i++){
String[] split = people[i].split(" ");
for(int j=0;j<C;j++){
arr[i][j] = Integer.parseInt(split[j]);
}
}

int maxMinRow = Integer.MIN_VALUE;
for(int i = 0;i<R;i++){
int minRow = Integer.MAX_VALUE;
for(int j=0;j<C;j++){
if(arr[i][j]< minRow)
minRow = arr[i][j];

}
if(maxMinRow < minRow)
maxMinRow = minRow;
}
ret[0] = maxMinRow;

int minMaxCol = Integer.MAX_VALUE;
for(int i = 0;i<C;i++){
int maxCol = Integer.MIN_VALUE;
for(int j=0;j<R;j++){
if(arr[j][i]> maxCol)
maxCol = arr[j][i];

}
if(minMaxCol > maxCol)
minMaxCol = maxCol;
}
ret[1] = minMaxCol;

return ret;
}


SRM 236 Div 1 : BusinessTasks

December 25, 2012

Hello Competitive Programming ! My first entry into topcoder :

SRM236 Div 1 : BusinessTasks


public class BusinessTasks
{
public String getTask(String[] list, int n)
{
List<String> myList = new ArrayList<String>();
for(int i=0;i<list.length;i++) {
myList.add(list[i]);
}
int pos = 0;
while (myList.size() > 1) {
pos = (pos + n - 1)%myList.size();
myList.remove(pos);
pos = pos % myList.size();
}
return myList.get(0);
}
}

Related Links :

  1. Josephus problem
  2. A variant of this also appeared in Amazon interviews

Implement an algorithm to print all valid (e g , properly opened and closed) combinations of n-pairs of parentheses

December 25, 2012

Input : 3

Output : ()()(), ()(()), (())(), ((()))


public static void printPar(int l, int r, char[] str, int count) {
if (l < 0 || r < l) return; // invalid state
if (l == 0 && r == 0) {
System.out.println(str); // found one, so print it
} else {
if (l > 0) { // try a left paren, if there are some available
str[count] = ‘(‘;
printPar(l - 1, r, str, count + 1);
}
if (r > l) { // try a right paren, if there’s a matching left
str[count] = ‘)’;
printPar(l, r - 1, str, count + 1);
}
}
}