org.pentaho.metadata.model.LogicalColumn Java Examples

The following examples show how to use org.pentaho.metadata.model.LogicalColumn. 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: 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 #2
Source File: OlapHierarchyLevel.java    From pentaho-metadata with GNU Lesser General Public License v2.1 6 votes vote down vote up
public Object clone() {
  // weak link again to the parent
  OlapHierarchyLevel hierarchyLevel = new OlapHierarchyLevel( olapHierarchy );

  hierarchyLevel.name = name;
  hierarchyLevel.levelType = levelType;
  if ( referenceColumn != null ) {
    hierarchyLevel.referenceColumn = (LogicalColumn) referenceColumn.clone();
  }
  if ( referenceOrdinalColumn != null ) {
    hierarchyLevel.referenceOrdinalColumn = (LogicalColumn) referenceOrdinalColumn.clone();
  }
  if ( referenceCaptionColumn != null ) {
    hierarchyLevel.referenceCaptionColumn = (LogicalColumn) referenceCaptionColumn.clone();
  }
  for ( int i = 0; i < logicalColumns.size(); i++ ) {
    LogicalColumn logicalColumn = (LogicalColumn) logicalColumns.get( i );
    hierarchyLevel.logicalColumns.add( (LogicalColumn) logicalColumn.clone() );
  }
  hierarchyLevel.havingUniqueMembers = havingUniqueMembers;

  return hierarchyLevel;
}
 
Example #3
Source File: ConceptUtilTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testFindFirstKeyColumn() throws Exception {
  final LogicalTable logicalTable = mock( LogicalTable.class );

  assertNull( ConceptUtil.findFirstKeyColumn( logicalTable ) );

  final LogicalColumn logicalColumn = mock( LogicalColumn.class );
  final LogicalColumn logicalColumnKey1 = mock( LogicalColumn.class );
  final LogicalColumn logicalColumnKey2 = mock( LogicalColumn.class );
  when( logicalColumnKey1.getFieldType() ).thenReturn( FieldType.KEY );
  when( logicalColumnKey2.getFieldType() ).thenReturn( FieldType.KEY );
  when( logicalTable.getLogicalColumns() ).thenReturn( new LinkedList<LogicalColumn>() {
    {
      add( logicalColumn );
      add( logicalColumnKey1 );
      add( logicalColumnKey2 );
    }
  } );

  final LogicalColumn firstKeyColumn = ConceptUtil.findFirstKeyColumn( logicalTable );
  assertEquals( logicalColumnKey1, firstKeyColumn );
}
 
Example #4
Source File: ConceptUtilTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testFindLogicalColumns() throws Exception {
  final LogicalTable logicalTable = mock( LogicalTable.class );
  final AttributeType attribute = AttributeType.ATTRIBUTE;

  final LogicalColumn logicalColumn1 = mock( LogicalColumn.class );
  when( logicalColumn1.getProperty( DefaultIDs.LOGICAL_COLUMN_ATTRIBUTE_TYPE ) ).thenReturn( attribute.name() );
  final LogicalColumn logicalColumn2 = mock( LogicalColumn.class );
  when( logicalColumn2.getProperty( DefaultIDs.LOGICAL_COLUMN_ATTRIBUTE_TYPE ) ).thenReturn( attribute.name() );
  when( logicalTable.getLogicalColumns() ).thenReturn( new LinkedList<LogicalColumn>() {
    {
      add( logicalColumn1 );
      add( logicalColumn2 );
    }
  } );

  assertTrue( ConceptUtil.findLogicalColumns( logicalTable, AttributeType.ATTRIBUTE_HISTORICAL ).isEmpty() );

  final List<LogicalColumn> logicalColumns = ConceptUtil.findLogicalColumns( logicalTable, attribute );
  assertEquals( 2, logicalColumns.size() );
  assertEquals( logicalColumn1, logicalColumns.get( 0 ) );
  assertEquals( logicalColumn2, logicalColumns.get( 1 ) );
}
 
