Collect value equivalence expressions across the entire SQL statement
@return a map of tuple value expressions to the other expressions,
TupleValueExpressions, ConstantValueExpressions, or ParameterValueExpressions,
that they are constrained to equal.
485569
HashMap<AbstractExpression, Set<AbstractExpression>> analyzeValueEquivalence() {
        // collect individual where/join expressions
        m_joinTree.analyzeJoinExpressions(m_noTableSelectionList);
        return m_joinTree.getAllEquivalenceFilters();
    }
377522
protected ExpressionList<T> peekExprList() {

    if (textMode) {
      // return the current text expression list
      return _peekText();
    }

    if (whereStack == null) {
      whereStack = new ArrayStack<>();
      whereStack.push(query.where());
    }
    // return the current expression list
    return whereStack.peek();
  }
414401
private static List<AbstractExpression> filterSingleTVEExpressions(List<AbstractExpression> exprs,
            List<AbstractExpression> otherExprs) {
        List<AbstractExpression> singleTVEExprs = new ArrayList<>();
        for (AbstractExpression expr : exprs) {
            List<TupleValueExpression> tves = ExpressionUtil.getTupleValueExpressions(expr);
            if (tves.size() == 1) {
                singleTVEExprs.add(expr);
            } else {
                otherExprs.add(expr);
            }
        }
        return singleTVEExprs;
    }
868104
private Iterator<Tuple> getSatisfyingTuples( final TestCaseDef testCase, VarTupleSet varTupleSet)
    {
    final Comparator<VarBindingDef> byUsage = byUsage( varTupleSet);

    return
      IteratorUtils.transformedIterator(
        // Iterate over all combinations of bindings...
        new CartesianProduct<VarBindingDef>(

          // ...combining members from all sets of bindings...
          new ArrayList<Set<VarBindingDef>>(
            CollectionUtils.collect(
              // ...where each set of bindings is derived from a disjunct of unsatisfied test case conditions....
              testCase.getRequired().getDisjuncts(),

              // ...and contains the set of compatible bindings that could satisfy this disjunct...
              disjunct ->
                {
                Set<String> unsatisfied =
                  CollectionUtils.collect(
                    disjunct.getAssertions(),
                    assertion -> assertion.getProperty(),
                    new HashSet<String>());

                Iterator<VarBindingDef> satisfyingBindings =
                  IteratorUtils.filteredIterator(
                    getPropertyProviders( unsatisfied).iterator(),
                    binding -> testCase.isCompatible( binding));

                // ...arranging satisfying bindings in order of decreasing preference...
                return
                  CollectionUtils.collect(
                    satisfyingBindings,
                    nopTransformer(),
                    new TreeSet<VarBindingDef>( byUsage));
                },

              // ...arranging sets in a well-defined order for repeatable combinations...
              new TreeSet<Set<VarBindingDef>>( varBindingSetSorter_))),
          
          // ...ignoring any infeasible combinations...
          bindings -> Tuple.of( bindings) != null),
        
         // ... forming each combination of satisfying bindings into a tuple...
        Tuple::of);
    }
702340
public List<String> getVariables() {
    return this.templateChunks.stream()
        .filter(templateChunk -> Expression.class.isAssignableFrom(templateChunk.getClass()))
        .map(templateChunk -> ((Expression) templateChunk).getName())
        .filter(Objects::nonNull)
        .collect(Collectors.toList());
  }
701161
@SafeVarargs
  static <T> String sqlArgumentList(T... values) {
    StringBuilder sb = new StringBuilder();
    if (values.length != 0) {
      sb.append(values[0]);
      for (int i=1; i < values.length; i++) {
        sb.append(',').append(' ').append(values[i]);
      }
    }
    return sb.toString();
  }
1361046
@Override
    public Map<String, String> mapToColumns(Tuple tuple) {
        Fields fields = tuple.getFields();
        Map<String, String> columns = new HashMap<String, String>();
        for (int i = 0; i < fields.size(); i++) {
            String name = fields.get(i);
            Boolean isRowField = Arrays.asList(this.rowKeyFields).contains(name);
            if (!isRowField) {
                Object value = tuple.getValueByField(name);
                columns.put(name, (value != null ? value.toString() : ""));
            }
        }
        return columns;
    }
