org.apache.calcite.sql.type.SqlTypeUtil Java Examples

The following examples show how to use org.apache.calcite.sql.type.SqlTypeUtil. 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 File: SqlLiteralChainOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
private boolean argTypesValid(SqlCallBinding callBinding) {
  if (callBinding.getOperandCount() < 2) {
    return true; // nothing to compare
  }
  RelDataType firstType = null;
  for (Ord<SqlNode> operand : Ord.zip(callBinding.operands())) {
    RelDataType type =
        callBinding.getValidator().deriveType(
            callBinding.getScope(),
            operand.e);
    if (operand.i == 0) {
      firstType = type;
    } else {
      if (!SqlTypeUtil.sameNamedType(firstType, type)) {
        return false;
      }
    }
  }
  return true;
}
 
Example #2
Source File: TypeCoercionImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Coerces operands in binary arithmetic expressions to NUMERIC types.
 *
 * <p>For binary arithmetic operators like [+, -, *, /, %]:
 * If the operand is VARCHAR,
 * coerce it to data type of the other operand if its data type is NUMERIC;
 * If the other operand is DECIMAL,
 * coerce the STRING operand to max precision/scale DECIMAL.
 */
public boolean binaryArithmeticCoercion(SqlCallBinding binding) {
  // Assume the operator has NUMERIC family operand type checker.
  SqlOperator operator = binding.getOperator();
  SqlKind kind = operator.getKind();
  boolean coerced = false;
  // Binary operator
  if (binding.getOperandCount() == 2) {
    final RelDataType type1 = binding.getOperandType(0);
    final RelDataType type2 = binding.getOperandType(1);
    // Special case for datetime + interval or datetime - interval
    if (kind == SqlKind.PLUS || kind == SqlKind.MINUS) {
      if (SqlTypeUtil.isInterval(type1) || SqlTypeUtil.isInterval(type2)) {
        return false;
      }
    }
    // Binary arithmetic operator like: + - * / %
    if (kind.belongsTo(SqlKind.BINARY_ARITHMETIC)) {
      coerced = binaryArithmeticWithStrings(binding, type1, type2);
    }
  }
  return coerced;
}
 
Example #3
Source File: RelDataTypeFactoryImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
private RelDataType copySimpleType(
    RelDataType type,
    boolean nullable) {
  if (type instanceof JavaType) {
    JavaType javaType = (JavaType) type;
    if (SqlTypeUtil.inCharFamily(javaType)) {
      return new JavaType(
          javaType.clazz,
          nullable,
          javaType.charset,
          javaType.collation);
    } else {
      return new JavaType(
          nullable
              ? Primitive.box(javaType.clazz)
              : Primitive.unbox(javaType.clazz),
          nullable);
    }
  } else {
    // REVIEW: RelCrossType if it stays around; otherwise get rid of
    // this comment
    return type;
  }
}
 
Example #4
Source File: StandardConvertletTable.java    From Bats with Apache License 2.0 6 votes vote down vote up
private Pair<RexNode, RexNode> convertOverlapsOperand(SqlRexContext cx,
    SqlParserPos pos, SqlNode operand) {
  final SqlNode a0;
  final SqlNode a1;
  switch (operand.getKind()) {
  case ROW:
    a0 = ((SqlCall) operand).operand(0);
    final SqlNode a10 = ((SqlCall) operand).operand(1);
    final RelDataType t1 = cx.getValidator().getValidatedNodeType(a10);
    if (SqlTypeUtil.isInterval(t1)) {
      // make t1 = t0 + t1 when t1 is an interval.
      a1 = plus(pos, a0, a10);
    } else {
      a1 = a10;
    }
    break;
  default:
    a0 = operand;
    a1 = operand;
  }

  final RexNode r0 = cx.convertExpression(a0);
  final RexNode r1 = cx.convertExpression(a1);
  return Pair.of(r0, r1);
}
 
