Examples of RexProgramBuilder


Examples of org.eigenbase.rex.RexProgramBuilder

  public void testAnalyzeTwoConstantProgram()
    {
    final RelDataTypeFactory typeFactory = new FieldTypeFactory();
    final RelDataType inputType = typeFactory.createStructType( new RelDataTypeFactory.FieldInfoBuilder() );
    final RexBuilder builder = new RexBuilder( typeFactory );
    final RexProgramBuilder programBuilder = new RexProgramBuilder( inputType, builder );
    programBuilder.addProject( builder.makeExactLiteral( BigDecimal.ONE ), "x" );
    programBuilder.addProject( builder.makeCharLiteral( new NlsString( "foo", null, null ) ), "y" );
    final RexProgram program = programBuilder.getProgram();
    final ProgramUtil.Analyzed analyze = ProgramUtil.analyze( program );
    assertTrue( analyze.hasConstants );
    assertFalse( analyze.hasFunctions );
    assertNull( analyze.permutation );
    assertFalse( analyze.isComplex );
View Full Code Here

Examples of org.eigenbase.rex.RexProgramBuilder

        if( analyze.permutation != null && !analyze.permutation.isIdentity() )
          {
          if( analyze.hasConstants || analyze.hasFunctions )
            throw new IllegalStateException( "permutation projection has constant and function transforms" );

          final RexProgramBuilder builder = new RexProgramBuilder( previous.getOutputRowType(), rexBuilder );

          for( int i = 0; i < analyze.permutation.getTargetCount(); i++ )
            {
            final int target = analyze.permutation.getTarget( i );
            builder.addProject( target, null );
            }

          previous = builder.getProgram();
          list.add( Pair.of( Op.RENAME, previous ) );
          break;
          }

        if( analyze.isFilter() )
          {
          // Build a program that has a condition (a possibly complex expression)
          // but projects all inputs.
          final RexProgramBuilder builder = new RexProgramBuilder( previous.getOutputRowType(), rexBuilder );
          builder.addIdentity();
          builder.addCondition( program.gatherExpr( program.getCondition() ) );
          previous = builder.getProgram();
          list.add( Pair.of( Op.FILTER, previous ) );

          // Remove condition from the remaining program.
          final RexProgramBuilder builder2 = RexProgramBuilder.forProgram( program, rexBuilder, false );
          builder2.clearCondition();
          program = builder2.getProgram( true );
          continue;
          }

        // TODO: remove "|| analyze.hasConstants" and generate a CONSTANTS slice
        if( analyze.isComplex || analyze.hasFunctions || analyze.hasConstants )
          {
          previous = program;
          list.add( Pair.of( Op.FUNCTION, previous ) );
          break;
          }

        if( analyze.hasConstants )
          {
          final RexProgramBuilder builder = new RexProgramBuilder( previous.getOutputRowType(), rexBuilder );

          if( true )
            throw new AssertionError(); // TODO:

          previous = builder.getProgram();
          list.add( Pair.of( Op.CONSTANT, previous ) );
          continue;
          }

        if( analyze.isOnlyRename )
          {
          // Create a program that projects all of its inputs, in order, but with different names.
          final RexProgramBuilder builder = new RexProgramBuilder( previous.getOutputRowType(), rexBuilder );
          final List<String> outputFieldNames = new ArrayList<String>( program.getInputRowType().getFieldNames() );

          for( Ord<String> name : Ord.zip( program.getOutputRowType().getFieldNames() ) )
            {
            final int source = program.getSourceField( name.i );

            if( source >= 0 )
              outputFieldNames.set( source, name.e );
            }

          for( int i = 0; i < outputFieldNames.size(); i++ )
            builder.addProject( i, outputFieldNames.get( i ) );

          previous = builder.getProgram();
          list.add( Pair.of( Op.RENAME, previous ) );

          // We're done. Remaining program would be the identity.
          break;
          }

        if( analyze.isRetainWithRename() )
          {
          final RexProgramBuilder builder = new RexProgramBuilder( previous.getOutputRowType(), rexBuilder );
          builder.addIdentity();
          builder.clearProjects();

          for( RexLocalRef pair : program.getProjectList() )
            {
            final int index = pair.getIndex();
            builder.addProject( index, program.getInputRowType().getFieldNames().get( index ) );
            }

          previous = builder.getProgram();
          list.add( Pair.of( Op.RETAIN, previous ) );

          // There may or may not be renames left.
          program = RexProgram.createIdentity( previous.getOutputRowType(), program.getOutputRowType() );
View Full Code Here

Examples of org.eigenbase.rex.RexProgramBuilder

  private static RexProgram renameInputs( RexProgram program, RexBuilder rexBuilder, List<String> names )
    {
    final RelDataType inputRowType = program.getInputRowType();
    if( inputRowType.getFieldNames().equals( names ) )
      return program;
    final RexProgramBuilder builder = RexProgramBuilder.create(
      rexBuilder,
      rexBuilder.getTypeFactory().createStructType(
        Pair.zip( names, RelOptUtil.getFieldTypeList( inputRowType ) ) ),
      program.getExprList(),
      program.getProjectList(),
      program.getCondition(),
      program.getOutputRowType(),
      false );
    return builder.getProgram();
    }
View Full Code Here

Examples of org.eigenbase.rex.RexProgramBuilder

  public static RexProgram createRexProgram( CascadingProjectRel projectRel )
    {
    RelOptCluster cluster = projectRel.getCluster();
    RelDataType rowType = projectRel.getChild().getRowType();

    RexProgramBuilder builder = new RexProgramBuilder( rowType, cluster.getRexBuilder() );

    List<Pair<RexNode, String>> projects = projectRel.getNamedProjects();

    for( int i = 0; i < projects.size(); i++ )
      {
      Pair<RexNode, String> exp = projects.get( i );

      if( !( exp.left instanceof RexInputRef ) ) // RexCall or RexLiteral
        builder.addExpr( exp.left );

      int index = i;

      if( exp.left instanceof RexInputRef )
        index = ( (RexInputRef) exp.left ).getIndex();

      builder.addProject( index, exp.right );
      }

    return builder.getProgram( false ); // todo: optimizer causes issues
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.