Example #5
Source File: AdvancedQueryIT.java    From pentaho-metadata with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testAliasedJoin2() throws Exception {

  LogicalModel model = getDefaultModel();
  LogicalColumn bc1 = model.findLogicalColumn( "bc1" ); //$NON-NLS-1$
  LogicalColumn bc3 = model.findLogicalColumn( "bc3" ); //$NON-NLS-1$

  DatabaseMeta databaseMeta = new DatabaseMeta( "", "ORACLE", "Native", "", "", "", "", "" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
  Query myTest = new Query( null, model );

  myTest.getSelections().add( new AliasedSelection( null, bc1, null, "alias1" ) );
  myTest.getSelections().add( new AliasedSelection( null, bc3, null, null ) );

  TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT \n" + "          bt1_alias1.pc1 AS COL0\n"
      + "         ,bt3.pc3 AS COL1\n" + "FROM \n" + "          pt3 bt3\n" + "         ,pt1 bt1_alias1\n"
      + "         ,pt2 bt2_alias1\n" + "WHERE \n" + "          (\n"
      + "             bt1_alias1.pc1 = bt2_alias1.pc2\n" + "          )\n" + "      AND (\n"
      + "             bt3.pc3 = bt2_alias1.pc2\n" + "          )\n", new AdvancedSqlGenerator().generateSql( myTest,
      "en_US", null, databaseMeta ).getQuery() );
}
 
Example #6
Source File: StarModelDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void addLogicalColumnToFactAttributesList(LogicalColumn column) {
  TableItem item = new TableItem(wFactAttributes.table, SWT.NONE);

  //  name, description, physical column name, data type, length, precision, source db, source table, source column, conversion remarks
  //
  int col=1;
  item.setText(col++, Const.NVL(ConceptUtil.getName(column,locale), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getDescription(column, locale), ""));
  item.setText(col++, ConceptUtil.getAttributeType(column).name());
  item.setText(col++, Const.NVL((String)column.getProperty(DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME), ""));
  DataType dataType = (DataType) column.getProperty(DefaultPropertyID.DATA_TYPE.getId());
  item.setText(col++, dataType==null ? "" : dataType.name() );
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_DIMENSION_NAME), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_LENGTH), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_PRECISION), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_SOURCE_DB), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_SOURCE_TABLE), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_SOURCE_COLUMN), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_CONVERSION_REMARKS), ""));
}
 
Example #7
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 #8
Source File: SQLModelGeneratorIT.java    From pentaho-metadata with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testQueryXmlSerialization() throws PentahoMetadataException {
  LogicalModel model = domain.findLogicalModel( "MODEL_1" );
  Query query = new Query( domain, model );
  Category category = model.findCategory( Settings.getBusinessCategoryIDPrefix() + "newdatasource" );
  LogicalColumn column = category.findLogicalColumn( "bc_CUSTOMERNAME" );
  query.getSelections().add( new Selection( category, column, null ) );
  query.getConstraints().add( new Constraint( CombinationType.AND, "[CATEGORY.bc_CUSTOMERNAME] = \"bob\"" ) );
  query.getOrders().add( new Order( new Selection( category, column, null ), Order.Type.ASC ) );

  QueryXmlHelper helper = new QueryXmlHelper();
  String xml = helper.toXML( query );
  InMemoryMetadataDomainRepository repo = new InMemoryMetadataDomainRepository();
  try {
    repo.storeDomain( domain, true );
  } catch ( Exception e ) {
    e.printStackTrace();
    fail();
  }
  Query newQuery = null;
  newQuery = helper.fromXML( repo, xml );
  // verify that when we serialize and deserialize, the xml stays the same.
  assertEquals( xml, helper.toXML( newQuery ) );
}
 
