Search in sources :

Example 1 with ITransformIOMeta

use of org.apache.hop.pipeline.transform.ITransformIOMeta in project hop by apache.

the class PipelinePainter method drawArrow.

@Override
protected void drawArrow(EImage arrow, int x1, int y1, int x2, int y2, double theta, int size, double factor, PipelineHopMeta pipelineHop, Object startObject, Object endObject) throws HopException {
    int mx;
    int my;
    int a;
    int b;
    int dist;
    double angle;
    gc.drawLine(x1, y1, x2, y2);
    // What's the distance between the 2 points?
    a = Math.abs(x2 - x1);
    b = Math.abs(y2 - y1);
    dist = (int) Math.sqrt(a * a + b * b);
    // 0-->100%)
    if (factor < 0) {
        if (dist >= 2 * iconSize) {
            factor = 1.3;
        } else {
            factor = 1.2;
        }
    }
    // in between 2 points
    mx = (int) (x1 + factor * (x2 - x1) / 2);
    my = (int) (y1 + factor * (y2 - y1) / 2);
    // calculate points for arrowhead
    angle = Math.atan2(y2 - y1, x2 - x1) + (Math.PI / 2);
    boolean q1 = Math.toDegrees(angle) >= 0 && Math.toDegrees(angle) < 90;
    boolean q2 = Math.toDegrees(angle) >= 90 && Math.toDegrees(angle) < 180;
    boolean q3 = Math.toDegrees(angle) >= 180 && Math.toDegrees(angle) < 270;
    boolean q4 = Math.toDegrees(angle) >= 270 || Math.toDegrees(angle) < 0;
    if (q1 || q3) {
        gc.drawImage(arrow, mx, my + 1, magnification, angle);
    } else if (q2 || q4) {
        gc.drawImage(arrow, mx, my, magnification, angle);
    }
    if (startObject instanceof TransformMeta && endObject instanceof TransformMeta) {
        factor = 0.8;
        TransformMeta fs = (TransformMeta) startObject;
        TransformMeta ts = (TransformMeta) endObject;
        // in between 2 points
        mx = (int) (x1 + factor * (x2 - x1) / 2) - miniIconSize / 2;
        my = (int) (y1 + factor * (y2 - y1) / 2) - miniIconSize / 2;
        boolean errorHop = fs.isSendingErrorRowsToTransform(ts) || (startErrorHopTransform && fs.equals(startHopTransform));
        boolean targetHop = Const.indexOfString(ts.getName(), fs.getTransform().getTransformIOMeta().getTargetTransformNames()) >= 0;
        if (targetHop) {
            ITransformIOMeta ioMeta = fs.getTransform().getTransformIOMeta();
            IStream targetStream = ioMeta.findTargetStream(ts);
            if (targetStream != null) {
                EImage image = BasePainter.getStreamIconImage(targetStream.getStreamIcon(), pipelineHop.isEnabled());
                gc.drawImage(image, mx, my, magnification);
                areaOwners.add(new AreaOwner(AreaType.TRANSFORM_TARGET_HOP_ICON, mx, my, 16, 16, offset, fs, targetStream));
            }
        } else if (fs.isDistributes() && fs.getRowDistribution() != null && !ts.getTransformPartitioningMeta().isMethodMirror() && !errorHop) {
            // Draw the custom row distribution plugin icon
            // 
            SvgFile svgFile = fs.getRowDistribution().getDistributionImage();
            if (svgFile != null) {
                // 
                gc.drawImage(svgFile, mx, my, 16, 16, magnification, 0);
                areaOwners.add(new AreaOwner(AreaType.ROW_DISTRIBUTION_ICON, mx, my, 16, 16, offset, fs, STRING_ROW_DISTRIBUTION));
                mx += 16;
            }
        } else if (!fs.isDistributes() && !ts.getTransformPartitioningMeta().isMethodMirror() && !errorHop) {
            // Draw the copy icon on the hop
            // 
            EImage image = (pipelineHop.isEnabled()) ? EImage.COPY_ROWS : EImage.COPY_ROWS_DISABLED;
            gc.drawImage(image, mx, my, magnification);
            areaOwners.add(new AreaOwner(AreaType.HOP_COPY_ICON, mx, my, 16, 16, offset, fs, STRING_HOP_TYPE_COPY));
            mx += 16;
        }
        if (errorHop) {
            EImage image = (pipelineHop.isEnabled()) ? EImage.ERROR : EImage.ERROR_DISABLED;
            gc.drawImage(image, mx, my, magnification);
            areaOwners.add(new AreaOwner(AreaType.HOP_ERROR_ICON, mx, my, 16, 16, offset, fs, ts));
            mx += 16;
        }
        ITransformIOMeta ioMeta = ts.getTransform().getTransformIOMeta();
        String[] infoTransformNames = ioMeta.getInfoTransformNames();
        if ((candidateHopType == StreamType.INFO && ts.equals(endHopTransform) && fs.equals(startHopTransform)) || Const.indexOfString(fs.getName(), infoTransformNames) >= 0) {
            EImage image = (pipelineHop.isEnabled()) ? EImage.INFO : EImage.INFO_DISABLED;
            gc.drawImage(image, mx, my, magnification);
            areaOwners.add(new AreaOwner(AreaType.HOP_INFO_ICON, mx, my, 16, 16, offset, fs, ts));
            mx += 16;
        }
        // 
        if (!Utils.isEmpty(infoTransformNames)) {
            // 
            for (String infoTransform : infoTransformNames) {
                if (fs.getName().equalsIgnoreCase(infoTransform)) {
                    // 
                    if (fs.isPartitioned() && ts.isPartitioned()) {
                        // TODO explain in the UI what's going on.
                        // 
                        gc.drawImage(EImage.PARALLEL, mx, my, magnification);
                        areaOwners.add(new AreaOwner(AreaType.HOP_INFO_TRANSFORMS_PARTITIONED, mx, my, miniIconSize, miniIconSize, offset, fs, ts));
                        mx += 16;
                    } else if (fs.getCopies(variables) > 1) {
                        // This is not a desirable situation, it will always end in error.
                        // As such, it's better not to give feedback on it.
                        // We do this by drawing an error icon over the hop...
                        // 
                        gc.drawImage(EImage.ERROR, mx, my, magnification);
                        areaOwners.add(new AreaOwner(AreaType.HOP_INFO_TRANSFORM_COPIES_ERROR, mx, my, miniIconSize, miniIconSize, offset, fs, ts));
                        mx += 16;
                    }
                }
            }
        }
    }
    PipelinePainterExtension extension = new PipelinePainterExtension(gc, areaOwners, pipelineMeta, null, pipelineHop, x1, y1, x2, y2, mx, my, offset, iconSize, stateMap);
    try {
        ExtensionPointHandler.callExtensionPoint(LogChannel.GENERAL, variables, HopExtensionPoint.PipelinePainterArrow.id, extension);
    } catch (Exception e) {
        LogChannel.GENERAL.logError("Error calling extension point(s) for the pipeline painter arrow", e);
    }
}
Also used : IStream(org.apache.hop.pipeline.transform.stream.IStream) SvgFile(org.apache.hop.core.svg.SvgFile) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint) HopException(org.apache.hop.core.exception.HopException) ITransformIOMeta(org.apache.hop.pipeline.transform.ITransformIOMeta) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta)

