当前位置: 首页>>代码示例>>Java>>正文


Java SqlTypeFamily.CHARACTER属性代码示例

本文整理汇总了Java中org.apache.calcite.sql.type.SqlTypeFamily.CHARACTER属性的典型用法代码示例。如果您正苦于以下问题:Java SqlTypeFamily.CHARACTER属性的具体用法?Java SqlTypeFamily.CHARACTER怎么用?Java SqlTypeFamily.CHARACTER使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.calcite.sql.type.SqlTypeFamily的用法示例。


在下文中一共展示了SqlTypeFamily.CHARACTER属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isText

public static boolean isText(final LayoutField field) {
  final Optional<SqlTypeFamily> familyOpt = getSqlTypeFamily(field);
  if (!familyOpt.isPresent()) {
    return false;
  }

  final SqlTypeFamily family = familyOpt.get();
  return family == SqlTypeFamily.CHARACTER;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:9,代码来源:TypeUtils.java

示例2: toSql

@Override public SqlNode toSql(RexProgram program, RexNode rex) {
  if (rex.getKind() == SqlKind.LITERAL) {
    final RexLiteral literal = (RexLiteral) rex;
    if (literal.getTypeName().getFamily() == SqlTypeFamily.CHARACTER) {
      return new SqlIdentifier(RexLiteral.stringValue(literal), POS);
    }
  }
  return super.toSql(program, rex);
}
 
开发者ID:apache,项目名称:calcite,代码行数:9,代码来源:SqlImplementor.java

示例3: isLosslessCast

/**
 * Returns whether the input is a 'loss-less' cast, that is, a cast from which
 * the original value of the field can be certainly recovered.
 *
 * <p>For instance, int &rarr; bigint is loss-less (as you can cast back to
 * int without loss of information), but bigint &rarr; int is not loss-less.
 *
 * <p>The implementation of this method does not return false positives.
 * However, it is not complete.
 */
public static boolean isLosslessCast(RexNode node) {
  if (!node.isA(SqlKind.CAST)) {
    return false;
  }
  final RelDataType source = ((RexCall) node).getOperands().get(0).getType();
  final SqlTypeName sourceSqlTypeName = source.getSqlTypeName();
  final RelDataType target = node.getType();
  final SqlTypeName targetSqlTypeName = target.getSqlTypeName();
  // 1) Both INT numeric types
  if (SqlTypeFamily.INTEGER.getTypeNames().contains(sourceSqlTypeName)
      && SqlTypeFamily.INTEGER.getTypeNames().contains(targetSqlTypeName)) {
    return targetSqlTypeName.compareTo(sourceSqlTypeName) >= 0;
  }
  // 2) Both CHARACTER types: it depends on the precision (length)
  if (SqlTypeFamily.CHARACTER.getTypeNames().contains(sourceSqlTypeName)
      && SqlTypeFamily.CHARACTER.getTypeNames().contains(targetSqlTypeName)) {
    return targetSqlTypeName.compareTo(sourceSqlTypeName) >= 0
        && source.getPrecision() <= target.getPrecision();
  }
  // 3) From NUMERIC family to CHARACTER family: it depends on the precision/scale
  if (sourceSqlTypeName.getFamily() == SqlTypeFamily.NUMERIC
      && targetSqlTypeName.getFamily() == SqlTypeFamily.CHARACTER) {
    int sourceLength = source.getPrecision() + 1; // include sign
    if (source.getScale() != -1 && source.getScale() != 0) {
      sourceLength += source.getScale() + 1; // include decimal mark
    }
    return target.getPrecision() >= sourceLength;
  }
  // Return FALSE by default
  return false;
}
 
开发者ID:apache,项目名称:calcite,代码行数:41,代码来源:RexUtil.java

示例4: consistentType

private static RelDataType consistentType(SqlRexContext cx,
    SqlOperandTypeChecker.Consistency consistency, List<RelDataType> types) {
  switch (consistency) {
  case COMPARE:
    final Set<RelDataTypeFamily> families =
        Sets.newHashSet(RexUtil.families(types));
    if (families.size() < 2) {
      // All arguments are of same family. No need for explicit casts.
      return null;
    }
    final List<RelDataType> nonCharacterTypes = Lists.newArrayList();
    for (RelDataType type : types) {
      if (type.getFamily() != SqlTypeFamily.CHARACTER) {
        nonCharacterTypes.add(type);
      }
    }
    if (!nonCharacterTypes.isEmpty()) {
      final int typeCount = types.size();
      types = nonCharacterTypes;
      if (nonCharacterTypes.size() < typeCount) {
        final RelDataTypeFamily family =
            nonCharacterTypes.get(0).getFamily();
        if (family instanceof SqlTypeFamily) {
          // The character arguments might be larger than the numeric
          // argument. Give ourselves some headroom.
          switch ((SqlTypeFamily) family) {
          case INTEGER:
          case NUMERIC:
            nonCharacterTypes.add(
                cx.getTypeFactory().createSqlType(SqlTypeName.BIGINT));
          }
        }
      }
    }
    // fall through
  case LEAST_RESTRICTIVE:
    return cx.getTypeFactory().leastRestrictive(types);
  default:
    return null;
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:41,代码来源:ConvertletTable.java


注:本文中的org.apache.calcite.sql.type.SqlTypeFamily.CHARACTER属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。