Example #9
Source File: QueryModelMetaDataTest.java    From pentaho-metadata with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Before
public void setUp() {
  property = new Object();

  LogicalColumn column = mock( LogicalColumn.class );
  when( column.getProperty( anyString() ) ).thenReturn( property );

  Selection selection = new Selection( null, column, null );

  columnHeaders = new String[][] { { "col1", "col2" } };
  rowHeaders = new String[][] { { "row1", "row2" } };
  columnNameFormat = "columnNameFormat";
  columnTypes = new String[] { "columnType1", "columnType2" };
  columnNames = new String[] { "columnName1", "columnName2" };
  rowHeaderNames = new String[] { "rowHeaderName1", "rowHeaderName2" };
  columns = Collections.singletonList( selection );
  columnNumber = 0; // we could use max column number according list of columns
  columnNumberIncorrect = columnNumber + 1;
}
 
Example #10
Source File: StarModelDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
protected boolean copyTable(Shell shell, LogicalModel logicalModel, String tableName) {

    LogicalTable originalTable = findLogicalTable(tableName);
    if (originalTable!=null) {
      // Copy
      //
      LogicalTable logicalTable = new LogicalTable();
      logicalTable.setId(UUID.randomUUID().toString());
      logicalTable.setName(new LocalizedString(locale, ConceptUtil.getName(originalTable, locale)+" (Copy)"));
      logicalTable.setDescription(new LocalizedString(locale, ConceptUtil.getDescription(originalTable, locale)+" (Copy)"));
      logicalTable.setProperty(DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME, originalTable.getProperty(DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME));
      logicalTable.setProperty(DefaultPropertyID.TABLE_TYPE.getId(), originalTable.getProperty(DefaultPropertyID.TABLE_TYPE.getId()));
      for (LogicalColumn column : originalTable.getLogicalColumns()) {
        logicalTable.getLogicalColumns().add((LogicalColumn) column.clone());
      }

      DimensionTableDialog dialog = new DimensionTableDialog(shell, logicalTable, locale);
      if (dialog.open()!=null) {
        logicalModel.addLogicalTable(logicalTable);
        return true;
      }
    }
    return false;
  }
 
Example #11
Source File: StarModelDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
protected void getRelationshipsFromFact() {
  logicalRelationships = new ArrayList<LogicalRelationship>();
  getFactColumns();
  for (LogicalColumn column : factTable.getLogicalColumns()) {
    String dimensionName = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_DIMENSION_NAME);
    if (!Utils.isEmpty(dimensionName)) {
      LogicalTable dimensionTable = ConceptUtil.findDimensionWithName(logicalModel, dimensionName, locale);
      if (dimensionTable!=null) {
        LogicalColumn tk = ConceptUtil.findLogicalColumn(dimensionTable, AttributeType.TECHNICAL_KEY);
        if (tk==null) {
          tk = ConceptUtil.findLogicalColumn(dimensionTable, AttributeType.SMART_TECHNICAL_KEY);
        }
        if (tk!=null) {
          LogicalTable fromTable = factTable;
          LogicalColumn fromColumn = column;
          LogicalTable toTable = dimensionTable;
          LogicalColumn toColumn = tk;
          LogicalRelationship relationship = new LogicalRelationship(logicalModel, fromTable, toTable, fromColumn, toColumn);
          logicalRelationships.add(relationship);
        }
      }
    }
  }

}
 
Example #12
Source File: OlapHierarchy.java    From pentaho-metadata with GNU Lesser General Public License v2.1 6 votes vote down vote up
public Object clone() {
  OlapHierarchy hierarchy = new OlapHierarchy( olapDimension ); // weak
                                                                // reference, no
                                                                // hard copy

  hierarchy.name = name;
  if ( logicalTable != null ) {
    hierarchy.logicalTable = (LogicalTable) logicalTable.clone();
  }
  if ( primaryKey != null ) {
    hierarchy.primaryKey = (LogicalColumn) primaryKey.clone();
  }
  for ( int i = 0; i < hierarchyLevels.size(); i++ ) {
    OlapHierarchyLevel hierarchyLevel = (OlapHierarchyLevel) hierarchyLevels.get( i );
    hierarchy.hierarchyLevels.add( (OlapHierarchyLevel) hierarchyLevel.clone() );
  }
  hierarchy.havingAll = havingAll;

  return hierarchy;
}
 