Example 2 with ITransformIOMeta

use of org.apache.hop.pipeline.transform.ITransformIOMeta in project hop by apache.

the class PipelinePainter method drawLine.

private void drawLine(TransformMeta fs, TransformMeta ts, PipelineHopMeta hi, boolean isCandidate) throws HopException {
    int[] line = getLine(fs, ts);
    EColor color;
    ELineStyle linestyle = ELineStyle.SOLID;
    int activeLinewidth = lineWidth;
    EImage arrow;
    if (isCandidate) {
        color = EColor.BLUE;
        arrow = EImage.ARROW_CANDIDATE;
    } else {
        if (hi.isEnabled()) {
            if (fs.isSendingErrorRowsToTransform(ts)) {
                color = EColor.RED;
                linestyle = ELineStyle.DASH;
                arrow = EImage.ARROW_ERROR;
            } else {
                color = EColor.HOP_DEFAULT;
                arrow = EImage.ARROW_DEFAULT;
            }
            ITransformIOMeta ioMeta = fs.getTransform().getTransformIOMeta();
            IStream targetStream = ioMeta.findTargetStream(ts);
            if (targetStream != null) {
                if (targetStream.getStreamIcon() == StreamIcon.TRUE) {
                    color = EColor.HOP_TRUE;
                    arrow = EImage.ARROW_TRUE;
                } else if (targetStream.getStreamIcon() == StreamIcon.FALSE) {
                    color = EColor.HOP_FALSE;
                    arrow = EImage.ARROW_FALSE;
                }
            }
        } else {
            color = EColor.GRAY;
            arrow = EImage.ARROW_DISABLED;
        }
    }
    if (hi.isSplit()) {
        activeLinewidth = lineWidth + 2;
    }
    // Check to see if the source transform is an info transform for the target transform.
    // 
    ITransformIOMeta ioMeta = ts.getTransform().getTransformIOMeta();
    List<IStream> infoStreams = ioMeta.getInfoStreams();
    if (!infoStreams.isEmpty()) {
        // 
        for (IStream stream : infoStreams) {
            if (fs.getName().equalsIgnoreCase(stream.getTransformName())) {
                // 
                if (fs.isPartitioned() && ts.isPartitioned()) {
                // 
                } else if (fs.getCopies(variables) > 1) {
                    // This is not a desirable situation, it will always end in error.
                    // As such, it's better not to give feedback on it.
                    // We do this by drawing an error icon over the hop...
                    // 
                    color = EColor.RED;
                    arrow = EImage.ARROW_ERROR;
                }
            }
        }
    }
    gc.setForeground(color);
    gc.setLineStyle(linestyle);
    gc.setLineWidth(activeLinewidth);
    drawArrow(arrow, line, hi, fs, ts);
    if (hi.isSplit()) {
        gc.setLineWidth(lineWidth);
    }
    gc.setForeground(EColor.BLACK);
    gc.setBackground(EColor.BACKGROUND);
    gc.setLineStyle(ELineStyle.SOLID);
}
Also used : ITransformIOMeta(org.apache.hop.pipeline.transform.ITransformIOMeta) IStream(org.apache.hop.pipeline.transform.stream.IStream) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint)

