Search in sources :

Example 11 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class MonetDBBulkLoaderMeta method injectStepMetadataEntries.

public void injectStepMetadataEntries(List<StepInjectionMetaEntry> metadata) {
    for (StepInjectionMetaEntry entry : metadata) {
        KettleAttributeInterface attr = findAttribute(entry.getKey());
        // 
        if (entry.getValueType() != ValueMetaInterface.TYPE_NONE) {
            if (entry.getKey().equals("SCHEMA")) {
                schemaName = (String) entry.getValue();
            } else if (entry.getKey().equals("TABLE")) {
                tableName = (String) entry.getValue();
            } else if (entry.getKey().equals("LOGFILE")) {
                logFile = (String) entry.getValue();
            } else if (entry.getKey().equals("FIELD_SEPARATOR")) {
                fieldSeparator = (String) entry.getValue();
            } else if (entry.getKey().equals("FIELD_ENCLOSURE")) {
                fieldEnclosure = (String) entry.getValue();
            } else if (entry.getKey().equals("NULL_REPRESENTATION")) {
                setNULLrepresentation((String) entry.getValue());
            } else if (entry.getKey().equals("ENCODING")) {
                encoding = (String) entry.getValue();
            } else if (entry.getKey().equals("BUFFER_SIZE")) {
                bufferSize = (String) entry.getValue();
            } else if (entry.getKey().equals("TRUNCATE")) {
                truncate = (Boolean) entry.getValue();
            } else if (entry.getKey().equals("FULLY_QUOTE_SQL")) {
                fullyQuoteSQL = (Boolean) entry.getValue();
            } else {
                throw new RuntimeException("Unhandled metadata injection of attribute: " + attr.toString() + " - " + attr.getDescription());
            }
        } else {
            // 
            if (attr.getKey().equals("MAPPINGS")) {
                List<StepInjectionMetaEntry> selectMappings = entry.getDetails();
                fieldTable = new String[selectMappings.size()];
                fieldStream = new String[selectMappings.size()];
                fieldFormatOk = new boolean[selectMappings.size()];
                for (int row = 0; row < selectMappings.size(); row++) {
                    StepInjectionMetaEntry selectField = selectMappings.get(row);
                    List<StepInjectionMetaEntry> fieldAttributes = selectField.getDetails();
                    // CHECKSTYLE:Indentation:OFF
                    for (int i = 0; i < fieldAttributes.size(); i++) {
                        StepInjectionMetaEntry fieldAttribute = fieldAttributes.get(i);
                        KettleAttributeInterface fieldAttr = findAttribute(fieldAttribute.getKey());
                        Object attributeValue = fieldAttribute.getValue();
                        if (attributeValue == null) {
                            continue;
                        }
                        if (fieldAttr.getKey().equals("STREAMNAME")) {
                            getFieldStream()[row] = (String) attributeValue;
                        } else if (fieldAttr.getKey().equals("FIELDNAME")) {
                            getFieldTable()[row] = (String) attributeValue;
                        } else if (fieldAttr.getKey().equals("FIELD_FORMAT_OK")) {
                            getFieldFormatOk()[row] = (Boolean) attributeValue;
                        } else {
                            throw new RuntimeException("Unhandled metadata injection of attribute: " + fieldAttr.toString() + " - " + fieldAttr.getDescription());
                        }
                    }
                }
            }
            if (!Utils.isEmpty(getFieldStream())) {
                for (int i = 0; i < getFieldStream().length; i++) {
                    logDetailed("row " + Integer.toString(i) + ": stream=" + getFieldStream()[i] + " : table=" + getFieldTable()[i]);
                }
            }
        }
    }
}
Also used : KettleAttributeInterface(org.pentaho.di.core.KettleAttributeInterface) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry)

Example 12 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class TableOutputMetaInjectionIT method testInjectionEntries.

