Java Code Examples for org.pentaho.metadata.model.LogicalColumn#getAggregationType()

The following examples show how to use org.pentaho.metadata.model.LogicalColumn#getAggregationType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryXmlHelper.java    From pentaho-metadata with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void addOrderBy( Query query, Category category, String columnId, String aggregation, Order.Type orderType )
  throws PentahoMetadataException {

  if ( category == null ) {
    throw new PentahoMetadataException( Messages.getErrorString( "QueryXmlHelper.ERROR_0016_BUSINESS_CATEGORY_NULL" ) ); //$NON-NLS-1$ 
  }

  LogicalColumn column = category.findLogicalColumn( columnId );
  if ( column == null ) {
    throw new PentahoMetadataException( Messages.getErrorString(
        "QueryXmlHelper.ERROR_0013_BUSINESS_COL_NOT_FOUND", category.getId(), columnId ) ); //$NON-NLS-1$ 
  }

  // this code verifies the aggregation setting provided is a
  // valid option
  AggregationType aggsetting = null;
  if ( aggregation != null ) {
    AggregationType setting = AggregationType.valueOf( aggregation.toUpperCase() );
    if ( ( column.getAggregationType() == setting ) || column.getAggregationList() != null
        && column.getAggregationList().contains( setting ) ) {
      aggsetting = setting;
    }
  }

  query.getOrders().add( new Order( new Selection( category, column, aggsetting ), orderType ) );
}
 
Example 2
Source File: SqlOpenFormulaIT.java    From pentaho-metadata with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * In this test we try to see to it :<br>
 * - that the formula engine picks the 2 specified columns from 2 different business tables<br>
 * - that we calculate the sum of the multiplication <br>
 */
@Test
public void testMultiTableColumnFormulasAggregate() throws Exception {
  LogicalColumn quantityOrdered = getOrdersModel().findLogicalColumn( "BC_ORDER_DETAILS_QUANTITYORDERED" );
  Assert.assertNotNull( "Expected to find the business column 'quantity ordered'", quantityOrdered );
  LogicalColumn buyPrice = getOrdersModel().findLogicalColumn( "BC_PRODUCTS_BUYPRICE" );
  Assert.assertNotNull( "Expected to find the business column 'buy price'", buyPrice );

  // let's remove the aggregations of the quantity ordered...
  //
  AggregationType qaBackup = quantityOrdered.getAggregationType();
  AggregationType paBackup = buyPrice.getAggregationType();
  quantityOrdered.setAggregationType( AggregationType.NONE );
  buyPrice.setAggregationType( AggregationType.NONE );

  // This changes the expected result...
  //
  String formula = "SUM( [BT_ORDER_DETAILS.BC_ORDER_DETAILS_QUANTITYORDERED] * [BT_PRODUCTS.BC_PRODUCTS_BUYPRICE] )";
  String sql = "SUM( BT_ORDER_DETAILS.QUANTITYORDERED  *  BT_PRODUCTS.BUYPRICE )";

  handleFormula( getOrdersModel(), "Hypersonic", formula, sql );

  // Set it back to the way it was for further testing.
  quantityOrdered.setAggregationType( qaBackup );
  buyPrice.setAggregationType( paBackup );
}
 
Example 3
Source File: SqlOpenFormulaIT.java    From pentaho-metadata with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * In this test we try to test :<br>
 * - if the formula engine picks the 2 specified columns from 2 different business tables<br>
 * - if we calculate the multiplication of the sums <br>
 */
@Test
public void testMultiTableColumnFormulasAggregate2() throws Exception {
  LogicalColumn quantityOrdered = getOrdersModel().findLogicalColumn( "BC_ORDER_DETAILS_QUANTITYORDERED" );
  Assert.assertNotNull( "Expected to find the business column 'quantity ordered'", quantityOrdered );
  LogicalColumn buyPrice = getOrdersModel().findLogicalColumn( "BC_PRODUCTS_BUYPRICE" );
  Assert.assertNotNull( "Expected to find the business column 'buy price'", buyPrice );

  // let's enable the aggregations of the quantity ordered...
  //
  AggregationType qaBackup = quantityOrdered.getAggregationType();
  AggregationType paBackup = buyPrice.getAggregationType();
  quantityOrdered.setAggregationType( AggregationType.SUM );
  buyPrice.setAggregationType( AggregationType.SUM );

  // This changes the expected result...
  //
  String formula = "[BT_ORDER_DETAILS.BC_ORDER_DETAILS_QUANTITYORDERED] * [BT_PRODUCTS.BC_PRODUCTS_BUYPRICE]";
  String sql = "SUM(BT_ORDER_DETAILS.QUANTITYORDERED)  *  SUM(BT_PRODUCTS.BUYPRICE)";

  handleFormula( getOrdersModel(), "Hypersonic", formula, sql );

  // Set it back to the way it was for further testing.
  quantityOrdered.setAggregationType( qaBackup );
  buyPrice.setAggregationType( paBackup );
}
 
