1 Reply Latest reply on Oct 30, 2017 8:46 AM by Steven Hawkins

    how to change the value of a where clause exprssion in createResultSetExecution

    Muhammad Kamran Newbie


      Hi Everyone,

      Using teiid-9.1.1 ,  i am writing a translator,  in  createResultSetExecution need to change the value of where clause in select command.

      like below

      select * from table where table_name='test-01';

      i need to chagne the value of test-01 to test before executing the request.

      Thanks in advance for any help.

      Kamran

        • 1. Re: how to change the value of a where clause exprssion in createResultSetExecution
          Steven Hawkins Master

          Your logic to do this will depend upon a few factors, such as what types of commands you can handle (just Select or also SetQuery), what predicates are allowed, etc.  Navigating directly looks like:

           

          Select select = (Select)command;

          Condition condition = select.getWhere();

          if (condition instanceof Comparison) {

          Comparison comparison = (Comparison)condition;

          Expression lex = comparison.getLeftExpression();

          if (lex instanceof ColumnReference) {

             //further test that it's the column reference you want

           

             //set the right to a new literal

             comparison.setRightExpression(new Literal("new value", String.class));

          }

          }

           

          You may also use a visitor:

           

          HierarchyVisitor visitor = new HierarchyVisitor() {

              public void visit(Comparison obj) {

                  //do something here

              }

          };

           

          Select select = (Select)command;

          Condition condition = select.getWhere();

          if (condition != null) {

            condition.acceptVisitor(visitor);

          }

           

          Finally you may also want to consider if there is a way to do this type of manipulation using a standard mechanism, such as row level data role conditions.