public void testInjectionEntries() throws Exception {
    TableOutputMeta meta = populateTableOutputMeta();
    List<StepInjectionMetaEntry> entries = meta.getStepMetaInjectionInterface().getStepInjectionMetadataEntries();
    assertEquals(16, entries.size());
    assertNotNull(StepInjectionUtil.findEntry(entries, TableOutputMetaInjection.Entry.TARGET_SCHEMA));
    assertNotNull(StepInjectionUtil.findEntry(entries, TableOutputMetaInjection.Entry.TARGET_TABLE));
    assertNotNull(StepInjectionUtil.findEntry(entries, TableOutputMetaInjection.Entry.COMMIT_SIZE));
    assertNotNull(StepInjectionUtil.findEntry(entries, TableOutputMetaInjection.Entry.TRUNCATE_TABLE));
    assertNotNull(StepInjectionUtil.findEntry(entries, TableOutputMetaInjection.Entry.SPECIFY_DATABASE_FIELDS));
    assertNotNull(StepInjectionUtil.findEntry(entries, TableOutputMetaInjection.Entry.IGNORE_INSERT_ERRORS));
    assertNotNull(StepInjectionUtil.findEntry(entries, TableOutputMetaInjection.Entry.USE_BATCH_UPDATE));
    assertNotNull(StepInjectionUtil.findEntry(entries, TableOutputMetaInjection.Entry.PARTITION_OVER_TABLES));
    assertNotNull(StepInjectionUtil.findEntry(entries, TableOutputMetaInjection.Entry.PARTITIONING_FIELD));
    assertNotNull(StepInjectionUtil.findEntry(entries, TableOutputMetaInjection.Entry.PARTITION_DATA_PER));
    assertNotNull(StepInjectionUtil.findEntry(entries, TableOutputMetaInjection.Entry.TABLE_NAME_DEFINED_IN_FIELD));
    assertNotNull(StepInjectionUtil.findEntry(entries, TableOutputMetaInjection.Entry.TABLE_NAME_FIELD));
    assertNotNull(StepInjectionUtil.findEntry(entries, TableOutputMetaInjection.Entry.STORE_TABLE_NAME));
    assertNotNull(StepInjectionUtil.findEntry(entries, TableOutputMetaInjection.Entry.RETURN_AUTO_GENERATED_KEY));
    assertNotNull(StepInjectionUtil.findEntry(entries, TableOutputMetaInjection.Entry.AUTO_GENERATED_KEY_FIELD));
    StepInjectionMetaEntry fieldsEntry = StepInjectionUtil.findEntry(entries, TableOutputMetaInjection.Entry.DATABASE_FIELDS);
    assertNotNull(fieldsEntry);
    StepInjectionMetaEntry fieldEntry = StepInjectionUtil.findEntry(fieldsEntry.getDetails(), TableOutputMetaInjection.Entry.DATABASE_FIELD);
    assertNotNull(fieldEntry);
    assertNotNull(StepInjectionUtil.findEntry(fieldEntry.getDetails(), TableOutputMetaInjection.Entry.DATABASE_FIELDNAME));
    assertNotNull(StepInjectionUtil.findEntry(fieldEntry.getDetails(), TableOutputMetaInjection.Entry.STREAM_FIELDNAME));
}
Also used : StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry)

Example 13 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class PGBulkLoaderMeta method injectStepMetadataEntries.

public void injectStepMetadataEntries(List<StepInjectionMetaEntry> metadata) {
    for (StepInjectionMetaEntry entry : metadata) {
        KettleAttributeInterface attr = findAttribute(entry.getKey());
        // 
        if (entry.getValueType() != ValueMetaInterface.TYPE_NONE) {
            if (entry.getKey().equals("SCHEMA")) {
                schemaName = (String) entry.getValue();
            } else if (entry.getKey().equals("TABLE")) {
                tableName = (String) entry.getValue();
            } else if (entry.getKey().equals("LOADACTION")) {
                loadAction = (String) entry.getValue();
            } else if (entry.getKey().equals("DBNAMEOVERRIDE")) {
                dbNameOverride = (String) entry.getValue();
            } else if (entry.getKey().equals("ENCLOSURE")) {
                enclosure = (String) entry.getValue();
            } else if (entry.getKey().equals("DELIMITER")) {
                delimiter = (String) entry.getValue();
            } else if (entry.getKey().equals("STOPONERROR")) {
                stopOnError = (Boolean) entry.getValue();
            } else {
                throw new RuntimeException("Unhandled metadata injection of attribute: " + attr.toString() + " - " + attr.getDescription());
            }
        } else {
            // 
            if (attr.getKey().equals("MAPPINGS")) {
                List<StepInjectionMetaEntry> selectMappings = entry.getDetails();
                fieldTable = new String[selectMappings.size()];
                fieldStream = new String[selectMappings.size()];
                dateMask = new String[selectMappings.size()];
                for (int row = 0; row < selectMappings.size(); row++) {
                    StepInjectionMetaEntry selectField = selectMappings.get(row);
                    List<StepInjectionMetaEntry> fieldAttributes = selectField.getDetails();
                    // CHECKSTYLE:Indentation:OFF
                    for (int i = 0; i < fieldAttributes.size(); i++) {
                        StepInjectionMetaEntry fieldAttribute = fieldAttributes.get(i);
                        KettleAttributeInterface fieldAttr = findAttribute(fieldAttribute.getKey());
                        String attributeValue = (String) fieldAttribute.getValue();
                        if (fieldAttr.getKey().equals("STREAMNAME")) {
                            getFieldStream()[row] = attributeValue;
                        } else if (fieldAttr.getKey().equals("FIELDNAME")) {
                            getFieldTable()[row] = attributeValue;
                        } else if (fieldAttr.getKey().equals("DATEMASK")) {
                            getDateMask()[row] = attributeValue;
                        } else {
                            throw new RuntimeException("Unhandled metadata injection of attribute: " + fieldAttr.toString() + " - " + fieldAttr.getDescription());
                        }
                    }
                }
            }
            if (!Utils.isEmpty(getFieldStream())) {
                for (int i = 0; i < getFieldStream().length; i++) {
                    logDetailed("row " + Integer.toString(i) + ": stream=" + getFieldStream()[i] + " : table=" + getFieldTable()[i]);
                }
            }
        }
    }
}
Also used : KettleAttributeInterface(org.pentaho.di.core.KettleAttributeInterface) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry)