679814
private PExp getImpliesExpression(ASetCompSetExp exp, ILexNameToken finmap,
			ILexNameToken findex)
	{
		if (exp.getPredicate() == null) // set comprehension has no predicate
		{
			return getImpliesExists(exp, finmap, findex);
		} else
		{
			return AstExpressionFactory.newAImpliesBooleanBinaryExp(exp.getPredicate().clone(), getImpliesExists(exp.clone(), finmap, findex));
		}
	}
60178
public TupleValueExpression getOutputExpression(int index) {
        SchemaColumn schemaCol = getSchemaColumn(index);
        TupleValueExpression tve = new TupleValueExpression(getTableAlias(), getTableAlias(),
                schemaCol.getColumnAlias(), schemaCol.getColumnAlias(), index);
        return tve;
    }
993427
@Override
  public String getSqlWithValues() {
    final StringBuilder sb = new StringBuilder();
    final String statementQuery = getStatementQuery();

    // iterate over the characters in the query replacing the parameter placeholders
    // with the actual values
    int currentParameter = 0;
    for( int pos = 0; pos < statementQuery.length(); pos ++) {
      char character = statementQuery.charAt(pos);
      if( statementQuery.charAt(pos) == '?' && currentParameter <= parameterValues.size()) {
        // replace with parameter value
        Value value = parameterValues.get(currentParameter);
        sb.append(value != null ? value.toString() : new Value().toString());
        currentParameter++;
      } else {
        sb.append(character);
      }
    }

    return sb.toString();
  }
239346
public List<AbstractExpression> bindingToIndexedExpression(
            AbstractExpression expr) {
        // Defer the result construction for as long as possible on the
        // assumption that this function mostly gets applied to eliminate
        // negative cases.
        if (m_type != expr.m_type) {
            // The only allowed difference in expression types is between a
            // parameter and its original constant value.
            // That's handled in the independent override.
            return null;
        }

        // From here, this is much like the straight equality check,
        // except that this function and "equals" must each call themselves
        // in their recursions.

        // Delegating to this factored-out component of the "equals"
        // implementation eases simultaneous refinement of both methods.
        if ( ! hasEqualAttributes(expr)) {
            return null;
        }
        // The derived classes have verified that any added attributes
        // are identical.

        // Check that the presence, or lack, of children is the same
        if ((expr.m_left == null) != (m_left == null)) {
            return null;
        }
        if ((expr.m_right == null) != (m_right == null)) {
            return null;
        }
        if ((expr.m_args == null) != (m_args == null)) {
            return null;
        }

        // Check that the children identify themselves as matching
        List<AbstractExpression> leftBindings = null;
        if (m_left != null) {
            leftBindings = m_left.bindingToIndexedExpression(expr.m_left);
            if (leftBindings == null) {
                return null;
            }
        }
        List<AbstractExpression> rightBindings = null;
        if (m_right != null) {
            rightBindings = m_right.bindingToIndexedExpression(expr.m_right);
            if (rightBindings == null) {
                return null;
            }
        }
        List<AbstractExpression> argBindings = null;
        if (m_args != null) {
            if (m_args.size() != expr.m_args.size()) {
                return null;
            }
            argBindings = new ArrayList<>();
            int ii = 0;
            // iterate the args lists in parallel, binding pairwise
            for (AbstractExpression rhs : expr.m_args) {
                AbstractExpression lhs = m_args.get(ii++);
                List<AbstractExpression> moreBindings =
                        lhs.bindingToIndexedExpression(rhs);
                if (moreBindings == null) { // fail on any non-match
                    return null;
                }
                argBindings.addAll(moreBindings);
            }
        }

        // It's a match, so gather up the details.
        // It's rare (if even possible) for the same bound parameter to get
        // listed twice, so don't worry about duplicate entries, here.
        // That should not cause any issue for the caller.
        List<AbstractExpression> result = new ArrayList<>();
        if (leftBindings != null) { // null here can only mean no left child
            result.addAll(leftBindings);
        }
        if (rightBindings != null) { // null here can only mean no right child
            result.addAll(rightBindings);
        }
        if (argBindings != null) { // null here can only mean no args
            result.addAll(argBindings);
        }
        return result;
    }
