Esempio 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;
        }
Esempio n. 2
0
 @Override
 public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
   final RelDataType type = super.inferReturnType(opBinding);
   if (opBinding.getGroupCount() == 0) {
     return opBinding.getTypeFactory().createTypeWithNullability(type, true);
   } else {
     return type;
   }
 }
Esempio n. 3
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);
 }
Esempio n. 4
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);
 }
Esempio n. 5
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;
        }
Esempio n. 6
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);
        }
Esempio n. 7
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;
 }
Esempio n. 8
0
 public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
   RelDataType type = opBinding.getOperandType(0);
   if (type.isStruct()) {
     type = type.getFieldList().get(0).getType();
   }
   assert type instanceof ArraySqlType || type instanceof MultisetSqlType;
   if (withOrdinality) {
     final RelDataTypeFactory.FieldInfoBuilder builder = opBinding.getTypeFactory().builder();
     if (type.getComponentType().isStruct()) {
       builder.addAll(type.getComponentType().getFieldList());
     } else {
       builder.add(SqlUtil.deriveAliasFromOrdinal(0), type.getComponentType());
     }
     return builder.add(ORDINALITY_COLUMN_NAME, SqlTypeName.INTEGER).build();
   } else {
     return type.getComponentType();
   }
 }
Esempio n. 9
0
        public RelDataType inferReturnType(final SqlOperatorBinding opBinding) {
          ExplicitOperatorBinding newBinding =
              new ExplicitOperatorBinding(
                  opBinding,
                  new AbstractList<RelDataType>() {
                    public RelDataType get(int index) {
                      RelDataType type = opBinding.getOperandType(index).getComponentType();
                      assert type != null;
                      return type;
                    }

                    public int size() {
                      return opBinding.getOperandCount();
                    }
                    // CHECKSTYLE: IGNORE 1
                  });
          RelDataType biggestElementType = LEAST_RESTRICTIVE.inferReturnType(newBinding);
          return opBinding.getTypeFactory().createMultisetType(biggestElementType, -1);
        }
 public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
   return opBinding.getOperandType(ordinal);
 }
Esempio n. 11
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);
 }
Esempio n. 12
0
 public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
   return opBinding.getTypeFactory().leastRestrictive(opBinding.collectOperandTypes());
 }