use of org.pentaho.di.core.exception.KettleDatabaseException in project pentaho-kettle by pentaho.
the class MondrianHelper method createFlattenedOutput.
/**
* Retrieve the rows from the opened query. Also create a description of the flattened output of the query. This call
* populated rowMetaInterface and rows The query needs to be opened beforehand.
*
* @throws KettleDatabaseException
* in case something goes wrong
*
* TODO: this is not quite working for our purposes.
*/
public void createFlattenedOutput() throws KettleDatabaseException {
final Axis[] axes = result.getAxes();
rows = new ArrayList<>();
headings = new ArrayList<>();
//
for (Axis axis : axes) {
final List<Position> positions = axis.getPositions();
if (positions.isEmpty()) {
// even deduce column headings.
return;
}
for (Member member : positions.get(0)) {
Hierarchy hierarchy = member.getHierarchy();
headings.add(hierarchy.getUniqueName());
}
}
int[] coords = new int[axes.length];
outputFlattenedRecurse(result, rows, new ArrayList<>(), coords, 0);
outputRowMeta = new RowMeta();
//
for (int i = 0; i < rows.size() && i < 1; i++) {
List<Object> rowValues = rows.get(i);
for (int c = 0; c < rowValues.size(); c++) {
Object valueData = rowValues.get(c);
int valueType;
if (valueData instanceof String) {
valueType = ValueMetaInterface.TYPE_STRING;
} else if (valueData instanceof Date) {
valueType = ValueMetaInterface.TYPE_DATE;
} else if (valueData instanceof Boolean) {
valueType = ValueMetaInterface.TYPE_BOOLEAN;
} else if (valueData instanceof Integer) {
valueType = ValueMetaInterface.TYPE_INTEGER;
valueData = Long.valueOf(((Integer) valueData).longValue());
} else if (valueData instanceof Short) {
valueType = ValueMetaInterface.TYPE_INTEGER;
valueData = Long.valueOf(((Short) valueData).longValue());
} else if (valueData instanceof Byte) {
valueType = ValueMetaInterface.TYPE_INTEGER;
valueData = Long.valueOf(((Byte) valueData).longValue());
} else if (valueData instanceof Long) {
valueType = ValueMetaInterface.TYPE_INTEGER;
} else if (valueData instanceof Double) {
valueType = ValueMetaInterface.TYPE_NUMBER;
} else if (valueData instanceof Float) {
valueType = ValueMetaInterface.TYPE_NUMBER;
valueData = Double.valueOf(((Float) valueData).doubleValue());
} else if (valueData instanceof BigDecimal) {
valueType = ValueMetaInterface.TYPE_BIGNUMBER;
} else {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "MondrianInputErrorUnhandledType", valueData.getClass().toString()));
}
try {
ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta(headings.get(c), valueType);
outputRowMeta.addValueMeta(valueMeta);
rowValues.set(i, valueData);
} catch (Exception e) {
throw new KettleDatabaseException(e);
}
}
}
// Now that we painstakingly found the metadata that comes out of the Mondrian database, cache it please...
//
DBCacheEntry cacheEntry = new DBCacheEntry(databaseMeta.getName(), queryString);
DBCache.getInstance().put(cacheEntry, outputRowMeta);
}
use of org.pentaho.di.core.exception.KettleDatabaseException in project pentaho-kettle by pentaho.
the class MondrianHelper method createRectangularOutput.
/**
* Outputs one row per tuple on the rows axis.
*
* @throws KettleDatabaseException
* in case some or other error occurs
*/
public void createRectangularOutput() throws KettleDatabaseException {
final Axis[] axes = result.getAxes();
if (axes.length != 2) {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "MondrianInputErrorOnlyTabular"));
}
headings = new ArrayList<>();
rows = new ArrayList<>();
final Axis rowsAxis = axes[1];
final Axis columnsAxis = axes[0];
int rowOrdinal = -1;
int[] coords = { 0, 0 };
for (Position rowPos : rowsAxis.getPositions()) {
++rowOrdinal;
coords[1] = rowOrdinal;
if (rowOrdinal == 0) {
// First headings are for the members on the rows axis.
for (Member rowMember : rowPos) {
headings.add(rowMember.getHierarchy().getUniqueName());
}
// concatenate the unique names.
for (Position columnPos : columnsAxis.getPositions()) {
String heading = "";
for (Member columnMember : columnPos) {
if (!heading.equals("")) {
heading += ", ";
}
heading += columnMember.getUniqueName();
}
headings.add(heading);
}
}
List<Object> rowValues = new ArrayList<>();
// The first row values describe the members on the rows axis.
for (Member rowMember : rowPos) {
rowValues.add(rowMember.getUniqueName());
}
// NOTE: Could also output all properties of each cell.
for (int columnOrdinal = 0; columnOrdinal < columnsAxis.getPositions().size(); ++columnOrdinal) {
coords[0] = columnOrdinal;
final Cell cell = result.getCell(coords);
rowValues.add(cell.getValue());
}
rows.add(rowValues);
}
outputRowMeta = new RowMeta();
// column, keep scanning until we find one line that has an actual value
if (rows.size() > 0) {
int columnCount = rows.get(0).size();
HashMap<Integer, ValueMetaInterface> valueMetaHash = new HashMap<>();
for (int i = 0; i < rows.size(); i++) {
List<Object> rowValues = rows.get(i);
for (int c = 0; c < rowValues.size(); c++) {
if (valueMetaHash.containsKey(new Integer(c))) {
// we have this value already
continue;
}
Object valueData = rowValues.get(c);
if (valueData == null) {
// skip this row and look for the metadata in a new one
continue;
}
String valueName = headings.get(c);
ValueMetaInterface valueMeta;
if (valueData instanceof String) {
valueMeta = new ValueMetaString(valueName);
} else if (valueData instanceof Date) {
valueMeta = new ValueMetaDate(valueName);
} else if (valueData instanceof Boolean) {
valueMeta = new ValueMetaBoolean(valueName);
} else if (valueData instanceof Integer) {
valueMeta = new ValueMetaInteger(valueName);
valueData = Long.valueOf(((Integer) valueData).longValue());
} else if (valueData instanceof Short) {
valueMeta = new ValueMetaInteger(valueName);
valueData = Long.valueOf(((Short) valueData).longValue());
} else if (valueData instanceof Byte) {
valueMeta = new ValueMetaInteger(valueName);
valueData = Long.valueOf(((Byte) valueData).longValue());
} else if (valueData instanceof Long) {
valueMeta = new ValueMetaInteger(valueName);
} else if (valueData instanceof Double) {
valueMeta = new ValueMetaNumber(valueName);
} else if (valueData instanceof Float) {
valueMeta = new ValueMetaNumber(valueName);
valueData = Double.valueOf(((Float) valueData).doubleValue());
} else if (valueData instanceof BigDecimal) {
valueMeta = new ValueMetaBigNumber(valueName);
} else {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "MondrianInputErrorUnhandledType", valueData.getClass().toString()));
}
valueMetaHash.put(c, valueMeta);
}
if (valueMetaHash.size() == columnCount) {
// we're done
break;
}
}
// Build the list of valueMetas
List<ValueMetaInterface> valueMetaList = new ArrayList<>();
for (int c = 0; c < columnCount; c++) {
if (valueMetaHash.containsKey(new Integer(c))) {
valueMetaList.add(valueMetaHash.get(new Integer(c)));
} else {
// If the entire column is null, assume the missing data as String.
// Irrelevant, anyway
ValueMetaInterface valueMeta = new ValueMetaString(headings.get(c));
valueMetaList.add(valueMeta);
}
}
outputRowMeta.setValueMetaList(valueMetaList);
}
// Now that we painstakingly found the meta data that comes out of the
// Mondrian database, cache it please...
//
DBCacheEntry cacheEntry = new DBCacheEntry(databaseMeta.getName(), queryString);
DBCache.getInstance().put(cacheEntry, outputRowMeta);
}
use of org.pentaho.di.core.exception.KettleDatabaseException in project pentaho-kettle by pentaho.
the class MondrianInputMeta method getFields.
public void getFields(RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
if (databaseMeta == null) {
// TODO: throw an exception here
return;
}
RowMetaInterface add = null;
try {
String mdx = getSQL();
if (isVariableReplacementActive()) {
mdx = space.environmentSubstitute(mdx);
}
MondrianHelper helper = new MondrianHelper(databaseMeta, catalog, mdx, space);
add = helper.getCachedRowMeta();
if (add == null) {
helper.openQuery();
helper.createRectangularOutput();
add = helper.getOutputRowMeta();
}
} catch (KettleDatabaseException dbe) {
throw new KettleStepException("Unable to get query result for MDX query: " + Const.CR + sql, dbe);
}
//
for (int i = 0; i < add.size(); i++) {
ValueMetaInterface v = add.getValueMeta(i);
v.setOrigin(origin);
}
row.addRowMeta(add);
}
use of org.pentaho.di.core.exception.KettleDatabaseException in project pentaho-kettle by pentaho.
the class MailMeta method readRep.
@Override
public void readRep(Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases) throws KettleException {
try {
// First load the common parts like name & description, then the attributes...
//
this.server = rep.getStepAttributeString(id_step, "server");
this.port = rep.getStepAttributeString(id_step, "port");
this.destination = rep.getStepAttributeString(id_step, "destination");
this.destinationCc = rep.getStepAttributeString(id_step, "destinationCc");
this.destinationBCc = rep.getStepAttributeString(id_step, "destinationBCc");
this.replyToAddresses = rep.getStepAttributeString(id_step, "replyToAddresses");
this.replyAddress = rep.getStepAttributeString(id_step, "replyto");
this.replyName = rep.getStepAttributeString(id_step, "replytoname");
this.subject = rep.getStepAttributeString(id_step, "subject");
this.includeDate = rep.getStepAttributeBoolean(id_step, "include_date");
this.includeSubFolders = rep.getStepAttributeBoolean(id_step, "include_subfolders");
this.zipFilenameDynamic = rep.getStepAttributeBoolean(id_step, "zipFilenameDynamic");
this.attachContentFromField = rep.getStepAttributeBoolean(id_step, "attachContentFromField");
this.attachContentField = rep.getStepAttributeString(id_step, "attachContentField");
this.attachContentFileNameField = rep.getStepAttributeString(id_step, "attachContentFileNameField");
this.isFilenameDynamic = rep.getStepAttributeBoolean(id_step, "isFilenameDynamic");
this.dynamicFieldname = rep.getStepAttributeString(id_step, "dynamicFieldname");
this.dynamicWildcard = rep.getStepAttributeString(id_step, "dynamicWildcard");
this.dynamicZipFilename = rep.getStepAttributeString(id_step, "dynamicZipFilename");
this.sourcefilefoldername = rep.getStepAttributeString(id_step, "sourcefilefoldername");
this.sourcewildcard = rep.getStepAttributeString(id_step, "sourcewildcard");
this.contactPerson = rep.getStepAttributeString(id_step, "contact_person");
this.contactPhone = rep.getStepAttributeString(id_step, "contact_phone");
this.comment = rep.getStepAttributeString(id_step, "comment");
this.encoding = rep.getStepAttributeString(id_step, "encoding");
this.priority = rep.getStepAttributeString(id_step, "priority");
this.importance = rep.getStepAttributeString(id_step, "importance");
this.sensitivity = rep.getStepAttributeString(id_step, "sensitivity");
this.includingFiles = rep.getStepAttributeBoolean(id_step, "include_files");
this.usingAuthentication = rep.getStepAttributeBoolean(id_step, "use_auth");
this.usingSecureAuthentication = rep.getStepAttributeBoolean(id_step, "use_secure_auth");
this.authenticationUser = rep.getStepAttributeString(id_step, "auth_user");
this.authenticationPassword = Encr.decryptPasswordOptionallyEncrypted(rep.getStepAttributeString(id_step, "auth_password"));
this.onlySendComment = rep.getStepAttributeBoolean(id_step, "only_comment");
this.useHTML = rep.getStepAttributeBoolean(id_step, "use_HTML");
this.usePriority = rep.getStepAttributeBoolean(id_step, "use_Priority");
this.secureconnectiontype = rep.getStepAttributeString(id_step, "secureconnectiontype");
this.zipFiles = rep.getStepAttributeBoolean(id_step, "zip_files");
this.zipFilename = rep.getStepAttributeString(id_step, "zip_name");
this.ziplimitsize = rep.getStepAttributeString(id_step, "zip_limit_size");
// How many arguments?
int imagesnr = rep.countNrStepAttributes(id_step, "embeddedimage");
allocate(imagesnr);
// Read them all...
for (int a = 0; a < imagesnr; a++) {
embeddedimages[a] = rep.getStepAttributeString(id_step, a, "embeddedimage");
contentids[a] = rep.getStepAttributeString(id_step, a, "contentid");
}
} catch (KettleDatabaseException dbe) {
throw new KettleException("Unable to load step type 'mail' from the repository with id_step=" + id_step, dbe);
}
}
use of org.pentaho.di.core.exception.KettleDatabaseException in project pentaho-kettle by pentaho.
the class MailInputMeta method saveRep.
@Override
public void saveRep(Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step) throws KettleException {
try {
rep.saveStepAttribute(id_transformation, id_step, "servername", servername);
rep.saveStepAttribute(id_transformation, id_step, "username", username);
rep.saveStepAttribute(id_transformation, id_step, "password", Encr.encryptPasswordIfNotUsingVariables(password));
rep.saveStepAttribute(id_transformation, id_step, "usessl", usessl);
rep.saveStepAttribute(id_transformation, id_step, "sslport", sslport);
rep.saveStepAttribute(id_transformation, id_step, "retrievemails", retrievemails);
rep.saveStepAttribute(id_transformation, id_step, "firstmails", firstmails);
rep.saveStepAttribute(id_transformation, id_step, "delete", delete);
rep.saveStepAttribute(id_transformation, id_step, "protocol", protocol);
rep.saveStepAttribute(id_transformation, id_step, "valueimaplist", MailConnectionMeta.getValueImapListCode(valueimaplist));
rep.saveStepAttribute(id_transformation, id_step, "imapfirstmails", imapfirstmails);
rep.saveStepAttribute(id_transformation, id_step, "imapfolder", imapfolder);
// search term
rep.saveStepAttribute(id_transformation, id_step, "sendersearch", senderSearch);
rep.saveStepAttribute(id_transformation, id_step, "nottermsendersearch", notTermSenderSearch);
rep.saveStepAttribute(id_transformation, id_step, "recipientsearch", recipientSearch);
rep.saveStepAttribute(id_transformation, id_step, "notTermRecipientSearch", notTermRecipientSearch);
rep.saveStepAttribute(id_transformation, id_step, "subjectsearch", subjectSearch);
rep.saveStepAttribute(id_transformation, id_step, "nottermsubjectsearch", notTermSubjectSearch);
rep.saveStepAttribute(id_transformation, id_step, "conditionreceiveddate", MailConnectionMeta.getConditionDateCode(conditionReceivedDate));
rep.saveStepAttribute(id_transformation, id_step, "nottermreceiveddatesearch", notTermReceivedDateSearch);
rep.saveStepAttribute(id_transformation, id_step, "receiveddate1", receivedDate1);
rep.saveStepAttribute(id_transformation, id_step, "receiveddate2", receivedDate2);
rep.saveStepAttribute(id_transformation, id_step, "includesubfolders", includesubfolders);
rep.saveStepAttribute(id_transformation, id_step, "useproxy", useproxy);
rep.saveStepAttribute(id_transformation, id_step, "proxyusername", proxyusername);
rep.saveStepAttribute(id_transformation, id_step, "usedynamicfolder", usedynamicfolder);
rep.saveStepAttribute(id_transformation, id_step, "folderfield", folderfield);
rep.saveStepAttribute(id_transformation, id_step, "rowlimit", rowlimit);
rep.saveStepAttribute(id_transformation, id_step, Tags.USE_BATCH, useBatch);
rep.saveStepAttribute(id_transformation, id_step, Tags.BATCH_SIZE, batchSize);
rep.saveStepAttribute(id_transformation, id_step, Tags.START_MSG, start);
rep.saveStepAttribute(id_transformation, id_step, Tags.END_MSG, end);
rep.saveStepAttribute(id_transformation, id_step, Tags.STOP_ON_ERROR, stopOnError);
for (int i = 0; i < inputFields.length; i++) {
MailInputField field = inputFields[i];
rep.saveStepAttribute(id_transformation, id_step, i, "field_name", field.getName());
rep.saveStepAttribute(id_transformation, id_step, i, "field_column", field.getColumnCode());
}
} catch (KettleDatabaseException dbe) {
throw new KettleException("Unable to save step of type 'get pop' to the repository for id_step=" + id_step, dbe);
}
}
Aggregations