You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by ga...@apache.org on 2008/02/29 21:28:11 UTC
svn commit: r632427 - in /incubator/pig/trunk: ./
src/org/apache/pig/backend/hadoop/executionengine/mapreduceExec/
src/org/apache/pig/backend/local/executionengine/ src/org/apache/pig/data/
src/org/apache/pig/impl/eval/ src/org/apache/pig/impl/logicalL...
Author: gates
Date: Fri Feb 29 12:28:06 2008
New Revision: 632427
URL: http://svn.apache.org/viewvc?rev=632427&view=rev
Log:
PIG-125: Improve exception handling in cases when an attempt is made to access a field as a tuple, and it turns out not to be a tuple.
Modified:
incubator/pig/trunk/CHANGES.txt
incubator/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapreduceExec/SortPartitioner.java
incubator/pig/trunk/src/org/apache/pig/backend/local/executionengine/LocalExecutionEngine.java
incubator/pig/trunk/src/org/apache/pig/backend/local/executionengine/POStore.java
incubator/pig/trunk/src/org/apache/pig/data/Tuple.java
incubator/pig/trunk/src/org/apache/pig/impl/eval/GenerateSpec.java
incubator/pig/trunk/src/org/apache/pig/impl/eval/ProjectSpec.java
incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOCogroup.java
Modified: incubator/pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/pig/trunk/CHANGES.txt?rev=632427&r1=632426&r2=632427&view=diff
==============================================================================
--- incubator/pig/trunk/CHANGES.txt (original)
+++ incubator/pig/trunk/CHANGES.txt Fri Feb 29 12:28:06 2008
@@ -141,3 +141,7 @@
(francisoud via olgan)
PIG-101: changes in tests to use enum type (francisoud via olgan)
+
+ PIG-125: Improve exception handling in cases when an attempt is made to
+ access a field as a tuple, and it turns out not to be a tuple (oae via
+ gates).
Modified: incubator/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapreduceExec/SortPartitioner.java
URL: http://svn.apache.org/viewvc/incubator/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapreduceExec/SortPartitioner.java?rev=632427&r1=632426&r2=632427&view=diff
==============================================================================
--- incubator/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapreduceExec/SortPartitioner.java (original)
+++ incubator/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapreduceExec/SortPartitioner.java Fri Feb 29 12:28:06 2008
@@ -39,15 +39,11 @@
public int getPartition(WritableComparable key, Writable value,
int numPartitions) {
- try{
- Tuple keyTuple = (Tuple)key;
- int index = Arrays.binarySearch(quantiles, keyTuple.getTupleField(0), comparator);
- if (index < 0)
- index = -index-1;
- return Math.min(index, numPartitions - 1);
- }catch(IOException e){
- throw new RuntimeException(e);
- }
+ Tuple keyTuple = (Tuple)key;
+ int index = Arrays.binarySearch(quantiles, keyTuple.getTupleField(0), comparator);
+ if (index < 0)
+ index = -index-1;
+ return Math.min(index, numPartitions - 1);
}
public void configure(JobConf job) {
Modified: incubator/pig/trunk/src/org/apache/pig/backend/local/executionengine/LocalExecutionEngine.java
URL: http://svn.apache.org/viewvc/incubator/pig/trunk/src/org/apache/pig/backend/local/executionengine/LocalExecutionEngine.java?rev=632427&r1=632426&r2=632427&view=diff
==============================================================================
--- incubator/pig/trunk/src/org/apache/pig/backend/local/executionengine/LocalExecutionEngine.java (original)
+++ incubator/pig/trunk/src/org/apache/pig/backend/local/executionengine/LocalExecutionEngine.java Fri Feb 29 12:28:06 2008
@@ -133,7 +133,7 @@
pp.close();
}
- catch (IOException e) {
+ catch (Exception e) {
throw new ExecException(e);
}
Modified: incubator/pig/trunk/src/org/apache/pig/backend/local/executionengine/POStore.java
URL: http://svn.apache.org/viewvc/incubator/pig/trunk/src/org/apache/pig/backend/local/executionengine/POStore.java?rev=632427&r1=632426&r2=632427&view=diff
==============================================================================
--- incubator/pig/trunk/src/org/apache/pig/backend/local/executionengine/POStore.java (original)
+++ incubator/pig/trunk/src/org/apache/pig/backend/local/executionengine/POStore.java Fri Feb 29 12:28:06 2008
@@ -110,6 +110,8 @@
materializedResults.put(logicalKey, materializedResult);
} catch(IOException e) {
throw e;
+ } catch(RuntimeException e) {
+ throw e;
} catch(Exception e) {
IOException ne = new IOException(e.getClass().getName() + ": " + e.getMessage());
ne.setStackTrace(e.getStackTrace());
Modified: incubator/pig/trunk/src/org/apache/pig/data/Tuple.java
URL: http://svn.apache.org/viewvc/incubator/pig/trunk/src/org/apache/pig/data/Tuple.java?rev=632427&r1=632426&r2=632427&view=diff
==============================================================================
--- incubator/pig/trunk/src/org/apache/pig/data/Tuple.java (original)
+++ incubator/pig/trunk/src/org/apache/pig/data/Tuple.java Fri Feb 29 12:28:06 2008
@@ -28,6 +28,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.io.WritableComparable;
+
/**
* an ordered list of Datums
*/
@@ -127,33 +128,33 @@
return s;
}
- public void setField(int i, Datum val) throws IOException {
+ public void setField(int i, Datum val) {
getField(i); // throws exception if field doesn't exist
fields.set(i, val);
}
- public void setField(int i, int val) throws IOException {
+ public void setField(int i, int val) {
setField(i, new DataAtom(val));
}
- public void setField(int i, double val) throws IOException {
+ public void setField(int i, double val) {
setField(i, new DataAtom(val));
}
- public void setField(int i, String val) throws IOException {
+ public void setField(int i, String val) {
setField(i, new DataAtom(val));
}
- public Datum getField(int i) throws IOException {
+ public Datum getField(int i) {
if (fields.size() >= i + 1)
return fields.get(i);
- else
- throw new IOException("Column number out of range: " + i + " -- " + toString());
+
+ throw new IndexOutOfBoundsException("Requested index " + i + " from tuple " + toString());
}
// Get field i, if it is an Atom or can be coerced into an Atom
- public DataAtom getAtomField(int i) throws IOException {
+ public DataAtom getAtomField(int i) {
Datum field = getField(i); // throws exception if field doesn't exist
if (field instanceof DataAtom) {
@@ -161,7 +162,7 @@
} else if (field instanceof Tuple) {
Tuple t = (Tuple) field;
if (t.arity() == 1) {
- log.error("Warning: Asked for an atom field but found a tuple with one field.");
+ log.warn("Requested for an atom field but found a tuple with one field.");
return t.getAtomField(0);
}
} else if (field instanceof DataBag) {
@@ -174,11 +175,18 @@
}
}
- throw new IOException("Incompatible type for request getAtomField().");
+ throw newTupleAccessException(field, "atom", i);
+ }
+
+ private RuntimeException newTupleAccessException(Datum field,
+ String requestedFieldType, int index) {
+ return new IllegalArgumentException("Requested " + requestedFieldType
+ + " field at index " + index + " but was '"
+ + field.getClass().getName() + "' in tuple: " + toString());
}
// Get field i, if it is a Tuple or can be coerced into a Tuple
- public Tuple getTupleField(int i) throws IOException {
+ public Tuple getTupleField(int i) {
Datum field = getField(i); // throws exception if field doesn't exist
if (field instanceof Tuple) {
@@ -190,18 +198,18 @@
}
}
- throw new IOException("Incompatible type for request getTupleField().");
+ throw newTupleAccessException(field, "tuple", i);
}
// Get field i, if it is a Bag or can be coerced into a Bag
- public DataBag getBagField(int i) throws IOException {
+ public DataBag getBagField(int i) {
Datum field = getField(i); // throws exception if field doesn't exist
if (field instanceof DataBag) {
return (DataBag) field;
}
- throw new IOException("Incompatible type for request getBagField().");
+ throw newTupleAccessException(field, "bag", i);
}
public void appendTuple(Tuple other){
@@ -366,13 +374,10 @@
@Override
public long getMemorySize() {
long used = 0;
- try {
- int sz = fields.size();
- for (int i = 0; i < sz; i++) used += getField(i).getMemorySize();
- used += 2 * OBJECT_SIZE + REF_SIZE;
- } catch (IOException ioe) {
- // Not really much I can do here.
- }
+ int sz = fields.size();
+ for (int i = 0; i < sz; i++)
+ used += getField(i).getMemorySize();
+ used += 2 * OBJECT_SIZE + REF_SIZE;
return used;
}
}
Modified: incubator/pig/trunk/src/org/apache/pig/impl/eval/GenerateSpec.java
URL: http://svn.apache.org/viewvc/incubator/pig/trunk/src/org/apache/pig/impl/eval/GenerateSpec.java?rev=632427&r1=632426&r2=632427&view=diff
==============================================================================
--- incubator/pig/trunk/src/org/apache/pig/impl/eval/GenerateSpec.java (original)
+++ incubator/pig/trunk/src/org/apache/pig/impl/eval/GenerateSpec.java Fri Feb 29 12:28:06 2008
@@ -128,11 +128,7 @@
return iter.hasNext();
}
public Datum next() {
- try{
- return iter.next().getField(0);
- }catch(IOException e){
- throw new RuntimeException(e);
- }
+ return iter.next().getField(0);
}
public void remove() {
throw new RuntimeException("Can't remove from read-only iterator");
@@ -224,12 +220,8 @@
for (int i=0; i< numItems; i++){
if (specs.get(i).isFlattened() && outData[i] instanceof Tuple){
Tuple t = (Tuple)outData[i];
- try{
- for (int j=0; j < t.arity(); j++){
- outTuple.appendField(t.getField(j));
- }
- }catch (IOException e){
- throw new RuntimeException(e);
+ for (int j=0; j < t.arity(); j++){
+ outTuple.appendField(t.getField(j));
}
}else{
outTuple.appendField(outData[i]);
Modified: incubator/pig/trunk/src/org/apache/pig/impl/eval/ProjectSpec.java
URL: http://svn.apache.org/viewvc/incubator/pig/trunk/src/org/apache/pig/impl/eval/ProjectSpec.java?rev=632427&r1=632426&r2=632427&view=diff
==============================================================================
--- incubator/pig/trunk/src/org/apache/pig/impl/eval/ProjectSpec.java (original)
+++ incubator/pig/trunk/src/org/apache/pig/impl/eval/ProjectSpec.java Fri Feb 29 12:28:06 2008
@@ -80,20 +80,14 @@
}
Tuple t = (Tuple)d;
- try{
- if (!wrapInTuple && cols.size() == 1){
- return t.getField(cols.get(0));
- }else{
- Tuple out = new Tuple();
- for (int i: cols){
- out.appendField(t.getField(i));
- }
- return out;
- }
- }catch (IOException e){
- //TODO: Based on a strictness level, insert null values here
- throw new RuntimeException(e);
+ if (!wrapInTuple && cols.size() == 1){
+ return t.getField(cols.get(0));
}
+ Tuple out = new Tuple();
+ for (int i: cols){
+ out.appendField(t.getField(i));
+ }
+ return out;
}
@Override
Modified: incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOCogroup.java
URL: http://svn.apache.org/viewvc/incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOCogroup.java?rev=632427&r1=632426&r2=632427&view=diff
==============================================================================
--- incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOCogroup.java (original)
+++ incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOCogroup.java Fri Feb 29 12:28:06 2008
@@ -17,7 +17,6 @@
*/
package org.apache.pig.impl.logicalLayer;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -25,7 +24,6 @@
import org.apache.pig.data.Datum;
import org.apache.pig.data.Tuple;
import org.apache.pig.impl.eval.EvalSpec;
-import org.apache.pig.impl.logicalLayer.schema.AtomSchema;
import org.apache.pig.impl.logicalLayer.schema.Schema;
import org.apache.pig.impl.logicalLayer.schema.TupleSchema;
@@ -76,20 +74,16 @@
}
Datum[]groupAndTuple = new Datum[2];
- try {
- if (output.arity() == 2) {
- groupAndTuple[0] = output.getField(0);
- groupAndTuple[1] = output.getField(1);
- } else {
- Tuple group = new Tuple();
- for (int j = 0; j < output.arity() - 1; j++) {
- group.appendField(output.getField(j));
- }
- groupAndTuple[0] = group;
- groupAndTuple[1] = output.getField(output.arity() - 1);
+ if (output.arity() == 2) {
+ groupAndTuple[0] = output.getField(0);
+ groupAndTuple[1] = output.getField(1);
+ } else {
+ Tuple group = new Tuple();
+ for (int j = 0; j < output.arity() - 1; j++) {
+ group.appendField(output.getField(j));
}
- } catch(IOException e) {
- throw new RuntimeException(e);
+ groupAndTuple[0] = group;
+ groupAndTuple[1] = output.getField(output.arity() - 1);
}
return groupAndTuple;
}