use of org.pentaho.metadata.model.LogicalColumn in project pentaho-kettle by pentaho.
the class StarModelDialog method copyTable.
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;
}
use of org.pentaho.metadata.model.LogicalColumn in project pentaho-kettle by pentaho.
the class StarModelDialog method getRelationshipsFromFact.
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);
}
}
}
}
}
use of org.pentaho.metadata.model.LogicalColumn in project pentaho-kettle by pentaho.
the class JobGenerator method generateDimensionLookupStepFromLogicalTable.
protected StepMeta generateDimensionLookupStepFromLogicalTable(DatabaseMeta databaseMeta, LogicalTable logicalTable) {
String name = ConceptUtil.getName(logicalTable, locale);
String description = ConceptUtil.getDescription(logicalTable, locale);
String phTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
String schemaTable = databaseMeta.getQuotedSchemaTableCombination(null, Const.NVL(phTable, name));
DimensionLookupMeta meta = new DimensionLookupMeta();
meta.setDatabaseMeta(databaseMeta);
// TODO
meta.setSchemaName(null);
meta.setTableName(schemaTable);
meta.setAutoIncrement(databaseMeta.supportsAutoinc());
meta.setCacheSize(5000);
meta.setCommitSize(500);
meta.setUpdate(true);
// Find the technical key (if any defined)
//
LogicalColumn keyColumn = ConceptUtil.findLogicalColumn(logicalTable, AttributeType.TECHNICAL_KEY);
if (keyColumn != null) {
ValueMetaInterface keyValue = getValueForLogicalColumn(databaseMeta, keyColumn);
meta.setKeyField(keyValue.getName());
}
// Simply add all the NATURAL_KEY columns...
//
List<LogicalColumn> naturalKeys = ConceptUtil.findLogicalColumns(logicalTable, AttributeType.NATURAL_KEY);
meta.setKeyLookup(new String[naturalKeys.size()]);
meta.setKeyStream(new String[naturalKeys.size()]);
for (int i = 0; i < naturalKeys.size(); i++) {
LogicalColumn logicalColumn = naturalKeys.get(i);
ValueMetaInterface valueMeta = getValueForLogicalColumn(databaseMeta, logicalColumn);
meta.getKeyLookup()[i] = valueMeta.getName();
meta.getKeyStream()[i] = valueMeta.getName();
}
// All other attribute columns go in the fields tab
//
List<LogicalColumn> attributes = new ArrayList<LogicalColumn>();
for (LogicalColumn logicalColumn : logicalTable.getLogicalColumns()) {
AttributeType attributeType = ConceptUtil.getAttributeType(logicalColumn);
if (attributeType.isAttribute()) {
attributes.add(logicalColumn);
}
}
meta.setFieldLookup(new String[attributes.size()]);
meta.setFieldStream(new String[attributes.size()]);
meta.setFieldUpdate(new int[attributes.size()]);
for (int i = 0; i < attributes.size(); i++) {
LogicalColumn logicalColumn = attributes.get(i);
AttributeType attributeType = ConceptUtil.getAttributeType(logicalColumn);
ValueMetaInterface valueMeta = getValueForLogicalColumn(databaseMeta, logicalColumn);
meta.getFieldLookup()[i] = valueMeta.getName();
meta.getFieldStream()[i] = valueMeta.getName();
if (attributeType == AttributeType.ATTRIBUTE_OVERWRITE) {
meta.getFieldUpdate()[i] = DimensionLookupMeta.TYPE_UPDATE_DIM_PUNCHTHROUGH;
} else {
// Historical or default: keep versions of the dimension records...
//
meta.getFieldUpdate()[i] = DimensionLookupMeta.TYPE_UPDATE_DIM_INSERT;
}
}
// The version field...
//
LogicalColumn versionColumn = ConceptUtil.findLogicalColumn(logicalTable, AttributeType.VERSION_FIELD);
if (versionColumn != null) {
String phName = ConceptUtil.getString(versionColumn, DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME);
meta.setVersionField(phName);
}
// Start of the date range
//
LogicalColumn startRangeColumn = ConceptUtil.findLogicalColumn(logicalTable, AttributeType.DATE_START);
if (startRangeColumn != null) {
String phName = ConceptUtil.getString(startRangeColumn, DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME);
meta.setDateFrom(phName);
}
// End of the date range
//
LogicalColumn endRangeColumn = ConceptUtil.findLogicalColumn(logicalTable, AttributeType.DATE_END);
if (endRangeColumn != null) {
String phName = ConceptUtil.getString(endRangeColumn, DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME);
meta.setDateTo(phName);
}
StepMeta stepMeta = new StepMeta(name, meta);
stepMeta.drawStep();
stepMeta.setDescription(description);
return stepMeta;
}
use of org.pentaho.metadata.model.LogicalColumn in project pentaho-kettle by pentaho.
the class JobGenerator method generateCombinationLookupStepFromLogicalTable.
protected StepMeta generateCombinationLookupStepFromLogicalTable(DatabaseMeta databaseMeta, LogicalTable logicalTable) {
String name = ConceptUtil.getName(logicalTable, locale);
String description = ConceptUtil.getDescription(logicalTable, locale);
String phTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
String schemaTable = databaseMeta.getQuotedSchemaTableCombination(null, Const.NVL(phTable, name));
CombinationLookupMeta meta = new CombinationLookupMeta();
meta.setDatabaseMeta(databaseMeta);
// TODO
meta.setSchemaName(null);
meta.setTablename(schemaTable);
meta.setUseAutoinc(databaseMeta.supportsAutoinc());
meta.setCacheSize(5000);
meta.setCommitSize(500);
// replace attribute fields with a TK
meta.setReplaceFields(true);
// Find the technical key (if any defined)
//
LogicalColumn keyColumn = ConceptUtil.findLogicalColumn(logicalTable, AttributeType.TECHNICAL_KEY);
if (keyColumn != null) {
ValueMetaInterface keyValue = getValueForLogicalColumn(databaseMeta, keyColumn);
meta.setTechnicalKeyField(keyValue.getName());
}
// Simply add all the attributes as key columns...
//
List<LogicalColumn> attributes = ConceptUtil.findLogicalColumns(logicalTable, AttributeType.ATTRIBUTE);
meta.setKeyLookup(new String[attributes.size()]);
meta.setKeyField(new String[attributes.size()]);
for (int i = 0; i < attributes.size(); i++) {
LogicalColumn logicalColumn = attributes.get(i);
ValueMetaInterface valueMeta = getValueForLogicalColumn(databaseMeta, logicalColumn);
meta.getKeyLookup()[i] = valueMeta.getName();
meta.getKeyField()[i] = valueMeta.getName();
}
StepMeta stepMeta = new StepMeta(name, meta);
stepMeta.drawStep();
stepMeta.setDescription(description);
return stepMeta;
}
use of org.pentaho.metadata.model.LogicalColumn in project pentaho-kettle by pentaho.
the class JobGenerator method getRowForLogicalTable.
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;
}
Aggregations