Example #13
Source File: SQLJoinIT.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
private LogicalTable getDummySingleColumnTable( String identifier ) {
  final LogicalTable bt1 = new LogicalTable();
  bt1.setId( "bt" + identifier );
  bt1.setProperty( SqlPhysicalTable.TARGET_TABLE, "pt" + identifier );
  final LogicalColumn bc1 = new LogicalColumn();
  bc1.setId( "bc" + identifier );
  bc1.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "pc" + identifier );
  bc1.setProperty( SqlPhysicalColumn.TARGET_COLUMN_TYPE, TargetColumnType.COLUMN_NAME );
  bc1.setLogicalTable( bt1 );
  bt1.addLogicalColumn( bc1 );
  bt1.setProperty( SqlPhysicalTable.RELATIVE_SIZE, 1 );
  return bt1;
}
 
Example #14
Source File: DimensionTableDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
protected void refreshAttributesList() {
  wAttributes.clearAll();

  for (LogicalColumn column : logicalTable.getLogicalColumns()) {
    addLogicalColumnToAttributesList(column);
  }
  wAttributes.removeEmptyRows();
  wAttributes.setRowNums();
  wAttributes.optWidth(true);
}
 
Example #15
Source File: XmiParserIT.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
@Ignore // ids aren't changed on the fly see http://jira.pentaho.com/browse/BISERVER-13338
public void incorrectIdsAreReplacedOnTheFly() throws Exception {
  final String modelName = "BV_HUMAN_RESOURCES";
  final String tableName = "BT_EMPLOYEES_EMPLOYEES";
  final String columnName = "BC_EMPLOYEES_EMPLOYEENUMBER";
  final String categoryName = "BC_OFFICES_";

  Domain domain = parser.parseXmi( getClass().getResourceAsStream( "/samples/steelwheels.xmi" ) );

  LogicalModel model = domain.findLogicalModel( modelName );
  assertNotNull( model );
  Category category = model.findCategory( categoryName );
  assertNotNull( category );
  LogicalTable table = model.findLogicalTable( tableName );
  assertValidId( table );
  LogicalColumn column = table.findLogicalColumn( columnName );
  assertValidId( column );

  setInvalidId( " (Cat_Id)", category, table, column );

  String spoiltXmi = parser.generateXmi( domain );
  domain = parser.parseXmi( new ByteArrayInputStream( spoiltXmi.getBytes() ) );

  model = domain.findLogicalModel( modelName );
  assertNotNull( model );

  category = findConceptStartingWith( categoryName, model.getCategories() );
  assertValidId( category );

  table = findConceptStartingWith( tableName, model.getLogicalTables() );
  assertValidId( table );

  column = findConceptStartingWith( columnName, table.getLogicalColumns() );
  assertValidId( column );
}
 
Example #16
Source File: AdvancedQueryIT.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testAliasedJoin() throws Exception {

  LogicalModel model = getDefaultModel();
  LogicalColumn bc1 = model.findLogicalColumn( "bc1" ); //$NON-NLS-1$
  LogicalColumn bc3 = model.findLogicalColumn( "bc3" ); //$NON-NLS-1$

  DatabaseMeta databaseMeta = new DatabaseMeta( "", "ORACLE", "Native", "", "", "", "", "" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
  Query myTest = new Query( null, model );

  myTest.getSelections().add( new AliasedSelection( null, bc1, null, null ) );
  myTest.getSelections().add( new AliasedSelection( null, bc1, null, "alias1" ) );
  myTest.getSelections().add( new AliasedSelection( null, bc3, null, null ) );
  myTest.getSelections().add( new AliasedSelection( "[alias1.bc1] * 3" ) );

  myTest.getConstraints().add( new Constraint( CombinationType.AND, "[alias1.bc1] > 10" ) );
  myTest.getConstraints().add( new Constraint( CombinationType.AND, "[bt3.bc3] > 10" ) );

  // SQLQueryTest.printOutJava(new AdvancedSqlGenerator().generateSql(myTest, "en_US", null,
  // databaseMeta).getQuery());
  TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT " + "bt1.pc1 AS COL0 ," + "bt1_alias1.pc1 AS COL1 ,"
      + "bt3.pc3 AS COL2 , " + "bt1_alias1.pc1 * 3 AS COL3 " + "FROM " + "pt1 bt1 ," + "pt2 bt2 ," + "pt3 bt3 ,"
      + "pt1 bt1_alias1 ," + "pt2 bt2_alias1 " + "WHERE " + "( bt1.pc1 = bt2.pc2 ) " + "AND ( bt3.pc3 = bt2.pc2 ) "
      + "AND ( bt1_alias1.pc1 = bt2_alias1.pc2 ) " + "AND ( bt3.pc3 = bt2_alias1.pc2 ) "
      + "AND (( bt1_alias1.pc1 > 10 ) " + "AND ( bt3.pc3 > 10 ))", new AdvancedSqlGenerator().generateSql( myTest,
      "en_US", null, databaseMeta ).getQuery() );
}
 
