org.apache.calcite.sql.fun.SqlMultisetQueryConstructor Java Examples

The following examples show how to use org.apache.calcite.sql.fun.SqlMultisetQueryConstructor. 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: StandardConvertletTable.java    From Bats with Apache License 2.0 6 votes vote down vote up
public RexNode convertMultisetQuery(
    SqlRexContext cx,
    SqlMultisetQueryConstructor op,
    SqlCall call) {
  final RelDataType originalType =
      cx.getValidator().getValidatedNodeType(call);
  RexRangeRef rr = cx.getSubQueryExpr(call);
  assert rr != null;
  RelDataType msType = rr.getType().getFieldList().get(0).getType();
  RexNode expr =
      cx.getRexBuilder().makeInputRef(
          msType,
          rr.getOffset());
  assert msType.getComponentType().isStruct();
  if (!originalType.getComponentType().isStruct()) {
    // If the type is not a struct, the multiset operator will have
    // wrapped the type as a record. Add a call to the $SLICE operator
    // to compensate. For example,
    // if '<ms>' has type 'RECORD (INTEGER x) MULTISET',
    // then '$SLICE(<ms>) has type 'INTEGER MULTISET'.
    // This will be removed as the expression is translated.
    expr =
        cx.getRexBuilder().makeCall(SqlStdOperatorTable.SLICE, expr);
  }
  return expr;
}
 
Example #2
Source File: StandardConvertletTable.java    From calcite with Apache License 2.0 6 votes vote down vote up
public RexNode convertMultisetQuery(
    SqlRexContext cx,
    SqlMultisetQueryConstructor op,
    SqlCall call) {
  final RelDataType originalType =
      cx.getValidator().getValidatedNodeType(call);
  RexRangeRef rr = cx.getSubQueryExpr(call);
  assert rr != null;
  RelDataType msType = rr.getType().getFieldList().get(0).getType();
  RexNode expr =
      cx.getRexBuilder().makeInputRef(
          msType,
          rr.getOffset());
  assert msType.getComponentType().isStruct();
  if (!originalType.getComponentType().isStruct()) {
    // If the type is not a struct, the multiset operator will have
    // wrapped the type as a record. Add a call to the $SLICE operator
    // to compensate. For example,
    // if '<ms>' has type 'RECORD (INTEGER x) MULTISET',
    // then '$SLICE(<ms>) has type 'INTEGER MULTISET'.
    // This will be removed as the expression is translated.
    expr =
        cx.getRexBuilder().makeCall(SqlStdOperatorTable.SLICE, expr);
  }
  return expr;
}