org.apache.hadoop.hive.common.type.Date类的使用及代码示例

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

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

Date介绍

[英]This is the internal type for Date. The full qualified input format of Date is "yyyy-MM-dd".
[中]这是日期的内部类型。日期的完整限定输入格式为“yyyy-MM-dd”。

代码示例

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

public static Date getRandDate(Random r) {
 String dateStr = String.format("%d-%02d-%02d",
   Integer.valueOf(1800 + r.nextInt(500)),  // year
   Integer.valueOf(1 + r.nextInt(12)),      // month
   Integer.valueOf(1 + r.nextInt(28)));     // day
 Date dateVal = Date.valueOf(dateStr);
 return dateVal;
}

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

@Override
public String vectorExpressionParameters() {
 Date dt = Date.ofEpochMilli(DateWritableV2.daysToMillis((int) value));
 return  "date " + dt.toString() + ", " + getColumnParamString(0, colNum);
}

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

@Override
public String vectorExpressionParameters() {
 String value;
 if (object instanceof Long) {
  Date tempDate = new Date();
  tempDate.setTimeInMillis(DateWritableV2.daysToMillis((int) longValue));
  value = tempDate.toString();
 } else if (object instanceof Timestamp) {
  value = org.apache.hadoop.hive.common.type.Timestamp.ofEpochMilli(
    timestampValue.getTime(), timestampValue.getNanos()).toString();
 } else if (object instanceof byte []) {
  value = new String(this.stringValue, StandardCharsets.UTF_8);
 } else {
  value = "unknown";
 }
 return "val " + value + ", " + getColumnParamString(0, colNum);
}

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

@Override
Date transform(final Date value) {
 int actualMonthValue = maskedMonthValue + 1;
 int year  = maskedYearValue  == UNMASKED_VAL ? value.getYear()  : maskedYearValue;
 int month = maskedMonthValue == UNMASKED_VAL ? value.getMonth() : actualMonthValue;
 int day   = maskedDayValue   == UNMASKED_VAL ? value.getDay()  : maskedDayValue;
 return Date.of(year, month, day);
}

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

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

代码示例来源: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

/**
 * 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

/**
 * Write DATE.
 * The representation of date in Teradata binary format is:
 * The Date D is a int with 4 bytes using little endian.
 * The representation is (YYYYMMDD - 19000000).toInt -> D
 * eg. 1911.11.11 -> 19111111 -> 111111 -> 07 b2 01 00 in little endian.
 * the null date will use 0 to pad.
 *
 * @param date the date
 * @throws IOException the io exception
 */
public void writeDate(DateWritableV2 date) throws IOException {
 if (date == null) {
  EndianUtils.writeSwappedInteger(this, 0);
  return;
 }
 int toWrite = date.get().getYear() * 10000 + date.get().getMonth() * 100 + date.get().getDay() - 19000000;
 EndianUtils.writeSwappedInteger(this, toWrite);
}

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

@Override
public String toString() {
 return date.toString();
}

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

/**
 * Return a copy of this object.
 */
public Object clone() {
 // LocalDateTime is immutable.
 return new Date(this.localDate);
}

代码示例来源: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 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

private Date evalDate(Date d) throws UDFArgumentException {
 date.setTimeInDays(d.toEpochDay());
 if ("MONTH".equals(fmtInput) || "MON".equals(fmtInput) || "MM".equals(fmtInput)) {
  date.setDayOfMonth(1);
  return date;
 } else if ("QUARTER".equals(fmtInput) || "Q".equals(fmtInput)) {
  int month = date.getMonth() - 1;
  int quarter = month / 3;
  int monthToSet = quarter * 3 + 1;
  date.setMonth(monthToSet);
  date.setDayOfMonth(1);
  return date;
 } else if ("YEAR".equals(fmtInput) || "YYYY".equals(fmtInput) || "YY".equals(fmtInput)) {
  date.setMonth(1);
  date.setDayOfMonth(1);
  return date;
 } else {
  return null;
 }
}

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

@Deprecated
public Object create(java.sql.Date value) {
 return Date.ofEpochMilli(value.getTime());
}

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

if (!value.equals(expected)) {
 TestCase.fail("Date field mismatch (expected " + expected.toString() + " found " + value.toString() + ")");

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

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

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

org.apache.hadoop.hive.common.type.Date date = new org.apache.hadoop.hive.common.type.Date();
date.setTimeInMillis(d.getTime());
return new DateWritableV2(date);

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

/**
 * Perform date + int operation .
 * @param dt the date
 * @param interval the int (days)
 * @return the resulting date
 */
public Date add(Date dt, int interval) {
 if (dt == null) {
  return null;
 }
 Date dtResult = new Date();
 dtResult.setTimeInDays(dt.toEpochDay() + interval);
 return dtResult;
}

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

public void testDate() throws HiveException {
 GenericUDFToUnixTimeStamp udf = new GenericUDFToUnixTimeStamp();
 ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
 ObjectInspector[] arguments = {valueOI};
 udf.initialize(arguments);
 Date date = Date.valueOf("1970-01-01");
 runAndVerify(udf,
   new DateWritableV2(date),
   new LongWritable(date.toEpochSecond()));
 // test null values
 runAndVerify(udf, null, null);
}

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

/**
 * Read DATE.
 * The representation of date in Teradata binary format is:
 * The Date D is a int with 4 bytes using little endian,
 * The representation is (D+19000000).ToString -> YYYYMMDD,
 * eg: Date 07 b2 01 00 -> 111111 in little endian -> 19111111 - > 1911.11.11.
 * the null date will use 0 to pad.
 *
 * @return the date
 * @throws IOException the io exception
 * @throws ParseException the parse exception
 */
public Date readDate() throws IOException, ParseException {
 int di = readInt();
 if (di == 0) {
  return null;
 }
 String dateString = String.valueOf(di + 19000000);
 if (dateString.length() < DATE_STRING_LENGTH) {
  dateString = StringUtils.leftPad(dateString, DATE_STRING_LENGTH, '0');
 }
 Date date = new Date();
 date.setYear(Integer.parseInt(dateString.substring(0, 4)));
 date.setMonth(Integer.parseInt(dateString.substring(4, 6)));
 date.setDayOfMonth(Integer.parseInt(dateString.substring(6, 8)));
 return date;
}

相关文章