Example #17
Source File: AdvancedQueryIT.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testQueryAggFunctions() throws Exception {

  LogicalModel model = getDefaultModel();
  LogicalColumn bc1 = model.findLogicalColumn( "bc1" ); //$NON-NLS-1$
  LogicalColumn bc3 = model.findLogicalColumn( "bc3" ); //$NON-NLS-1$

  DatabaseMeta databaseMeta = new DatabaseMeta( "", "ORACLE", "Native", "", "", "", "", "" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
  Query myTest = new Query( null, model );

  myTest.getSelections().add( new AliasedSelection( null, bc1, null, "alias1" ) );
  myTest.getSelections().add( new AliasedSelection( "SUM([bt3.bc3])" ) );

  myTest.getConstraints().add( new Constraint( CombinationType.AND, "SUM([bt3.bc3]) > 30" ) );

  myTest.getOrders().add( new Order( new AliasedSelection( "SUM([bt3.bc3])" ), Type.ASC ) );

  // SQLQueryTest.printOutJava(new AdvancedSqlGenerator().generateSql(myTest, "en_US", null,
  // databaseMeta).getQuery());

  TestHelper.assertEqualsIgnoreWhitespaces( "SELECT \n" + "          bt1_alias1.pc1 AS COL0\n"
      + "         , SUM( bt3.pc3 ) AS COL1\n" + "FROM \n" + "          pt3 bt3\n" + "         ,pt1 bt1_alias1\n"
      + "         ,pt2 bt2_alias1\n" + "WHERE \n" + "          (\n"
      + "             bt1_alias1.pc1 = bt2_alias1.pc2\n" + "          )\n" + "      AND (\n"
      + "             bt3.pc3 = bt2_alias1.pc2\n" + "          )\n" + "GROUP BY \n" + "          bt1_alias1.pc1\n"
      + "HAVING \n" + "          (\n" + "              SUM( bt3.pc3 ) > 30\n" + "          )\n" + "ORDER BY \n"
      + "           SUM( bt3.pc3 )\n", new AdvancedSqlGenerator().generateSql( myTest, "en_US", null, databaseMeta )
      .getQuery() );
}
 
Example #18
Source File: DimensionTableDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void addAttribute(String name, String description, String phName, AttributeType attributeType, DataType dataType, int length, int precision, String comment) {
  LogicalColumn column = new LogicalColumn();
  column.setLogicalTable(logicalTable);
  column.setName(new LocalizedString(locale, name));
  column.setDescription(new LocalizedString(locale, description));
  column.setDataType(dataType);
  column.setProperty(DefaultIDs.LOGICAL_COLUMN_ATTRIBUTE_TYPE, attributeType.name());
  column.setProperty(DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME, phName);
  if (length>=0) column.setProperty(DefaultIDs.LOGICAL_COLUMN_LENGTH, Integer.toString(length));
  if (precision>=0) column.setProperty(DefaultIDs.LOGICAL_COLUMN_PRECISION, Integer.toString(precision));
  column.setProperty(DefaultIDs.LOGICAL_COLUMN_CONVERSION_REMARKS, comment);

  addLogicalColumnToAttributesList(column);
}
 
Example #19
Source File: ConceptUtilTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAttributeType() throws Exception {
  final LogicalColumn logicalColumn = mock( LogicalColumn.class );
  final AttributeType attribute = AttributeType.ATTRIBUTE;
  when( logicalColumn.getProperty( DefaultIDs.LOGICAL_COLUMN_ATTRIBUTE_TYPE ) ).thenReturn( attribute.name() );

  final AttributeType attributeType = ConceptUtil.getAttributeType( logicalColumn );
  assertEquals( attribute, attributeType );
}
 
Example #20
Source File: ConceptUtil.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static LogicalColumn findFirstKeyColumn(LogicalTable logicalTable) {
  for (LogicalColumn column : logicalTable.getLogicalColumns()) {
    FieldType fieldType = column.getFieldType();
    if (fieldType!=null && fieldType==FieldType.KEY) {
      return column;
    }
  }
  return null;
}
 
Example #21
Source File: ConceptUtil.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static LogicalColumn findLogicalColumn(LogicalTable logicalTable, AttributeType attributeType) {
  for (LogicalColumn logicalColumn : logicalTable.getLogicalColumns()) {
    AttributeType type = getAttributeType(logicalColumn);
    if (type == attributeType) return logicalColumn;
  }
  return null;
}
 
Example #22
Source File: MQLEditorServiceDelegate.java    From mql-editor with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Category createCategory( LogicalModel m, org.pentaho.metadata.model.Category c ) {
  Category cat = new Category();
  cat.setName( c.getName( getLocale() ) );
  cat.setId( c.getId() );
  for ( LogicalColumn col : c.getLogicalColumns() ) {
    boolean isHidden = ( col.getProperty( "hidden" ) != null ) ? (Boolean) col.getProperty( "hidden" ) : false;
    if ( !isHidden ) {
      cat.getBusinessColumns().add( createColumn( m, col ) );
    }
  }
  return cat;
}
 
Example #23
Source File: AutoModeler.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
private LogicalColumn findBusinessColumn( LogicalTable logicalTable, String columnName ) {
  for ( LogicalColumn logicalColumn : logicalTable.getLogicalColumns() ) {
    if ( columnName.equals( ( (SqlPhysicalColumn) logicalColumn.getPhysicalColumn() ).getTargetColumn() ) ) {
      return logicalColumn;
    }
  }
  return null;
}
 
Example #24
Source File: XmiParserIT.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void collisionAfterCorrectionAreResolved() throws Exception {
  Domain domain = parser.parseXmi( getClass().getResourceAsStream( "/samples/steelwheels.xmi" ) );
  LogicalTable table = domain.getLogicalModels().get( 0 ).getLogicalTables().get( 0 );

  assertTrue( table.getLogicalColumns().size() >= 2 );
  LogicalColumn col1 = table.getLogicalColumns().get( 0 );
  col1.setId( "column[x]" );

  LogicalColumn col2 = table.getLogicalColumns().get( 1 );
  col2.setId( "column{x}" );

  assertFalse( "Columns have different raw ids", col1.getId().equals( col2.getId() ) );
  assertEquals( "Columns have equal validated ids", validateId( col1.getId() ), validateId( col2.getId() ) );

  String xmi = parser.generateXmi( domain );
  domain = parser.parseXmi( new ByteArrayInputStream( xmi.getBytes() ) );

  List<LogicalColumn> columns =
      domain.getLogicalModels().get( 0 ).getLogicalTables().get( 0 ).getLogicalColumns();

  col1 = columns.get( 0 );
  col2 = columns.get( 1 );
  assertTrue( col1.getId(), col1.getId().startsWith( "column" ) );
  assertTrue( col2.getId(), col2.getId().startsWith( "column" ) );
  assertFalse( "Columns have different corrected ids", col1.getId().equals( col2.getId() ) );
}
 
Example #25
Source File: ThinQueryIT.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testQueryConversion() throws Exception {
  Domain domain = TestHelper.getBasicDomain();
  LogicalModel model = domain.findLogicalModel( "MODEL" );
  Query query = new Query( domain, model );

  Category category = model.findCategory( "CATEGORY" );
  LogicalColumn column = category.findLogicalColumn( "LC_CUSTOMERNAME" );
  query.getSelections().add( new Selection( category, column, null ) );

  query.getConstraints().add( new Constraint( CombinationType.AND, "[CATEGORY.LC_CUSTOMERNAME] = \"bob\"" ) );

  query.getOrders().add( new Order( new Selection( category, column, null ), Order.Type.ASC ) );

  MQLQueryImpl impl = null;
  try {
    impl = ThinModelConverter.convertToLegacy( query, null );
  } catch ( Exception e ) {
    e.printStackTrace();
    Assert.fail();
  }
  Assert.assertNotNull( impl );
  TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT \n" + "          LT.customername AS COL0\n" + "FROM \n"
      + "          (select * from customers) LT\n" + "WHERE \n" + "        (\n" + "          (\n"
      + "              LT.customername  = 'bob'\n" + "          )\n" + "        )\n" + "ORDER BY \n"
      + "          COL0\n", impl.getQuery().getQuery() );

  query.setLimit( 10 );
  impl = ThinModelConverter.convertToLegacy( query, null );
  Assert.assertEquals( 10, impl.getLimit() );
}
 
