public static String formatToCompactDateStr(long millis) { return formatToDateStr(millis, COMPACT_DATE_PATTERN); }
public static String formatToDateStr(long millis) { return formatToDateStr(millis, DEFAULT_DATE_PATTERN); }
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)); }
private static String datePlus(String date, int plusDays) { long millis = DateFormat.stringToMillis(date); millis += (1000L * 3600L * 24L) * plusDays; return DateFormat.formatToDateStr(millis); }
@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(); } }
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 + "'"); }
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(")");
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:
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"); } } }
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; }
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()); } }
private void checkPair(String dateStr) { long id = encode(dateStr); String millisStr = decode(id); String dateStrBack = DateFormat.formatToDateStr(Long.parseLong(millisStr)); assertEquals(dateStr, dateStrBack); }
@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()); }
@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(); } }
public static String formatToCompactDateStr(long millis) { return formatToDateStr(millis, COMPACT_DATE_PATTERN); }
public static String formatToDateStr(long millis) { return formatToDateStr(millis, DEFAULT_DATE_PATTERN); }
public static String formatToDateStr(long millis) { return formatToDateStr(millis, DEFAULT_DATE_PATTERN); }
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)); }
private static String datePlus(String date, int plusDays) { long millis = DateFormat.stringToMillis(date); millis += (1000L * 3600L * 24L) * plusDays; return DateFormat.formatToDateStr(millis); }
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; }