Search in sources :

Example 91 with ValueMetaInterface

use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.

the class ValueMetaFactoryTest method testGetValueMetaPluginClasses.

@Test
public void testGetValueMetaPluginClasses() throws KettlePluginException {
    List<ValueMetaInterface> dataTypes = ValueMetaFactory.getValueMetaPluginClasses();
    boolean numberExists = false;
    boolean stringExists = false;
    boolean dateExists = false;
    boolean booleanExists = false;
    boolean integerExists = false;
    boolean bignumberExists = false;
    boolean serializableExists = false;
    boolean binaryExists = false;
    boolean timestampExists = false;
    boolean inetExists = false;
    for (ValueMetaInterface obj : dataTypes) {
        if (obj instanceof ValueMetaNumber) {
            numberExists = true;
        }
        if (obj.getClass().equals(ValueMetaString.class)) {
            stringExists = true;
        }
        if (obj.getClass().equals(ValueMetaDate.class)) {
            dateExists = true;
        }
        if (obj.getClass().equals(ValueMetaBoolean.class)) {
            booleanExists = true;
        }
        if (obj.getClass().equals(ValueMetaInteger.class)) {
            integerExists = true;
        }
        if (obj.getClass().equals(ValueMetaBigNumber.class)) {
            bignumberExists = true;
        }
        if (obj.getClass().equals(ValueMetaSerializable.class)) {
            serializableExists = true;
        }
        if (obj.getClass().equals(ValueMetaBinary.class)) {
            binaryExists = true;
        }
        if (obj.getClass().equals(ValueMetaTimestamp.class)) {
            timestampExists = true;
        }
        if (obj.getClass().equals(ValueMetaInternetAddress.class)) {
            inetExists = true;
        }
    }
    assertTrue(numberExists);
    assertTrue(stringExists);
    assertTrue(dateExists);
    assertTrue(booleanExists);
    assertTrue(integerExists);
    assertTrue(bignumberExists);
    assertTrue(serializableExists);
    assertTrue(binaryExists);
    assertTrue(timestampExists);
    assertTrue(inetExists);
}
Also used : ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 92 with ValueMetaInterface

use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.

the class ValueMetaFactoryTest method testClone.

@Test
public void testClone() throws KettleException {
    ValueMetaInterface original = new ValueMetaString();
    original.setCollatorLocale(Locale.CANADA);
    original.setCollatorStrength(3);
    ValueMetaInterface cloned = ValueMetaFactory.cloneValueMeta(original);
    assertNotNull(cloned);
    assertNotSame(original, cloned);
    valueMetaDeepEquals(original, cloned);
}
Also used : ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 93 with ValueMetaInterface

use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.

the class ValueMetaFactoryTest method testGetNativeDataTypeClass.

@Test
public void testGetNativeDataTypeClass() throws KettlePluginException {
    for (String valueMetaName : ValueMetaFactory.getValueMetaNames()) {
        int valueMetaID = ValueMetaFactory.getIdForValueMeta(valueMetaName);
        ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta(valueMetaID);
        try {
            Class<?> clazz = valueMeta.getNativeDataTypeClass();
            assertNotNull(clazz);
        } catch (KettleValueException kve) {
            fail(valueMetaName + " should implement getNativeDataTypeClass()");
        }
    }
}
Also used : KettleValueException(org.pentaho.di.core.exception.KettleValueException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 94 with ValueMetaInterface

use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.

the class TransMeta method isSomethingDifferentInRow.

private boolean isSomethingDifferentInRow(RowMetaInterface before, RowMetaInterface after) {
    if (before.size() != after.size()) {
        return true;
    }
    for (int i = 0; i < before.size(); i++) {
        ValueMetaInterface beforeValueMeta = before.getValueMeta(i);
        ValueMetaInterface afterValueMeta = after.getValueMeta(i);
        if (stringsDifferent(beforeValueMeta.getName(), afterValueMeta.getName())) {
            return true;
        }
        if (beforeValueMeta.getType() != afterValueMeta.getType()) {
            return true;
        }
        if (beforeValueMeta.getLength() != afterValueMeta.getLength()) {
            return true;
        }
        if (beforeValueMeta.getPrecision() != afterValueMeta.getPrecision()) {
            return true;
        }
        if (stringsDifferent(beforeValueMeta.getOrigin(), afterValueMeta.getOrigin())) {
            return true;
        }
        if (stringsDifferent(beforeValueMeta.getComments(), afterValueMeta.getComments())) {
            return true;
        }
        if (stringsDifferent(beforeValueMeta.getConversionMask(), afterValueMeta.getConversionMask())) {
            return true;
        }
        if (stringsDifferent(beforeValueMeta.getStringEncoding(), afterValueMeta.getStringEncoding())) {
            return true;
        }
        if (stringsDifferent(beforeValueMeta.getDecimalSymbol(), afterValueMeta.getDecimalSymbol())) {
            return true;
        }
        if (stringsDifferent(beforeValueMeta.getGroupingSymbol(), afterValueMeta.getGroupingSymbol())) {
            return true;
        }
    }
    return false;
}
Also used : Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 95 with ValueMetaInterface

use of org.pentaho.di.core.row.ValueMetaInterface 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.getSchemaName(), 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 (Map.Entry<ValueMetaInterface, String> entry : values.entrySet()) {
                String message = entry.getValue();
                ValueMetaInterface v = entry.getKey();
                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);
    }
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) Hashtable(java.util.Hashtable) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleRowException(org.pentaho.di.core.exception.KettleRowException) FileSystemException(org.apache.commons.vfs2.FileSystemException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) IOException(java.io.IOException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) CheckResult(org.pentaho.di.core.CheckResult) KettleRowException(org.pentaho.di.core.exception.KettleRowException) Database(org.pentaho.di.core.database.Database) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)908 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)345 KettleException (org.pentaho.di.core.exception.KettleException)269 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)243 RowMeta (org.pentaho.di.core.row.RowMeta)232 Test (org.junit.Test)212 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)146 KettleStepException (org.pentaho.di.core.exception.KettleStepException)120 ArrayList (java.util.ArrayList)111 TableItem (org.eclipse.swt.widgets.TableItem)78 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)76 KettleValueException (org.pentaho.di.core.exception.KettleValueException)58 FileObject (org.apache.commons.vfs2.FileObject)55 Date (java.util.Date)49 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)48 StepMeta (org.pentaho.di.trans.step.StepMeta)47 Database (org.pentaho.di.core.database.Database)46 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)46 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)44 TableItemInsertListener (org.pentaho.di.ui.trans.step.TableItemInsertListener)43