Example #5
Source File: AggregateCall.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Creates an AggregateCall, inferring its type if {@code type} is null. */
public static AggregateCall create(SqlAggFunction aggFunction,
    boolean distinct, boolean approximate, boolean ignoreNulls,
    List<Integer> argList, int filterArg, RelCollation collation,
    int groupCount,
    RelNode input, RelDataType type, String name) {
  if (type == null) {
    final RelDataTypeFactory typeFactory =
        input.getCluster().getTypeFactory();
    final List<RelDataType> types =
        SqlTypeUtil.projectTypes(input.getRowType(), argList);
    final Aggregate.AggCallBinding callBinding =
        new Aggregate.AggCallBinding(typeFactory, aggFunction, types,
            groupCount, filterArg >= 0);
    type = aggFunction.inferReturnType(callBinding);
  }
  return create(aggFunction, distinct, approximate, ignoreNulls, argList,
      filterArg, collation, type, name);
}
 
Example #6
Source File: RelStructuredTypeFlattener.java    From Bats with Apache License 2.0 6 votes vote down vote up
private int calculateFlattenedOffset(RelDataType rowType, int ordinal) {
    int offset = 0;
    if (SqlTypeUtil.needsNullIndicator(rowType)) {
        // skip null indicator
        ++offset;
    }
    List<RelDataTypeField> oldFields = rowType.getFieldList();
    for (int i = 0; i < ordinal; ++i) {
        RelDataType oldFieldType = oldFields.get(i).getType();
        if (oldFieldType.isStruct()) {
            // TODO jvs 10-Feb-2005: this isn't terribly efficient;
            // keep a mapping somewhere
            RelDataType flattened = SqlTypeUtil.flattenRecordType(rexBuilder.getTypeFactory(), oldFieldType, null);
            final List<RelDataTypeField> fields = flattened.getFieldList();
            offset += fields.size();
        } else {
            ++offset;
        }
    }
    return offset;
}
 
Example #7
Source File: SqlDialect.java    From Bats with Apache License 2.0 6 votes vote down vote up
public SqlNode getCastSpec(RelDataType type) {
  if (type instanceof BasicSqlType) {
    int precision = type.getPrecision();
    switch (type.getSqlTypeName()) {
    case VARCHAR:
      // if needed, adjust varchar length to max length supported by the system
      int maxPrecision = getTypeSystem().getMaxPrecision(type.getSqlTypeName());
      if (type.getPrecision() > maxPrecision) {
        precision = maxPrecision;
      }
    }
    return new SqlDataTypeSpec(
        new SqlIdentifier(type.getSqlTypeName().name(), SqlParserPos.ZERO),
            precision,
            type.getScale(),
            type.getCharset() != null
                && supportsCharSet()
                ? type.getCharset().name()
                : null,
            null,
            SqlParserPos.ZERO);
  }
  return SqlTypeUtil.convertTypeToSpec(type);
}
 
Example #8
Source File: SqlMultisetQueryConstructor.java    From calcite with Apache License 2.0 6 votes vote down vote up
public boolean checkOperandTypes(
    SqlCallBinding callBinding,
    boolean throwOnFailure) {
  final List<RelDataType> argTypes =
      SqlTypeUtil.deriveAndCollectTypes(
          callBinding.getValidator(),
          callBinding.getScope(),
          callBinding.operands());
  final RelDataType componentType =
      getComponentType(
          callBinding.getTypeFactory(),
          argTypes);
  if (null == componentType) {
    if (throwOnFailure) {
      throw callBinding.newValidationError(RESOURCE.needSameTypeParameter());
    }
    return false;
  }
  return true;
}
 
Example #9
Source File: RexSimplify.java    From calcite with Apache License 2.0 6 votes vote down vote up
public RexNode simplifyPreservingType(RexNode e, RexUnknownAs unknownAs,
    boolean matchNullability) {
  final RexNode e2 = simplifyUnknownAs(e, unknownAs);
  if (e2.getType() == e.getType()) {
    return e2;
  }
  if (!matchNullability
      && SqlTypeUtil.equalSansNullability(rexBuilder.typeFactory, e2.getType(), e.getType())) {
    return e2;
  }
  final RexNode e3 = rexBuilder.makeCast(e.getType(), e2, matchNullability);
  if (e3.equals(e)) {
    return e;
  }
  return e3;
}
 
