org.apache.kylin.common.util.DateFormat.formatToDateStr()方法的使用及代码示例

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

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

DateFormat.formatToDateStr介绍

暂无

代码示例

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

public static String formatToCompactDateStr(long millis) {
  return formatToDateStr(millis, COMPACT_DATE_PATTERN);
}

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

public static String formatToDateStr(long millis) {
  return formatToDateStr(millis, DEFAULT_DATE_PATTERN);
}

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

private static void buildSingleColumnRangeCondAsYmdInt(StringBuilder builder, TblColRef partitionColumn,
                            long startInclusive, long endExclusive, String partitionColumnDateFormat) {
  String partitionColumnName = partitionColumn.getIdentity();
  builder.append(partitionColumnName + " >= "
      + DateFormat.formatToDateStr(startInclusive, partitionColumnDateFormat));
  builder.append(" AND ");
  builder.append(
      partitionColumnName + " < " + DateFormat.formatToDateStr(endExclusive, partitionColumnDateFormat));
}

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

private static String datePlus(String date, int plusDays) {
  long millis = DateFormat.stringToMillis(date);
  millis += (1000L * 3600L * 24L) * plusDays;
  return DateFormat.formatToDateStr(millis);
}

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

@Override
  public String buildDateRangeCondition(PartitionDesc partDesc, ISegment seg, SegmentRange segRange) {
    long startInclusive = (Long) segRange.start.v;
    long endExclusive = (Long) segRange.end.v;
    TblColRef partitionColumn = partDesc.getPartitionDateColumnRef();
    String tableAlias = partitionColumn.getTableAlias();
    String concatField = String.format(Locale.ROOT, "CONCAT(%s.YEAR,'-',%s.MONTH,'-',%s.DAY)", tableAlias,
        tableAlias, tableAlias);
    StringBuilder builder = new StringBuilder();
    if (startInclusive > 0) {
      builder.append(concatField + " >= '" + DateFormat.formatToDateStr(startInclusive) + "' ");
      builder.append("AND ");
    }
    builder.append(concatField + " < '" + DateFormat.formatToDateStr(endExclusive) + "'");
    return builder.toString();
  }
}

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

private static void buildSingleColumnRangeCondition(StringBuilder builder, TblColRef partitionColumn,
                          long startInclusive, long endExclusive, String partitionColumnDateFormat) {
  String partitionColumnName = partitionColumn.getIdentity();
  if (endExclusive <= startInclusive) {
    builder.append("1=0");
    return;
  }
  String startInc = null;
  String endInc = null;
  if (StringUtils.isBlank(partitionColumnDateFormat)) {
    startInc = String.valueOf(startInclusive);
    endInc = String.valueOf(endExclusive);
  } else {
    startInc = DateFormat.formatToDateStr(startInclusive, partitionColumnDateFormat);
    endInc = DateFormat.formatToDateStr(endExclusive, partitionColumnDateFormat);
  }
  builder.append(partitionColumnName + " >= '" + startInc + "'");
  builder.append(" AND ");
  builder.append(partitionColumnName + " < '" + endInc + "'");
}

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

builder.append("(");
builder.append(partitionDateColumnName + " = " + singleQuotation
    + DateFormat.formatToDateStr(startInclusive, partitionColumnDateFormat) + singleQuotation).append(" AND ")
    .append(partitionTimeColumnName + " >= '"
        + DateFormat.formatToDateStr(startInclusive, partitionColumnTimeFormat) + "'");
builder.append(")");
builder.append(" OR ");
builder.append("(");
builder.append(partitionDateColumnName + " > " + singleQuotation
    + DateFormat.formatToDateStr(startInclusive, partitionColumnDateFormat) + singleQuotation);
builder.append(")");
builder.append(")");
builder.append("(");
builder.append(partitionDateColumnName + " = " + singleQuotation
    + DateFormat.formatToDateStr(endExclusive, partitionColumnDateFormat) + singleQuotation).append(" AND ")
    .append(partitionTimeColumnName + " < '"
        + DateFormat.formatToDateStr(endExclusive, partitionColumnTimeFormat) + "'");
builder.append(")");
builder.append(" OR ");
builder.append("(");
builder.append(partitionDateColumnName + " < " + singleQuotation
    + DateFormat.formatToDateStr(endExclusive, partitionColumnDateFormat) + singleQuotation);
builder.append(")");
builder.append(")");

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

case 3:
  normalized = TimeUtil.getDayStart(t);
  result.add(DateFormat.formatToDateStr(normalized));
  break;
case 4:
  normalized = TimeUtil.getWeekStart(t);
  result.add(DateFormat.formatToDateStr(normalized));
  break;
case 5:
  normalized = TimeUtil.getMonthStart(t);
  result.add(DateFormat.formatToDateStr(normalized));
  break;
case 6:
  normalized = TimeUtil.getQuarterStart(t);
  result.add(DateFormat.formatToDateStr(normalized));
  break;
case 7:
  normalized = TimeUtil.getYearStart(t);
  result.add(DateFormat.formatToDateStr(normalized));
  break;
default:

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

private String formatTime(String dateStr, DataType dataType) {
    if (dataType.isDatetime() || dataType.isTime()) {
      throw new RuntimeException("Datetime and time type are not supported yet");
    }

    if (DateFormat.isSupportedDateFormat(dateStr)) {
      return dateStr;
    }

    long millis = Long.parseLong(dateStr);
    if (dataType.isTimestamp()) {
      return DateFormat.formatToTimeStr(millis);
    } else if (dataType.isDate()) {
      return DateFormat.formatToDateStr(millis);
    } else {
      throw new RuntimeException("Unknown type " + dataType + " to formatTime");
    }
  }
}

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

