Relational Filtering Table Examples

 

The following coding example sets a simple filter  to a data selection which says "height >= 60".

 

 

/**

*

* A simple method creates a filter result of a relational table.

* @param input data selection

* @return modified data selection containing the result

*

* @throws Exception

*/

private  com.sas.iquery.metadata.business.DataSelection FilterRelationalTableDisplay(java.util.List dsDataItems, com.sas.iquery.metadata.business.DataSelection query) throws Exception  

{

for(int i = 0; i < dsDataItems.size(); i++)

{            com.sas.iquery.metadata.business.DataItem tdi = (com.sas.iquery.metadata.business.DataItem)dsDataItems.get(i);

            String label = tdi.getLabel();

 

             //create a numeric constant with the value 60:

com.sas.iquery.metadata.expr.ConstantExpression sixtyConstant = new com.sas.iquery.metadata.expr.ConstantExpression();

sixtyConstant.setExpressionType(com.sas.iquery.metadata.expr.ExpressionTypes.EXP_TYPE_NUMERIC);

sixtyConstant.setValue("60");

 

//note that even numeric values are set as strings

//now create a >= comparison expression between height and the constant:

com.sas.iquery.metadata.expr.relational.SimpleConditionalExpression_Comparison heightGreaterThanSixty = new com.sas.iquery.metadata.expr.relational.SimpleConditionalExpression_Comparison();

 

//apply filter to height dataItem    

            if ( label.equalsIgnoreCase("Height") )

            {  

heightGreaterThanSixty.setLeftExpression(tdi);

heightGreaterThanSixty.setComparisonOperator(com.sas.iquery.metadata.expr.ComparisonOperator.COMPARE_GE); heightGreaterThanSixty.setRightExpression(sixtyConstant);

 

//make a new filter which uses the expression:

com.sas.iquery.metadata.business.FilterItem tallPupilsFilter = query.newFilterItem();

tallPupilsFilter.setExpression(heightGreaterThanSixty);

 

 //the new filter must be added to the query as a business item:

query.addBusinessItem(tallPupilsFilter);

query.setFilters(java.util.Collections.singletonList(tallPupilsFilter));

                  

             }

 

// Assign Column to all dataitems and add to dataselection.

query.addResultItem(tdi, com.sas.iquery.metadata.business.Role.COLUMN);

}

         

   

// Get data selection 

return query;

}