Example #10
Source File: ReduceDecimalsRule.java    From Bats with Apache License 2.0 6 votes vote down vote up
@Override
public RexNode expand(RexCall call) {
    ImmutableList.Builder<RexNode> opBuilder = ImmutableList.builder();
    for (RexNode operand : call.getOperands()) {
        if (SqlTypeUtil.isNumeric(operand.getType())) {
            opBuilder.add(accessValue(operand));
        } else {
            opBuilder.add(operand);
        }
    }

    RexNode newCall = builder.makeCall(call.getType(), call.getOperator(), opBuilder.build());
    if (SqlTypeUtil.isDecimal(call.getType())) {
        return encodeValue(newCall, call.getType());
    } else {
        return newCall;
    }
}
 
Example #11
Source File: AbstractTypeCoercion.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Sync the data type additional attributes before casting,
 * i.e. nullability, charset, collation.
 */
RelDataType syncAttributes(
    RelDataType fromType,
    RelDataType toType) {
  RelDataType syncedType = toType;
  if (fromType != null) {
    syncedType = factory.createTypeWithNullability(syncedType, fromType.isNullable());
    if (SqlTypeUtil.inCharOrBinaryFamilies(fromType)
        && SqlTypeUtil.inCharOrBinaryFamilies(toType)) {
      Charset charset = fromType.getCharset();
      SqlCollation collation = fromType.getCollation();
      if (charset != null && SqlTypeUtil.inCharFamily(syncedType)) {
        syncedType = factory.createTypeWithCharsetAndCollation(syncedType,
            charset,
            collation);
      }
    }
  }
  return syncedType;
}
 
Example #12
Source File: SqlDialect.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Returns SqlNode for type in "cast(column as type)", which might be
* different between databases by type name, precision etc. */
public SqlNode getCastSpec(RelDataType type) {
  if (type instanceof BasicSqlType) {
    int maxPrecision = -1;
    switch (type.getSqlTypeName()) {
    case VARCHAR:
      // if needed, adjust varchar length to max length supported by the system
      maxPrecision = getTypeSystem().getMaxPrecision(type.getSqlTypeName());
    }
    String charSet = type.getCharset() != null && supportsCharSet()
        ? type.getCharset().name()
        : null;
    return SqlTypeUtil.convertTypeToSpec(type, charSet, maxPrecision);
  }
  return SqlTypeUtil.convertTypeToSpec(type);
}
 
Example #13
Source File: TypeCoercionImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Datetime and STRING equality: cast STRING type to datetime type, SqlToRelConverter already
 * makes the conversion but we still keep this interface overridable
 * so user can have their custom implementation.
 */
protected boolean dateTimeStringEquality(
    SqlCallBinding binding,
    RelDataType left,
    RelDataType right) {
  // REVIEW Danny 2018-05-23 we do not need to coerce type for EQUALS
  // because SqlToRelConverter already does this.
  // REVIEW Danny 2019-09-23, we should unify the coercion rules in TypeCoercion
  // instead of SqlToRelConverter.
  if (SqlTypeUtil.isCharacter(left)
      && SqlTypeUtil.isDatetime(right)) {
    return coerceOperandType(binding.getScope(), binding.getCall(), 0, right);
  }
  if (SqlTypeUtil.isCharacter(right)
      && SqlTypeUtil.isDatetime(left)) {
    return coerceOperandType(binding.getScope(), binding.getCall(), 1, left);
  }
  return false;
}
 
Example #14
Source File: SqlMultisetValueConstructor.java    From Bats with Apache License 2.0 6 votes vote down vote up
public boolean checkOperandTypes(
    SqlCallBinding callBinding,
    boolean throwOnFailure) {
  final List<RelDataType> argTypes =
      SqlTypeUtil.deriveAndCollectTypes(
          callBinding.getValidator(),
          callBinding.getScope(),
          callBinding.operands());
  if (argTypes.size() == 0) {
    throw callBinding.newValidationError(RESOURCE.requireAtLeastOneArg());
  }
  final RelDataType componentType =
      getComponentType(
          callBinding.getTypeFactory(),
          argTypes);
  if (null == componentType) {
    if (throwOnFailure) {
      throw callBinding.newValidationError(RESOURCE.needSameTypeParameter());
    }
    return false;
  }
  return true;
}
 
