org.pentaho.metadata.model.LogicalTable Java Examples

The following examples show how to use org.pentaho.metadata.model.LogicalTable. 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: JobGeneratorTest.java    From pentaho-kettle with 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 #2
Source File: StarModelDialog.java    From pentaho-kettle with 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 #3
Source File: StarModelDialog.java    From pentaho-kettle with 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 #4
Source File: JobGenerator.java    From pentaho-kettle with 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 #5
Source File: SqlGenerator.java    From pentaho-metadata with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * @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 #6
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 #7
Source File: JobGenerator.java    From pentaho-kettle with 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 #8
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 #9
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 #10
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 #11
Source File: JobGeneratorTest.java    From pentaho-kettle with 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 #12
Source File: JobGenerator.java    From pentaho-kettle with 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 #13
Source File: SqlOpenFormula.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 #14
Source File: StarModelPainter.java    From pentaho-kettle with 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 #15
Source File: Node.java    From pentaho-metadata with 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 #16
Source File: JobGeneratorTest.java    From pentaho-kettle with 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 #17
Source File: MqlGraph.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 #18
Source File: ConceptUtil.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static LogicalTable findDimensionWithName(LogicalModel logicalModel, String dimensionName, String locale) {
  for (LogicalTable table : logicalModel.getLogicalTables()) {
    TableType tableType = ConceptUtil.getTableType(table);
    if (tableType==TableType.DIMENSION) {
      String name = ConceptUtil.getName(table, locale);
      if (name!=null && name.equalsIgnoreCase(dimensionName)) return table;
    }
  }
  return null;
}
 
Example #19
Source File: MqlGraph.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 #20
Source File: ConceptUtil.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static List<LogicalTable> findLogicalTables(LogicalModel logicalModel, TableType tableType) {
  List<LogicalTable> logicalColumns = new ArrayList<LogicalTable>();
  for (LogicalTable logicalTable : logicalModel.getLogicalTables()) {
    TableType type = getTableType(logicalTable);
    if (type == tableType) {
      logicalColumns.add(logicalTable);
    }
  }
  return logicalColumns;
}
 
Example #21
Source File: StarModelerPerspective.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Delete a shared dimension in the domain
 *
 * @param domain the domain to delete the dimension from
 * @param modelName the name of the dimension to delete
 */
private boolean deleteSharedDimension(Shell shell, StarDomain starDomain, String locale, String modelName) {
  LogicalTable logicalTable = findSharedDimension(starDomain, locale, modelName);
  if (logicalTable!=null) {
    // TODO: show warning dialog.
    //
    starDomain.getSharedDimensions().remove(logicalTable);
    starDomain.setChanged(true);

    return true;
  }
  return false;
}
 
Example #22
Source File: Util.java    From pentaho-metadata with 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;
}
 
Example #23
Source File: JobGenerator.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private RowMetaInterface getRowForLogicalTable(DatabaseMeta databaseMeta, LogicalTable logicalTable) {
  RowMetaInterface fields = new RowMeta();
  for (LogicalColumn column : logicalTable.getLogicalColumns()) {
    ValueMetaInterface valueMeta = getValueForLogicalColumn(databaseMeta, column);
    fields.addValueMeta(valueMeta);
  }
  return fields;
}
 
Example #24
Source File: Util.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static final String proposeSqlBasedLogicalColumnId( String locale, LogicalTable businessTable,
    SqlPhysicalColumn physicalColumn ) {
  String baseID = Util.toId( businessTable.getName( locale ) );
  String namePart = Util.toId( Util.NVL( physicalColumn.getName( locale ), physicalColumn.getTargetColumn() ) );
  String id = Util.getLogicalColumnIdPrefix() + baseID + "_" + namePart; //$NON-NLS-1$
  return id.toUpperCase();
}
 
Example #25
Source File: AutoModeler.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 #26
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 #27
Source File: StarModelerPerspective.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public boolean save(EngineMetaInterface meta, String fname, boolean isExport) {
  try {

    // We only expect a start domain here. How else would we end up here?
    //
    if (meta instanceof StarDomain) {
      StarDomain starDomain = (StarDomain) meta;

      // Make sure we pick the active MetaStore to save to, otherwise it's hard to verify
      //
      IMetaStore metaStore = Spoon.getInstance().metaStore.getActiveMetaStore();

      LogChannel.GENERAL.logBasic("Saving star domain to meta store: "+metaStore.getName());

      // Save the name and description of the shared dimension in the metastore
      //
      StarDomainMetaStoreUtil.saveStarDomain(metaStore, starDomain);

      // Save the shared dimensions in the Spoon IMetaStore (update or create)
      //
      for (LogicalTable sharedDimension : starDomain.getSharedDimensions()) {
        SharedDimensionMetaStoreUtil.saveSharedDimension(metaStore, sharedDimension, defaultLocale);
      }

      meta.clearChanged();
      Spoon.getInstance().enableMenus();

      return true;
    }
  } catch(Exception e) {
    new ErrorDialog(Spoon.getInstance().getShell(), "Error saving model", "There was an error while saving the model:", e);
  }

  return false;
}
 
Example #28
Source File: SQLJoinIT.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
private LogicalTable[] getTablesWithRelationships( RelationshipType relationship1, RelationshipType relationship2,
                                                   Category category, LogicalModel model ) {
  LogicalTable table = getDummySingleColumnTable( "1" );
  category.addLogicalColumn( table.getLogicalColumns().get( 0 ) );

  LogicalTable table2 = getDummySingleColumnTable( "2" );
  category.addLogicalColumn( table2.getLogicalColumns().get( 0 ) );

  LogicalTable table3 = getDummySingleColumnTable( "3" );
  category.addLogicalColumn( table3.getLogicalColumns().get( 0 ) );

  final LogicalRelationship rl1 = new LogicalRelationship();
  rl1.setRelationshipType( relationship1 );
  rl1.setFromTable( table );
  rl1.setFromColumn( table.getLogicalColumns().get( 0 ) );
  rl1.setToTable( table2 );
  rl1.setToColumn( table2.getLogicalColumns().get( 0 ) );

  final LogicalRelationship rl2 = new LogicalRelationship();
  rl2.setRelationshipType( relationship2 );
  rl2.setFromTable( table2 );
  rl2.setFromColumn( table2.getLogicalColumns().get( 0 ) );
  rl2.setToTable( table3 );
  rl2.setToColumn( table3.getLogicalColumns().get( 0 ) );

  model.getLogicalRelationships().add( rl1 );
  model.getLogicalRelationships().add( rl2 );

  return new LogicalTable[] { table, table2, table3 };
}
 
Example #29
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 #30
Source File: InlineEtlQueryExecutor.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
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() ) );
  }

}