Java Code Examples for org.pentaho.metadata.model.LogicalTable#getLogicalColumns()

The following examples show how to use org.pentaho.metadata.model.LogicalTable#getLogicalColumns() . 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: 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 2
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 3
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 4
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 5
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 6
Source File: ConceptUtil.java    From pentaho-kettle with 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 7
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 8
Source File: JobGenerator.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private StepMeta generateTableInputStepFromLogicalTable(LogicalTable logicalTable) {

    String name = ConceptUtil.getName(logicalTable, locale);
    String description = ConceptUtil.getDescription(logicalTable, locale);

    TableInputMeta meta = new TableInputMeta();

    // Source database, retain first
    // Source table, retain first
    // Source columns, retain all
    //
    DatabaseMeta sourceDatabaseMeta = null;
    String sourceTable = null;
    List<String> sourceColumns = new ArrayList<String>();
    for (LogicalColumn column : logicalTable.getLogicalColumns()) {
      String phDb = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_SOURCE_DB);
      String phTable = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_SOURCE_TABLE);
      String phCol = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_SOURCE_COLUMN);
      if (!Utils.isEmpty(phDb) && sourceDatabaseMeta==null) {
        sourceDatabaseMeta = DatabaseMeta.findDatabase(databases, phDb);
      }
      if (!Utils.isEmpty(phTable)) {
        sourceTable = phDb;
      }
      if (!Utils.isEmpty(phCol)) {
        sourceColumns.add(phCol);
      }
    }
    String sql = "SELECT * FROM --< Source query for dimension '"+name+"'";

    meta.setDatabaseMeta(sourceDatabaseMeta);

    if (sourceDatabaseMeta!=null && !Utils.isEmpty(sourceTable)) {
      sql = "SELECT ";
      if (sourceColumns.isEmpty()) {
        sql+=" * ";
      } else {
        sql+=Const.CR;
      }
      boolean first=true;
      for (String sourceColumn : sourceColumns) {
        if (first) {
          first=false;
        } else {
          sql+="      , ";
        }
        sql+=sourceDatabaseMeta.quoteField(sourceColumn)+Const.CR;
      }
      sql+="FROM "+sourceDatabaseMeta.getQuotedSchemaTableCombination(null, sourceTable);
    }
    meta.setSQL(sql);

    // Wrap it up...
    //
    StepMeta stepMeta = new StepMeta("Source data for '"+name+"'", meta);
    stepMeta.drawStep();
    stepMeta.setDescription("Reads data for '"+name+"' : "+description);

    return stepMeta;
  }