Example #1
0
 public static double getAsConstDouble(@Nonnull final ObjectInspector numberOI)
     throws UDFArgumentException {
   final String typeName = numberOI.getTypeName();
   if (DOUBLE_TYPE_NAME.equals(typeName)) {
     DoubleWritable v = getConstValue(numberOI);
     return v.get();
   } else if (FLOAT_TYPE_NAME.equals(typeName)) {
     FloatWritable v = getConstValue(numberOI);
     return v.get();
   } else if (INT_TYPE_NAME.equals(typeName)) {
     IntWritable v = getConstValue(numberOI);
     return v.get();
   } else if (BIGINT_TYPE_NAME.equals(typeName)) {
     LongWritable v = getConstValue(numberOI);
     return v.get();
   } else if (SMALLINT_TYPE_NAME.equals(typeName)) {
     ShortWritable v = getConstValue(numberOI);
     return v.get();
   } else if (TINYINT_TYPE_NAME.equals(typeName)) {
     ByteWritable v = getConstValue(numberOI);
     return v.get();
   }
   throw new UDFArgumentException(
       "Unexpected argument type to cast as double: "
           + TypeInfoUtils.getTypeInfoFromObjectInspector(numberOI));
 }
Example #2
0
 public static PrimitiveObjectInspector asPrimitiveObjectInspector(
     @Nonnull final ObjectInspector oi) throws UDFArgumentException {
   if (oi.getCategory() != Category.PRIMITIVE) {
     throw new UDFArgumentException(
         "Is not PrimitiveObjectInspector: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi));
   }
   return (PrimitiveObjectInspector) oi;
 }
Example #3
0
 public static long getConstLong(@Nonnull final ObjectInspector oi) throws UDFArgumentException {
   if (!isBigIntOI(oi)) {
     throw new UDFArgumentException(
         "argument must be a BigInt value: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi));
   }
   LongWritable v = getConstValue(oi);
   return v.get();
 }
Example #4
0
 @Nonnull
 public static ConstantObjectInspector asConstantObjectInspector(@Nonnull final ObjectInspector oi)
     throws UDFArgumentException {
   if (!ObjectInspectorUtils.isConstantObjectInspector(oi)) {
     throw new UDFArgumentException(
         "argument must be a constant value: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi));
   }
   return (ConstantObjectInspector) oi;
 }
Example #5
0
 public static String getConstString(@Nonnull final ObjectInspector oi)
     throws UDFArgumentException {
   if (!isStringOI(oi)) {
     throw new UDFArgumentException(
         "argument must be a Text value: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi));
   }
   Text v = getConstValue(oi);
   return v == null ? null : v.toString();
 }
Example #6
0
 public static boolean getConstBoolean(@Nonnull final ObjectInspector oi)
     throws UDFArgumentException {
   if (!isBooleanOI(oi)) {
     throw new UDFArgumentException(
         "argument must be a Boolean value: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi));
   }
   BooleanWritable v = getConstValue(oi);
   return v.get();
 }
Example #7
0
 @SuppressWarnings("unchecked")
 @Nullable
 public static <T extends Writable> T getConstValue(@Nonnull final ObjectInspector oi)
     throws UDFArgumentException {
   if (!ObjectInspectorUtils.isConstantObjectInspector(oi)) {
     throw new UDFArgumentException(
         "argument must be a constant value: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi));
   }
   ConstantObjectInspector constOI = (ConstantObjectInspector) oi;
   Object v = constOI.getWritableConstantValue();
   return (T) v;
 }
 /** Get the list of field type as csv from a StructObjectInspector. */
 public static String getFieldTypes(StructObjectInspector soi) {
   List<? extends StructField> fields = soi.getAllStructFieldRefs();
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < fields.size(); i++) {
     if (i > 0) {
       sb.append(":");
     }
     sb.append(
         TypeInfoUtils.getTypeInfoFromObjectInspector(fields.get(i).getFieldObjectInspector())
             .getTypeName());
   }
   return sb.toString();
 }
Example #9
0
  /*
   * add array<struct> to the list of columns
   */
  protected static RowResolver createSelectListRR(MatchPath evaluator, PTFInputDef inpDef)
      throws SemanticException {
    RowResolver rr = new RowResolver();
    RowResolver inputRR = inpDef.getOutputShape().getRr();

    evaluator.inputColumnNamesMap = new HashMap<String, String>();
    ArrayList<String> inputColumnNames = new ArrayList<String>();

    ArrayList<ObjectInspector> inpColOIs = new ArrayList<ObjectInspector>();

    for (ColumnInfo inpCInfo : inputRR.getColumnInfos()) {
      ColumnInfo cInfo = new ColumnInfo(inpCInfo);
      String colAlias = cInfo.getAlias();

      String[] tabColAlias = inputRR.reverseLookup(inpCInfo.getInternalName());
      if (tabColAlias != null) {
        colAlias = tabColAlias[1];
      }
      ASTNode inExpr = null;
      inExpr = PTFTranslator.getASTNode(inpCInfo, inputRR);
      if (inExpr != null) {
        rr.putExpression(inExpr, cInfo);
        colAlias = inExpr.toStringTree().toLowerCase();
      } else {
        colAlias = colAlias == null ? cInfo.getInternalName() : colAlias;
        rr.put(cInfo.getTabAlias(), colAlias, cInfo);
      }

      evaluator.inputColumnNamesMap.put(cInfo.getInternalName(), colAlias);
      inputColumnNames.add(colAlias);
      inpColOIs.add(cInfo.getObjectInspector());
    }

    StandardListObjectInspector pathAttrOI =
        ObjectInspectorFactory.getStandardListObjectInspector(
            ObjectInspectorFactory.getStandardStructObjectInspector(inputColumnNames, inpColOIs));

    ColumnInfo pathColumn =
        new ColumnInfo(
            PATHATTR_NAME,
            TypeInfoUtils.getTypeInfoFromObjectInspector(pathAttrOI),
            null,
            false,
            false);
    rr.put(null, PATHATTR_NAME, pathColumn);

    return rr;
  }
Example #10
0
 @Nonnull
 public static String[] getConstStringArray(@Nonnull final ObjectInspector oi)
     throws UDFArgumentException {
   if (!ObjectInspectorUtils.isConstantObjectInspector(oi)) {
     throw new UDFArgumentException(
         "argument must be a constant value: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi));
   }
   ConstantObjectInspector constOI = (ConstantObjectInspector) oi;
   final List<?> lst = (List<?>) constOI.getWritableConstantValue();
   final int size = lst.size();
   final String[] ary = new String[size];
   for (int i = 0; i < size; i++) {
     Object o = lst.get(i);
     if (o != null) {
       ary[i] = o.toString();
     }
   }
   return ary;
 }
Example #11
0
 private static ArrayList<? extends Object>[] getTypeMap(StructObjectInspector oi) {
   StructTypeInfo t = (StructTypeInfo) TypeInfoUtils.getTypeInfoFromObjectInspector(oi);
   ArrayList<String> fnames = t.getAllStructFieldNames();
   ArrayList<TypeInfo> fields = t.getAllStructFieldTypeInfos();
   return new ArrayList<?>[] {fnames, fields};
 }
Example #12
0
 static StructTypeInfo typeInfo(StructObjectInspector inspector) {
   return (StructTypeInfo) TypeInfoUtils.getTypeInfoFromObjectInspector(inspector);
 }