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

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

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

DateFormat.stringToMillis介绍

暂无

代码示例

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

@Override
public long valueToCode(String value) {
  long millis = DateFormat.stringToMillis(value);
  return millis / 1000;
}

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

private static int dateToEpicDays(String strValue) {
  long millis = DateFormat.stringToMillis(strValue);
  return (int) (millis / (1000 * 3600 * 24));
}

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

@Override
protected String[] convertRow(String[] cols) {
  for (int i = 0; i < cols.length; i++) {
    if (colIsDateTime[i]) {
      if (cols[i] != null)
        cols[i] = String.valueOf(DateFormat.stringToMillis(cols[i]));
    }
  }
  return cols;
}

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

@Override
  public Long toComparable(String s) {
    if (s == null || s.isEmpty())
      return null;
    else
      return DateFormat.stringToMillis(s);
  }
}

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

@Override
public boolean addValue(String value) {
  if (StringUtils.isBlank(value)) // empty string is treated as null
    return false;
  // check the time format
  DateFormat.stringToMillis(value);
  return true;
}

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

@Override
public Long valueOf(String str) {
  return Long.valueOf(DateFormat.stringToMillis(str));
}

代码示例来源: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
protected int getIdFromValueImpl(String value, int roundingFlag) {
  long millis = DateFormat.stringToMillis(value);
  long seconds = millis / 1000;
  if (seconds > MAX_ID) {
    return nullId();
  } else if (seconds < 0) {
    throw new IllegalArgumentException("Illegal value: " + value + ", parsed seconds: " + seconds);
  }
  return (int) seconds;
}

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

@Override
public long valueToCode(String value) {
  //if data type is integer, DateFormat.stringToMillis recognizes format like "20001010"
  long millis = DateFormat.stringToMillis(value);
  return getNumOfDaysSince0000FromMillis(millis);
}

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

private String millis(String dateStr) {
  return String.valueOf(DateFormat.stringToMillis(dateStr));
}

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

private String millis(String dateStr) {
  return String.valueOf(DateFormat.stringToMillis(dateStr));
}

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

case "datetime":
case "timestamp":
  return Long.valueOf(DateFormat.stringToMillis(strValue));
case "tinyint":
  return Byte.valueOf(strValue);

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

private TupleFilter cast(TupleFilter filter, RelDataType type) {
  if ((filter instanceof ConstantTupleFilter) == false) {
    return filter;
  }
  ConstantTupleFilter constFilter = (ConstantTupleFilter) filter;
  if (type.getFamily() == SqlTypeFamily.DATE || type.getFamily() == SqlTypeFamily.DATETIME
      || type.getFamily() == SqlTypeFamily.TIMESTAMP) {
    List<String> newValues = Lists.newArrayList();
    for (Object v : constFilter.getValues()) {
      if (v == null)
        newValues.add(null);
      else
        newValues.add(String.valueOf(DateFormat.stringToMillis(v.toString())));
    }
    constFilter = new ConstantTupleFilter(newValues);
  }
  return constFilter;
}

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

private void bindVariable(TupleFilter filter, DataContext dataContext) {
  if (filter == null) {
    return;
  }
  for (TupleFilter childFilter : filter.getChildren()) {
    bindVariable(childFilter, dataContext);
  }
  if (filter instanceof CompareTupleFilter && dataContext != null) {
    CompareTupleFilter compFilter = (CompareTupleFilter) filter;
    for (Map.Entry<String, Object> entry : compFilter.getVariables().entrySet()) {
      String variable = entry.getKey();
      Object value = dataContext.get(variable);
      if (value != null) {
        String str = value.toString();
        if (compFilter.getColumn().getType().isDateTimeFamily())
          str = String.valueOf(DateFormat.stringToMillis(str));
        compFilter.clearPreviousVariableValues(variable);
        compFilter.bindVariable(variable, str);
      }
    }
  }
}
// ============================================================================

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

System.out.println(org.apache.kylin.common.util.DateFormat.stringToMillis("2015-06-01 00:00:00"));
System.out.println(org.apache.kylin.common.util.DateFormat.stringToMillis("2015-05-15 17:00:00"));

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

