Java Code Examples for org.pentaho.metadata.model.LogicalTable

The following examples show how to use org.pentaho.metadata.model.LogicalTable. These examples are extracted from open source projects. 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 Project: pentaho-kettle   Source File: StarModelDialog.java    License: Apache License 2.0 6 votes vote down vote up
protected void refreshTablesList() {
  wTablesList.clearAll();

  for (LogicalTable logicalTable : logicalModel.getLogicalTables()) {
    TableType tableType = (TableType) logicalTable.getProperty(DefaultPropertyID.TABLE_TYPE.getId());
    if (tableType==TableType.DIMENSION) {
      TableItem item = new TableItem(wTablesList.table, SWT.NONE);
      item.setText(1, Const.NVL(ConceptUtil.getName(logicalTable, locale), ""));
      item.setText(2, Const.NVL(ConceptUtil.getDescription(logicalTable, locale), ""));
      String typeDescription = tableType==null ? "" : tableType.name();
      if (tableType==TableType.DIMENSION) {
        DimensionType dimType = ConceptUtil.getDimensionType(logicalTable);
        if (dimType!=DimensionType.OTHER) {
          typeDescription+=" - "+dimType.name();
        }
      }
      item.setText(3, typeDescription );
    }
  }
  wTablesList.removeEmptyRows();
  wTablesList.setRowNums();
  wTablesList.optWidth(true);

  String[] dimensionNames = getDimensionTableNames();
  factColumns[5].setComboValues(dimensionNames);
}
 
Example 2
Source Project: pentaho-kettle   Source File: JobGenerator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get a list of all unique physical table names wrapped in their logical tables
 * @return
 */
