Search in sources :

Example 11 with TableOutputMeta

use of org.pentaho.di.trans.steps.tableoutput.TableOutputMeta in project pentaho-kettle by pentaho.

the class TableAgileMart method dropTable.

@Override
public boolean dropTable() {
    TableOutputMeta meta = getMeta();
    TableOutputData data = getData();
    String schema = meta.getSchemaName();
    String table = meta.getTableName();
    if (schema != null && !schema.equals("")) {
        table = schema + "." + table;
    }
    String sql = "drop table " + table + ";";
    try {
        Result result = data.db.execStatement(sql);
        int status = result.getExitStatus();
        if (status == 0) {
            util.updateMetadata(meta, -1);
        }
        return status == 0;
    } catch (KettleDatabaseException e) {
        message = "Could not drop table: " + table;
        logError(message, e);
    }
    return false;
}
Also used : TableOutputData(org.pentaho.di.trans.steps.tableoutput.TableOutputData) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) Result(org.pentaho.di.core.Result)

Example 12 with TableOutputMeta

use of org.pentaho.di.trans.steps.tableoutput.TableOutputMeta in project pentaho-kettle by pentaho.

the class TableAgileMart method truncateTable.

@Override
public boolean truncateTable() {
    TableOutputMeta meta = getMeta();
    TableOutputData data = getData();
    try {
        data.db.truncateTable(environmentSubstitute(meta.getSchemaName()), environmentSubstitute(meta.getTableName()));
        util.updateMetadata(meta, -1);
        return true;
    } catch (KettleDatabaseException e) {
        message = "Could not truncate table: " + meta.getTableName();
        logError(message, e);
    }
    return false;
}
Also used : TableOutputData(org.pentaho.di.trans.steps.tableoutput.TableOutputData) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta)

Example 13 with TableOutputMeta

use of org.pentaho.di.trans.steps.tableoutput.TableOutputMeta in project pentaho-kettle by pentaho.

the class TableAgileMart method processRow.

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    if (rowLimit != -1 && rowsWritten >= rowLimit) {
        // we are done, ignore any new rows
        TableOutputMeta meta = (TableOutputMeta) smi;
        util.updateMetadata(meta, rowsWritten);
        throw new KettleException("Row limit exceeded");
    }
    boolean result = super.processRow(smi, sdi);
    if (result) {
        rowsWritten++;
    } else {
        TableOutputMeta meta = (TableOutputMeta) smi;
        util.updateMetadata(meta, rowsWritten);
    }
    return result;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta)

Example 14 with TableOutputMeta

use of org.pentaho.di.trans.steps.tableoutput.TableOutputMeta in project pentaho-kettle by pentaho.

the class TableOutputDialog method sql.

