use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class TransMeta method checkRowMixingStatically.
/**
* Check a step to see if there are no multiple steps to read from. If so, check to see if the receiving rows are all
* the same in layout. We only want to ONLY use the DBCache for this to prevent GUI stalls.
*
* @param stepMeta
* the step to check
* @param monitor
* the monitor
* @throws KettleRowException
* in case we detect a row mixing violation
*/
public void checkRowMixingStatically(StepMeta stepMeta, ProgressMonitorListener monitor) throws KettleRowException {
List<StepMeta> prevSteps = findPreviousSteps(stepMeta);
int nrPrevious = prevSteps.size();
if (nrPrevious > 1) {
RowMetaInterface referenceRow = null;
// See if all previous steps send out the same rows...
for (int i = 0; i < nrPrevious; i++) {
StepMeta previousStep = prevSteps.get(i);
try {
// Throws KettleStepException
RowMetaInterface row = getStepFields(previousStep, monitor);
if (referenceRow == null) {
referenceRow = row;
} else if (!stepMeta.getStepMetaInterface().excludeFromRowLayoutVerification()) {
BaseStep.safeModeChecking(referenceRow, row);
}
} catch (KettleStepException e) {
// We ignore this one because we are in the process of designing the transformation, anything intermediate can
// go wrong.
}
}
}
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class TransMeta method checkSteps.
/**
* Checks all the steps and fills a List of (CheckResult) remarks.
*
* @param remarks
* The remarks list to add to.
* @param only_selected
* true to check only the selected steps, false for all steps
* @param monitor
* a progress monitor listener to be updated as the SQL statements are generated
*/
public void checkSteps(List<CheckResultInterface> remarks, boolean only_selected, ProgressMonitorListener monitor, VariableSpace space, Repository repository, IMetaStore metaStore) {
try {
// Start with a clean slate...
remarks.clear();
Map<ValueMetaInterface, String> values = new Hashtable<>();
String[] stepnames;
StepMeta[] steps;
List<StepMeta> selectedSteps = getSelectedSteps();
if (!only_selected || selectedSteps.isEmpty()) {
stepnames = getStepNames();
steps = getStepsArray();
} else {
stepnames = getSelectedStepNames();
steps = selectedSteps.toArray(new StepMeta[selectedSteps.size()]);
}
ExtensionPointHandler.callExtensionPoint(getLogChannel(), KettleExtensionPoint.BeforeCheckSteps.id, new CheckStepsExtension(remarks, space, this, steps, repository, metaStore));
boolean stop_checking = false;
if (monitor != null) {
monitor.beginTask(BaseMessages.getString(PKG, "TransMeta.Monitor.VerifyingThisTransformationTask.Title"), steps.length + 2);
}
for (int i = 0; i < steps.length && !stop_checking; i++) {
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.VerifyingStepTask.Title", stepnames[i]));
}
StepMeta stepMeta = steps[i];
int nrinfo = findNrInfoSteps(stepMeta);
StepMeta[] infostep = null;
if (nrinfo > 0) {
infostep = getInfoStep(stepMeta);
}
RowMetaInterface info = null;
if (infostep != null) {
try {
info = getStepFields(infostep);
} catch (KettleStepException kse) {
info = null;
CheckResult cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "TransMeta.CheckResult.TypeResultError.ErrorOccurredGettingStepInfoFields.Description", "" + stepMeta, Const.CR + kse.getMessage()), stepMeta);
remarks.add(cr);
}
}
// The previous fields from non-informative steps:
RowMetaInterface prev = null;
try {
prev = getPrevStepFields(stepMeta);
} catch (KettleStepException kse) {
CheckResult cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "TransMeta.CheckResult.TypeResultError.ErrorOccurredGettingInputFields.Description", "" + stepMeta, Const.CR + kse.getMessage()), stepMeta);
remarks.add(cr);
// This is a severe error: stop checking...
// Otherwise we wind up checking time & time again because nothing gets put in the database
// cache, the timeout of certain databases is very long... (Oracle)
stop_checking = true;
}
if (isStepUsedInTransHops(stepMeta) || getSteps().size() == 1) {
// Get the input & output steps!
// Copy to arrays:
String[] input = getPrevStepNames(stepMeta);
String[] output = getNextStepNames(stepMeta);
// Check step specific info...
ExtensionPointHandler.callExtensionPoint(getLogChannel(), KettleExtensionPoint.BeforeCheckStep.id, new CheckStepsExtension(remarks, space, this, new StepMeta[] { stepMeta }, repository, metaStore));
stepMeta.check(remarks, this, prev, input, output, info, space, repository, metaStore);
ExtensionPointHandler.callExtensionPoint(getLogChannel(), KettleExtensionPoint.AfterCheckStep.id, new CheckStepsExtension(remarks, space, this, new StepMeta[] { stepMeta }, repository, metaStore));
// See if illegal characters etc. were used in field-names...
if (prev != null) {
for (int x = 0; x < prev.size(); x++) {
ValueMetaInterface v = prev.getValueMeta(x);
String name = v.getName();
if (name == null) {
values.put(v, BaseMessages.getString(PKG, "TransMeta.Value.CheckingFieldName.FieldNameIsEmpty.Description"));
} else if (name.indexOf(' ') >= 0) {
values.put(v, BaseMessages.getString(PKG, "TransMeta.Value.CheckingFieldName.FieldNameContainsSpaces.Description"));
} else {
char[] list = new char[] { '.', ',', '-', '/', '+', '*', '\'', '\t', '"', '|', '@', '(', ')', '{', '}', '!', '^' };
for (int c = 0; c < list.length; c++) {
if (name.indexOf(list[c]) >= 0) {
values.put(v, BaseMessages.getString(PKG, "TransMeta.Value.CheckingFieldName.FieldNameContainsUnfriendlyCodes.Description", String.valueOf(list[c])));
}
}
}
}
// Check if 2 steps with the same name are entering the step...
if (prev.size() > 1) {
String[] fieldNames = prev.getFieldNames();
String[] sortedNames = Const.sortStrings(fieldNames);
String prevName = sortedNames[0];
for (int x = 1; x < sortedNames.length; x++) {
// Checking for doubles
if (prevName.equalsIgnoreCase(sortedNames[x])) {
// Give a warning!!
CheckResult cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "TransMeta.CheckResult.TypeResultWarning.HaveTheSameNameField.Description", prevName), stepMeta);
remarks.add(cr);
} else {
prevName = sortedNames[x];
}
}
}
} else {
CheckResult cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "TransMeta.CheckResult.TypeResultError.CannotFindPreviousFields.Description") + stepMeta.getName(), stepMeta);
remarks.add(cr);
}
} else {
CheckResult cr = new CheckResult(CheckResultInterface.TYPE_RESULT_WARNING, BaseMessages.getString(PKG, "TransMeta.CheckResult.TypeResultWarning.StepIsNotUsed.Description"), stepMeta);
remarks.add(cr);
}
// Also check for mixing rows...
try {
checkRowMixingStatically(stepMeta, null);
} catch (KettleRowException e) {
CheckResult cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, e.getMessage(), stepMeta);
remarks.add(cr);
}
if (monitor != null) {
// progress bar...
monitor.worked(1);
if (monitor.isCanceled()) {
stop_checking = true;
}
}
}
// Also, check the logging table of the transformation...
if (monitor == null || !monitor.isCanceled()) {
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.CheckingTheLoggingTableTask.Title"));
}
if (transLogTable.getDatabaseMeta() != null) {
Database logdb = new Database(this, transLogTable.getDatabaseMeta());
logdb.shareVariablesWith(this);
try {
logdb.connect();
CheckResult cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "TransMeta.CheckResult.TypeResultOK.ConnectingWorks.Description"), null);
remarks.add(cr);
if (transLogTable.getTableName() != null) {
if (logdb.checkTableExists(transLogTable.getTableName())) {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "TransMeta.CheckResult.TypeResultOK.LoggingTableExists.Description", transLogTable.getTableName()), null);
remarks.add(cr);
RowMetaInterface fields = transLogTable.getLogRecord(LogStatus.START, null, null).getRowMeta();
String sql = logdb.getDDL(transLogTable.getTableName(), fields);
if (sql == null || sql.length() == 0) {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "TransMeta.CheckResult.TypeResultOK.CorrectLayout.Description"), null);
remarks.add(cr);
} else {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "TransMeta.CheckResult.TypeResultError.LoggingTableNeedsAdjustments.Description") + Const.CR + sql, null);
remarks.add(cr);
}
} else {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "TransMeta.CheckResult.TypeResultError.LoggingTableDoesNotExist.Description"), null);
remarks.add(cr);
}
} else {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "TransMeta.CheckResult.TypeResultError.LogTableNotSpecified.Description"), null);
remarks.add(cr);
}
} catch (KettleDatabaseException dbe) {
// Ignore errors
} finally {
logdb.disconnect();
}
}
if (monitor != null) {
monitor.worked(1);
}
}
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.CheckingForDatabaseUnfriendlyCharactersInFieldNamesTask.Title"));
}
if (values.size() > 0) {
for (ValueMetaInterface v : values.keySet()) {
String message = values.get(v);
CheckResult cr = new CheckResult(CheckResultInterface.TYPE_RESULT_WARNING, BaseMessages.getString(PKG, "TransMeta.CheckResult.TypeResultWarning.Description", v.getName(), message, v.getOrigin()), findStep(v.getOrigin()));
remarks.add(cr);
}
} else {
CheckResult cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "TransMeta.CheckResult.TypeResultOK.Description"), null);
remarks.add(cr);
}
if (monitor != null) {
monitor.worked(1);
}
ExtensionPointHandler.callExtensionPoint(getLogChannel(), KettleExtensionPoint.AfterCheckSteps.id, new CheckStepsExtension(remarks, space, this, steps, repository, metaStore));
} catch (Exception e) {
log.logError(Const.getStackTracker(e));
throw new RuntimeException(e);
}
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class TransMeta method getSQLStatements.
/**
* Builds a list of all the SQL statements that this transformation needs in order to work properly.
*
* @param monitor
* a progress monitor listener to be updated as the SQL statements are generated
* @return An ArrayList of SQLStatement objects.
* @throws KettleStepException
* if any errors occur during SQL statement generation
*/
public List<SQLStatement> getSQLStatements(ProgressMonitorListener monitor) throws KettleStepException {
if (monitor != null) {
monitor.beginTask(BaseMessages.getString(PKG, "TransMeta.Monitor.GettingTheSQLForTransformationTask.Title"), nrSteps() + 1);
}
List<SQLStatement> stats = new ArrayList<>();
for (int i = 0; i < nrSteps(); i++) {
StepMeta stepMeta = getStep(i);
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.GettingTheSQLForStepTask.Title", "" + stepMeta));
}
RowMetaInterface prev = getPrevStepFields(stepMeta);
SQLStatement sqlCompat = compatibleStepMetaGetSQLStatements(stepMeta.getStepMetaInterface(), stepMeta, prev);
if (sqlCompat.getSQL() != null || sqlCompat.hasError()) {
stats.add(sqlCompat);
}
SQLStatement sql = stepMeta.getStepMetaInterface().getSQLStatements(this, stepMeta, prev, repository, metaStore);
if (sql.getSQL() != null || sql.hasError()) {
stats.add(sql);
}
if (monitor != null) {
monitor.worked(1);
}
}
//
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.GettingTheSQLForTransformationTask.Title2"));
}
if (transLogTable.getDatabaseMeta() != null && (!Utils.isEmpty(transLogTable.getTableName()) || !Utils.isEmpty(performanceLogTable.getTableName()))) {
try {
for (LogTableInterface logTable : new LogTableInterface[] { transLogTable, performanceLogTable, channelLogTable, stepLogTable }) {
if (logTable.getDatabaseMeta() != null && !Utils.isEmpty(logTable.getTableName())) {
Database db = null;
try {
db = new Database(this, transLogTable.getDatabaseMeta());
db.shareVariablesWith(this);
db.connect();
RowMetaInterface fields = logTable.getLogRecord(LogStatus.START, null, null).getRowMeta();
String schemaTable = logTable.getDatabaseMeta().getQuotedSchemaTableCombination(logTable.getSchemaName(), logTable.getTableName());
String sql = db.getDDL(schemaTable, fields);
if (!Utils.isEmpty(sql)) {
SQLStatement stat = new SQLStatement("<this transformation>", transLogTable.getDatabaseMeta(), sql);
stats.add(stat);
}
} catch (Exception e) {
throw new KettleDatabaseException("Unable to connect to logging database [" + logTable.getDatabaseMeta() + "]", e);
} finally {
if (db != null) {
db.disconnect();
}
}
}
}
} catch (KettleDatabaseException dbe) {
SQLStatement stat = new SQLStatement("<this transformation>", transLogTable.getDatabaseMeta(), null);
stat.setError(BaseMessages.getString(PKG, "TransMeta.SQLStatement.ErrorDesc.ErrorObtainingTransformationLogTableInfo") + dbe.getMessage());
stats.add(stat);
}
}
if (monitor != null) {
monitor.worked(1);
}
if (monitor != null) {
monitor.done();
}
return stats;
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class TransDebugMeta method addRowListenersToTransformation.
public synchronized void addRowListenersToTransformation(final Trans trans) {
final TransDebugMeta self = this;
//
for (final StepMeta stepMeta : stepDebugMetaMap.keySet()) {
final StepDebugMeta stepDebugMeta = stepDebugMetaMap.get(stepMeta);
//
for (StepInterface baseStep : trans.findBaseSteps(stepMeta.getName())) {
baseStep.addRowListener(new RowAdapter() {
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
try {
// This block of code is called whenever there is a row written by the step
// So we want to execute the debugging actions that are specified by the step...
//
int rowCount = stepDebugMeta.getRowCount();
if (stepDebugMeta.isReadingFirstRows() && rowCount > 0) {
int bufferSize = stepDebugMeta.getRowBuffer().size();
if (bufferSize < rowCount) {
// This is the classic preview mode.
// We add simply add the row to the buffer.
//
stepDebugMeta.setRowBufferMeta(rowMeta);
stepDebugMeta.getRowBuffer().add(rowMeta.cloneRow(row));
} else {
// pause the transformation...
//
trans.pauseRunning();
// Also call the pause / break-point listeners on the step debugger...
//
stepDebugMeta.fireBreakPointListeners(self);
}
} else if (stepDebugMeta.isPausingOnBreakPoint() && stepDebugMeta.getCondition() != null) {
//
if (rowCount > 0) {
// Keep a number of rows in memory
// Store them in a reverse order to keep it intuitive for the user.
//
stepDebugMeta.setRowBufferMeta(rowMeta);
stepDebugMeta.getRowBuffer().add(0, rowMeta.cloneRow(row));
// Only keep a number of rows in memory
// If we have too many, remove the last (oldest)
//
int bufferSize = stepDebugMeta.getRowBuffer().size();
if (bufferSize > rowCount) {
stepDebugMeta.getRowBuffer().remove(bufferSize - 1);
}
} else {
//
if (stepDebugMeta.getRowBuffer().isEmpty()) {
stepDebugMeta.getRowBuffer().add(rowMeta.cloneRow(row));
} else {
stepDebugMeta.getRowBuffer().set(0, rowMeta.cloneRow(row));
}
}
//
if (stepDebugMeta.getCondition().evaluate(rowMeta, row)) {
// We hit the break-point: pause the transformation
//
trans.pauseRunning();
// Also fire off the break point listeners...
//
stepDebugMeta.fireBreakPointListeners(self);
}
}
} catch (KettleException e) {
throw new KettleStepException(e);
}
}
});
}
}
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class BaseStep method putRow.
/**
* putRow is used to copy a row, to the alternate rowset(s) This should get priority over everything else!
* (synchronized) If distribute is true, a row is copied only once to the output rowsets, otherwise copies are sent to
* each rowset!
*
* @param row The row to put to the destination rowset(s).
* @throws KettleStepException
*/
@Override
public void putRow(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
if (rowMeta != null) {
String property = System.getProperties().getProperty(Const.ALLOW_EMPTY_FIELD_NAMES_AND_TYPES, "false");
boolean allowEmpty = Boolean.parseBoolean(property);
if (!allowEmpty) {
// check row meta for empty field name (BACKLOG-18004)
for (ValueMetaInterface vmi : rowMeta.getValueMetaList()) {
if (StringUtils.isBlank(vmi.getName())) {
throw new KettleStepException("Please set a field name for all field(s) that have 'null'.");
}
if (vmi.getType() <= 0) {
throw new KettleStepException("Please set a value for the missing field(s) type.");
}
}
}
}
getRowHandler().putRow(rowMeta, row);
}
Aggregations