protected List<LogicalTable> getUniqueLogicalTables() {
  List<LogicalTable> tables = new ArrayList<LogicalTable>();
  List<String> phTabs = new ArrayList<String>();
  for (LogicalModel model : domain.getLogicalModels()) {
    for (LogicalTable table : model.getLogicalTables()) {
      String phTable = ConceptUtil.getString(table, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
      if (!Utils.isEmpty(phTable)) {
        if (!phTabs.contains(phTable)) {
          phTabs.add(phTable);
          tables.add(table);
        }
      }
    }
  }

  return tables;
}
 
Example 3
/**
 * @param businessTable
 *          The table to calculate the number of neighbours for.
 * @param selectedTables
 *          The list of selected business tables.
 * @return The number of neighbours in a list of selected tables using the relationships defined in this business
 *         Model.
 */
private static int
  getNrNeighbours( LogicalModel model, LogicalTable businessTable, List<LogicalTable> selectedTables ) {
  int nr = 0;

  for ( LogicalRelationship relationship : model.getLogicalRelationships() ) {
    if ( relationship.isUsingTable( businessTable ) ) {
      // See if one of the selected tables is also using this relationship.
      // If so, we have a neighbour in the selected tables.
      //
      boolean found = false;
      for ( int s = 0; s < selectedTables.size() && !found; s++ ) {
        LogicalTable selectedTable = selectedTables.get( s );
        if ( relationship.isUsingTable( selectedTable ) && !businessTable.equals( selectedTable ) ) {
          nr++;
        }
      }
    }
  }
  return nr;
}
 
Example 4
Source Project: pentaho-kettle   Source File: ConceptUtilTest.java    License: 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 5
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 6
Source Project: pentaho-kettle   Source File: ConceptUtilTest.java    License: 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 7
Source Project: pentaho-kettle   Source File: JobGenerator.java    License: Apache License 2.0 6 votes vote down vote up
private TransMeta generateTimeTransformation(DatabaseMeta databaseMeta, LogicalTable logicalTable) throws KettleException {
  // We actually load the transformation from a template and then slightly modify it.
  //
  String filename = "/org/pentaho/di/resources/Generate time dimension.ktr";
  InputStream inputStream = getClass().getResourceAsStream(filename);
  TransMeta transMeta = new TransMeta(inputStream, Spoon.getInstance().rep, true, new Variables(), null);

  // Find the table output step and inject the target table name and database...
  //
  StepMeta stepMeta = transMeta.findStep("TARGET");
  if (stepMeta!=null) {
    TableOutputMeta meta = (TableOutputMeta) stepMeta.getStepMetaInterface();
    meta.setDatabaseMeta(databaseMeta);
    String phTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
    meta.setTableName(phTable);
  }

  return transMeta;
}
 
Example 8
Source Project: pentaho-kettle   Source File: JobGeneratorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateDimensionTransformations() throws Exception {
  final LogicalModel logicalModel = mock( LogicalModel.class );
  when( jobGenerator.domain.getLogicalModels() ).thenReturn( new LinkedList<LogicalModel>() { {
      add( logicalModel );
    } } );

  final LogicalTable logicalTable = mock( LogicalTable.class );
  when( logicalTable.getProperty( eq( DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME ) ) )
      .thenReturn( "test_table_name" );
  when( logicalModel.getLogicalTables() ).thenReturn( new LinkedList<LogicalTable>() { {
      add( logicalTable );
    } } );

  when( logicalTable.getProperty( eq( DefaultPropertyID.TABLE_TYPE.getId() ) ) ).thenReturn( TableType.DIMENSION );
  when( logicalTable.getProperty( eq( DefaultIDs.LOGICAL_TABLE_DIMENSION_TYPE ) ) ).thenReturn( DimensionType.JUNK_DIMENSION.name() );

  final List<TransMeta> transMetas = jobGenerator.generateDimensionTransformations();

  assertNotNull( transMetas );
  assertEquals( 1, transMetas.size() );
}
 
Example 9
Source Project: pentaho-kettle   Source File: JobGeneratorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetUniqueLogicalTables() throws Exception {
  final LogicalModel logicalModel = mock( LogicalModel.class );
  when( jobGenerator.domain.getLogicalModels() ).thenReturn( new LinkedList<LogicalModel>() { {
      add( logicalModel );
    } } );

  final LogicalTable logicalTable = mock( LogicalTable.class );
  when( logicalTable.getProperty( eq( DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME ) ) )
      .thenReturn( "test_table_name" );
  when( logicalModel.getLogicalTables() ).thenReturn( new LinkedList<LogicalTable>() { {
      add( logicalTable );
    } } );

  final List<LogicalTable> uniqueLogicalTables = jobGenerator.getUniqueLogicalTables();

  assertNotNull( uniqueLogicalTables );
  assertEquals( 1, uniqueLogicalTables.size() );
  assertEquals( logicalTable, uniqueLogicalTables.get( 0 ) );
}
 
Example 10
Source Project: pentaho-kettle   Source File: StarModelDialog.java    License: 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 11
Source Project: pentaho-kettle   Source File: JobGenerator.java    License: Apache License 2.0 6 votes vote down vote up
private TransMeta generateDateTransformation(DatabaseMeta databaseMeta, LogicalTable logicalTable) throws KettleException {
  // We actually load the transformation from a template and then slightly modify it.
  //
  String filename = "/org/pentaho/di/resources/Generate date dimension.ktr";
  InputStream inputStream = getClass().getResourceAsStream(filename);
  TransMeta transMeta = new TransMeta(inputStream, Spoon.getInstance().rep, true, new Variables(), null);

  // Find the table output step and inject the target table name and database...
  //
  StepMeta stepMeta = transMeta.findStep("TARGET");
  if (stepMeta!=null) {
    TableOutputMeta meta = (TableOutputMeta) stepMeta.getStepMetaInterface();
    meta.setDatabaseMeta(databaseMeta);
    String phTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
    meta.setTableName(phTable);
  }

  return transMeta;
}
 
Example 12
Source Project: pentaho-kettle   Source File: StarModelDialog.java    License: Apache License 2.0 6 votes vote down vote up
public StarModelDialog(Shell parent, LogicalModel logicalModel, String locale) {
  super(parent, SWT.DIALOG_TRIM);
  this.logicalModel = logicalModel;
  this.props = PropsUI.getInstance();
  this.locale = locale;

  List<LogicalTable> factTables = ConceptUtil.findLogicalTables(logicalModel, TableType.FACT);
  if (factTables.isEmpty()) {
    this.factTable = new LogicalTable();
    this.factTable.setId(UUID.randomUUID().toString());
    this.factTable.setProperty(DefaultPropertyID.TABLE_TYPE.getId(), TableType.FACT);
    logicalModel.addLogicalTable(this.factTable);
  } else {
    this.factTable = factTables.get(0);
  }
}
 
Example 13
private LogicalColumn findBusinessColumn( LogicalTable logicalTable, String columnName ) {
  for ( LogicalColumn logicalColumn : logicalTable.getLogicalColumns() ) {
    if ( columnName.equals( ( (SqlPhysicalColumn) logicalColumn.getPhysicalColumn() ).getTargetColumn() ) ) {
      return logicalColumn;
    }
  }
  return null;
}
 
Example 14
private LogicalTable createBusinessTable( SqlPhysicalTable physicalTable, String locale ) {

    // Create a business table with a new ID and localized name
    //
    LogicalTable businessTable = new LogicalTable( null, physicalTable );

    // Try to set the name of the business table to something nice (beautify)
    //
    String tableName = PhysicalTableImporter.beautifyName( physicalTable.getTargetTable() );
    businessTable.setName( new LocalizedString( locale, tableName ) );

    businessTable.setId( Util.proposeSqlBasedLogicalTableId( locale, businessTable, physicalTable ) );

    // Add columns to this by copying the physical columns to the business
    // columns...
    //
    for ( IPhysicalColumn physicalColumn : physicalTable.getPhysicalColumns() ) {

      LogicalColumn businessColumn = new LogicalColumn();
      businessColumn.setPhysicalColumn( physicalColumn );
      businessColumn.setLogicalTable( businessTable );

      // We're done, add the business column.
      //
      // Propose a new ID
      businessColumn.setId( Util.proposeSqlBasedLogicalColumnId( locale, businessTable,
          (SqlPhysicalColumn) physicalColumn ) );
      businessTable.addLogicalColumn( businessColumn );
    }

    return businessTable;
  }
 
Example 15
protected void doInputWiring( Query query, TransMeta transMeta ) {
  //
  // CSV FILE LOCATION AND FIELDS
  //

  InlineEtlPhysicalModel physicalModel = (InlineEtlPhysicalModel) query.getLogicalModel().getPhysicalModel();

  CsvInputMeta csvinput = (CsvInputMeta) getStepMeta( transMeta, "CSV file input" ).getStepMetaInterface(); //$NON-NLS-1$

  // the file name might need to be translated to the correct location here
  if ( csvFileLoc != null ) {
    csvinput.setFilename( csvFileLoc + physicalModel.getFileLocation() );
  } else {
    csvinput.setFilename( physicalModel.getFileLocation() );
  }

  csvinput.setDelimiter( physicalModel.getDelimiter() );
  csvinput.setEnclosure( physicalModel.getEnclosure() );
  csvinput.setHeaderPresent( physicalModel.getHeaderPresent() );

  // update fields

  LogicalTable table = query.getLogicalModel().getLogicalTables().get( 0 );

  csvinput.allocate( table.getLogicalColumns().size() );

  for ( int i = 0; i < csvinput.getInputFields().length; i++ ) {
    // Update csv input

    LogicalColumn col = table.getLogicalColumns().get( i );
    csvinput.getInputFields()[i] = new TextFileInputField();
    String fieldName = (String) col.getProperty( InlineEtlPhysicalColumn.FIELD_NAME );
    if ( logger.isDebugEnabled() ) {
      logger.debug( "FROM CSV: " + fieldName ); //$NON-NLS-1$
    }
    csvinput.getInputFields()[i].setName( fieldName );
    csvinput.getInputFields()[i].setType( convertType( col.getDataType() ) );
  }

}
 
Example 16
Source Project: pentaho-kettle   Source File: StarModelPainter.java    License: Apache License 2.0 5 votes vote down vote up
private Point findPointOfTable(List<TablePoint> points, LogicalTable fromTable) {
  for (TablePoint tablePoint : points) {
    if (tablePoint.logicalTable.equals(fromTable)) {
      return tablePoint.point;
    }
  }
  return null;
}
 
Example 17
/**
 * @param sql
 * @param usedTable
 */
public SqlAndTables( String sql, LogicalTable usedTable, Selection usedColumn ) {
  this.sql = sql;
  this.usedTables = new ArrayList<LogicalTable>();
  this.usedTables.add( usedTable );
  this.usedColumns = new ArrayList<Selection>();
  this.usedColumns.add( usedColumn );
}
 
Example 18
/**
 * this method adds the order by statements to the query model
 * 
 * @param query
 *          SQL query model.
 * @param model
 *          The business model.
 * @param orderBy
 *          List of order bys.
 * @param databaseMeta
 *          Database Info.
 * @param locale
 *          Locale String.
 * @param tableAliases
 *          Aliases of the tables to be used during query generation.
 * @param columnsMap
 *          The column map is a unique mapping of Column alias to the column ID.
 * @param parameters
 *          Parameters to be used during query generation.
 * @param genAsPreparedStatement
 *          Tells the method generate query as prepared statement.
 */
protected void generateOrderBy( SQLQueryModel query, LogicalModel model, List<Order> orderBy,
    DatabaseMeta databaseMeta, String locale, Map<LogicalTable, String> tableAliases, Map<String, String> columnsMap,
    Map<String, Object> parameters, boolean genAsPreparedStatement ) {
  if ( orderBy != null ) {
    for ( Order orderItem : orderBy ) {
      LogicalColumn businessColumn = orderItem.getSelection().getLogicalColumn();
      String alias = null;
      if ( columnsMap != null ) {
        // The column map is a unique mapping of Column alias to the column ID
        // Here we have the column ID and we need the alias.
        // We need to do the order by on the alias, not the column name itself.
        // For most databases, it can be both, but the alias is more standard.
        //
        // Using the column name and not the alias caused an issue on Apache Derby.
        //
        for ( String key : columnsMap.keySet() ) {
          String value = columnsMap.get( key );
          if ( value.equals( businessColumn.getId() ) ) {
            // Found it: the alias is the key
            alias = key;
            break;
          }
        }
      }
      SqlAndTables sqlAndTables =
          getBusinessColumnSQL( model, orderItem.getSelection(), tableAliases, parameters, genAsPreparedStatement,
              databaseMeta, locale );
      query.addOrderBy( sqlAndTables.getSql(), databaseMeta.quoteField( alias ), orderItem.getType() != Type.ASC
          ? OrderType.DESCENDING : null );
    }
  }
}
 
Example 19
private void createRelationship( LogicalTable from, LogicalTable to, int fromColId, int toColId, LogicalModel model )
  throws Exception {
  LogicalRelationship rel = new LogicalRelationship();
  rel.setFromTable( from );
  rel.setToTable( to );
  rel.setFromColumn( from.getLogicalColumns().get( fromColId ) );
  rel.setToColumn( to.getLogicalColumns().get( toColId ) );
  rel.setRelationshipType( RelationshipType._1_N );
  model.getLogicalRelationships().add( rel );
}
 
Example 20
private static LogicalRelationship findRelationshipUsing( LogicalModel model, LogicalTable one, LogicalTable two ) {
  for ( LogicalRelationship rel : model.getLogicalRelationships() ) {
    if ( rel.isUsingTable( one ) && rel.isUsingTable( two ) ) {
      return rel;
    }
  }
  return null;
}
 
Example 21
Source Project: pentaho-metadata   Source File: Path.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
}
 