101716
public final hqlParser.equalityExpression_return equalityExpression() throws RecognitionException {
		hqlParser.equalityExpression_return retval = new hqlParser.equalityExpression_return();
		retval.start = input.LT(1);

		CommonTree root_0 = null;

		Token isx=null;
		Token ne=null;
		Token EQ163=null;
		Token NOT164=null;
		Token NE165=null;
		ParserRuleReturnScope x =null;
		ParserRuleReturnScope y =null;

		CommonTree isx_tree=null;
		CommonTree ne_tree=null;
		CommonTree EQ163_tree=null;
		CommonTree NOT164_tree=null;
		CommonTree NE165_tree=null;

		try {
			// hql.g:441:2: (x= relationalExpression ( ( EQ ^|isx= IS ^ ( NOT !)? | NE ^|ne= SQL_NE ^) y= relationalExpression )* )
			// hql.g:441:4: x= relationalExpression ( ( EQ ^|isx= IS ^ ( NOT !)? | NE ^|ne= SQL_NE ^) y= relationalExpression )*
			{
			root_0 = (CommonTree)adaptor.nil();


			pushFollow(FOLLOW_relationalExpression_in_equalityExpression1987);
			x=relationalExpression();
			state._fsp--;

			adaptor.addChild(root_0, x.getTree());

			// hql.g:441:27: ( ( EQ ^|isx= IS ^ ( NOT !)? | NE ^|ne= SQL_NE ^) y= relationalExpression )*
			loop56:
			while (true) {
				int alt56=2;
				int LA56_0 = input.LA(1);
				if ( (LA56_0==EQ||LA56_0==IS||LA56_0==NE||LA56_0==SQL_NE) ) {
					alt56=1;
				}

				switch (alt56) {
				case 1 :
					// hql.g:442:3: ( EQ ^|isx= IS ^ ( NOT !)? | NE ^|ne= SQL_NE ^) y= relationalExpression
					{
					// hql.g:442:3: ( EQ ^|isx= IS ^ ( NOT !)? | NE ^|ne= SQL_NE ^)
					int alt55=4;
					switch ( input.LA(1) ) {
					case EQ:
						{
						alt55=1;
						}
						break;
					case IS:
						{
						alt55=2;
						}
						break;
					case NE:
						{
						alt55=3;
						}
						break;
					case SQL_NE:
						{
						alt55=4;
						}
						break;
					default:
						NoViableAltException nvae =
							new NoViableAltException("", 55, 0, input);
						throw nvae;
					}
					switch (alt55) {
						case 1 :
							// hql.g:442:5: EQ ^
							{
							EQ163=(Token)match(input,EQ,FOLLOW_EQ_in_equalityExpression1995);
							EQ163_tree = (CommonTree)adaptor.create(EQ163);
							root_0 = (CommonTree)adaptor.becomeRoot(EQ163_tree, root_0);

							}
							break;
						case 2 :
							// hql.g:443:5: isx= IS ^ ( NOT !)?
							{
							isx=(Token)match(input,IS,FOLLOW_IS_in_equalityExpression2004);
							isx_tree = (CommonTree)adaptor.create(isx);
							root_0 = (CommonTree)adaptor.becomeRoot(isx_tree, root_0);

							 isx.setType(EQ);
							// hql.g:443:35: ( NOT !)?
							int alt54=2;
							int LA54_0 = input.LA(1);
							if ( (LA54_0==NOT) ) {
								alt54=1;
							}
							switch (alt54) {
								case 1 :
									// hql.g:443:36: NOT !
									{
									NOT164=(Token)match(input,NOT,FOLLOW_NOT_in_equalityExpression2010);
									 isx.setType(NE);
									}
									break;

							}

							}
							break;
						case 3 :
							// hql.g:444:5: NE ^
							{
							NE165=(Token)match(input,NE,FOLLOW_NE_in_equalityExpression2022);
							NE165_tree = (CommonTree)adaptor.create(NE165);
							root_0 = (CommonTree)adaptor.becomeRoot(NE165_tree, root_0);

							}
							break;
						case 4 :
							// hql.g:445:5: ne= SQL_NE ^
							{
							ne=(Token)match(input,SQL_NE,FOLLOW_SQL_NE_in_equalityExpression2031);
							ne_tree = (CommonTree)adaptor.create(ne);
							root_0 = (CommonTree)adaptor.becomeRoot(ne_tree, root_0);

							 ne.setType(NE);
							}
							break;

					}

					pushFollow(FOLLOW_relationalExpression_in_equalityExpression2042);
					y=relationalExpression();
					state._fsp--;

					adaptor.addChild(root_0, y.getTree());

					}
					break;

				default :
					break loop56;
				}
			}

			}

			retval.stop = input.LT(-1);

			retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
			adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);


						// Post process the equality expression to clean up 'is null', etc.
						retval.tree = ProcessEqualityExpression(retval.tree);

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
			retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);
		}
		finally {
			// do for sure before leaving
		}
		return retval;
	}