Example #26
Source File: SharedDimensionMetaStoreUtil.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private static void populateElementWithSharedDimension(IMetaStore metaStore, LogicalTable sharedDimension, String locale, IMetaStoreElementType elementType, IMetaStoreElement element) throws MetaStoreException {
  element.setElementType(elementType);
  element.setName(sharedDimension.getName(locale));
  element.addChild(metaStore.newAttribute(Attribute.ID_SHARED_DIMENSION_DESCRIPTION.id, sharedDimension.getDescription(locale)));
  IMetaStoreAttribute columnsAttribute = metaStore.newAttribute(Attribute.ID_SHARED_DIMENSION_COLUMNS.id, null);
  element.addChild(columnsAttribute);
  for (LogicalColumn column : sharedDimension.getLogicalColumns()) {
    IMetaStoreAttribute columnAttribute = metaStore.newAttribute(Attribute.ID_SHARED_DIMENSION_COLUMN.id, null);
    columnsAttribute.addChild(columnAttribute);
    columnAttribute.addChild(metaStore.newAttribute(Attribute.ID_SHARED_DIMENSION_COLUMN_NAME.id, column.getName(locale)));
    columnAttribute.addChild(metaStore.newAttribute(Attribute.ID_SHARED_DIMENSION_COLUMN_DESCRIPTION.id, column.getDescription(locale)));
  }
}
 
