Java Code Examples for org.apache.calcite.rel.type.RelDataType#getFamily()

The following examples show how to use org.apache.calcite.rel.type.RelDataType#getFamily() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Bats   File: StandardConvertletTable.java    License: Apache License 2.0 5 votes vote down vote up
private static RelDataType consistentType(SqlRexContext cx,
    SqlOperandTypeChecker.Consistency consistency, List<RelDataType> types) {
  switch (consistency) {
  case COMPARE:
    if (SqlTypeUtil.areSameFamily(types)) {
      // All arguments are of same family. No need for explicit casts.
      return null;
    }
    final List<RelDataType> nonCharacterTypes = new ArrayList<>();
    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;
  }
}
 
Example 2
public boolean checkOperandTypes(
    SqlCallBinding callBinding,
    boolean throwOnFailure) {
  if (!OperandTypes.MULTISET.checkSingleOperandType(
      callBinding,
      callBinding.operand(1),
      0,
      throwOnFailure)) {
    return false;
  }

  MultisetSqlType mt =
      (MultisetSqlType) callBinding.getValidator().deriveType(
          callBinding.getScope(),
          callBinding.operand(1));

  RelDataType t0 =
      callBinding.getValidator().deriveType(
          callBinding.getScope(),
          callBinding.operand(0));
  RelDataType t1 = mt.getComponentType();

  if (t0.getFamily() != t1.getFamily()) {
    if (throwOnFailure) {
      throw callBinding.newValidationError(
          RESOURCE.typeNotComparableNear(t0.toString(), t1.toString()));
    }
    return false;
  }
  return true;
}
 
Example 3
Source Project: Bats   File: SqlTypeUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether a value can be assigned to a site.
 *
 * @param toType   type of the target site
 * @param fromType type of the source value
 * @return true iff assignable
 */
public static boolean canAssignFrom(
    RelDataType toType,
    RelDataType fromType) {
  if (isAny(toType) || isAny(fromType)) {
    return true;
  }

  // TODO jvs 2-Jan-2005:  handle all the other cases like
  // rows, collections, UDT's
  if (fromType.getSqlTypeName() == SqlTypeName.NULL) {
    // REVIEW jvs 4-Dec-2008: We allow assignment from NULL to any
    // type, including NOT NULL types, since in the case where no
    // rows are actually processed, the assignment is legal
    // (FRG-365).  However, it would be better if the validator's
    // NULL type inference guaranteed that we had already
    // assigned a real (nullable) type to every NULL literal.
    return true;
  }

  if (fromType.getSqlTypeName() == SqlTypeName.ARRAY) {
    if (toType.getSqlTypeName() != SqlTypeName.ARRAY) {
      return false;
    }
    return canAssignFrom(toType.getComponentType(), fromType.getComponentType());
  }

  if (areCharacterSetsMismatched(toType, fromType)) {
    return false;
  }

  return toType.getFamily() == fromType.getFamily();
}
 
Example 4
Source Project: calcite   File: StandardConvertletTable.java    License: Apache License 2.0 5 votes vote down vote up
private static RelDataType consistentType(SqlRexContext cx,
    SqlOperandTypeChecker.Consistency consistency, List<RelDataType> types) {
  switch (consistency) {
  case COMPARE:
    if (SqlTypeUtil.areSameFamily(types)) {
      // All arguments are of same family. No need for explicit casts.
      return null;
    }
    final List<RelDataType> nonCharacterTypes = new ArrayList<>();
    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;
  }
}
 
Example 5
public boolean checkOperandTypes(
    SqlCallBinding callBinding,
    boolean throwOnFailure) {
  if (!OperandTypes.MULTISET.checkSingleOperandType(
      callBinding,
      callBinding.operand(1),
      0,
      throwOnFailure)) {
    return false;
  }

  MultisetSqlType mt =
      (MultisetSqlType) callBinding.getValidator().deriveType(
          callBinding.getScope(),
          callBinding.operand(1));

  RelDataType t0 =
      callBinding.getValidator().deriveType(
          callBinding.getScope(),
          callBinding.operand(0));
  RelDataType t1 = mt.getComponentType();

  if (t0.getFamily() != t1.getFamily()) {
    if (throwOnFailure) {
      throw callBinding.newValidationError(
          RESOURCE.typeNotComparableNear(t0.toString(), t1.toString()));
    }
    return false;
  }
  return true;
}
 
Example 6
Source Project: calcite   File: SqlTypeUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether a value can be assigned to a site.
 *
 * @param toType   type of the target site
 * @param fromType type of the source value
 * @return true iff assignable
 */
