本文整理汇总了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;
}
示例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);
}
示例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 → bigint is loss-less (as you can cast back to
* int without loss of information), but bigint → 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;
}
示例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;
}
}