org.apache.hadoop.hive.common.type.Date.toEpochMilli()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(212)

本文整理了Java中org.apache.hadoop.hive.common.type.Date.toEpochMilli()方法的一些代码示例,展示了Date.toEpochMilli()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Date.toEpochMilli()方法的具体详情如下:
包路径:org.apache.hadoop.hive.common.type.Date
类名称:Date
方法名:toEpochMilli

Date.toEpochMilli介绍

暂无

代码示例

代码示例来源:origin: apache/hive

public static long daysToMillis(int days) {
 return Date.ofEpochDay(days).toEpochMilli();
}

代码示例来源:origin: apache/hive

private Calendar addMonth(Date d, int numMonths) {
 calendar.setTimeInMillis(d.toEpochMilli());
 return addMonth(numMonths);
}

代码示例来源:origin: apache/hive

public IntWritable evaluate(DateWritableV2 d) {
 if (d == null) {
  return null;
 }
 Date date = d.get();
 calendar.setTimeInMillis(date.toEpochMilli());
 result.set(calendar.get(Calendar.WEEK_OF_YEAR));
 return result;
}

代码示例来源:origin: apache/hive

@Override
public boolean isDistanceGreater(Object v1, Object v2, int amt) {
 Date l1 = PrimitiveObjectInspectorUtils.getDate(v1,
   (PrimitiveObjectInspector) expressionDef.getOI());
 Date l2 = PrimitiveObjectInspectorUtils.getDate(v2,
   (PrimitiveObjectInspector) expressionDef.getOI());
 if (l1 != null && l2 != null) {
   return (double)(l1.toEpochMilli() - l2.toEpochMilli())/1000 > (long)amt * 24 * 3600; // Converts amt days to milliseconds
 }
 return l1 != l2; // True if only one date is null
}

代码示例来源:origin: apache/hive

/**
 * Get the week of the year from a date string.
 *
 * @param dateString
 *          the dateString in the format of "yyyy-MM-dd HH:mm:ss" or
 *          "yyyy-MM-dd".
 * @return an int from 1 to 53. null if the dateString is not a valid date
 *         string.
 */
public IntWritable evaluate(Text dateString) {
 if (dateString == null) {
  return null;
 }
 try {
  Date date = Date.valueOf(dateString.toString());
  calendar.setTimeInMillis(date.toEpochMilli());
  result.set(calendar.get(Calendar.WEEK_OF_YEAR));
  return result;
 } catch (IllegalArgumentException e) {
  return null;
 }
}

代码示例来源:origin: apache/hive

public boolean parseDate(String strValue, Date result) {
  Date parsedVal;
  try {
   parsedVal = Date.valueOf(strValue);
  } catch (IllegalArgumentException e) {
   parsedVal = null;
  }
  if (parsedVal == null) {
   return false;
  }
  result.setTimeInMillis(parsedVal.toEpochMilli());
  return true;
 }
}

代码示例来源:origin: apache/hive

protected void evaluateString(ColumnVector columnVector, LongColumnVector outputVector, int i) {
 BytesColumnVector bcv = (BytesColumnVector) columnVector;
 text.set(bcv.vector[i], bcv.start[i], bcv.length[i]);
 org.apache.hadoop.hive.common.type.Date hDate = new org.apache.hadoop.hive.common.type.Date();
 boolean parsed = dateParser.parseDate(text.toString(), hDate);
 if (!parsed) {
  outputVector.noNulls = false;
  outputVector.isNull[i] = true;
  return;
 }
 long days = DateWritableV2.millisToDays(hDate.toEpochMilli());
 if (isPositive) {
  days += numDays;
 } else {
  days -= numDays;
 }
 outputVector.vector[i] = days;
}

代码示例来源:origin: apache/hive

protected void evaluateString(BytesColumnVector inputColumnVector1, LongColumnVector outputVector, int index, long numDays) {
 if (inputColumnVector1.isNull[index]) {
  outputVector.noNulls = false;
  outputVector.isNull[index] = true;
 } else {
  text.set(inputColumnVector1.vector[index], inputColumnVector1.start[index], inputColumnVector1.length[index]);
  Date hDate = new Date();
  boolean parsed = dateParser.parseDate(text.toString(), hDate);
  if (!parsed) {
   outputVector.noNulls = false;
   outputVector.isNull[index] = true;
   return;
  }
  long days = DateWritableV2.millisToDays(hDate.toEpochMilli());
  if (isPositive) {
   days += numDays;
  } else {
   days -= numDays;
  }
  outputVector.vector[index] = days;
 }
}

代码示例来源:origin: apache/hive

public boolean add(Date dt, HiveIntervalYearMonth interval, Date result) {
 if (dt == null || interval == null) {
  return false;
 }
 long resultMillis = addMonthsToMillis(dt.toEpochMilli(), interval.getTotalMonths());
 result.setTimeInMillis(resultMillis);
 return true;
}

代码示例来源:origin: apache/hive

@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
 if (formatter == null) {
  return null;
 }
 // the function should support both short date and full timestamp format
 // time part of the timestamp should not be skipped
 Timestamp ts = getTimestampValue(arguments, 0, tsConverters);
 if (ts == null) {
  Date d = getDateValue(arguments, 0, dtInputTypes, dtConverters);
  if (d == null) {
   return null;
  }
  ts = Timestamp.ofEpochMilli(d.toEpochMilli());
 }
 date.setTime(ts.toEpochMilli());
 String res = formatter.format(date);
 if (res == null) {
  return null;
 }
 output.set(res);
 return output;
}

