예제 #1
0
 private Date convertToDate(
     PrimitiveCategory inputType, Converter converter, DeferredObject argument)
     throws HiveException {
   assert (converter != null);
   assert (argument != null);
   if (argument.get() == null) {
     return null;
   }
   Date date = new Date();
   switch (inputType) {
     case STRING:
     case VARCHAR:
     case CHAR:
       String dateString = converter.convert(argument.get()).toString();
       try {
         date = formatter.parse(dateString);
       } catch (ParseException e) {
         return null;
       }
       break;
     case TIMESTAMP:
       Timestamp ts = ((TimestampWritable) converter.convert(argument.get())).getTimestamp();
       date.setTime(ts.getTime());
       break;
     case DATE:
       DateWritable dw = (DateWritable) converter.convert(argument.get());
       date = dw.get();
       break;
     default:
       throw new UDFArgumentException(
           "TO_DATE() only takes STRING/TIMESTAMP/DATEWRITABLE types, got " + inputType);
   }
   return date;
 }
예제 #2
0
 /**
  * Converts the skewedValue available as a string in the metadata to the appropriate object by
  * using the type of the column from the join key.
  *
  * @param skewedValue
  * @param keyCol
  * @return an expression node descriptor of the appropriate constant
  */
 private ExprNodeConstantDesc createConstDesc(String skewedValue, ExprNodeColumnDesc keyCol) {
   ObjectInspector inputOI =
       TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(TypeInfoFactory.stringTypeInfo);
   ObjectInspector outputOI =
       TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(keyCol.getTypeInfo());
   Converter converter = ObjectInspectorConverters.getConverter(inputOI, outputOI);
   Object skewedValueObject = converter.convert(skewedValue);
   return new ExprNodeConstantDesc(keyCol.getTypeInfo(), skewedValueObject);
 }
예제 #3
0
    @Override
    protected SymbolFunctionResult match(Object row, PTFPartitionIterator<Object> pItr)
        throws HiveException {
      Object val = null;
      val = symbolExprEval.evaluate(row);
      val = converter.convert(val);
      result.matches = ((Boolean) val).booleanValue();
      result.nextRow = pItr.getIndex();

      return result;
    }
예제 #4
0
파일: MapOperator.java 프로젝트: Leolh/hive
 private Object readRow(Writable value, ExecMapperContext context) throws SerDeException {
   Object deserialized = deserializer.deserialize(value);
   Object row = partTblObjectInspectorConverter.convert(deserialized);
   if (hasVC()) {
     rowWithPartAndVC[0] = row;
     if (context != null) {
       populateVirtualColumnValues(context, vcs, vcValues, deserializer);
     }
     int vcPos = isPartitioned() ? 2 : 1;
     rowWithPartAndVC[vcPos] = vcValues;
     return rowWithPartAndVC;
   } else if (isPartitioned()) {
     rowWithPart[0] = row;
     return rowWithPart;
   }
   return row;
 }