783707
@SuppressWarnings("unchecked")
    public static <T> Expression<T> list(Class<T> clazz, List<? extends Expression<?>> exprs) {
        Expression<T> rv = (Expression<T>) exprs.get(0);
        if (exprs.size() == 1) {
            rv = operation(clazz, Ops.SINGLETON, rv, exprs.get(0));
        } else {
            for (int i = 1; i < exprs.size(); i++) {
                rv = operation(clazz, Ops.LIST, rv, exprs.get(i));
            }
        }

        return rv;
    }
1318187
public Map<String, String> collectValues() {

        Map<String, String> result = new HashMap<String, String>();
        for (Map.Entry<String, I_CmsFormField> entry : m_fields.entrySet()) {
            String key = entry.getKey();
            String value = null;
            I_CmsFormField field = entry.getValue();
            value = field.getModelValue();
            result.put(key, value);
        }
        return result;
    }
334753
List<Expression> parseArrayValueList( IType componentType )
  {
    while( componentType instanceof TypeVariableType )
    {
      componentType = ((TypeVariableType)componentType).getBoundingType();
    }
    List<Expression> valueExpressions = new ArrayList<>();
    do
    {
      parseExpression( new ContextType( componentType ) );
      Expression e = popExpression();
      valueExpressions.add( e );
    }
    while( match( null, ',' ) );

    return valueExpressions;
  }
1052370
public static Expression asEquals(List<String> properties) {
		PredicateDefAnd predicate = PredicateDefAnd.create();
		for (String property : properties) {
			predicate.add(cmpEq(
					property(self(), property),
					property(cast(arg(0), ExpressionCast.THIS_TYPE), property)));
		}
		return predicate;
	}
1045556
private static Collection<Tuple> getTuples( List<VarDef> varDefs, int varStart, int varEnd, int tupleSize)
    {
    Collection<Tuple> tuples = new ArrayList<Tuple>();

    // For each variable up to the last included...
    for( int i = varStart; i < varEnd; i++)
      {
      // Combine each valid value...
      VarDef                nextVar   = varDefs.get(i);
      Iterator<VarValueDef> values    = nextVar.getValidValues();
      if( !values.hasNext())
        {
        throw new IllegalStateException( "Can't complete tuples -- no valid values defined for var=" + nextVar);
        }

      // With all subtuples from the remaining variables.
      Collection<Tuple> subTuples =
        tupleSize==1
        ? null
        : getTuples( varDefs, i + 1, varEnd + 1, tupleSize - 1);

      // Only one variable to combine?
      if( subTuples == null)
        {
        // Yes, return list of 1-tuples for this variable.
        while( values.hasNext())
          {
          tuples.add( new Tuple( new VarBindingDef( nextVar, values.next())));
          }
        }

      // Any compatible subtuples for remaining variables?
      else if( !subTuples.isEmpty())
        {
        // Yes, add all compatible combinations with values for this variable.
        while( values.hasNext())
          {
          VarBindingDef nextBinding = new VarBindingDef( nextVar, values.next());
          for( Tuple subTuple : subTuples)
            {
            Tuple nextTuple = new Tuple( nextBinding).addAll( subTuple);
            if( nextTuple.isCompatible())
              {
              tuples.add( nextTuple);
              }
            }
          }
        }
      }
    
    return tuples;
    }