Example #27
Source File: StarModelDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void getFactColumns() {
  factTable.getLogicalColumns().clear();
  int nr = wFactAttributes.nrNonEmpty();
  for (int i=0;i<nr;i++) {
    TableItem item = wFactAttributes.getNonEmpty(i);
    LogicalColumn logicalColumn = new LogicalColumn();

    int col=1;
    logicalColumn.setId(UUID.randomUUID().toString());
    logicalColumn.setName(new LocalizedString(locale, item.getText(col++)));
    logicalColumn.setDescription(new LocalizedString(locale, item.getText(col++)));
    String fieldTypeString = item.getText(col++);
    logicalColumn.setProperty(DefaultIDs.LOGICAL_COLUMN_ATTRIBUTE_TYPE, AttributeType.getAttributeType(fieldTypeString).name());
    logicalColumn.setProperty(DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME, item.getText(col++));
    logicalColumn.setDataType(ConceptUtil.getDataType(item.getText(col++)));
    logicalColumn.setProperty(DefaultIDs.LOGICAL_COLUMN_DIMENSION_NAME, item.getText(col++));
    logicalColumn.setProperty(DefaultIDs.LOGICAL_COLUMN_LENGTH, item.getText(col++));
    logicalColumn.setProperty(DefaultIDs.LOGICAL_COLUMN_PRECISION, item.getText(col++));
    logicalColumn.setProperty(DefaultIDs.LOGICAL_COLUMN_SOURCE_DB, item.getText(col++));
    logicalColumn.setProperty(DefaultIDs.LOGICAL_COLUMN_SOURCE_TABLE, item.getText(col++));
    logicalColumn.setProperty(DefaultIDs.LOGICAL_COLUMN_SOURCE_COLUMN, item.getText(col++));
    logicalColumn.setProperty(DefaultIDs.LOGICAL_COLUMN_CONVERSION_REMARKS, item.getText(col++));

    logicalColumn.setLogicalTable(factTable);
    factTable.getLogicalColumns().add(logicalColumn);
  }
}
 
