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);
}
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);
}
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()");
}
}
}
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;
}
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);
}
}
Aggregations