Example 22
Source Project: pentaho-metadata   Source File: Path.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public boolean contains( LogicalTable tab ) {
  if ( tab == null ) {
    return false;
  }
  for ( int i = 0; i < size(); i++ ) {
    LogicalRelationship check = getRelationship( i );
    if ( check.isUsingTable( tab ) ) {
      return true;
    }
  }
  return false;
}
 
Example 23
Source Project: pentaho-kettle   Source File: ConceptUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static List<LogicalColumn> findLogicalColumns(LogicalTable logicalTable, AttributeType attributeType) {
  List<LogicalColumn> logicalColumns = new ArrayList<LogicalColumn>();
  for (LogicalColumn logicalColumn : logicalTable.getLogicalColumns()) {
    AttributeType type = getAttributeType(logicalColumn);
    if (type == attributeType) {
      logicalColumns.add(logicalColumn);
    }
  }
  return logicalColumns;
}
 
Example 24
/**
 * constructor, used for constraints, security, and complex joins
 * 
 * @param model
 *          logical model for logical column lookup
 * @param formulaString
 *          formula string
 * @throws PentahoMetadataException
 *           throws an exception if we're missing anything important
 */
public SqlOpenFormula( LogicalModel model, DatabaseMeta databaseMeta, String formulaString,
    Map<LogicalTable, String> tableAliases, Map<String, Object> parameters, boolean genAsPreparedStatement )
  throws PentahoMetadataException {

  this.model = model;
  this.formulaString = formulaString;
  this.databaseMeta = databaseMeta;
  this.tableAliases = tableAliases;
  this.tables = new ArrayList<LogicalTable>();
  this.parameters = parameters;
  this.genAsPreparedStatement = genAsPreparedStatement;

  if ( model == null ) {
    throw new PentahoMetadataException( Messages
        .getErrorString( "SqlOpenFormula.ERROR_0001_NO_BUSINESS_MODEL_PROVIDED" ) ); //$NON-NLS-1$
  }

  if ( databaseMeta == null ) {
    throw new PentahoMetadataException( Messages
        .getErrorString( "SqlOpenFormula.ERROR_0002_NO_DATABASE_META_PROVIDED" ) ); //$NON-NLS-1$
  }

  this.sqlDialect = SQLDialectFactory.getSQLDialect( databaseMeta );

  if ( sqlDialect == null ) {
    throw new PentahoMetadataException( Messages.getErrorString(
        "SqlOpenFormula.ERROR_0018_DATABASE_DIALECT_NOT_FOUND", databaseMeta.getDatabaseTypeDesc() ) ); //$NON-NLS-1$
  }

  if ( formulaString == null ) {
    throw new PentahoMetadataException( Messages
        .getErrorString( "SqlOpenFormula.ERROR_0003_NO_FORMULA_STRING_PROVIDED" ) ); //$NON-NLS-1$
  }
}
 