Example 3 with ITransformIOMeta

use of org.apache.hop.pipeline.transform.ITransformIOMeta in project hop by apache.

the class SimpleMappingMeta method getTransformIOMeta.

@Override
public ITransformIOMeta getTransformIOMeta() {
    ITransformIOMeta ioMeta = super.getTransformIOMeta(false);
    if (ioMeta == null) {
        ioMeta = new TransformIOMeta(true, true, false, false, false, false);
        setTransformIOMeta(ioMeta);
    }
    return ioMeta;
}
Also used : ITransformIOMeta(org.apache.hop.pipeline.transform.ITransformIOMeta) TransformIOMeta(org.apache.hop.pipeline.transform.TransformIOMeta) ITransformIOMeta(org.apache.hop.pipeline.transform.ITransformIOMeta)

Example 4 with ITransformIOMeta

use of org.apache.hop.pipeline.transform.ITransformIOMeta in project hop by apache.

the class FuzzyMatchTest method testReadLookupValues.

@Test
public void testReadLookupValues() throws Exception {
    FuzzyMatchData data = spy(new FuzzyMatchData());
    data.indexOfCachedFields = new int[2];
    data.minimalDistance = 0;
    data.maximalDistance = 5;
    FuzzyMatchMeta meta = spy(new FuzzyMatchMeta());
    meta.setOutputMatchField("I don't want NPE here!");
    data.readLookupValues = true;
    fuzzyMatch = new FuzzyMatchHandler(mockHelper.transformMeta, meta, data, 0, mockHelper.pipelineMeta, mockHelper.pipeline);
    fuzzyMatch.init();
    IRowSet lookupRowSet = mockHelper.getMockInputRowSet(binaryLookupRows);
    fuzzyMatch.addRowSetToInputRowSets(mockHelper.getMockInputRowSet(binaryRows));
    fuzzyMatch.addRowSetToInputRowSets(lookupRowSet);
    fuzzyMatch.rowset = lookupRowSet;
    IRowMeta iRowMeta = new RowMeta();
    IValueMeta valueMeta = new ValueMetaString("field1");
    valueMeta.setStorageMetadata(new ValueMetaString("field1"));
    valueMeta.setStorageType(IValueMeta.STORAGE_TYPE_BINARY_STRING);
    iRowMeta.addValueMeta(valueMeta);
    when(lookupRowSet.getRowMeta()).thenReturn(iRowMeta);
    when(meta.getLookupField()).thenReturn("field1");
    when(meta.getMainStreamField()).thenReturn("field1");
    fuzzyMatch.setInputRowMeta(iRowMeta.clone());
    when(meta.getAlgorithmType()).thenReturn(1);
    ITransformIOMeta transformIOMetaInterface = mock(ITransformIOMeta.class);
    when(meta.getTransformIOMeta()).thenReturn(transformIOMetaInterface);
    IStream streamInterface = mock(IStream.class);
    List<IStream> streamInterfaceList = new ArrayList<>();
    streamInterfaceList.add(streamInterface);
    when(streamInterface.getTransformMeta()).thenReturn(mockHelper.transformMeta);
    when(transformIOMetaInterface.getInfoStreams()).thenReturn(streamInterfaceList);
    fuzzyMatch.processRow();
    Assert.assertEquals(iRowMeta.getString(row3B, 0), data.outputRowMeta.getString(fuzzyMatch.resultRow, 1));
}
Also used : IValueMeta(org.apache.hop.core.row.IValueMeta) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) ITransformIOMeta(org.apache.hop.pipeline.transform.ITransformIOMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) RowMeta(org.apache.hop.core.row.RowMeta) IRowSet(org.apache.hop.core.IRowSet) IRowMeta(org.apache.hop.core.row.IRowMeta) IStream(org.apache.hop.pipeline.transform.stream.IStream) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with ITransformIOMeta