public void encodeDecode(String origin) {
  long a = encode(origin);
  String back = decode(a);
  String originChoppingMilis = DateFormat.formatToTimeWithoutMilliStr(DateFormat.stringToMillis(origin));
  String backMillis = DateFormat.formatToTimeWithoutMilliStr(Long.parseLong(back));
  Assert.assertEquals(originChoppingMilis, backMillis);
}

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

public void encodeDecode(String origin) {
  int a = dict.getIdFromValue(origin);
  String back = dict.getValueFromId(a);
  String originChoppingMilis = DateFormat.formatToTimeWithoutMilliStr(DateFormat.stringToMillis(origin));
  Assert.assertEquals(originChoppingMilis, back);
}

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

@Test
public void testTimePartition() {
  PartitionDesc partitionDesc = new PartitionDesc();
  TblColRef col = TblColRef.mockup(TableDesc.mockup("DEFAULT.TABLE_NAME"), 2, "HOUR_COLUMN", "string");
  partitionDesc.setPartitionTimeColumnRef(col);
  partitionDesc.setPartitionTimeColumn(col.getCanonicalName());
  partitionDesc.setPartitionTimeFormat("HH");
  TSRange range = new TSRange(DateFormat.stringToMillis("2016-02-22 00:00:00"),
      DateFormat.stringToMillis("2016-02-23 01:00:00"));
  String condition = partitionConditionBuilder.buildDateRangeCondition(partitionDesc, null, range);
  Assert.assertEquals("UNKNOWN_ALIAS.HOUR_COLUMN >= '00' AND UNKNOWN_ALIAS.HOUR_COLUMN < '01'", condition);
}

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

@Test
public void testDatePartition() {
  PartitionDesc partitionDesc = new PartitionDesc();
  TblColRef col = TblColRef.mockup(TableDesc.mockup("DEFAULT.TABLE_NAME"), 1, "DATE_COLUMN", "string");
  partitionDesc.setPartitionDateColumnRef(col);
  partitionDesc.setPartitionDateColumn(col.getCanonicalName());
  partitionDesc.setPartitionDateFormat("yyyy-MM-dd");
  TSRange range = new TSRange(DateFormat.stringToMillis("2016-02-22"), DateFormat.stringToMillis("2016-02-23"));
  String condition = partitionConditionBuilder.buildDateRangeCondition(partitionDesc, null, range);
  Assert.assertEquals("UNKNOWN_ALIAS.DATE_COLUMN >= '2016-02-22' AND UNKNOWN_ALIAS.DATE_COLUMN < '2016-02-23'",
      condition);
  range = new TSRange(0L, 0L);
  condition = partitionConditionBuilder.buildDateRangeCondition(partitionDesc, null, range);
  Assert.assertEquals("1=0", condition);
}

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

@Test
public void testDateAndTimePartition() {
  PartitionDesc partitionDesc = new PartitionDesc();
  TblColRef col1 = TblColRef.mockup(TableDesc.mockup("DEFAULT.TABLE_NAME"), 1, "DATE_COLUMN", "string");
  partitionDesc.setPartitionDateColumnRef(col1);
  partitionDesc.setPartitionDateColumn(col1.getCanonicalName());
  partitionDesc.setPartitionDateFormat("yyyy-MM-dd");
  TblColRef col2 = TblColRef.mockup(TableDesc.mockup("DEFAULT.TABLE_NAME"), 2, "HOUR_COLUMN", "string");
  partitionDesc.setPartitionTimeColumnRef(col2);
  partitionDesc.setPartitionTimeColumn(col2.getCanonicalName());
  partitionDesc.setPartitionTimeFormat("H");
  TSRange range = new TSRange(DateFormat.stringToMillis("2016-02-22 00:00:00"),
      DateFormat.stringToMillis("2016-02-23 01:00:00"));
  String condition = partitionConditionBuilder.buildDateRangeCondition(partitionDesc, null, range);
  Assert.assertEquals(
      "((UNKNOWN_ALIAS.DATE_COLUMN = '2016-02-22' AND UNKNOWN_ALIAS.HOUR_COLUMN >= '0') OR (UNKNOWN_ALIAS.DATE_COLUMN > '2016-02-22')) AND ((UNKNOWN_ALIAS.DATE_COLUMN = '2016-02-23' AND UNKNOWN_ALIAS.HOUR_COLUMN < '1') OR (UNKNOWN_ALIAS.DATE_COLUMN < '2016-02-23'))",
      condition);
}

相关文章