org.apache.calcite.rex.RexLiteral.getTimeUnits()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(1.9k)|赞(0)|评价(0)|浏览(69)

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

RexLiteral.getTimeUnits介绍

[英]Returns a list of the time units covered by an interval type such as HOUR TO SECOND. Adds MILLISECOND if the end is SECOND, to deal with fractional seconds.
[中]返回间隔类型(如小时到秒)覆盖的时间单位列表。如果终点是秒,则添加毫秒,以处理小数秒。

代码示例

代码示例来源:origin: Qihoo360/Quicksql

private String intervalString(BigDecimal v) {
 final List<TimeUnit> timeUnits = getTimeUnits(type.getSqlTypeName());
 final StringBuilder b = new StringBuilder();
 for (TimeUnit timeUnit : timeUnits) {
  final BigDecimal[] result = v.divideAndRemainder(timeUnit.multiplier);
  if (b.length() > 0) {
   b.append(timeUnit.separator);
  }
  final int width = b.length() == 0 ? -1 : width(timeUnit); // don't pad 1st
  pad(b, result[0].toString(), width);
  v = result[1];
 }
 if (Util.last(timeUnits) == TimeUnit.MILLISECOND) {
  while (b.toString().matches(".*\\.[0-9]*0")) {
   if (b.toString().endsWith(".0")) {
    b.setLength(b.length() - 2); // remove ".0"
   } else {
    b.setLength(b.length() - 1); // remove "0"
   }
  }
 }
 return b.toString();
}

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

private String intervalString(BigDecimal v) {
 final List<TimeUnit> timeUnits = getTimeUnits(type.getSqlTypeName());
 final StringBuilder b = new StringBuilder();
 for (TimeUnit timeUnit : timeUnits) {
  final BigDecimal[] result = v.divideAndRemainder(timeUnit.multiplier);
  if (b.length() > 0) {
   b.append(timeUnit.separator);
  }
  final int width = b.length() == 0 ? -1 : width(timeUnit); // don't pad 1st
  pad(b, result[0].toString(), width);
  v = result[1];
 }
 if (Util.last(timeUnits) == TimeUnit.MILLISECOND) {
  while (b.toString().matches(".*\\.[0-9]*0")) {
   if (b.toString().endsWith(".0")) {
    b.setLength(b.length() - 2); // remove ".0"
   } else {
    b.setLength(b.length() - 1); // remove "0"
   }
  }
 }
 return b.toString();
}

相关文章