Created
August 21, 2012 02:40
-
-
Save singhgurjeet/3410948 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void oldMakeTable(HTable table, int numRows, int numCols) throws IOException { | |
table.setAutoFlush(false); | |
Random random = new Random(); | |
byte[] family = Bytes.toBytes("family"); | |
for (int i = 0; i < numRows; i++) { | |
byte[] rowBytes = Bytes.toBytes(i); | |
for (int j = 0 ; j < numCols; j++) { | |
table.put(new Put(rowBytes).add(family, Bytes.toBytes(j), Bytes.toBytes(random.nextDouble()))); | |
} | |
System.out.println(String.format("Done ingesting %d rows", i)); | |
} | |
table.flushCommits(); | |
} | |
public static void oldScanTable(HTable table, int numRows, int numCols) throws IOException { | |
Scan scan = new Scan(); | |
byte[] family = Bytes.toBytes("family"); | |
scan.addFamily(family); | |
ResultScanner results = table.getScanner(scan); | |
int i = 0; | |
for (Result result : results) { | |
for (KeyValue kv : result.list()) { | |
// System.out.print(Bytes.toDouble(kv.getValue()) + "\t"); | |
} | |
// System.out.println(""); | |
System.out.println(String.format("Done scanning %d rows", i++)); | |
} | |
results.close(); | |
} | |
public static void newMakeTable(HTable table, int numRows, int numCols, int segmentSize) throws IOException { | |
table.setAutoFlush(false); | |
Random random = new Random(); | |
byte[] family = Bytes.toBytes("family"); | |
for (int i = 0; i < numRows; i++) { | |
byte[] rowBytes = Bytes.toBytes(i); | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
DataOutputStream dos = new DataOutputStream(baos); | |
dos.writeInt(segmentSize); | |
int k = 0; | |
int segmentNum = 0; | |
for (int j = 0 ; j < numCols; j++) { | |
dos.writeDouble(random.nextDouble()); | |
k++; | |
if (k >= segmentSize || j == numCols - 1) { | |
k = 0; | |
table.put(new Put(rowBytes).add(family, Bytes.toBytes(segmentNum++), baos.toByteArray())); | |
baos = new ByteArrayOutputStream(); | |
dos = new DataOutputStream(baos); | |
if (numCols - j - 1 > segmentSize) | |
dos.writeInt(segmentSize); | |
else if (numCols - j - 1 != 0) | |
dos.writeInt(numCols - j - 1); | |
} | |
} | |
System.out.println(String.format("Done ingesting %d rows", i)); | |
} | |
table.flushCommits(); | |
} | |
public static void newScanTable(HTable table, int numRows, int numCols, int segmentSize) throws IOException { | |
Scan scan = new Scan(); | |
byte[] family = Bytes.toBytes("family"); | |
scan.addFamily(family); | |
ResultScanner results = table.getScanner(scan); | |
int j = 0; | |
for (Result result : results) { | |
for (KeyValue kv : result.list()) { | |
int segmentNum = Bytes.toInt(kv.getQualifier()); | |
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(kv.getValue())); | |
int valuesInSegment = dis.readInt(); | |
for (int i = 0; i < valuesInSegment; i++) { | |
// System.out.print(dis.readDouble() + "\t"); | |
} | |
} | |
System.out.println(String.format("Done scanning %d rows", j++)); | |
// System.out.println(""); | |
} | |
results.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment