coral-beam/src/main/java/com/linkedin/beam/utils/RexToBeamConverter.java
Expression convertLiteral(RexLiteral literal, String schemaName) {
    if (literal.getValue() == null) {
      return Expressions.constant(null);
    }
    switch (literal.getType().getSqlTypeName()) {
      case CHAR:
      case VARCHAR:
        return Expressions.constant(((NlsString) literal.getValue()).getValue(), String.class);
      case INTEGER:
        return Expressions.constant(((BigDecimal) literal.getValue()).intValue(), int.class);
      case BIGINT:
        return Expressions.constant(((BigDecimal) literal.getValue()).longValue(), long.class);
      case DOUBLE:
        return Expressions.constant(((BigDecimal) literal.getValue()).doubleValue(), double.class);
      case BOOLEAN:
        return Expressions.constant(literal.getValue(), boolean.class);
      case ROW: {
        if (!(literal.getValue() instanceof List)) {
          throw new UnsupportedOperationException("Record constant must be a list");
        }
        final List<RexLiteral> literals = (List<RexLiteral>) literal.getValue();
        final List<Expression> literalExprs = new ArrayList<>();
        for (RexLiteral rexLiteral : literals) {
          literalExprs.add(convertLiteral(rexLiteral, schemaName));
        }
        final Expression pigTuple = Expressions.call(Methods.BUILD_TUPLE, literalExprs);
        if (pigUDFContext) {
          return pigTuple;
        }
        final ParameterExpression schemaExpr = registerSchema(schemaName, literal.getType());
        return toAvroRecord(pigTuple, schemaExpr);
      }
      case MULTISET: {
        if (!(literal.getValue() instanceof List)) {
          throw new UnsupportedOperationException("Multiset constant must be a list");
        }
        final List<RexLiteral> literals = (List<RexLiteral>) literal.getValue();
        final List<Expression> literalExprs = new ArrayList<>();
        final String componentSchema = schemaName + "_COMP";
        for (RexLiteral rexLiteral : literals) {
          literalExprs.add(convertLiteral(rexLiteral, componentSchema));
        }

        final Expression pigDatabag = Expressions.call(Methods.BUILD_BAG, literalExprs);
        if (pigUDFContext) {
          return pigDatabag;
        }
        final ParameterExpression schemaExpr = registerSchema(schemaName, literal.getType());
        return toAvroArray(pigDatabag, schemaExpr);
      }
      default:
        throw new UnsupportedOperationException(
            "constant type: " + literal.getType().getSqlTypeName() + " not supported");
    }
  }
/**
   * Converts a relational literal into a Java code constant expression
   *
   * TODO This method should be aware of whether the literal is for PigUDF (then Pig constant) or not (Avro constants)
   */
Converts a relational literal into a Java code constant expression
TODO This method should be aware of whether the literal is for PigUDF (then Pig constant) or not (Avro constants)
Converts a relational literal into a Java code constant expression TODO This method should be aware of whether the literal is for PigUDF ( then Pig constant ) or not ( Avro constants )
Expression convertLiteral(RexLiteral literal, String schemaName) {
    if (literal.getValue() == null) {
      return Expressions.constant(null);
    }
    switch (literal.getType().getSqlTypeName()) {
      case CHAR:
      case VARCHAR:
        return Expressions.constant(((NlsString) literal.getValue()).getValue(), String.class);
      case INTEGER:
        return Expressions.constant(((BigDecimal) literal.getValue()).intValue(), int.class);
      case BIGINT:
        return Expressions.constant(((BigDecimal) literal.getValue()).longValue(), long.class);
      case DOUBLE:
        return Expressions.constant(((BigDecimal) literal.getValue()).doubleValue(), double.class);
      case BOOLEAN:
        return Expressions.constant(literal.getValue(), boolean.class);
      case ROW: {
        if (!(literal.getValue() instanceof List)) {
          throw new UnsupportedOperationException("Record constant must be a list");
        }
        final List<RexLiteral> literals = (List<RexLiteral>) literal.getValue();
        final List<Expression> literalExprs = new ArrayList<>();
        for (RexLiteral rexLiteral : literals) {
          literalExprs.add(convertLiteral(rexLiteral, schemaName));
        }
        final Expression pigTuple = Expressions.call(Methods.BUILD_TUPLE, literalExprs);
        if (pigUDFContext) {
          return pigTuple;
        }
        final ParameterExpression schemaExpr = registerSchema(schemaName, literal.getType());
        return toAvroRecord(pigTuple, schemaExpr);
      }
      case MULTISET: {
        if (!(literal.getValue() instanceof List)) {
          throw new UnsupportedOperationException("Multiset constant must be a list");
        }
        final List<RexLiteral> literals = (List<RexLiteral>) literal.getValue();
        final List<Expression> literalExprs = new ArrayList<>();
        final String componentSchema = schemaName + "_COMP";
        for (RexLiteral rexLiteral : literals) {
          literalExprs.add(convertLiteral(rexLiteral, componentSchema));
        }
        final Expression pigDatabag = Expressions.call(Methods.BUILD_BAG, literalExprs);
        if (pigUDFContext) {
          return pigDatabag;
        }
        final ParameterExpression schemaExpr = registerSchema(schemaName, literal.getType());
        return toAvroArray(pigDatabag, schemaExpr);
      }
      default:
        throw new UnsupportedOperationException(
            "constant type: " + literal.getType().getSqlTypeName() + " not supported");
    }
  }