Example 4
Source File: QueryXmlHelper.java    From pentaho-metadata with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void addSelectionFromXmlNode( Query query, Element selectionElement ) {

    NodeList viewnodes = selectionElement.getElementsByTagName( "view" ); //$NON-NLS-1$
    NodeList nodes = selectionElement.getElementsByTagName( "column" ); //$NON-NLS-1$
    if ( nodes.getLength() == 0 ) {
      // should throw exception here
      return;
    }
    String columnId = XMLHandler.getNodeValue( nodes.item( 0 ) );
    String viewId = null;
    Category category = null;
    if ( viewnodes.getLength() != 0 ) {
      // this is due to legacy reasons, the query doesn't really need the category.
      viewId = XMLHandler.getNodeValue( viewnodes.item( 0 ) );
      category = query.getLogicalModel().findCategory( viewId );
    }
    LogicalColumn column = null;
    if ( category != null ) {
      column = category.findLogicalColumn( columnId );
    } else {
      column = query.getLogicalModel().findLogicalColumnInCategories( columnId );
    }
    if ( column != null ) {
      AggregationType aggsetting = null;
      NodeList aggnodes = selectionElement.getElementsByTagName( "aggregation" ); //$NON-NLS-1$
      if ( aggnodes.getLength() > 0 ) {
        String aggvalue = XMLHandler.getNodeValue( aggnodes.item( 0 ) );
        AggregationType setting = AggregationType.valueOf( aggvalue.toUpperCase() );
        if ( setting == null ) {
          Messages.getErrorString( "QueryXmlHelper.ERROR_0011_AGG_NOT_RECOGNIZED", columnId, aggvalue ); //$NON-NLS-1$
        } else {
          // verify that the setting is one of the options for this business column
          if ( ( column.getAggregationType() == setting ) || column.getAggregationList() != null
              && column.getAggregationList().contains( setting ) ) {
            aggsetting = setting;
          } else {
            Messages.getErrorString( "QueryXmlHelper.ERROR_0012_INVALID_AGG_FOR_BUSINESS_COL", columnId, aggvalue ); //$NON-NLS-1$
          }
        }
      }

      query.getSelections().add( new Selection( category, column, aggsetting ) );
    } else {
      // print a warning message
      Messages.getErrorString( "QueryXmlHelper.ERROR_0013_BUSINESS_COL_NOT_FOUND", viewId, columnId ); //$NON-NLS-1$
    }
  }
 
Example 5
Source File: MQLEditorServiceCWMDelegate.java    From mql-editor with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Column createColumn( LogicalModel m, LogicalColumn c ) {
  Column col = new Column();
  col.setName( c.getName( locale ) );
  col.setId( c.getId() );

  ColumnType ourType = null;
  if ( c.getDataType() != null ) {
    int type = c.getDataType().getType();
    switch ( type ) {
      case DataTypeSettings.DATA_TYPE_BOOLEAN:
        ourType = ColumnType.BOOLEAN;
        break;
      case DataTypeSettings.DATA_TYPE_STRING:
        ourType = ColumnType.TEXT;
        break;
      case DataTypeSettings.DATA_TYPE_NUMERIC:
        ourType = ColumnType.FLOAT;
        break;
      case DataTypeSettings.DATA_TYPE_DATE:
        ourType = ColumnType.DATE;
        break;
    }
  }
  col.setType( ourType );
  List<AggregationType> possibleAggs = c.getAggregationList();
  if ( possibleAggs != null ) {
    for ( AggregationType agg : possibleAggs ) {
      col.getAggTypes().add( getAggType( agg.ordinal() ) );
    }
  }

  // There might be a default agg, but no agg list. If so, add it to the list.

  AggType defaultAggType = null;
  if ( c.getAggregationType() != null ) {
    defaultAggType = getAggType( c.getAggregationType().ordinal() );
  } else {
    defaultAggType = AggType.NONE;
  }
  if ( col.getAggTypes().contains( defaultAggType ) == false ) {
    col.getAggTypes().add( defaultAggType );
  }
  col.setDefaultAggType( defaultAggType );
  col.setSelectedAggType( defaultAggType );

  return col;
}
 
Example 6
Source File: MQLEditorServiceDelegate.java    From mql-editor with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Column createColumn( LogicalModel m, LogicalColumn c ) {
  Column col = new Column();
  col.setName( c.getName( getLocale() ) );
  col.setId( c.getId() );

  ColumnType ourType = null;
  if ( c.getDataType() != null ) {
    int type = c.getDataType().getType();
    switch ( type ) {
      case DataTypeSettings.DATA_TYPE_BOOLEAN:
        ourType = ColumnType.BOOLEAN;
        break;
      case DataTypeSettings.DATA_TYPE_STRING:
        ourType = ColumnType.TEXT;
        break;
      case DataTypeSettings.DATA_TYPE_NUMERIC:
        ourType = ColumnType.FLOAT;
        break;
      case DataTypeSettings.DATA_TYPE_DATE:
        ourType = ColumnType.DATE;
        break;
    }
  }
  col.setType( ourType );
  List<AggregationType> possibleAggs = c.getAggregationList();
  if ( possibleAggs != null ) {
    for ( AggregationType agg : possibleAggs ) {
      col.getAggTypes().add( getAggType( agg.ordinal() ) );
    }
  }

  // There might be a default agg, but no agg list. If so, add it to the list.

  AggType defaultAggType = null;
  if ( c.getAggregationType() != null ) {
    defaultAggType = getAggType( c.getAggregationType().ordinal() );
  } else {
    defaultAggType = AggType.NONE;
  }
  if ( col.getAggTypes().contains( defaultAggType ) == false ) {
    col.getAggTypes().add( defaultAggType );
  }
  col.setDefaultAggType( defaultAggType );
  col.setSelectedAggType( defaultAggType );

  return col;
}