private static LogicalRelationship duplicateRelationshipForOlap( LogicalRelationship rel, LogicalModel olapModel ) { LogicalTable olapFromTable = findCorrespondingOlapTable( rel.getFromTable(), olapModel ); LogicalTable olapToTable = findCorrespondingOlapTable( rel.getToTable(), olapModel ); LogicalColumn olapFromCol = findCorrespondingOlapColumn( rel.getFromColumn(), olapModel ); LogicalColumn olapToCol = findCorrespondingOlapColumn( rel.getToColumn(), olapModel ); LogicalRelationship olapRel = new LogicalRelationship( olapModel, olapFromTable, olapToTable, olapFromCol, olapToCol ); olapRel.setComplex( rel.isComplex() ); olapRel.setRelationshipType( rel.getRelationshipType() ); olapRel.setJoinOrderKey( rel.getJoinOrderKey() ); olapRel.setComplexJoin( rel.getComplexJoin() ); olapRel.setRelationshipDescription( rel.getRelationshipDescription() ); return olapRel; }
private LogicalColumn findPrimaryKeyFor( LogicalModel model, LogicalTable factTable, LogicalTable dimTable ) { LogicalRelationship ship = model.findRelationshipUsing( dimTable, factTable ); if ( ship == null ) { throw new IllegalStateException( "Unable to find a primary key for table: " + dimTable.getId() ); } if ( ship.getFromTable().equals( dimTable ) ) { return ship.getFromColumn(); } else { return ship.getToColumn(); } }
public List<LogicalTable> getUsedTables() { Set<LogicalTable> treeSet = new TreeSet<LogicalTable>(); for ( int i = 0; i < size(); i++ ) { LogicalRelationship rel = getRelationship( i ); treeSet.add( rel.getFromTable() ); treeSet.add( rel.getToTable() ); } return new ArrayList<LogicalTable>( treeSet ); } }
nvp = getKeyValuePairs( rel, "CWM:TaggedValue", "tag", "value" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ LogicalRelationship relation = new LogicalRelationship(); String type = nvp.get( "RELATIONSHIP_TYPE" ); //$NON-NLS-1$ RelationshipType reltype = RelationshipType.values()[RelationshipMeta.getType( type )]; relation.setRelationshipType( reltype ); relation.setLogicalModel( logicalModel ); String fieldparent = nvp.get( "RELATIONSHIP_FIELDNAME_PARENT" ); //$NON-NLS-1$ relation.setFromTable( logicalModel.findLogicalTable( tableparent ) ); if ( fieldparent != null ) { relation.setFromColumn( logicalModel.findLogicalColumn( fieldparent ) ); relation.setToTable( logicalModel.findLogicalTable( tablechild ) ); if ( fieldchild != null ) { relation.setToColumn( logicalModel.findLogicalColumn( fieldchild ) ); relation.setComplex( "Y".equals( nvp.get( "RELATIONSHIP_IS_COMPLEX" ) ) ); //$NON-NLS-1$ //$NON-NLS-2$ String val = nvp.get( "RELATIONSHIP_COMPLEX_JOIN" ); //$NON-NLS-1$ if ( val != null ) { relation.setComplexJoin( val ); relation.setRelationshipDescription( nvp.get( "RELATIONSHIP_DESCRIPTION" ) ); //$NON-NLS-1$ relation.setJoinOrderKey( joinOrderKey );
@Deprecated public List<LogicalRelationship> generateLogicalRelationships( List<JoinRelationshipModel> joins ) { String locale = LocalizedString.DEFAULT_LOCALE; List<LogicalRelationship> logicalRelationships = new ArrayList<LogicalRelationship>(); for ( JoinRelationshipModel join : joins ) { LogicalTable fromTable = new LogicalTable(); fromTable.setName( new LocalizedString( locale, join.getLeftKeyFieldModel().getParentTable().getName() ) ); LogicalTable toTable = new LogicalTable(); toTable.setName( new LocalizedString( locale, join.getRightKeyFieldModel().getParentTable().getName() ) ); LogicalColumn fromColumn = new LogicalColumn(); fromColumn.setName( new LocalizedString( locale, join.getLeftKeyFieldModel().getName() ) ); LogicalColumn toColumn = new LogicalColumn(); toColumn.setName( new LocalizedString( locale, join.getRightKeyFieldModel().getName() ) ); LogicalRelationship logicalRelationship = new LogicalRelationship(); logicalRelationship.setFromTable( fromTable ); logicalRelationship.setToTable( toTable ); logicalRelationship.setFromColumn( fromColumn ); logicalRelationship.setToColumn( toColumn ); logicalRelationships.add( logicalRelationship ); } return logicalRelationships; }
keyRel.appendChild( modelElement ); modelElement.appendChild( createTaggedValue( doc, "RELATIONSHIP_TYPE", rel.getRelationshipType().getType(), idGen.getNextId() ) ); //$NON-NLS-1$ if ( rel.getToColumn() != null ) { modelElement.appendChild( createTaggedValue( doc, "RELATIONSHIP_FIELDNAME_CHILD", rel.getToColumn().getId(), idGen.getNextId() ) ); //$NON-NLS-1$ if ( rel.getFromColumn() != null ) { modelElement.appendChild( createTaggedValue( doc, "RELATIONSHIP_FIELDNAME_PARENT", rel.getFromColumn().getId(), idGen.getNextId() ) ); //$NON-NLS-1$ if ( rel.getToTable() != null ) { modelElement.appendChild( createTaggedValue( doc, "RELATIONSHIP_TABLENAME_CHILD", rel.getToTable().getId(), idGen.getNextId() ) ); //$NON-NLS-1$ if ( rel.getFromTable() != null ) { modelElement.appendChild( createTaggedValue( doc, "RELATIONSHIP_TABLENAME_PARENT", rel.getFromTable().getId(), idGen.getNextId() ) ); //$NON-NLS-1$ if ( rel.isComplex() ) { modelElement.appendChild( createTaggedValue( doc, "RELATIONSHIP_IS_COMPLEX", "Y", "RELATIONSHIP_COMPLEX_JOIN", rel.getComplexJoin(), idGen.getNextId() ) ); //$NON-NLS-1$ if ( rel.getDescription() != null ) { modelElement.appendChild( createTaggedValue( doc, "RELATIONSHIP_DESCRIPTION", rel.getRelationshipDescription(), idGen.getNextId() ) ); //$NON-NLS-1$
if ( relation.relation.isComplex() ) { String formulaString = relation.relation.getComplexJoin(); AliasAwareSqlOpenFormula formula = new AliasAwareSqlOpenFormula( LogicalModel, databaseMeta, formulaString, selections, DEFAULT_ALIAS ); Map<String, String> LogicalTableToAliasMap = new HashMap<String, String>(); if ( !relation.rightAlias.equals( DEFAULT_ALIAS ) ) { LogicalTableToAliasMap.put( relation.relation.getToTable().getId(), relation.rightAlias ); LogicalTableToAliasMap.put( relation.relation.getFromTable().getId(), relation.leftAlias ); } else if ( relation.relation.getFromTable() != null && relation.relation.getToTable() != null && relation.relation.getFromColumn() != null && relation.relation.getToColumn() != null ) { String rightAlias = relation.relation.getToTable().getId(); if ( !relation.rightAlias.equals( DEFAULT_ALIAS ) ) { rightAlias = rightAlias + "_" + relation.rightAlias; //$NON-NLS-1$ String leftAlias = relation.relation.getFromTable().getId(); if ( !relation.leftAlias.equals( DEFAULT_ALIAS ) ) { leftAlias = leftAlias + "_" + relation.leftAlias; //$NON-NLS-1$ join += "."; //$NON-NLS-1$ join += databaseMeta.quoteField( (String) relation.relation.getFromColumn().getProperty( SqlPhysicalColumn.TARGET_COLUMN ) ); join += "."; //$NON-NLS-1$ join +=
String joinFormula = getJoin( model, relation, tableAliases, parameters, genAsPreparedStatement, databaseMeta, locale ); String joinOrderKey = relation.getJoinOrderKey(); JoinType joinType; switch ( RelationshipType.getJoinType( relation.getRelationshipType() ) ) { case LEFT_OUTER: joinType = JoinType.LEFT_OUTER_JOIN; databaseMeta.getQuotedSchemaTableCombination( (String) relation.getFromTable().getProperty( SqlPhysicalTable.TARGET_SCHEMA ), (String) relation.getFromTable().getProperty( SqlPhysicalTable.TARGET_TABLE ) ); String leftTableAlias = databaseMeta.quoteField( tableAliases.get( relation.getFromTable() ) ); String rightTableName = databaseMeta.getQuotedSchemaTableCombination( (String) relation.getToTable().getProperty( SqlPhysicalTable.TARGET_SCHEMA ), (String) relation.getToTable().getProperty( SqlPhysicalTable.TARGET_TABLE ) ); String rightTableAlias = databaseMeta.quoteField( tableAliases.get( relation.getToTable() ) );
protected static void splitOlapRelationships( LogicalModel relationalModel, LogicalModel olapModel ) { List<LogicalRelationship> relationalRelationships = new ArrayList<LogicalRelationship>(); List<LogicalRelationship> olapRelationships = new ArrayList<LogicalRelationship>(); if ( relationalModel.getLogicalRelationships() != null ) { for ( LogicalRelationship rel : relationalModel.getLogicalRelationships() ) { if ( isOlap( rel.getFromColumn() ) && isOlap( rel.getToColumn() ) && isOlap( rel.getFromTable() ) && isOlap( rel.getToTable() ) ) { LogicalRelationship olapRel = duplicateRelationshipForOlap( rel, olapModel ); olapRelationships.add( olapRel ); } else { relationalRelationships.add( rel ); } } relationalModel.getLogicalRelationships().clear(); relationalModel.getLogicalRelationships().addAll( relationalRelationships ); olapModel.getLogicalRelationships().addAll( olapRelationships ); } }
continue; if ( rel.isUsingTable( aliasedTable ) ) { if ( rel.isUsingTable( defaultTable ) ) { boolean inAliasedTables = false; for ( LogicalTable aliased : aliasedTables ) { String leftAlias = null; String rightAlias = null; if ( aliasedTable.equals( rel.getFromTable() ) ) { leftAlias = alias; rightAlias = DEFAULT_ALIAS; LogicalTable tbl = rel.getFromTable() == aliasedTable ? rel.getToTable() : rel.getFromTable(); traversePath( alias, tbl, aliasedPath, aliasedTables, defaultTables, allTables, allRelationships );
private void moveDimensionToModel( final ModelerWorkspace dimensionWorkspace, final ModelerWorkspace factWorkspace, final String factKey, final String dimKey ) throws ModelerException { DimensionMetaData dimension = getLastDimension( dimensionWorkspace ); dimension.setName( getName() ); removeExistingDimension( factWorkspace ); factWorkspace.addDimension( dimension ); LogicalTable dimTable = dimensionWorkspace.getLogicalModel( ModelerPerspective.ANALYSIS ).getLogicalTables().get( 0 ); LogicalTable factTable = factWorkspace.getLogicalModel( ModelerPerspective.ANALYSIS ).getLogicalTables().get( 0 ); LogicalModel logicalModel = factWorkspace.getLogicalModel( ModelerPerspective.ANALYSIS ); logicalModel.addLogicalTable( dimTable ); @SuppressWarnings( "unchecked" ) List<SqlPhysicalTable> physicalTables = (List<SqlPhysicalTable>) factWorkspace.getDomain().getPhysicalModels().get( 0 ).getPhysicalTables(); physicalTables.add( (SqlPhysicalTable) dimTable.getPhysicalTable() ); logicalModel.addLogicalRelationship( new LogicalRelationship( logicalModel, factTable, dimTable, locateLogicalColumn( factWorkspace, factKey ), locateLogicalColumn( dimensionWorkspace, dimKey ) ) ); }
LogicalRelationship logical = new LogicalRelationship(); logical.setComplex( rel.isComplex() ); logical.setComplexJoin( rel.getComplexJoin() ); logical.setJoinOrderKey( rel.getJoinOrderKey() ); if ( domain.getLocales().size() > 0 ) { logical.setRelationshipDescription( rel.getDescription() ); logical.setRelationshipType( RelationshipType.values()[rel.getType()] ); logical.setToTable( toTable ); logical.setToColumn( toColumn ); logical.setFromTable( fromTable ); logical.setFromColumn( fromColumn ); logical.setId( logicalRelationshipId ); logical.setLogicalModel( logicalModel ); logicalModel.getLogicalRelationships().add( logical );
LogicalRelationship logicalRelationship = new LogicalRelationship(); logicalRelationship.setRelationshipType( RelationshipType._1_1 ); logicalRelationship.setFromTable( fromTable ); logicalRelationship.setFromColumn( fromColumn ); logicalRelationship.setToTable( toTable ); logicalRelationship.setToColumn( toColumn ); logicalModel.addLogicalRelationship( logicalRelationship );
DatabaseMeta databaseMeta, String locale ) throws PentahoMetadataException { String join = ""; //$NON-NLS-1$ if ( relation.isComplex() ) { try { new SqlOpenFormula( businessModel, databaseMeta, relation.getComplexJoin(), tableAliases, parameters, genAsPreparedStatement ); formula.parseAndValidate(); "SqlGenerator.ERROR_0017_FAILED_TO_PARSE_COMPLEX_JOIN", relation.getComplexJoin() ), e ); //$NON-NLS-1$ join = relation.getComplexJoin(); } else if ( relation.getFromTable() != null && relation.getToTable() != null && relation.getFromColumn() != null && relation.getToColumn() != null ) { leftTableAlias = tableAliases.get( relation.getFromColumn().getLogicalTable() ); } else { leftTableAlias = relation.getFromColumn().getLogicalTable().getId(); join += "."; //$NON-NLS-1$ join += databaseMeta.quoteField( (String) relation.getFromColumn().getProperty( SqlPhysicalColumn.TARGET_COLUMN ) ); rightTableAlias = tableAliases.get( relation.getToColumn().getLogicalTable() ); } else { rightTableAlias = relation.getToColumn().getLogicalTable().getId(); join += databaseMeta.quoteField( (String) relation.getToColumn().getProperty( SqlPhysicalColumn.TARGET_COLUMN ) ); } else {
AliasedLogicalRelationship aliasedRelation = allRelationships.get( i ); String joinFormula = getJoin( model, aliasedRelation, databaseMeta, locale, selections ); String joinOrderKey = aliasedRelation.relation.getJoinOrderKey(); JoinType joinType; switch ( RelationshipType.getJoinType( aliasedRelation.relation.getRelationshipType() ) ) { case LEFT_OUTER: joinType = JoinType.LEFT_OUTER_JOIN; (String) aliasedRelation.relation.getFromTable().getProperty( SqlPhysicalTable.TARGET_SCHEMA ); String leftTable = (String) aliasedRelation.relation.getFromTable().getProperty( SqlPhysicalTable.TARGET_TABLE ); String rightSchema = (String) aliasedRelation.relation.getToTable().getProperty( SqlPhysicalTable.TARGET_SCHEMA ); String rightTable = (String) aliasedRelation.relation.getToTable().getProperty( SqlPhysicalTable.TARGET_TABLE ); String leftTableAlias = aliasedRelation.relation.getFromTable().getId(); if ( !aliasedRelation.leftAlias.equals( DEFAULT_ALIAS ) ) { leftTableAlias = leftTableAlias + "_" + aliasedRelation.leftAlias; //$NON-NLS-1$ String rightTableAlias = aliasedRelation.relation.getToTable().getId(); if ( !aliasedRelation.rightAlias.equals( DEFAULT_ALIAS ) ) { rightTableAlias = rightTableAlias + "_" + aliasedRelation.rightAlias; //$NON-NLS-1$
public boolean contains( LogicalRelationship rel ) { if ( rel == null ) { return false; } for ( int i = 0; i < size(); i++ ) { LogicalRelationship check = getRelationship( i ); LogicalTable from = check.getFromTable(); LogicalTable to = check.getToTable(); if ( ( rel.getFromTable().equals( from ) && rel.getToTable().equals( to ) ) || ( rel.getFromTable().equals( to ) && rel.getToTable().equals( from ) ) ) { return true; } } return false; }
if ( relationshipMeta != null ) { LogicalColumn keyColumn; if ( relationshipMeta.getFromTable().equals( dimTable ) ) { keyColumn = relationshipMeta.getToColumn(); } else { keyColumn = relationshipMeta.getFromColumn();
model.addLogicalRelationship( new LogicalRelationship( model, leftTable, rightTable, leftColumn, rightColumn ) );
public String toString() { String thisPath = ""; //$NON-NLS-1$ for ( int i = 0; i < size(); i++ ) { LogicalRelationship relationship = getRelationship( i ); if ( i > 0 ) { thisPath += ", "; //$NON-NLS-1$ } thisPath += "[" + relationship.getFromTable().getId() + "-" + relationship.getToTable().getId() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } return thisPath; }
/** * Builds this graph based on data stored in list of relationships * * @param relationships * List of relationships that describe the graph */ private void build( List<LogicalRelationship> relationships ) { // loop through relationships and add necessary arcs // to the graph for ( LogicalRelationship relationship : relationships ) { // obtains nodes corresponding to tables Node left = getNodeForTable( relationship.getFromTable() ); Node right = getNodeForTable( relationship.getToTable() ); // record arcs that correspond to change Arc arc = createArc( left, right, relationship ); // TODO: if any table requires a relationship when the table is // used to ensure proper filtering, add dependency here // // if (relationship.getTableFrom() requires relationship) // left.addRequiredArc(arc); // // if (relationship.getTableTo() requires relationship) // right.addRequiredArc(arc); } }