public static boolean canAssignFrom(
    RelDataType toType,
    RelDataType fromType) {
  if (isAny(toType) || isAny(fromType)) {
    return true;
  }

  // TODO jvs 2-Jan-2005:  handle all the other cases like
  // rows, collections, UDT's
  if (fromType.getSqlTypeName() == SqlTypeName.NULL) {
    // REVIEW jvs 4-Dec-2008: We allow assignment from NULL to any
    // type, including NOT NULL types, since in the case where no
    // rows are actually processed, the assignment is legal
    // (FRG-365).  However, it would be better if the validator's
    // NULL type inference guaranteed that we had already
    // assigned a real (nullable) type to every NULL literal.
    return true;
  }

  if (fromType.getSqlTypeName() == SqlTypeName.ARRAY) {
    if (toType.getSqlTypeName() != SqlTypeName.ARRAY) {
      return false;
    }
    return canAssignFrom(toType.getComponentType(), fromType.getComponentType());
  }

  if (areCharacterSetsMismatched(toType, fromType)) {
    return false;
  }

  return toType.getFamily() == fromType.getFamily();
}
 
Example 7
Source Project: Bats   File: SqlTypeUtil.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return true if type is in SqlTypeFamily.Character
 */
public static boolean inCharFamily(RelDataType type) {
  return type.getFamily() == SqlTypeFamily.CHARACTER;
}
 
Example 8
Source Project: Bats   File: SqlTypeUtil.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return true if type is in SqlTypeFamily.Boolean
 */
public static boolean inBooleanFamily(RelDataType type) {
  return type.getFamily() == SqlTypeFamily.BOOLEAN;
}
 
Example 9
Source Project: Bats   File: SqlTypeUtil.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return true if two types are in same type family
 */
public static boolean inSameFamily(RelDataType t1, RelDataType t2) {
  return t1.getFamily() == t2.getFamily();
}
 
Example 10
Source Project: Bats   File: SqlTypeUtil.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return true if two types are in same type family, or one or the other is
 * of type {@link SqlTypeName#NULL}.
 */
public static boolean inSameFamilyOrNull(RelDataType t1, RelDataType t2) {
  return (t1.getSqlTypeName() == SqlTypeName.NULL)
      || (t2.getSqlTypeName() == SqlTypeName.NULL)
      || (t1.getFamily() == t2.getFamily());
}
 
Example 11
Source Project: Bats   File: SqlTypeUtil.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return true if type family is either character or binary
 */
public static boolean inCharOrBinaryFamilies(RelDataType type) {
  return (type.getFamily() == SqlTypeFamily.CHARACTER)
      || (type.getFamily() == SqlTypeFamily.BINARY);
}
 
Example 12
Source Project: Bats   File: SqlTypeUtil.java    License: Apache License 2.0 4 votes vote down vote up
private static boolean isAny(RelDataType t) {
  return t.getFamily() == SqlTypeFamily.ANY;
}
 
Example 13
Source Project: dremio-oss   File: ConvertletTable.java    License: Apache License 2.0 4 votes vote down vote up
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;
  }
}
 
Example 14
Source Project: calcite   File: SqlTypeUtil.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return true if type is in SqlTypeFamily.Character
 */
public static boolean inCharFamily(RelDataType type) {
  return type.getFamily() == SqlTypeFamily.CHARACTER;
}
 
Example 15
Source Project: calcite   File: SqlTypeUtil.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return true if type is in SqlTypeFamily.Boolean
 */
public static boolean inBooleanFamily(RelDataType type) {
  return type.getFamily() == SqlTypeFamily.BOOLEAN;
}
 
Example 16
Source Project: calcite   File: SqlTypeUtil.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return true if two types are in same type family
 */
public static boolean inSameFamily(RelDataType t1, RelDataType t2) {
  return t1.getFamily() == t2.getFamily();
}
 
Example 17
Source Project: calcite   File: SqlTypeUtil.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return true if two types are in same type family, or one or the other is
 * of type {@link SqlTypeName#NULL}.
 */
public static boolean inSameFamilyOrNull(RelDataType t1, RelDataType t2) {
  return (t1.getSqlTypeName() == SqlTypeName.NULL)
      || (t2.getSqlTypeName() == SqlTypeName.NULL)
      || (t1.getFamily() == t2.getFamily());
}
 
Example 18
Source Project: calcite   File: SqlTypeUtil.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return true if type family is either character or binary
 */
public static boolean inCharOrBinaryFamilies(RelDataType type) {
  return (type.getFamily() == SqlTypeFamily.CHARACTER)
      || (type.getFamily() == SqlTypeFamily.BINARY);
}
 
Example 19
Source Project: calcite   File: SqlTypeUtil.java    License: Apache License 2.0 4 votes vote down vote up
private static boolean isAny(RelDataType t) {
  return t.getFamily() == SqlTypeFamily.ANY;
}