Example 25
Source Project: pentaho-kettle   Source File: StarModelPainter.java    License: Apache License 2.0 5 votes vote down vote up
private List<TablePoint> getCirclePoints(Point center, int width, int heigth, List<LogicalTable> tableList) {
  List<TablePoint> points = new ArrayList<TablePoint>();
  int nrPoints = tableList.size();
  double alpha = Math.PI * 2 / nrPoints;
  for (int i=0;i<nrPoints;i++) {
    double tetha = alpha*i;
    Point point = new Point(center.x, center.y);
    point.x += (int)Math.round(Math.cos(tetha)*width);
    point.y += (int)Math.round(Math.sin(tetha)*(heigth-5));

    points.add(new TablePoint(tableList.get(i), point));
  }

  return points;
}
 
Example 26
Source Project: pentaho-metadata   Source File: Node.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public Node( int id, LogicalTable table, GraphElementChangeListener listener ) {
  this.id = id;
  this.table = table;
  this.listener = listener;
  this.domain = new GraphElementDomain( this );
  this.arcs = new ArrayList<Arc>();
}
 
Example 27
Source Project: pentaho-kettle   Source File: JobGeneratorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateDimensionTransformation() throws Exception {
  final LogicalTable logicalTable = mock( LogicalTable.class );
  final DatabaseMeta databaseMeta = mock( DatabaseMeta.class );

  final TransMeta transMeta = jobGenerator.generateDimensionTransformation( databaseMeta, logicalTable );
  assertNotNull( transMeta );
  assertTrue( transMeta.getDatabases().contains( databaseMeta ) );
  assertEquals( 2, transMeta.getSteps().size() );
  assertEquals( 1, transMeta.nrTransHops() );
}
 