// Generate code for create table...
// Conversions done by Database
// 
private void sql() {
    try {
        TableOutputMeta info = new TableOutputMeta();
        getInfo(info);
        RowMetaInterface prev = transMeta.getPrevStepFields(stepname);
        if (info.isTableNameInField() && !info.isTableNameInTable() && info.getTableNameField().length() > 0) {
            int idx = prev.indexOfValue(info.getTableNameField());
            if (idx >= 0) {
                prev.removeValueMeta(idx);
            }
        }
        StepMeta stepMeta = transMeta.findStep(stepname);
        if (info.specifyFields()) {
            // Only use the fields that were specified.
            RowMetaInterface prevNew = new RowMeta();
            for (int i = 0; i < info.getFieldDatabase().length; i++) {
                ValueMetaInterface insValue = prev.searchValueMeta(info.getFieldStream()[i]);
                if (insValue != null) {
                    ValueMetaInterface insertValue = insValue.clone();
                    insertValue.setName(info.getFieldDatabase()[i]);
                    prevNew.addValueMeta(insertValue);
                } else {
                    throw new KettleStepException(BaseMessages.getString(PKG, "TableOutputDialog.FailedToFindField.Message", info.getFieldStream()[i]));
                }
            }
            prev = prevNew;
        }
        boolean autoInc = false;
        String pk = null;
        // 
        if (info.isReturningGeneratedKeys() && !Utils.isEmpty(info.getGeneratedKeyField())) {
            ValueMetaInterface valueMeta = new ValueMetaInteger(info.getGeneratedKeyField());
            valueMeta.setLength(15);
            prev.addValueMeta(0, valueMeta);
            autoInc = true;
            pk = info.getGeneratedKeyField();
        }
        if (isValidRowMeta(prev)) {
            SQLStatement sql = info.getSQLStatements(transMeta, stepMeta, prev, pk, autoInc, pk);
            if (!sql.hasError()) {
                if (sql.hasSQL()) {
                    SQLEditor sqledit = new SQLEditor(transMeta, shell, SWT.NONE, info.getDatabaseMeta(), transMeta.getDbCache(), sql.getSQL());
                    sqledit.open();
                } else {
                    String message = getBaseMessage("TableOutputDialog.NoSQL.DialogMessage");
                    String text = getBaseMessage("TableOutputDialog.NoSQL.DialogTitle");
                    showMessage(shell, SWT.OK | SWT.ICON_INFORMATION, message, text);
                }
            } else {
                String text = getBaseMessage("System.Dialog.Error.Title");
                showMessage(shell, SWT.OK | SWT.ICON_ERROR, sql.getError(), text);
            }
        } else {
            String message = getBaseMessage("TableOutputDialog.NoSQL.EmptyCSVFields");
            String text = getBaseMessage("TableOutputDialog.NoSQL.DialogTitle");
            showMessage(shell, SWT.OK | SWT.ICON_ERROR, message, text);
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "TableOutputDialog.BuildSQLError.DialogTitle"), BaseMessages.getString(PKG, "TableOutputDialog.BuildSQLError.DialogMessage"), ke);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) SQLEditor(org.pentaho.di.ui.core.database.dialog.SQLEditor) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) SQLStatement(org.pentaho.di.core.SQLStatement) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger)

Example 15 with TableOutputMeta

use of org.pentaho.di.trans.steps.tableoutput.TableOutputMeta in project pentaho-kettle by pentaho.

the class JobGenerator method generateDateTransformation.

private TransMeta generateDateTransformation(DatabaseMeta databaseMeta, LogicalTable logicalTable) throws KettleException {
    // We actually load the transformation from a template and then slightly modify it.
    // 
    String filename = "/org/pentaho/di/resources/Generate date dimension.ktr";
    InputStream inputStream = getClass().getResourceAsStream(filename);
    TransMeta transMeta = new TransMeta(inputStream, Spoon.getInstance().rep, true, new Variables(), null);
    // Find the table output step and inject the target table name and database...
    // 
    StepMeta stepMeta = transMeta.findStep("TARGET");
    if (stepMeta != null) {
        TableOutputMeta meta = (TableOutputMeta) stepMeta.getStepMetaInterface();
        meta.setDatabaseMeta(databaseMeta);
        String phTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
        meta.setTableName(phTable);
    }
    return transMeta;
}
Also used : Variables(org.pentaho.di.core.variables.Variables) InputStream(java.io.InputStream) TransMeta(org.pentaho.di.trans.TransMeta) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) StepMeta(org.pentaho.di.trans.step.StepMeta)

Aggregations

TableOutputMeta (org.pentaho.di.trans.steps.tableoutput.TableOutputMeta)18 StepMeta (org.pentaho.di.trans.step.StepMeta)9 KettleException (org.pentaho.di.core.exception.KettleException)6 TransMeta (org.pentaho.di.trans.TransMeta)6 Test (org.junit.Test)4 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)4 ArrayList (java.util.ArrayList)3 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)3 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)3 TableInputMeta (org.pentaho.di.trans.steps.tableinput.TableInputMeta)3 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)3 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 NotePadMeta (org.pentaho.di.core.NotePadMeta)2 SQLStatement (org.pentaho.di.core.SQLStatement)2 DatabaseInterface (org.pentaho.di.core.database.DatabaseInterface)2 KettleStepException (org.pentaho.di.core.exception.KettleStepException)2 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)2 Variables (org.pentaho.di.core.variables.Variables)2 TransHopMeta (org.pentaho.di.trans.TransHopMeta)2