Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.apache.pig.backend.hadoop;
 
 import java.util.Map;
 
A class of helper methods for converting from pig data types to hadoop data types, and vice versa.
 
 public class HDataType {
     static NullableText stringWrit = new NullableText();
     static NullableIntWritable intWrit = new NullableIntWritable();
     static NullableBag defDB = new NullableBag();
     static NullableTuple defTup = new NullableTuple();
     static Map<ByteStringtypeToName = null;
 
     private static final HashMap<StringByteclassToTypeMap = new HashMap<StringByte>();
     static {
         .put("org.apache.pig.impl.io.NullableBag".);
         .put("org.apache.pig.impl.io.NullableBigDecimalWritable".);
         .put("org.apache.pig.impl.io.NullableBigIntegerWritable".);
         .put("org.apache.pig.impl.io.NullableBooleanWritable".);
         .put("org.apache.pig.impl.io.NullableBytesWritable".);
         .put("org.apache.pig.impl.io.NullableDateTimeWritable".);
         .put("org.apache.pig.impl.io.NullableDoubleWritable".);
         .put("org.apache.pig.impl.io.NullableFloatWritable".);
         .put("org.apache.pig.impl.io.NullableIntWritable".);
         .put("org.apache.pig.impl.io.NullableLongWritable".);
         .put("org.apache.pig.impl.io.NullableText".);
         .put("org.apache.pig.impl.io.NullableTuple".);
     }
 
     public static PigNullableWritable getWritableComparable(String classNamethrows ExecException {
         if (.containsKey(className)) {
             return getWritableComparableTypes(null.get(className));
         } else {
             throw new ExecException("Unable to map " + className + " to known types." + Arrays.toString(.keySet().toArray()));
         }
     }
 
     public static PigNullableWritable getWritableComparableTypes(Object obyte keyTypethrows ExecException{
 
         byte newKeyType = keyType;
         if (o==null)
             newKeyType = .;
 
         switch (newKeyType) {
         case .:
             return new NullableBag((DataBag)o);
 
         case .:
            return new NullableBooleanWritable((Boolean)o);
        case .:
            return new NullableBytesWritable(o);
        case .:
            return new NullableText((String)o);
        case .:
            return new NullableDoubleWritable((Double)o);
        case .:
            return new NullableFloatWritable((Float)o);
        case .:
            return new NullableIntWritable((Integer)o);
        case .:
            return new NullableLongWritable((Long)o);
        case .:
            return new NullableBigIntegerWritable((BigInteger)o);
        case .:
            return new NullableBigDecimalWritable((BigDecimal)o);
        case .:
            return new NullableDateTimeWritable((DateTime)o);
        case .:
            return new NullableTuple((Tuple)o);
        case .: {
            int errCode = 1068;
            String msg = "Using Map as key not supported.";
            throw new ExecException(msgerrCode.);
        }
        case .:
            switch (keyType) {
            case .:
                NullableBag nbag = new NullableBag();
                nbag.setNull(true);
                return nbag;
            case .:
                NullableBooleanWritable nboolWrit = new NullableBooleanWritable();
                nboolWrit.setNull(true);
                return nboolWrit;
            case .:
                NullableBytesWritable nBytesWrit = new NullableBytesWritable();
                nBytesWrit.setNull(true);
                return nBytesWrit;
            case .:
                NullableText nStringWrit = new NullableText();
                nStringWrit.setNull(true);
                return nStringWrit;
            case .:
                NullableDoubleWritable nDoubleWrit = new NullableDoubleWritable();
                nDoubleWrit.setNull(true);
                return nDoubleWrit;
            case .:
                NullableFloatWritable nFloatWrit = new NullableFloatWritable();
                nFloatWrit.setNull(true);
                return nFloatWrit;
            case .:
                NullableIntWritable nIntWrit = new NullableIntWritable();
                nIntWrit.setNull(true);
                return nIntWrit;
            case .:
                NullableBigIntegerWritable nBigIntWrit = new NullableBigIntegerWritable();
                nBigIntWrit.setNull(true);
                return nBigIntWrit;
            case .:
                NullableBigDecimalWritable nBigDecWrit = new NullableBigDecimalWritable();
                nBigDecWrit.setNull(true);
                return nBigDecWrit;
            case .:
                NullableLongWritable nLongWrit = new NullableLongWritable();
                nLongWrit.setNull(true);
                return nLongWrit;
            case .:
                NullableDateTimeWritable nDateTimeWrit = new NullableDateTimeWritable();
                nDateTimeWrit.setNull(true);
                return nDateTimeWrit;
            case .:
                NullableTuple ntuple = new NullableTuple();
                ntuple.setNull(true);
                return ntuple;
            case .: {
                int errCode = 1068;
                String msg = "Using Map as key not supported.";
                throw new ExecException(msgerrCode.);
            }
            }
            break;
        default:
            if ( == null = DataType.genTypeToNameMap();
            int errCode = 2044;
            String msg = "The type "
                + .get(keyType)
                + " cannot be collected as a Key type";
            throw new ExecException(msgerrCode.);
        }
        // should never come here
        return null;
    }
    public static PigNullableWritable getWritableComparableTypes(byte typethrows ExecException{
        PigNullableWritable wcKey = null;
         switch (type) {
        case .:
            wcKey = ;
            break;
        case .:
            wcKey = ;
            break;
        case .:
            wcKey = ;
            break;
        case .:
            wcKey = ;
            break;
        case .:
            wcKey = ;
            break;
        case .:
            wcKey = ;
            break;
        case .:
            wcKey = ;
            break;
        case .:
            wcKey = ;
            break;
        case .:
            wcKey = ;
            break;
        case .:
            wcKey = ;
            break;
        case .:
            wcKey = ;
            break;
        case .:
            wcKey = ;
            break;
        case .: {
            int errCode = 1068;
            String msg = "Using Map as key not supported.";
            throw new ExecException(msgerrCode.);
        }
        default:
            if ( == null = DataType.genTypeToNameMap();
            int errCode = 2044;
            String msg = "The type "
                + .get(type)
                + " cannot be collected as a Key type";
            throw new ExecException(msgerrCode.);
        }
        return wcKey;
    }
    public static byte findTypeFromNullableWritable(PigNullableWritable othrows ExecException {
        if (o instanceof NullableBooleanWritable)
            return .;
        else if (o instanceof NullableBytesWritable)
            return .;
        else if (o instanceof NullableText)
            return .;
        else if (o instanceof NullableFloatWritable)
            return .;
        else if (o instanceof NullableDoubleWritable)
            return .;
        else if (o instanceof NullableIntWritable)
            return .;
        else if (o instanceof NullableLongWritable)
            return .;
        else if (o instanceof NullableBigIntegerWritable)
            return .;
        else if (o instanceof NullableBigDecimalWritable)
            return .;
        else if (o instanceof NullableDateTimeWritable)
            return .;
        else if (o instanceof NullableBag)
            return .;
        else if (o instanceof NullableTuple)
            return .;
        else {
            int errCode = 2044;
            String msg = "Cannot find Pig type for " + o.getClass().getName();
            throw new ExecException(msgerrCode.);
        }
    }
New to GrepCode? Check out our FAQ X