public String buildUnionSubQuery(String typeDiscriminatorColumn,String[] unionColumns,Set<String> columnsPresentInTable,int computedColumnsOffset,String typeDiscriminatorValue,String selection,String groupBy,String having){
  int unionColumnsCount=unionColumns.length;
  String[] projectionIn=new String[unionColumnsCount];
  for (int i=0; i < unionColumnsCount; i++) {
    String unionColumn=unionColumns[i];
    if (unionColumn.equals(typeDiscriminatorColumn)) {
      projectionIn[i]="'" + typeDiscriminatorValue + "' AS "+ typeDiscriminatorColumn;
    }
 else     if (i <= computedColumnsOffset || columnsPresentInTable.contains(unionColumn)) {
      projectionIn[i]=unionColumn;
    }
 else {
      projectionIn[i]="NULL AS " + unionColumn;
    }
  }
  return buildQuery(projectionIn,selection,groupBy,having,null,null);
}

public String buildUnionSubQuery ( String typeDiscriminatorColumn , String [ ] unionColumns , Set < String > columnsPresentInTable , int computedColumnsOffset , String typeDiscriminatorValue , String selection , String groupBy , String having ) { int unionColumnsCount = unionColumns . length ; String [ ] projectionIn = new String [ unionColumnsCount ] ; for ( int i = 0 ; i < unionColumnsCount ; i ++ ) { String unionColumn = unionColumns [ i ] ; if ( unionColumn . equals ( typeDiscriminatorColumn ) ) { projectionIn [ i ] = "'" + typeDiscriminatorValue + "' AS " + typeDiscriminatorColumn ; } else if ( i <= computedColumnsOffset || columnsPresentInTable . contains ( unionColumn ) ) { projectionIn [ i ] = unionColumn ; } else { projectionIn [ i ] = "NULL AS " + unionColumn ; } } return buildQuery ( projectionIn , selection , groupBy , having , null , null ) ; }
construct a select statement suitable for use in a group of select statements that will be joined through union operators in buildunionquery .
