Review Board 1.7.22


PIG-3156 TestSchemaTuple fails in trunk

Review Request #9395 - Created Feb. 10, 2013 and submitted

Cheolsoo Park
PIG-3156
Reviewers
pig
jcoveney
pig-git
This patch adds missing methods that handle BigDecimal and BigInteger to SchemaTuple and SchemaTupleClassGenerator.
ant clean test -Dtestcase=TestSchema passes.
src/org/apache/pig/data/SchemaTuple.java
Revision d036eec New Change
[20] 17 lines
[+20]
18
package org.apache.pig.data;
18
package org.apache.pig.data;
19

    
   
19

   
20
import java.io.DataInput;
20
import java.io.DataInput;
21
import java.io.DataOutput;
21
import java.io.DataOutput;
22
import java.io.IOException;
22
import java.io.IOException;

    
   
23
import java.math.BigDecimal;

    
   
24
import java.math.BigInteger;
23
import java.util.Iterator;
25
import java.util.Iterator;
24
import java.util.List;
26
import java.util.List;
25
import java.util.Map;
27
import java.util.Map;
26

    
   
28

   
27
import org.joda.time.DateTime;
29
import org.joda.time.DateTime;
28
import org.joda.time.DateTimeZone;
30
import org.joda.time.DateTimeZone;
29

    
   