代码示例来源:origin: apache/hive

public boolean add(HiveIntervalYearMonth interval, Date dt, Date result) {
 if (dt == null || interval == null) {
  return false;
 }
 long resultMillis = addMonthsToMillis(dt.toEpochMilli(), interval.getTotalMonths());
 result.setTimeInMillis(resultMillis);
 return true;
}

代码示例来源:origin: apache/hive

protected void evaluateRepeatedString(BytesColumnVector inputColumnVector1,
  long[] vector2, LongColumnVector outputVector,
  boolean selectedInUse, int[] selected, int n) {
 if (inputColumnVector1.isNull[0]) {
  outputVector.noNulls = false;
  outputVector.isNull[0] = true;
  outputVector.isRepeating = true;
  return;
 }
 text.set(
   inputColumnVector1.vector[0], inputColumnVector1.start[0], inputColumnVector1.length[0]);
 Date date = new Date();
 boolean parsed = dateParser.parseDate(text.toString(), date);
 if (!parsed) {
  outputVector.noNulls = false;
  outputVector.isNull[0] = true;
  outputVector.isRepeating = true;
  return;
 }
 long days = DateWritableV2.millisToDays(date.toEpochMilli());
 evaluateRepeatedCommon(days, vector2, outputVector, selectedInUse, selected, n);
}

代码示例来源:origin: apache/hive

return null;
date1 = Timestamp.ofEpochMilli(date.toEpochMilli());
 return null;
date2 = Timestamp.ofEpochMilli(date.toEpochMilli());

代码示例来源:origin: apache/hive

@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
 switch (inputTypes[0]) {
  case INTERVAL_YEAR_MONTH:
   HiveIntervalYearMonth intervalYearMonth = getIntervalYearMonthValue(arguments, 0, inputTypes, converters);
   if (intervalYearMonth == null) {
    return null;
   }
   output.set(intervalYearMonth.getYears());
   break;
  case STRING:
  case CHAR:
  case VARCHAR:
  case DATE:
  case TIMESTAMP:
  case TIMESTAMPLOCALTZ:
  case VOID:
   Date date = getDateValue(arguments, 0, inputTypes, converters);
   if (date == null) {
    return null;
   }
   calendar.setTimeInMillis(date.toEpochMilli());
   output.set(calendar.get(Calendar.YEAR));
 }
 return output;
}

代码示例来源:origin: apache/hive

@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
 switch (inputTypes[0]) {
  case INTERVAL_YEAR_MONTH:
   HiveIntervalYearMonth intervalYearMonth = getIntervalYearMonthValue(arguments, 0, inputTypes, converters);
   if (intervalYearMonth == null) {
    return null;
   }
   output.set(intervalYearMonth.getMonths());
   break;
  case STRING:
  case CHAR:
  case VARCHAR:
  case DATE:
  case TIMESTAMP:
  case TIMESTAMPLOCALTZ:
  case VOID:
   Date date = getDateValue(arguments, 0, inputTypes, converters);
   if (date == null) {
    return null;
   }
   calendar.setTimeInMillis(date.toEpochMilli());
   output.set(1 + calendar.get(Calendar.MONTH));
 }
 return output;
}

代码示例来源:origin: apache/hive

@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
 switch (inputTypes[0]) {
  case INTERVAL_DAY_TIME:
   HiveIntervalDayTime intervalDayTime = getIntervalDayTimeValue(arguments, 0, inputTypes, converters);
   if (intervalDayTime == null) {
    return null;
   }
   output.set(intervalDayTime.getDays());
   break;
  case STRING:
  case CHAR:
  case VARCHAR:
  case DATE:
  case TIMESTAMP:
  case TIMESTAMPLOCALTZ:
  case VOID:
   Date date = getDateValue(arguments, 0, inputTypes, converters);
   if (date == null) {
    return null;
   }
   calendar.setTimeInMillis(date.toEpochMilli());
   output.set(calendar.get(Calendar.DAY_OF_MONTH));
 }
 return output;
}

代码示例来源:origin: apache/hive

public static Timestamp stringToTimestamp(String s) {
  s = s.trim();
  // Handle simpler cases directly avoiding exceptions
  if (s.length() == DATE_LENGTH) {
   // Its a date!
   return Timestamp.ofEpochMilli(Date.valueOf(s).toEpochMilli());
  }
  try {
   return Timestamp.valueOf(s);
  } catch (IllegalArgumentException eT) {
   // Try zoned timestamp
   try {
    return Timestamp.valueOf(
      TimestampTZUtil.parse(s).getZonedDateTime().toLocalDateTime().toString());
   } catch (IllegalArgumentException | DateTimeParseException eTZ) {
    // Last attempt
    return Timestamp.ofEpochMilli(Date.valueOf(s).toEpochMilli());
   }
  }
 }
}

代码示例来源:origin: apache/hive

long baseDateDays = DateWritableV2.millisToDays(baseDate.toEpochMilli());
if (inputCol.isRepeating) {
 if (inputCol.noNulls || !inputCol.isNull[0]) {

代码示例来源:origin: apache/hive

Assert.assertEquals(adt.get().toEpochMilli(),
  DateWritableV2.daysToMillis((int) b));

代码示例来源:origin: apache/hive

case DATE:
 result = Timestamp.ofEpochMilli(
   ((DateObjectInspector) inputOI).getPrimitiveWritableObject(o).get().toEpochMilli());
 break;
case TIMESTAMP:

相关文章