Java Code Examples for org.apache.calcite.sql.fun.SqlMultisetValueConstructor

The following examples show how to use org.apache.calcite.sql.fun.SqlMultisetValueConstructor. These examples are extracted from open source projects. 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 Project: Bats   Source File: StandardConvertletTable.java    License: Apache License 2.0 5 votes vote down vote up
public RexNode convertMultiset(
    SqlRexContext cx,
    SqlMultisetValueConstructor 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(originalType, SqlStdOperatorTable.SLICE,
            ImmutableList.of(expr));
  }
  return expr;
}
 
Example 2
Source Project: calcite   Source File: StandardConvertletTable.java    License: Apache License 2.0 5 votes vote down vote up
public RexNode convertMultiset(
    SqlRexContext cx,
    SqlMultisetValueConstructor 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(originalType, SqlStdOperatorTable.SLICE,
            ImmutableList.of(expr));
  }
  return expr;
}