31

   
30
import org.apache.commons.codec.binary.Base64;

   
31
import org.apache.pig.backend.executionengine.ExecException;
32
import org.apache.pig.backend.executionengine.ExecException;
32
import org.apache.pig.classification.InterfaceAudience;
33
import org.apache.pig.classification.InterfaceAudience;
33
import org.apache.pig.classification.InterfaceStability;
34
import org.apache.pig.classification.InterfaceStability;
34
import org.apache.pig.data.utils.MethodHelper;
35
import org.apache.pig.data.utils.MethodHelper;
35
import org.apache.pig.data.utils.MethodHelper.NotImplemented;
36
import org.apache.pig.data.utils.MethodHelper.NotImplemented;
[+20] [20] 143 lines
[+20] [+] protected static void write(DataOutput out, double v) throws IOException {
179
    protected static void write(DataOutput out, DateTime v) throws IOException {
180
    protected static void write(DataOutput out, DateTime v) throws IOException {
180
        out.writeLong(v.getMillis());
181
        out.writeLong(v.getMillis());
181
        out.writeShort(v.getZone().getOffset(v) / ONE_MINUTE);
182
        out.writeShort(v.getZone().getOffset(v) / ONE_MINUTE);
182
    }
183
    }
183

    
   
184

   

    
   
185
    protected static void write(DataOutput out, BigDecimal v) throws IOException {

    
   
186
        bis.writeDatum(out, v, DataType.BIGDECIMAL);

    
   
187
    }

    
   
188

   

    
   
189
    protected static void write(DataOutput out, BigInteger v) throws IOException {

    
   
190
        bis.writeDatum(out, v, DataType.BIGINTEGER);

    
   
191
    }

    
   
192

   
184
    protected static void write(DataOutput out, byte[] v) throws IOException {
193
    protected static void write(DataOutput out, byte[] v) throws IOException {
185
        SedesHelper.writeBytes(out, v);
194
        SedesHelper.writeBytes(out, v);
186
    }
195
    }
187

    
   
196

   
188
    protected static void write(DataOutput out, String v) throws IOException {
197
    protected static void write(DataOutput out, String v) throws IOException {
[+20] [20] 31 lines
[+20] [+] protected static double read(DataInput in, double v) throws IOException {
220

    
   
229

   
221
    protected static DateTime read(DataInput in, DateTime v) throws IOException {
230
    protected static DateTime read(DataInput in, DateTime v) throws IOException {
222
        return new DateTime(in.readLong(), DateTimeZone.forOffsetMillis(in.readShort() * ONE_MINUTE));
231
        return new DateTime(in.readLong(), DateTimeZone.forOffsetMillis(in.readShort() * ONE_MINUTE));
223
    }
232
    }
224

    
   
233

   

    
   
234
    protected static BigDecimal read(DataInput in, BigDecimal v) throws IOException {

    
   
235
        return (BigDecimal) bis.readDatum(in);

    
   
236
    }

    
   
237

   

    
   
238
    protected static BigInteger read(DataInput in, BigInteger v) throws IOException {

    
   
239
        return (BigInteger) bis.readDatum(in);

    
   
240
    }

    
   
241

   
225
    protected static String read(DataInput in, String v) throws IOException {
242
    protected static String read(DataInput in, String v) throws IOException {
226
        return SedesHelper.readChararray(in, in.readByte());
243
        return SedesHelper.readChararray(in, in.readByte());
227
    }
244
    }
228

    
   
245

   
229
    protected static byte[] read(DataInput in, byte[] v) throws IOException {
246
    protected static byte[] read(DataInput in, byte[] v) throws IOException {
[+20] [20] 157 lines
[+20] [+] protected boolean unbox(Object v, boolean t) {
387

    
   
404

   
388
    protected DateTime unbox(Object v, DateTime t) {
405
    protected DateTime unbox(Object v, DateTime t) {
389
        return (DateTime)v;
406
        return (DateTime)v;
390
    }
407
    }
391

    
   
408

   

    
   
409
    protected BigDecimal unbox(Object v, BigDecimal t) {

    
   
410
        return (BigDecimal)v;

    
   
411
    }

    
   
412

   

    
   
413
    protected BigInteger unbox(Object v, BigInteger t) {

    
   
414
        return (BigInteger)v;

    
   
415
    }

    
   
416

   
392
    protected String unbox(Object v, String t) {
417
    protected String unbox(Object v, String t) {
393
        return (String)v;
418
        return (String)v;
394
    }
419
    }
395

    
   
420

   
396
    protected Tuple unbox(Object v, Tuple t) {
421
    protected Tuple unbox(Object v, Tuple t) {
[+20] [20] 84 lines
[+20] [+] protected Boolean box(boolean v) {
481

    
   
506

   
482
    protected DateTime box(DateTime v) {
507
    protected DateTime box(DateTime v) {
483
        return v;
508
        return v;
484
    }
509
    }
485

    
   
510

   

    
   
511
    protected BigDecimal box(BigDecimal v) {

    
   
512
        return v;

    
   
513
    }

    
   
514

   

    
   
515
    protected BigInteger box(BigInteger v) {

    
   
516
        return v;

    
   
517
    }

    
   
518

   
486
    protected int hashCodePiece(int hash, int v, boolean isNull) {
519
    protected int hashCodePiece(int hash, int v, boolean isNull) {
487
        return isNull ? hash : 31 * hash + v;
520
        return isNull ? hash : 31 * hash + v;
488
    }
521
    }
489

    
   
522

   
490
    protected int hashCodePiece(int hash, long v, boolean isNull) {
523
    protected int hashCodePiece(int hash, long v, boolean isNull) {
[+20] [20] 15 lines
[+20] [+] protected int hashCodePiece(int hash, boolean v, boolean isNull) {
506

    
   
539

   
507
    protected int hashCodePiece(int hash, DateTime v, boolean isNull) {
540
    protected int hashCodePiece(int hash, DateTime v, boolean isNull) {
508
        return isNull ? hash : 31 * hash + v.hashCode();
541
        return isNull ? hash : 31 * hash + v.hashCode();
509
    }
542
    }
510

    
   
543

   

    
   
544
    protected int hashCodePiece(int hash, BigDecimal v, boolean isNull) {

    
   
545
        return isNull ? hash : 31 * hash + v.hashCode();

    
   
546
    }

    
   
547

   

    
   
548
    protected int hashCodePiece(int hash, BigInteger v, boolean isNull) {

    
   
549
        return isNull ? hash : 31 * hash + v.hashCode();

    
   
550
    }

    
   
551

   
511
    protected int hashCodePiece(int hash, byte[] v, boolean isNull) {
552
    protected int hashCodePiece(int hash, byte[] v, boolean isNull) {
512
        return isNull ? hash : 31 * hash + DataByteArray.hashCode(v);
553
        return isNull ? hash : 31 * hash + DataByteArray.hashCode(v);
513
    }
554
    }
514

    
   
555

   
515
    protected int hashCodePiece(int hash, String v, boolean isNull) {
556
    protected int hashCodePiece(int hash, String v, boolean isNull) {
[+20] [20] 96 lines
[+20] [+] public void setDateTime(int fieldNum, DateTime val) throws ExecException {
612
    }
653
    }
613

    
   
654

   
614
    protected abstract void generatedCodeSetDateTime(int fieldNum, DateTime val) throws ExecException;
655
    protected abstract void generatedCodeSetDateTime(int fieldNum, DateTime val) throws ExecException;
615

    
   
656

   
616
    @Override
657
    @Override

    
   
658
    public void setBigDecimal(int fieldNum, BigDecimal val) throws ExecException {

    
   
659
         generatedCodeSetBigDecimal(fieldNum, val);

    
   
660
    }

    
   
661

   

    
   
662
    protected abstract void generatedCodeSetBigDecimal(int fieldNum, BigDecimal val) throws ExecException;

    
   
663

   

    
   
664
    @Override

    
   
665
    public void setBigInteger(int fieldNum, BigInteger val) throws ExecException {

    
   
666
         generatedCodeSetBigInteger(fieldNum, val);

    
   
667
    }

    
   
668

   

    
   
669
    protected abstract void generatedCodeSetBigInteger(int fieldNum, BigInteger val) throws ExecException;

    
   
670

   

    
   
671
    @Override
617
    public void setString(int fieldNum, String val) throws ExecException {
672
    public void setString(int fieldNum, String val) throws ExecException {
618
         generatedCodeSetString(fieldNum, val);
673
         generatedCodeSetString(fieldNum, val);
619
    }
674
    }
620

    
   
675

   
621
    protected abstract void generatedCodeSetString(int fieldNum, String val) throws ExecException;
676
    protected abstract void generatedCodeSetString(int fieldNum, String val) throws ExecException;
[+20] [20] 60 lines
[+20] [+] protected boolean returnUnlessNull(boolean isNull, boolean val) throws FieldIsNullException {
682
    protected DateTime returnUnlessNull(boolean isNull, DateTime val) throws FieldIsNullException {
737
    protected DateTime returnUnlessNull(boolean isNull, DateTime val) throws FieldIsNullException {
683
        errorIfNull(isNull, "DateTime");
738
        errorIfNull(isNull, "DateTime");
684
        return val;
739
        return val;
685
    }
740
    }
686

    
   
741

   

    
   
742
    protected BigDecimal returnUnlessNull(boolean isNull, BigDecimal val) throws FieldIsNullException {

    
   
743
        errorIfNull(isNull, "BigDecimal");

    
   
744
        return val;

    
   
745
    }

    
   
746

   

    
   
747
    protected BigInteger returnUnlessNull(boolean isNull, BigInteger val) throws FieldIsNullException {

    
   
748
        errorIfNull(isNull, "BigInteger");

    
   
749
        return val;

    
   
750
    }

    
   
751

   
687
    protected Tuple returnUnlessNull(boolean isNull, Tuple val) throws FieldIsNullException {
752
    protected Tuple returnUnlessNull(boolean isNull, Tuple val) throws FieldIsNullException {
688
        errorIfNull(isNull, "Tuple");
753
        errorIfNull(isNull, "Tuple");
689
        return val;
754
        return val;
690
    }
755
    }
691

    
   
756

   
[+20] [20] 138 lines
[+20] [+] protected DataBag unboxDataBag(Object val) {
830
    @SuppressWarnings("unchecked")
895
    @SuppressWarnings("unchecked")
831
    protected Map<String, Object> unboxMap(Object val) {
896
    protected Map<String, Object> unboxMap(Object val) {
832
        return (Map<String, Object>)val;
897
        return (Map<String, Object>)val;
833
    }
898
    }
834

    
   
899

   

    
   
900
    @Override

    
   
901
    public BigDecimal getBigDecimal(int fieldNum) throws ExecException {

    
   
902
        return generatedCodeGetBigDecimal(fieldNum);

    
   
903
    }

    
   
904

   

    
   
905
    protected abstract BigDecimal generatedCodeGetBigDecimal(int fieldNum)

    
   
906
            throws ExecException;

    
   
907

   

    
   
908
    public BigDecimal unboxBigDecimal(Object val) {

    
   
909
        return (BigDecimal) val;

    
   
910
    }

    
   
911

   

    
   
912
    @Override

    
   
913
    public BigInteger getBigInteger(int fieldNum) throws ExecException {

    
   
914
        return generatedCodeGetBigInteger(fieldNum);

    
   
915
    }

    
   
916

   

    
   
917
    protected abstract BigInteger generatedCodeGetBigInteger(int fieldNum)

    
   
918
            throws ExecException;

    
   
919

   

    
   
920
    public BigInteger unboxBigInteger(Object val) {

    
   
921
        return (BigInteger) val;

    
   
922
    }

    
   
923

   
835
    protected static Schema staticSchemaGen(String s) {
924
    protected static Schema staticSchemaGen(String s) {
836
        try {
925
        try {
837
            if (s.equals("")) {
926
            if (s.equals("")) {
838
                Log.warn("No Schema present in SchemaTuple generated class");
927
                Log.warn("No Schema present in SchemaTuple generated class");
839
                return new Schema();
928
                return new Schema();
[+20] [20] 262 lines
[+20] [+] protected int compareWithElementAtPos(boolean isNull, DateTime val, SchemaTuple<?> t, int pos) {
1102
            throw new RuntimeException("Unable to retrieve String field " + pos + " in given Tuple: " + t, e);
1191
            throw new RuntimeException("Unable to retrieve String field " + pos + " in given Tuple: " + t, e);
1103
        }
1192
        }
1104
        return compare(isNull, val, themNull, themVal);
1193
        return compare(isNull, val, themNull, themVal);
1105
    }
1194
    }
1106

    
   
1195

   

    
   
1196
    protected int compare(boolean usNull, BigDecimal usVal, boolean themNull, BigDecimal themVal) {

    
   
1197
        if (usNull && themNull) {

    
   
1198
            return 0;

    
   
1199
        } else if (themNull) {

    
   
1200
            return 1;

    
   
1201
        } else if (usNull) {

    
   
1202
            return -1;

    
   
1203
        }

    
   
1204
        return compare(usVal, themVal);

    
   
1205
    }

    
   
1206

   

    
   
1207
    protected int compare(BigDecimal val, BigDecimal themVal) {

    
   
1208
        return val.compareTo(themVal);

    
   
1209
    }

    
   
1210

   

    
   
1211
    protected int compareWithElementAtPos(boolean isNull, BigDecimal val, SchemaTuple<?> t, int pos) {

    
   
1212
        BigDecimal themVal;

    
   
1213
        boolean themNull;

    
   
1214
        try {

    
   
1215
            themVal = t.getBigDecimal(pos);

    
   
1216
            themNull = t.isNull(pos);

    
   
1217
        } catch (ExecException e) {

    
   
1218
            throw new RuntimeException("Unable to retrieve String field " + pos + " in given Tuple: " + t, e);

    
   
1219
        }

    
   
1220
        return compare(isNull, val, themNull, themVal);

    
   
1221
    }

    
   
1222

   

    
   
1223
    protected int compare(boolean usNull, BigInteger usVal, boolean themNull, BigInteger themVal) {

    
   
1224
        if (usNull && themNull) {

    
   
1225
            return 0;

    
   
1226
        } else if (themNull) {

    
   
1227
            return 1;

    
   
1228
        } else if (usNull) {

    
   
1229
            return -1;

    
   
1230
        }

    
   
1231
        return compare(usVal, themVal);

    
   
1232
    }

    
   
1233

   

    
   
1234
    protected int compare(BigInteger val, BigInteger themVal) {

    
   
1235
        return val.compareTo(themVal);

    
   
1236
    }

    
   
1237

   

    
   
1238
    protected int compareWithElementAtPos(boolean isNull, BigInteger val, SchemaTuple<?> t, int pos) {

    
   
1239
        BigInteger themVal;

    
   
1240
        boolean themNull;

    
   
1241
        try {

    
   
1242
            themVal = t.getBigInteger(pos);

    
   
1243
            themNull = t.isNull(pos);

    
   
1244
        } catch (ExecException e) {

    
   
1245
            throw new RuntimeException("Unable to retrieve String field " + pos + " in given Tuple: " + t, e);

    
   
1246
        }

    
   
1247
        return compare(isNull, val, themNull, themVal);

    
   
1248
    }

    
   
1249

   
1107
    protected int compare(boolean usNull, String usVal, boolean themNull, String themVal) {
1250
    protected int compare(boolean usNull, String usVal, boolean themNull, String themVal) {
1108
        if (usNull && themNull) {
1251
        if (usNull && themNull) {
1109
            return 0;
1252
            return 0;
1110
        } else if (themNull) {
1253
        } else if (themNull) {
1111
            return 1;
1254
            return 1;
[+20] [20] 127 lines
src/org/apache/pig/data/SchemaTupleClassGenerator.java
Revision 633c8d8 New Change
 
test/org/apache/pig/data/TestSchemaTuple.java
Revision 3e89996 New Change
 
  1. src/org/apache/pig/data/SchemaTuple.java: Loading...
  2. src/org/apache/pig/data/SchemaTupleClassGenerator.java: Loading...
  3. test/org/apache/pig/data/TestSchemaTuple.java: Loading...