Example #15
Source File: AbstractTypeCoercion.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Promote all the way to VARCHAR.
 */
private RelDataType promoteToVarChar(RelDataType type1, RelDataType type2) {
  RelDataType resultType = null;
  // No promotion for char and varchar.
  if (SqlTypeUtil.isCharacter(type1) && SqlTypeUtil.isCharacter(type2)) {
    return null;
  }
  // 1. Do not distinguish CHAR and VARCHAR, i.e. (INTEGER + CHAR(3))
  //    and (INTEGER + VARCHAR(5)) would both deduce VARCHAR type.
  // 2. VARCHAR has 65536 as default precision.
  // 3. Following MS-SQL: BINARY or BOOLEAN can be casted to VARCHAR.
  if (SqlTypeUtil.isAtomic(type1) && SqlTypeUtil.isCharacter(type2)) {
    resultType = factory.createSqlType(SqlTypeName.VARCHAR);
  }

  if (SqlTypeUtil.isCharacter(type1) && SqlTypeUtil.isAtomic(type2)) {
    resultType = factory.createSqlType(SqlTypeName.VARCHAR);
  }
  return resultType;
}
 
Example #16
Source File: SqlJsonObjectFunction.java    From Bats with Apache License 2.0 6 votes vote down vote up
@Override public boolean checkOperandTypes(SqlCallBinding callBinding,
    boolean throwOnFailure) {
  final int count = callBinding.getOperandCount();
  for (int i = 1; i < count; i += 2) {
    RelDataType nameType = callBinding.getOperandType(i);
    if (!SqlTypeUtil.inCharFamily(nameType)) {
      if (throwOnFailure) {
        throw callBinding.newError(RESOURCE.expectedCharacter());
      }
      return false;
    }
    if (nameType.isNullable()) {
      if (throwOnFailure) {
        throw callBinding.newError(
            RESOURCE.argumentMustNotBeNull(
                callBinding.operand(i).toString()));
      }
      return false;
    }
  }
  return true;
}
 
Example #17
Source File: ValuesRel.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
private static void verifyRowType(final ImmutableList<ImmutableList<RexLiteral>> tuples, RelDataType rowType){
    for (List<RexLiteral> tuple : tuples) {
      assert (tuple.size() == rowType.getFieldCount());

      for (Pair<RexLiteral, RelDataTypeField> pair : Pair.zip(tuple, rowType.getFieldList())) {
        RexLiteral literal = pair.left;
        RelDataType fieldType = pair.right.getType();

        if ((!(RexLiteral.isNullLiteral(literal)))
            && (!(SqlTypeUtil.canAssignFrom(fieldType, literal.getType())))) {
          throw new AssertionError("to " + fieldType + " from " + literal);
        }
      }
    }

}
 
Example #18
Source File: SqlMapValueConstructor.java    From Bats with Apache License 2.0 6 votes vote down vote up
public boolean checkOperandTypes(
    SqlCallBinding callBinding,
    boolean throwOnFailure) {
  final List<RelDataType> argTypes =
      SqlTypeUtil.deriveAndCollectTypes(
          callBinding.getValidator(),
          callBinding.getScope(),
          callBinding.operands());
  if (argTypes.size() == 0) {
    throw callBinding.newValidationError(RESOURCE.mapRequiresTwoOrMoreArgs());
  }
  if (argTypes.size() % 2 > 0) {
    throw callBinding.newValidationError(RESOURCE.mapRequiresEvenArgCount());
  }
  final Pair<RelDataType, RelDataType> componentType =
      getComponentTypes(
          callBinding.getTypeFactory(), argTypes);
  if (null == componentType.left || null == componentType.right) {
    if (throwOnFailure) {
      throw callBinding.newValidationError(RESOURCE.needSameTypeParameter());
    }
    return false;
  }
  return true;
}
 