private String tsRangeToStr(long ts, PartitionDesc part) {
  String value;
  DataType partitionColType = part.getPartitionDateColumnRef().getType();
  if (partitionColType.isDate()) {
    value = DateFormat.formatToDateStr(ts);
  } else if (partitionColType.isTimeFamily()) {
    value = DateFormat.formatToTimeWithoutMilliStr(ts);
  } else if (partitionColType.isStringFamily() || partitionColType.isIntegerFamily()) {//integer like 20160101
    String partitionDateFormat = part.getPartitionDateFormat();
    if (StringUtils.isEmpty(partitionDateFormat)) {
      value = "" + ts;
    } else {
      value = DateFormat.formatToDateStr(ts, partitionDateFormat);
    }
  } else {
    throw new RuntimeException("Type " + partitionColType + " is not valid partition column type");
  }
  return value;
}

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

private ByteArray encodeTime(long ts, int index, int roundingFlag) {
    String value;
    DataType partitionColType = info.getColumnType(index);
    if (partitionColType.isDate()) {
      value = DateFormat.formatToDateStr(ts);
    } else if (partitionColType.isTimeFamily()) {
      value = DateFormat.formatToTimeWithoutMilliStr(ts);
    } else if (partitionColType.isStringFamily() || partitionColType.isIntegerFamily()) {//integer like 20160101
      String partitionDateFormat = segment.getModel().getPartitionDesc().getPartitionDateFormat();
      if (StringUtils.isEmpty(partitionDateFormat)) {
        value = "" + ts;
      } else {
        value = DateFormat.formatToDateStr(ts, partitionDateFormat);
      }
    } else {
      throw new RuntimeException("Type " + partitionColType + " is not valid partition column type");
    }

    ByteBuffer buffer = ByteBuffer.allocate(info.getMaxColumnLength());
    info.getCodeSystem().encodeColumnValue(index, value, roundingFlag, buffer);

    return ByteArray.copyOf(buffer.array(), 0, buffer.position());
  }
}

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

private void checkPair(String dateStr) {
  long id = encode(dateStr);
  String millisStr = decode(id);
  String dateStrBack = DateFormat.formatToDateStr(Long.parseLong(millisStr));
  assertEquals(dateStr, dateStrBack);
}

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

@Test
public void testMapRange2() throws Exception {
  Pair<String, String> results = lookupTable.mapRange("WEEK_BEG_DT", millis("2013-05-01"), millis("2013-08-01"), "CAL_DT");
  System.out.println(DateFormat.formatToDateStr(Long.parseLong(results.getFirst())));
  System.out.println(DateFormat.formatToDateStr(Long.parseLong(results.getSecond())));
  Assert.assertEquals(millis("2013-05-05"), results.getFirst());
  Assert.assertEquals(millis("2013-08-03"), results.getSecond());
}

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

@Override
public String next() {
  if (type.isStringFamily()) {
    // string
    return format.replace(ColumnGenConfig.$RANDOM, "" + randomInt());
  } else if (type.isTimeFamily()) {
    // time
    return DateFormat.formatToTimeStr(randomMillis(), format);
  } else if (type.isDateTimeFamily()) {
    // date
    return DateFormat.formatToDateStr(randomMillis(), format);
  } else if (type.isIntegerFamily()) {
    // integer
    return formatNumber(randomInt());
  } else if (type.isNumberFamily()) {
    // double
    return formatNumber(randomDouble());
  } else {
    throw new IllegalStateException();
  }
}

代码示例来源:origin: org.apache.kylin/kylin-core-common

public static String formatToCompactDateStr(long millis) {
  return formatToDateStr(millis, COMPACT_DATE_PATTERN);
}

代码示例来源:origin: org.apache.kylin/kylin-common

public static String formatToDateStr(long millis) {
  return formatToDateStr(millis, DEFAULT_DATE_PATTERN);
}

代码示例来源:origin: org.apache.kylin/kylin-core-common

public static String formatToDateStr(long millis) {
  return formatToDateStr(millis, DEFAULT_DATE_PATTERN);
}

代码示例来源:origin: org.apache.kylin/kylin-core-metadata

private static void buildSingleColumnRangeCondAsYmdInt(StringBuilder builder, TblColRef partitionColumn,
                            long startInclusive, long endExclusive, String partitionColumnDateFormat) {
  String partitionColumnName = partitionColumn.getIdentity();
  builder.append(partitionColumnName + " >= "
      + DateFormat.formatToDateStr(startInclusive, partitionColumnDateFormat));
  builder.append(" AND ");
  builder.append(
      partitionColumnName + " < " + DateFormat.formatToDateStr(endExclusive, partitionColumnDateFormat));
}

代码示例来源:origin: org.apache.kylin/kylin-core-cube

private static String datePlus(String date, int plusDays) {
  long millis = DateFormat.stringToMillis(date);
  millis += (1000L * 3600L * 24L) * plusDays;
  return DateFormat.formatToDateStr(millis);
}

代码示例来源:origin: org.apache.kylin/kylin-metadata

private static String formatTimeStr(DataType type, long ts) {
  String ret;
  if (type == DataType.getInstance("date")) {
    ret = DateFormat.formatToDateStr(ts);
  } else if (type == DataType.getInstance("long")) {
    ret = String.valueOf(ts);
  } else {
    throw new IllegalArgumentException("Illegal type for partition column " + type);
  }
  return ret;
}

相关文章