Example 28
/**
 * Creates a new graph for a business model
 * 
 * @param model
 *          Business model to base graph upon
 */
public MqlGraph( LogicalModel model ) {
  this.nodes = new ArrayList<Node>();
  this.arcs = new ArrayList<Arc>();
  this.tableNodeMap = new HashMap<LogicalTable, Node>();
  this.basicNodeQueue = new GraphElementQueue();
  this.extendedNodeQueue = new GraphElementQueue();

  // build the graph for this model
  build( model.getLogicalRelationships() );
}
 
Example 29
/**
 * Calculates and returns a path that satisfies the required tables list or null if one cannot be found
 * 
 * @param requiredTables
 *          Tables that are required to be in path
 * @return Path with smallest number of relationships to ensure all required tables are included
 */
public Path getPath( PathType searchTechnique, List<LogicalTable> requiredTables ) {
  // if reset works and validity check passes, build path
  if ( reset( requiredTables ) && isValid( searchTechnique ) ) {
    logger.debug( "Path determined sucessfully" );

    Path path = new Path();
    for ( Arc arc : arcs ) {
      if ( arc.isRequired() ) {
        if ( logger.isDebugEnabled() ) {
          logger.debug( "Arc selected for path: " + arc );
        }
        path.addRelationship( arc.getRelationship() );
      } else if ( logger.isDebugEnabled() ) {
        logger.debug( "Arc not used for path: Requirement Known[" + arc.isRequirementKnown() + "], Required["
            + arc.isRequired() + "]" );
      }
    }

    if ( logger.isDebugEnabled() ) {
      for ( Node n : nodes ) {
        logger.debug( "Node selection state: Requirement Known[" + n.isRequirementKnown() + "], Required["
            + n.isRequired() + "]" );
      }
    }
    if ( path.size() > 0 ) {
      return path;
    }
  }

  return null;
}
 
Example 30
Source Project: pentaho-metadata   Source File: Util.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public static final String proposeSqlBasedLogicalTableId( String locale, LogicalTable businessTable,
    SqlPhysicalTable physicalTable ) {
  String baseID = Util.toId( businessTable.getName( locale ) );
  String namePart = Util.toId( Util.NVL( physicalTable.getName( locale ), physicalTable.getTargetTable() ) );
  String id = Settings.getBusinessTableIDPrefix() + baseID + "_" + namePart; //$NON-NLS-1$
  if ( Settings.isAnIdUppercase() ) {
    id = id.toUpperCase();
  }
  return id;
}