Example 14 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class ConcatFieldsMetaInjection method injectStepMetadataEntries.

@Override
public void injectStepMetadataEntries(List<StepInjectionMetaEntry> all) throws KettleException {
    List<String> concatFields = new ArrayList<String>();
    List<String> concatTypes = new ArrayList<String>();
    List<String> concatLengths = new ArrayList<String>();
    List<String> concatFormats = new ArrayList<String>();
    List<String> concatPrecisions = new ArrayList<String>();
    List<String> concatCurrencies = new ArrayList<String>();
    List<String> concatDecimals = new ArrayList<String>();
    List<String> concatGroups = new ArrayList<String>();
    List<String> concatTrims = new ArrayList<String>();
    List<String> concatNulls = new ArrayList<String>();
    // 
    for (StepInjectionMetaEntry lookFields : all) {
        Entry fieldsEntry = Entry.findEntry(lookFields.getKey());
        if (fieldsEntry == null) {
            continue;
        }
        String lookValue = (String) lookFields.getValue();
        switch(fieldsEntry) {
            case CONCAT_FIELDS:
                for (StepInjectionMetaEntry lookField : lookFields.getDetails()) {
                    Entry fieldEntry = Entry.findEntry(lookField.getKey());
                    if (fieldEntry == Entry.CONCAT_FIELD) {
                        String concatFieldname = null;
                        String concatType = null;
                        String concatLength = null;
                        String concatFormat = null;
                        String concatPrecision = null;
                        String concatCurrency = null;
                        String concatDecimal = null;
                        String concatGroup = null;
                        String concatTrim = null;
                        String concatNull = null;
                        List<StepInjectionMetaEntry> entries = lookField.getDetails();
                        for (StepInjectionMetaEntry entry : entries) {
                            Entry metaEntry = Entry.findEntry(entry.getKey());
                            if (metaEntry != null) {
                                String value = (String) entry.getValue();
                                switch(metaEntry) {
                                    case CONCAT_FIELDNAME:
                                        concatFieldname = value;
                                        break;
                                    case CONCAT_TYPE:
                                        concatType = value;
                                        break;
                                    case CONCAT_LENGTH:
                                        concatLength = value;
                                        break;
                                    case CONCAT_FORMAT:
                                        concatFormat = value;
                                        break;
                                    case CONCAT_PRECISION:
                                        concatPrecision = value;
                                        break;
                                    case CONCAT_CURRENCY:
                                        concatCurrency = value;
                                        break;
                                    case CONCAT_DECIMAL:
                                        concatDecimal = value;
                                        break;
                                    case CONCAT_GROUP:
                                        concatGroup = value;
                                        break;
                                    case CONCAT_TRIM:
                                        concatTrim = value;
                                        break;
                                    case CONCAT_NULL:
                                        concatNull = value;
                                        break;
                                    default:
                                        break;
                                }
                            }
                        }
                        concatFields.add(concatFieldname);
                        concatTypes.add(concatType);
                        concatLengths.add(concatLength);
                        concatFormats.add(concatFormat);
                        concatPrecisions.add(concatPrecision);
                        concatCurrencies.add(concatCurrency);
                        concatDecimals.add(concatDecimal);
                        concatGroups.add(concatGroup);
                        concatTrims.add(concatTrim);
                        concatNulls.add(concatNull);
                    }
                }
                break;
            case TARGET_FIELDNAME:
                meta.setTargetFieldName(lookValue);
                break;
            case TARGET_LENGTH:
                meta.setTargetFieldLength(Const.toInt(lookValue, 0));
                break;
            case SEPARATOR:
                meta.setSeparator(lookValue);
                break;
            case ENCLOSURE:
                meta.setEnclosure(lookValue);
                break;
            case REMOVE_FIELDS:
                meta.setRemoveSelectedFields("Y".equalsIgnoreCase(lookValue));
                break;
            case FORCE_ENCLOSURE:
                meta.setEnclosureForced("Y".equalsIgnoreCase(lookValue));
                break;
            case DISABLE_ENCLOSURE_FIX:
                meta.setEnclosureFixDisabled("Y".equalsIgnoreCase(lookValue));
                break;
            case HEADER:
                meta.setHeaderEnabled("Y".equalsIgnoreCase(lookValue));
                break;
            case FOOTER:
                meta.setFooterEnabled("Y".equalsIgnoreCase(lookValue));
                break;
            case ENCODING:
                meta.setEncoding(lookValue);
                break;
            case RIGHT_PAD_FIELDS:
                meta.setPadded("Y".equalsIgnoreCase(lookValue));
                break;
            case FAST_DATA_DUMP:
                meta.setFastDump("Y".equalsIgnoreCase(lookValue));
                break;
            case SPLIT_EVERY:
                meta.setSplitEvery(Const.toInt(lookValue, 0));
                break;
            case ADD_ENDING_LINE:
                meta.setEndedLine(lookValue);
                break;
            default:
                break;
        }
    }
    // 
    if (concatFields.size() > 0) {
        TextFileField[] tff = new TextFileField[concatFields.size()];
        Iterator<String> iConcatFields = concatFields.iterator();
        Iterator<String> iConcatTypes = concatTypes.iterator();
        Iterator<String> iConcatLengths = concatLengths.iterator();
        Iterator<String> iConcatFormats = concatFormats.iterator();
        Iterator<String> iConcatPrecisions = concatPrecisions.iterator();
        Iterator<String> iConcatCurrencies = concatCurrencies.iterator();
        Iterator<String> iConcatDecimals = concatDecimals.iterator();
        Iterator<String> iConcatGroups = concatGroups.iterator();
        Iterator<String> iConcatTrims = concatTrims.iterator();
        Iterator<String> iConcatNulls = concatNulls.iterator();
        int i = 0;
        while (iConcatFields.hasNext()) {
            TextFileField field = new TextFileField();
            field.setName(iConcatFields.next());
            field.setType(ValueMetaFactory.getIdForValueMeta(iConcatTypes.next()));
            field.setFormat(iConcatFormats.next());
            field.setLength(Const.toInt(iConcatLengths.next(), -1));
            field.setPrecision(Const.toInt(iConcatPrecisions.next(), -1));
            field.setCurrencySymbol(iConcatCurrencies.next());
            field.setDecimalSymbol(iConcatDecimals.next());
            field.setGroupingSymbol(iConcatGroups.next());
            field.setNullString(iConcatNulls.next());
            field.setTrimType(ValueMetaBase.getTrimTypeByDesc(iConcatTrims.next()));
            tff[i] = field;
            i++;
        }
        meta.setOutputFields(tff);
    }
}
Also used : StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) TextFileField(org.pentaho.di.trans.steps.textfileoutput.TextFileField) ArrayList(java.util.ArrayList) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry)