use of org.apache.hop.pipeline.transform.ITransformIOMeta in project hop by apache.

the class MultiMergeJoin method processFirstRow.

private boolean processFirstRow(MultiMergeJoinMeta smi, MultiMergeJoinData sdi) throws HopException {
    PipelineMeta pipelineMeta = getPipelineMeta();
    PipelineHopMeta pipelineHopMeta;
    ITransformIOMeta transformIOMeta = meta.getTransformIOMeta();
    List<IStream> infoStreams = transformIOMeta.getInfoStreams();
    IStream stream;
    TransformMeta toTransformMeta = meta.getParentTransformMeta();
    TransformMeta fromTransformMeta;
    ArrayList<String> inputTransformNameList = new ArrayList<>();
    String[] inputTransformNames = meta.getInputTransforms();
    String inputTransformName;
    for (int i = 0; i < infoStreams.size(); i++) {
        inputTransformName = inputTransformNames[i];
        stream = infoStreams.get(i);
        fromTransformMeta = stream.getTransformMeta();
        if (fromTransformMeta == null) {
            // should not arrive here, shoud typically have been caught by init.
            throw new HopException(BaseMessages.getString(PKG, "MultiMergeJoin.Log.UnableToFindReferenceStream", inputTransformName));
        }
        // check the hop
        pipelineHopMeta = pipelineMeta.findPipelineHop(fromTransformMeta, toTransformMeta, true);
        // there is no hop: this is unexpected.
        if (pipelineHopMeta == null) {
            // should not arrive here, shoud typically have been caught by init.
            throw new HopException(BaseMessages.getString(PKG, "MultiMergeJoin.Log.UnableToFindReferenceStream", inputTransformName));
        } else if (pipelineHopMeta.isEnabled()) {
            inputTransformNameList.add(inputTransformName);
        } else {
            logDetailed(BaseMessages.getString(PKG, "MultiMergeJoin.Log.IgnoringTransform", inputTransformName));
        }
    }
    int streamSize = inputTransformNameList.size();
    if (streamSize == 0) {
        return false;
    }
    String keyField;
    String[] keyFields;
    data.rowSets = new IRowSet[streamSize];
    IRowSet rowSet;
    Object[] row;
    data.rows = new Object[streamSize][];
    data.metas = new IRowMeta[streamSize];
    data.rowLengths = new int[streamSize];
    MultiMergeJoinData.QueueComparator comparator = new MultiMergeJoinData.QueueComparator(data);
    data.queue = new PriorityQueue<>(streamSize, comparator);
    data.results = new ArrayList<>(streamSize);
    MultiMergeJoinData.QueueEntry queueEntry;
    data.queueEntries = new MultiMergeJoinData.QueueEntry[streamSize];
    data.drainIndices = new int[streamSize];
    data.keyNrs = new int[streamSize][];
    data.dummy = new Object[streamSize][];
    IRowMeta rowMeta;
    data.outputRowMeta = new RowMeta();
    for (int i = 0, j = 0; i < inputTransformNames.length; i++) {
        inputTransformName = inputTransformNames[i];
        if (!inputTransformNameList.contains(inputTransformName)) {
            // ignore transform with disabled hop.
            continue;
        }
        queueEntry = new MultiMergeJoinData.QueueEntry();
        queueEntry.index = j;
        data.queueEntries[j] = queueEntry;
        data.results.add(new ArrayList<>());
        rowSet = findInputRowSet(inputTransformName);
        if (rowSet == null) {
            throw new HopException(BaseMessages.getString(PKG, "MultiMergeJoin.Exception.UnableToFindSpecifiedTransform", inputTransformName));
        }
        data.rowSets[j] = rowSet;
        row = getRowFrom(rowSet);
        data.rows[j] = row;
        if (row == null) {
            rowMeta = getPipelineMeta().getTransformFields(this, inputTransformName);
            data.metas[j] = rowMeta;
        } else {
            queueEntry.row = row;
            rowMeta = rowSet.getRowMeta();
            keyField = meta.getKeyFields()[i];
            String[] keyFieldParts = keyField.split(",");
            String keyFieldPart;
            data.keyNrs[j] = new int[keyFieldParts.length];
            for (int k = 0; k < keyFieldParts.length; k++) {
                keyFieldPart = keyFieldParts[k];
                data.keyNrs[j][k] = rowMeta.indexOfValue(keyFieldPart);
                if (data.keyNrs[j][k] < 0) {
                    String message = BaseMessages.getString(PKG, "MultiMergeJoin.Exception.UnableToFindFieldInReferenceStream", keyFieldPart, inputTransformName);
                    logError(message);
                    throw new HopTransformException(message);
                }
            }
            data.metas[j] = rowMeta;
            data.queue.add(data.queueEntries[j]);
        }
        data.outputRowMeta.mergeRowMeta(rowMeta.clone());
        data.rowLengths[j] = rowMeta.size();
        data.dummy[j] = RowDataUtil.allocateRowData(rowMeta.size());
        j++;
    }
    return true;
}
Also used : HopException(org.apache.hop.core.exception.HopException) IRowMeta(org.apache.hop.core.row.IRowMeta) RowMeta(org.apache.hop.core.row.RowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) PipelineHopMeta(org.apache.hop.pipeline.PipelineHopMeta) IStream(org.apache.hop.pipeline.transform.stream.IStream) ArrayList(java.util.ArrayList) HopTransformException(org.apache.hop.core.exception.HopTransformException) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) ITransformIOMeta(org.apache.hop.pipeline.transform.ITransformIOMeta) IRowSet(org.apache.hop.core.IRowSet) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta)