Example #19
Source File: SqlMapValueConstructor.java    From calcite with Apache License 2.0 6 votes vote down vote up
public boolean checkOperandTypes(
    SqlCallBinding callBinding,
    boolean throwOnFailure) {
  final List<RelDataType> argTypes =
      SqlTypeUtil.deriveAndCollectTypes(
          callBinding.getValidator(),
          callBinding.getScope(),
          callBinding.operands());
  if (argTypes.size() == 0) {
    throw callBinding.newValidationError(RESOURCE.mapRequiresTwoOrMoreArgs());
  }
  if (argTypes.size() % 2 > 0) {
    throw callBinding.newValidationError(RESOURCE.mapRequiresEvenArgCount());
  }
  final Pair<RelDataType, RelDataType> componentType =
      getComponentTypes(
          callBinding.getTypeFactory(), argTypes);
  if (null == componentType.left || null == componentType.right) {
    if (throwOnFailure) {
      throw callBinding.newValidationError(RESOURCE.needSameTypeParameter());
    }
    return false;
  }
  return true;
}
 
Example #20
Source File: SqlHopTableFunction.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public boolean checkOperandTypes(SqlCallBinding callBinding,
    boolean throwOnFailure) {
  final SqlNode operand0 = callBinding.operand(0);
  final SqlValidator validator = callBinding.getValidator();
  final RelDataType type = validator.getValidatedNodeType(operand0);
  if (type.getSqlTypeName() != SqlTypeName.ROW) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  final SqlNode operand1 = callBinding.operand(1);
  if (operand1.getKind() != SqlKind.DESCRIPTOR) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  validateColumnNames(validator, type.getFieldNames(), ((SqlCall) operand1).getOperandList());
  final RelDataType type2 = validator.getValidatedNodeType(callBinding.operand(2));
  if (!SqlTypeUtil.isInterval(type2)) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  final RelDataType type3 = validator.getValidatedNodeType(callBinding.operand(3));
  if (!SqlTypeUtil.isInterval(type3)) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  return true;
}
 
Example #21
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
protected void validateWhereOrOn(
	SqlValidatorScope scope,
	SqlNode condition,
	String clause) {
	validateNoAggs(aggOrOverOrGroupFinder, condition, clause);
	inferUnknownTypes(
		booleanType,
		scope,
		condition);
	condition.validate(this, scope);

	final RelDataType type = deriveType(scope, condition);
	if (!SqlTypeUtil.inBooleanFamily(type)) {
		throw newValidationError(condition, RESOURCE.condMustBeBoolean(clause));
	}
}
 
Example #22
Source File: SqlSessionTableFunction.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public boolean checkOperandTypes(SqlCallBinding callBinding,
    boolean throwOnFailure) {
  final SqlNode operand0 = callBinding.operand(0);
  final SqlValidator validator = callBinding.getValidator();
  final RelDataType type = validator.getValidatedNodeType(operand0);
  if (type.getSqlTypeName() != SqlTypeName.ROW) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  final SqlNode operand1 = callBinding.operand(1);
  if (operand1.getKind() != SqlKind.DESCRIPTOR) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  validateColumnNames(validator, type.getFieldNames(), ((SqlCall) operand1).getOperandList());
  final SqlNode operand2 = callBinding.operand(2);
  if (operand2.getKind() != SqlKind.DESCRIPTOR) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  validateColumnNames(validator, type.getFieldNames(), ((SqlCall) operand2).getOperandList());
  final RelDataType type3 = validator.getValidatedNodeType(callBinding.operand(3));
  if (!SqlTypeUtil.isInterval(type3)) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  return true;
}
 
Example #23
Source File: SqlLiteralChainOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
private boolean argTypesValid(SqlCallBinding callBinding) {
  if (callBinding.getOperandCount() < 2) {
    return true; // nothing to compare
  }
  RelDataType firstType = null;
  for (Ord<SqlNode> operand : Ord.zip(callBinding.operands())) {
    RelDataType type =
        callBinding.getValidator().deriveType(
            callBinding.getScope(),
            operand.e);
    if (operand.i == 0) {
      firstType = type;
    } else {
      if (!SqlTypeUtil.sameNamedType(firstType, type)) {
        return false;
      }
    }
  }
  return true;
}
 