Example 15 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class MonetDBBulkLoaderMetaTest method testChildLevelMetadataEntries.

@Test
public void testChildLevelMetadataEntries() {
    try {
        List<StepInjectionMetaEntry> entries = loader.getStepMeta().getStepMetaInterface().getStepMetaInjectionInterface().getStepInjectionMetadataEntries();
        String childKeys = "STREAMNAME FIELDNAME FIELD_FORMAT_OK ";
        StepInjectionMetaEntry mappingEntry = null;
        for (StepInjectionMetaEntry entry : entries) {
            String key = entry.getKey();
            if (key.equals("MAPPINGS")) {
                mappingEntry = entry;
                break;
            }
        }
        assertNotNull(mappingEntry);
        List<StepInjectionMetaEntry> fieldAttributes = mappingEntry.getDetails().get(0).getDetails();
        for (StepInjectionMetaEntry attribute : fieldAttributes) {
            String key = attribute.getKey();
            assertTrue(childKeys.contains(key));
            childKeys = childKeys.replace(key, "");
        }
        assertTrue(childKeys.trim().length() == 0);
    } catch (KettleException e) {
        fail(e.getMessage());
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) Test(org.junit.Test)

Aggregations

StepInjectionMetaEntry (org.pentaho.di.trans.step.StepInjectionMetaEntry)54 ArrayList (java.util.ArrayList)31 Test (org.junit.Test)17 KettleException (org.pentaho.di.core.exception.KettleException)10 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)6 KettleAttributeInterface (org.pentaho.di.core.KettleAttributeInterface)3 TextFileInputField (org.pentaho.di.trans.steps.textfileinput.TextFileInputField)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 ShellEvent (org.eclipse.swt.events.ShellEvent)1