当前位置: 首页>>代码示例>>Java>>正文


Java SqlKind.CAST属性代码示例

本文整理汇总了Java中org.apache.calcite.sql.SqlKind.CAST属性的典型用法代码示例。如果您正苦于以下问题:Java SqlKind.CAST属性的具体用法?Java SqlKind.CAST怎么用?Java SqlKind.CAST使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.calcite.sql.SqlKind的用法示例。


在下文中一共展示了SqlKind.CAST属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addResult

private void addResult(RexNode exp) {
  // Cast of literal can't be reduced, so skip those (otherwise we'd
  // go into an infinite loop as we add them back).
  if (exp.getKind() == SqlKind.CAST) {
    RexCall cast = (RexCall) exp;
    RexNode operand = cast.getOperands().get(0);
    if (operand instanceof RexLiteral) {
      return;
    }
  }
  constExprs.add(exp);

  // In the case where the expression corresponds to a UDR argument,
  // we need to preserve casts.  Note that this only applies to
  // the topmost argument, not expressions nested within the UDR
  // call.
  //
  // REVIEW zfong 6/13/08 - Are there other expressions where we
  // also need to preserve casts?
  if (parentCallTypeStack.isEmpty()) {
    addCasts.add(false);
  } else {
    addCasts.add(isUdf(parentCallTypeStack.peek()));
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:25,代码来源:ReduceExpressionsRule.java

示例2: visitCall

@Override public String visitCall(RexCall call) {
  final String name = isItem(call);
  if (name != null) {
    return "\"" + name + "\"";
  }

  final List<String> strings = visitList(call.operands);
  if (call.getKind() == SqlKind.CAST) {
    return strings.get(0).startsWith("$") ? strings.get(0).substring(1) : strings.get(0);
  }
  if (call.getOperator() == SqlStdOperatorTable.ITEM) {
    final RexNode op1 = call.getOperands().get(1);
    if (op1 instanceof RexLiteral && op1.getType().getSqlTypeName() == SqlTypeName.INTEGER) {
      return stripQuotes(strings.get(0)) + "[" + ((RexLiteral) op1).getValue2() + "]";
    }
  }
  throw new IllegalArgumentException("Translation of " + call.toString()
    + "is not supported by ElasticsearchProject");
}
 
开发者ID:apache,项目名称:calcite,代码行数:19,代码来源:ElasticsearchRules.java

示例3: makeCast

@Override
public RexNode makeCast(
  RelDataType type,
  RexNode exp,
  boolean matchNullability) {
  // Special case: bypassing Calcite for interval types
  if (!(exp instanceof RexLiteral)
      && SqlTypeUtil.isExactNumeric(type)
      && SqlTypeUtil.isInterval(exp.getType())) {
    return makeAbstractCast(type, exp);
  }
  RexNode castRexNode = super.makeCast(type, exp, matchNullability);

  // If we have a CAST(A, TYPE) and A is already of the same TYPE (including nullability),
  // then return just A.
  if (castRexNode instanceof RexCall
    && castRexNode.getKind() == SqlKind.CAST
    && castRexNode.getType().equals(((RexCall) castRexNode).getOperands().get(0).getType())) {
    return ((RexCall) castRexNode).getOperands().get(0);
  }

  // If the types do not match (especially nullability), then cast it.
  if (!castRexNode.getType().equals(type)) {
    return makeAbstractCast(type, castRexNode);
  }

  return castRexNode;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:28,代码来源:DremioRexBuilder.java

示例4: stripCastFromString

/** Removes cast from string.
 *
 * <p>For example, {@code x > CAST('2015-01-07' AS DATE)}
 * becomes {@code x > '2015-01-07'}.
 */
private static RexNode stripCastFromString(RexNode node) {
  switch (node.getKind()) {
  case EQUALS:
  case IS_NOT_DISTINCT_FROM:
  case NOT_EQUALS:
  case GREATER_THAN:
  case GREATER_THAN_OR_EQUAL:
  case LESS_THAN:
  case LESS_THAN_OR_EQUAL:
    final RexCall call = (RexCall) node;
    final RexNode o0 = call.operands.get(0);
    final RexNode o1 = call.operands.get(1);
    if (o0.getKind() == SqlKind.CAST
        && o1.getKind() != SqlKind.CAST) {
      final RexNode o0b = ((RexCall) o0).getOperands().get(0);
      switch (o0b.getType().getSqlTypeName()) {
      case CHAR:
      case VARCHAR:
        return call.clone(call.getType(), ImmutableList.of(o0b, o1));
      }
    }
    if (o1.getKind() == SqlKind.CAST
        && o0.getKind() != SqlKind.CAST) {
      final RexNode o1b = ((RexCall) o1).getOperands().get(0);
      switch (o1b.getType().getSqlTypeName()) {
      case CHAR:
      case VARCHAR:
        return call.clone(call.getType(), ImmutableList.of(o0, o1b));
      }
    }
  }
  return node;
}
 
开发者ID:apache,项目名称:calcite,代码行数:38,代码来源:SqlImplementor.java

示例5: SqlCastFunction

public SqlCastFunction() {
  super(
      "CAST",
      SqlKind.CAST,
      null,
      InferTypes.FIRST_KNOWN,
      null,
      SqlFunctionCategory.SYSTEM);
}
 
开发者ID:apache,项目名称:calcite,代码行数:9,代码来源:SqlCastFunction.java

示例6: inferViewPredicates

/** Decomposes the WHERE clause of a view into predicates that constraint
 * a column to a particular value.
 *
 * <p>This method is key to the validation of a modifiable view. Columns that
 * are constrained to a single value can be omitted from the
 * SELECT clause of a modifiable view.
 *
 * @param projectMap Mapping from column ordinal to the expression that
 * populate that column, to be populated by this method
 * @param filters List of remaining filters, to be populated by this method
 * @param constraint Constraint to be analyzed
 */
public static void inferViewPredicates(Map<Integer, RexNode> projectMap,
    List<RexNode> filters, RexNode constraint) {
  for (RexNode node : conjunctions(constraint)) {
    switch (node.getKind()) {
    case EQUALS:
      final List<RexNode> operands = ((RexCall) node).getOperands();
      RexNode o0 = operands.get(0);
      RexNode o1 = operands.get(1);
      if (o0 instanceof RexLiteral) {
        o0 = operands.get(1);
        o1 = operands.get(0);
      }
      if (o0.getKind() == SqlKind.CAST) {
        o0 = ((RexCall) o0).getOperands().get(0);
      }
      if (o0 instanceof RexInputRef && o1 instanceof RexLiteral) {
        final int index = ((RexInputRef) o0).getIndex();
        if (projectMap.get(index) == null) {
          projectMap.put(index, o1);
          continue;
        }
      }
    }
    filters.add(node);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:38,代码来源:RelOptUtil.java

示例7: visitCall

@Override
public RexNode visitCall(final RexCall call) {
	RexNode newCall;

	boolean[] update = {false};
	List<RexNode> clonedOperands = visitList(call.operands, update);
	if (update[0]) {
		SqlOperator operator = call.getOperator();

		boolean isSpecialCast = false;
		if (operator instanceof SqlFunction) {
			SqlFunction function = (SqlFunction) operator;
			if (function.getKind() == SqlKind.CAST) {
				if (call.operands.size() < 2) {
					isSpecialCast = true;
				}
			}
		}

		final RelDataType newType;
		if (!isSpecialCast) {
			// TODO: ideally this only needs to be called if the result
			// type will also change. However, since that requires
			// support from type inference rules to tell whether a rule
			// decides return type based on input types, for now all
			// operators will be recreated with new type if any operand
			// changed, unless the operator has "built-in" type.
			newType = rexBuilder.deriveReturnType(operator, clonedOperands);
		} else {
			// Use the current return type when creating a new call, for
			// operators with return type built into the operator
			// definition, and with no type inference rules, such as
			// cast function with less than 2 operands.

			// TODO: Comments in RexShuttle.visitCall() mention other
			// types in this category. Need to resolve those together
			// and preferably in the base class RexShuttle.
			newType = call.getType();
		}
		newCall = rexBuilder.makeCall(newType, operator, clonedOperands);
	} else {
		newCall = call;
	}

	if (projectPulledAboveLeftCorrelator && (nullIndicator != null)) {
		return createCaseExpression(nullIndicator, rexBuilder.constantNull(), newCall);
	}
	return newCall;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:49,代码来源:FlinkRelDecorrelator.java

示例8: visitCall

@Override public String visitCall(RexCall call) {
  String name = isItem(call);
  if (name != null) {
    return "'$" + name + "'";
  }
  final List<String> strings = visitList(call.operands);
  if (call.getKind() == SqlKind.CAST) {
    return strings.get(0);
  }
  String stdOperator = MONGO_OPERATORS.get(call.getOperator());
  if (stdOperator != null) {
    return "{" + stdOperator + ": [" + Util.commaList(strings) + "]}";
  }
  if (call.getOperator() == SqlStdOperatorTable.ITEM) {
    final RexNode op1 = call.operands.get(1);
    if (op1 instanceof RexLiteral
        && op1.getType().getSqlTypeName() == SqlTypeName.INTEGER) {
      if (!Bug.CALCITE_194_FIXED) {
        return "'" + stripQuotes(strings.get(0)) + "["
            + ((RexLiteral) op1).getValue2() + "]'";
      }
      return strings.get(0) + "[" + strings.get(1) + "]";
    }
  }
  if (call.getOperator() == SqlStdOperatorTable.CASE) {
    StringBuilder sb = new StringBuilder();
    StringBuilder finish = new StringBuilder();
    // case(a, b, c)  -> $cond:[a, b, c]
    // case(a, b, c, d) -> $cond:[a, b, $cond:[c, d, null]]
    // case(a, b, c, d, e) -> $cond:[a, b, $cond:[c, d, e]]
    for (int i = 0; i < strings.size(); i += 2) {
      sb.append("{$cond:[");
      finish.append("]}");

      sb.append(strings.get(i));
      sb.append(',');
      sb.append(strings.get(i + 1));
      sb.append(',');
      if (i == strings.size() - 3) {
        sb.append(strings.get(i + 2));
        break;
      }
      if (i == strings.size() - 2) {
        sb.append("null");
        break;
      }
    }
    sb.append(finish);
    return sb.toString();
  }
  throw new IllegalArgumentException("Translation of " + call.toString()
      + " is not supported by MongoProject");
}
 
开发者ID:apache,项目名称:calcite,代码行数:53,代码来源:MongoRules.java

示例9: visitCall

@Override public RexNode visitCall(final RexCall call) {
  RexNode newCall;

  boolean[] update = {false};
  List<RexNode> clonedOperands = visitList(call.operands, update);
  if (update[0]) {
    SqlOperator operator = call.getOperator();

    boolean isSpecialCast = false;
    if (operator instanceof SqlFunction) {
      SqlFunction function = (SqlFunction) operator;
      if (function.getKind() == SqlKind.CAST) {
        if (call.operands.size() < 2) {
          isSpecialCast = true;
        }
      }
    }

    final RelDataType newType;
    if (!isSpecialCast) {
      // TODO: ideally this only needs to be called if the result
      // type will also change. However, since that requires
      // support from type inference rules to tell whether a rule
      // decides return type based on input types, for now all
      // operators will be recreated with new type if any operand
      // changed, unless the operator has "built-in" type.
      newType = rexBuilder.deriveReturnType(operator, clonedOperands);
    } else {
      // Use the current return type when creating a new call, for
      // operators with return type built into the operator
      // definition, and with no type inference rules, such as
      // cast function with less than 2 operands.

      // TODO: Comments in RexShuttle.visitCall() mention other
      // types in this category. Need to resolve those together
      // and preferably in the base class RexShuttle.
      newType = call.getType();
    }
    newCall =
        rexBuilder.makeCall(
            newType,
            operator,
            clonedOperands);
  } else {
    newCall = call;
  }

  if (projectPulledAboveLeftCorrelator && (nullIndicator != null)) {
    return createCaseExpression(
        nullIndicator,
        rexBuilder.constantNull(),
        newCall);
  }
  return newCall;
}
 
开发者ID:apache,项目名称:calcite,代码行数:55,代码来源:RelDecorrelator.java


注:本文中的org.apache.calcite.sql.SqlKind.CAST属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。