Example #24
Source File: NumericExceptFirstOperandChecker.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
	for (int i = 1; i < callBinding.getOperandCount(); i++) {
		if (!SqlTypeUtil.isNumeric(callBinding.getOperandType(i))) {
			if (!throwOnFailure) {
				return false;
			}
			throw callBinding.newValidationSignatureError();
		}
	}
	return true;
}
 
Example #25
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
private SqlNode maybeCast(SqlNode node, RelDataType currentType,
	RelDataType desiredType) {
	return currentType.equals(desiredType)
		|| (currentType.isNullable() != desiredType.isNullable()
			    && typeFactory.createTypeWithNullability(currentType,
		desiredType.isNullable()).equals(desiredType))
		? node
		: SqlStdOperatorTable.CAST.createCall(SqlParserPos.ZERO,
		node, SqlTypeUtil.convertTypeToSpec(desiredType));
}
 
Example #26
Source File: SqlMultisetValueConstructor.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelDataType inferReturnType(
    SqlOperatorBinding opBinding) {
  RelDataType type =
      getComponentType(
          opBinding.getTypeFactory(),
          opBinding.collectOperandTypes());
  if (null == type) {
    return null;
  }
  return SqlTypeUtil.createMultisetType(
      opBinding.getTypeFactory(),
      type,
      false);
}
 
Example #27
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
protected void validateHavingClause(SqlSelect select) {
	// HAVING is validated in the scope after groups have been created.
	// For example, in "SELECT empno FROM emp WHERE empno = 10 GROUP BY
	// deptno HAVING empno = 10", the reference to 'empno' in the HAVING
	// clause is illegal.
	SqlNode having = select.getHaving();
	if (having == null) {
		return;
	}
	final AggregatingScope havingScope =
		(AggregatingScope) getSelectScope(select);
	if (getConformance().isHavingAlias()) {
		SqlNode newExpr = expandGroupByOrHavingExpr(having, havingScope, select, true);
		if (having != newExpr) {
			having = newExpr;
			select.setHaving(newExpr);
		}
	}
	havingScope.checkAggregateExpr(having, true);
	inferUnknownTypes(
		booleanType,
		havingScope,
		having);
	having.validate(this, havingScope);
	final RelDataType type = deriveType(havingScope, having);
	if (!SqlTypeUtil.inBooleanFamily(type)) {
		throw newValidationError(having, RESOURCE.havingMustBeBoolean());
	}
}
 
Example #28
Source File: JSqlTable.java    From kafka-eagle with Apache License 2.0 5 votes vote down vote up
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
	if (dataType == null) {
		RelDataTypeFactory.FieldInfoBuilder fieldInfo = typeFactory.builder();
		for (JSqlMapData.Column column : this.sourceTable.columns) {
			RelDataType sqlType = typeFactory.createJavaType(JSqlMapData.JAVATYPE_MAPPING.get(column.type));
			sqlType = SqlTypeUtil.addCharsetAndCollation(sqlType, typeFactory);
			fieldInfo.add(column.name, sqlType);
		}
		this.dataType = typeFactory.createStructType(fieldInfo);
	}
	return this.dataType;
}
 
Example #29
Source File: SqlMapValueConstructor.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
  Pair<RelDataType, RelDataType> type =
      getComponentTypes(
          opBinding.getTypeFactory(), opBinding.collectOperandTypes());
  if (null == type) {
    return null;
  }
  return SqlTypeUtil.createMapType(
      opBinding.getTypeFactory(),
      type.left,
      type.right,
      false);
}
 
Example #30
Source File: SqlMultisetQueryConstructor.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelDataType inferReturnType(
    SqlOperatorBinding opBinding) {
  RelDataType type =
      getComponentType(
          opBinding.getTypeFactory(),
          opBinding.collectOperandTypes());
  if (null == type) {
    return null;
  }
  return SqlTypeUtil.createMultisetType(
      opBinding.getTypeFactory(),
      type,
      false);
}