Ejemplo n.º 1
0
        public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
          RelDataType type1 = opBinding.getOperandType(0);
          RelDataType type2 = opBinding.getOperandType(1);
          if (SqlTypeUtil.isExactNumeric(type1) && SqlTypeUtil.isExactNumeric(type2)) {
            if (SqlTypeUtil.isDecimal(type1) || SqlTypeUtil.isDecimal(type2)) {
              int p1 = type1.getPrecision();
              int p2 = type2.getPrecision();
              int s1 = type1.getScale();
              int s2 = type2.getScale();

              int scale = Math.max(s1, s2);
              assert scale <= SqlTypeName.MAX_NUMERIC_SCALE;
              int precision = Math.max(p1 - s1, p2 - s2) + scale + 1;
              precision = Math.min(precision, SqlTypeName.MAX_NUMERIC_PRECISION);
              assert precision > 0;

              RelDataType ret;
              ret = opBinding.getTypeFactory().createSqlType(SqlTypeName.DECIMAL, precision, scale);

              return ret;
            }
          }

          return null;
        }
Ejemplo n.º 2
0
 public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
   assert opBinding.getOperandCount() == 1;
   final RelDataType multisetType = opBinding.getOperandType(0);
   RelDataType componentType = multisetType.getComponentType();
   assert componentType != null : "expected a multiset type: " + multisetType;
   final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
   final RelDataType type =
       typeFactory.builder().add(SqlUtil.deriveAliasFromOrdinal(0), componentType).build();
   return typeFactory.createMultisetType(type, -1);
 }
Ejemplo n.º 3
0
 public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
   assert opBinding.getOperandCount() == 1;
   final RelDataType recordMultisetType = opBinding.getOperandType(0);
   RelDataType multisetType = recordMultisetType.getComponentType();
   assert multisetType != null : "expected a multiset type: " + recordMultisetType;
   final List<RelDataTypeField> fields = multisetType.getFieldList();
   assert fields.size() > 0;
   final RelDataType firstColType = fields.get(0).getType();
   return opBinding.getTypeFactory().createMultisetType(firstColType, -1);
 }
Ejemplo n.º 4
0
        /** @pre SqlTypeUtil.sameNamedType(argTypes[0], (argTypes[1])) */
        public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
          final RelDataType argType0 = opBinding.getOperandType(0);
          final RelDataType argType1 = opBinding.getOperandType(1);
          if (!(SqlTypeUtil.inCharOrBinaryFamilies(argType0)
              && SqlTypeUtil.inCharOrBinaryFamilies(argType1))) {
            Util.pre(
                SqlTypeUtil.sameNamedType(argType0, argType1),
                "SqlTypeUtil.sameNamedType(argTypes[0], argTypes[1])");
          }
          SqlCollation pickedCollation = null;
          if (SqlTypeUtil.inCharFamily(argType0)) {
            if (!SqlTypeUtil.isCharTypeComparable(opBinding.collectOperandTypes().subList(0, 2))) {
              throw opBinding.newError(
                  RESOURCE.typeNotComparable(
                      argType0.getFullTypeString(), argType1.getFullTypeString()));
            }

            pickedCollation =
                SqlCollation.getCoercibilityDyadicOperator(
                    argType0.getCollation(), argType1.getCollation());
            assert null != pickedCollation;
          }

          // Determine whether result is variable-length
          SqlTypeName typeName = argType0.getSqlTypeName();
          if (SqlTypeUtil.isBoundedVariableWidth(argType1)) {
            typeName = argType1.getSqlTypeName();
          }

          RelDataType ret;
          ret =
              opBinding
                  .getTypeFactory()
                  .createSqlType(typeName, argType0.getPrecision() + argType1.getPrecision());
          if (null != pickedCollation) {
            RelDataType pickedType;
            if (argType0.getCollation().equals(pickedCollation)) {
              pickedType = argType0;
            } else if (argType1.getCollation().equals(pickedCollation)) {
              pickedType = argType1;
            } else {
              throw Util.newInternal("should never come here");
            }
            ret =
                opBinding
                    .getTypeFactory()
                    .createTypeWithCharsetAndCollation(
                        ret, pickedType.getCharset(), pickedType.getCollation());
          }
          return ret;
        }
Ejemplo n.º 5
0
        public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
          assert opBinding.getOperandCount() == 1;

          final RelDataType recordType = opBinding.getOperandType(0);

          boolean isStruct = recordType.isStruct();
          int fieldCount = recordType.getFieldCount();

          assert isStruct && (fieldCount == 1);

          RelDataTypeField fieldType = recordType.getFieldList().get(0);
          assert fieldType != null : "expected a record type with one field: " + recordType;
          final RelDataType firstColType = fieldType.getType();
          return opBinding.getTypeFactory().createTypeWithNullability(firstColType, true);
        }
Ejemplo n.º 6
0
 public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
   RelDataType type1 = opBinding.getOperandType(0);
   if (SqlTypeUtil.isDecimal(type1)) {
     if (type1.getScale() == 0) {
       return type1;
     } else {
       int p = type1.getPrecision();
       RelDataType ret;
       ret = opBinding.getTypeFactory().createSqlType(SqlTypeName.DECIMAL, p, 0);
       if (type1.isNullable()) {
         ret = opBinding.getTypeFactory().createTypeWithNullability(ret, true);
       }
       return ret;
     }
   }
   return null;
 }
 public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
   return opBinding.getOperandType(ordinal);
 }
Ejemplo n.º 8
0
 public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
   RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
   RelDataType type1 = opBinding.getOperandType(0);
   RelDataType type2 = opBinding.getOperandType(1);
   return typeFactory.createDecimalQuotient(type1, type2);
 }