Aggregations

ITransformIOMeta (org.apache.hop.pipeline.transform.ITransformIOMeta)10 IStream (org.apache.hop.pipeline.transform.stream.IStream)8 ArrayList (java.util.ArrayList)4 TransformMeta (org.apache.hop.pipeline.transform.TransformMeta)4 IRowSet (org.apache.hop.core.IRowSet)3 HopException (org.apache.hop.core.exception.HopException)3 IRowMeta (org.apache.hop.core.row.IRowMeta)3 HopTransformException (org.apache.hop.core.exception.HopTransformException)2 HopExtensionPoint (org.apache.hop.core.extension.HopExtensionPoint)2 RowMeta (org.apache.hop.core.row.RowMeta)2 Test (org.junit.Test)2 PCollection (org.apache.beam.sdk.values.PCollection)1 PCollectionTuple (org.apache.beam.sdk.values.PCollectionTuple)1 PCollectionView (org.apache.beam.sdk.values.PCollectionView)1 HopRow (org.apache.hop.beam.core.HopRow)1 StringToHopRowFn (org.apache.hop.beam.core.fn.StringToHopRowFn)1 VariableValue (org.apache.hop.beam.core.shared.VariableValue)1 TransformBatchTransform (org.apache.hop.beam.core.transform.TransformBatchTransform)1 TransformTransform (org.apache.hop.beam.core.transform.TransformTransform)1 ILoggingObject (org.apache.hop.core.logging.ILoggingObject)1