Expression convertLiteral ( RexLiteral literal , String schemaName ) { if ( literal . getValue ( ) == null ) { return Expressions . constant ( null ) ; } switch ( literal . getType ( ) . getSqlTypeName ( ) ) { case CHAR : case VARCHAR : return Expressions . constant ( ( ( NlsString ) literal . getValue ( ) ) . getValue ( ) , String . class ) ; case INTEGER : return Expressions . constant ( ( ( BigDecimal ) literal . getValue ( ) ) . intValue ( ) , int . class ) ; case BIGINT : return Expressions . constant ( ( ( BigDecimal ) literal . getValue ( ) ) . longValue ( ) , long . class ) ; case DOUBLE : return Expressions . constant ( ( ( BigDecimal ) literal . getValue ( ) ) . doubleValue ( ) , double . class ) ; case BOOLEAN : return Expressions . constant ( literal . getValue ( ) , boolean . class ) ; case ROW : { if ( ! ( literal . getValue ( ) instanceof List ) ) { throw new UnsupportedOperationException ( "Record constant must be a list" ) ; } final List < RexLiteral > literals = ( List < RexLiteral > ) literal . getValue ( ) ; final List < Expression > literalExprs = new ArrayList < > ( ) ; for ( RexLiteral rexLiteral : literals ) { literalExprs . add ( convertLiteral ( rexLiteral , schemaName ) ) ; } final Expression pigTuple = Expressions . call ( Methods . BUILD_TUPLE , literalExprs ) ; if ( pigUDFContext ) { return pigTuple ; } final ParameterExpression schemaExpr = registerSchema ( schemaName , literal . getType ( ) ) ; return toAvroRecord ( pigTuple , schemaExpr ) ; } case MULTISET : { if ( ! ( literal . getValue ( ) instanceof List ) ) { throw new UnsupportedOperationException ( "Multiset constant must be a list" ) ; } final List < RexLiteral > literals = ( List < RexLiteral > ) literal . getValue ( ) ; final List < Expression > literalExprs = new ArrayList < > ( ) ; final String componentSchema = schemaName + "_COMP" ; for ( RexLiteral rexLiteral : literals ) { literalExprs . add ( convertLiteral ( rexLiteral , componentSchema ) ) ; } final Expression pigDatabag = Expressions . call ( Methods . BUILD_BAG , literalExprs ) ; if ( pigUDFContext ) { return pigDatabag ; } final ParameterExpression schemaExpr = registerSchema ( schemaName , literal . getType ( ) ) ; return toAvroArray ( pigDatabag , schemaExpr ) ; } default : throw new UnsupportedOperationException ( "constant type: " + literal . getType ( ) . getSqlTypeName ( ) + " not supported" ) ; } }
Converts a relational literal into a Java code constant expression
 TODO This method should be aware of whether the literal is for PigUDF (then Pig constant) or not (Avro constants)
Converts a relational literal into a Java code constant expression TODO This method should be aware of whether the literal is for PigUDF ( then Pig constant ) or not ( Avro constants )