Example #28
Source File: SpiderWebTestModel.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
private LogicalTable createLogicalTable( String tblId, LogicalModel model, Category mainCat ) throws Exception {

    LogicalTable rtn = new LogicalTable();
    rtn.setId( "bt_" + tblId );
    rtn.setProperty( SqlPhysicalTable.TARGET_TABLE, "pt_" + tblId ); //$NON-NLS-1$
    createBusinessKeyColumn( tblId, "keya", rtn, mainCat ); // 0
    createBusinessKeyColumn( tblId, "keyb", rtn, mainCat ); // 1
    createBusinessKeyColumn( tblId, "keyc", rtn, mainCat ); // 2
    createBusinessKeyColumn( tblId, "keyd", rtn, mainCat ); // 3
    createBusinessKeyColumn( tblId, "keye", rtn, mainCat ); // 4
    createBusinessKeyColumn( tblId, "keyf", rtn, mainCat ); // 5
    createBusinessKeyColumn( tblId, "keyg", rtn, mainCat ); // 6
    createBusinessKeyColumn( tblId, "keyh", rtn, mainCat ); // 7
    createBusinessKeyColumn( tblId, "keyi", rtn, mainCat ); // 8
    createBusinessKeyColumn( tblId, "keyj", rtn, mainCat ); // 9
    createBusinessKeyColumn( tblId, "keyk", rtn, mainCat ); // 10
    createBusinessKeyColumn( tblId, "keyl", rtn, mainCat ); // 11

    LogicalColumn bcs1 = new LogicalColumn();
    bcs1.setId( "bcs_" + tblId );
    bcs1.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "pc_" + tblId ); //$NON-NLS-1$
    bcs1.setProperty( IPhysicalColumn.AGGREGATIONTYPE_PROPERTY, AggregationType.SUM );
    bcs1.setLogicalTable( rtn );
    rtn.addLogicalColumn( bcs1 );
    mainCat.addLogicalColumn( bcs1 );
    model.addLogicalTable( rtn );
    return rtn;

  }
 
Example #29
Source File: SpiderWebTestModel.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
private LogicalColumn createBusinessKeyColumn( String tblId, String columnId, LogicalTable tbl, Category cat )
  throws Exception {
  LogicalColumn rtn = new LogicalColumn();
  rtn.setId( "bc_" + columnId + "_" + tblId );
  rtn.setProperty( SqlPhysicalColumn.TARGET_COLUMN, "pc_" + columnId + "_" + tblId ); //$NON-NLS-1$
  rtn.setLogicalTable( tbl );
  tbl.addLogicalColumn( rtn );
  cat.addLogicalColumn( rtn );
  return rtn;
}
 
Example #30
Source File: MQLEditorServiceCWMDelegate.java    From mql-editor with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Category createCategory( LogicalModel m, org.pentaho.metadata.model.Category c ) {
  Category cat = new Category();
  cat.setName( c.getName( locale ) );
  cat.setId( c.getId() );
  for ( LogicalColumn col : c.getLogicalColumns() ) {
    cat.getBusinessColumns().add( createColumn( m, col ) );
  }

  return cat;
}