Search in sources :

Example 1 with ValueMetaGraph

use of org.apache.hop.neo4j.core.value.ValueMetaGraph in project hop by apache.

the class CypherMeta method getFields.

@Override
public void getFields(IRowMeta rowMeta, String name, IRowMeta[] info, TransformMeta nextStep, IVariables space, IHopMetadataProvider metadataProvider) throws HopTransformException {
    if (usingUnwind) {
        // Unwind only outputs results, not input
        // 
        rowMeta.clear();
    }
    if (returningGraph) {
        // We send out a single Graph value per input row
        // 
        IValueMeta valueMetaGraph = new ValueMetaGraph(Const.NVL(returnGraphField, "graph"));
        valueMetaGraph.setOrigin(name);
        rowMeta.addValueMeta(valueMetaGraph);
    } else {
        // 
        for (ReturnValue returnValue : returnValues) {
            try {
                int type = ValueMetaFactory.getIdForValueMeta(returnValue.getType());
                IValueMeta valueMeta = ValueMetaFactory.createValueMeta(returnValue.getName(), type);
                valueMeta.setOrigin(name);
                rowMeta.addValueMeta(valueMeta);
            } catch (HopPluginException e) {
                throw new HopTransformException("Unknown data type '" + returnValue.getType() + "' for value named '" + returnValue.getName() + "'");
            }
        }
    }
}
Also used : IValueMeta(org.apache.hop.core.row.IValueMeta) ValueMetaGraph(org.apache.hop.neo4j.core.value.ValueMetaGraph) HopPluginException(org.apache.hop.core.exception.HopPluginException) HopTransformException(org.apache.hop.core.exception.HopTransformException)

Example 2 with ValueMetaGraph

use of org.apache.hop.neo4j.core.value.ValueMetaGraph in project hop by apache.

the class GraphOutputMeta method getFields.

@Override
public void getFields(IRowMeta rowMeta, String name, IRowMeta[] info, TransformMeta nextStep, IVariables space, IHopMetadataProvider metadataProvider) {
    if (returningGraph) {
        IValueMeta valueMetaGraph = new ValueMetaGraph(Const.NVL(returnGraphField, "graph"));
        valueMetaGraph.setOrigin(name);
        rowMeta.addValueMeta(valueMetaGraph);
    }
}
Also used : IValueMeta(org.apache.hop.core.row.IValueMeta) ValueMetaGraph(org.apache.hop.neo4j.core.value.ValueMetaGraph)

Example 3 with ValueMetaGraph

use of org.apache.hop.neo4j.core.value.ValueMetaGraph in project hop by apache.

the class SplitGraph method processRow.

@Override
public boolean processRow() throws HopException {
    Object[] row = getRow();
    if (row == null) {
        setOutputDone();
        return false;
    }
    if (first) {
        first = false;
        data.outputRowMeta = getInputRowMeta().clone();
        meta.getFields(data.outputRowMeta, getTransformName(), null, null, this, metadataProvider);
        data.graphFieldIndex = getInputRowMeta().indexOfValue(meta.getGraphField());
        if (data.graphFieldIndex < 0) {
            throw new HopException("Unable to find graph field " + meta.getGraphField() + "' in the transform input");
        }
        IValueMeta valueMeta = getInputRowMeta().getValueMeta(data.graphFieldIndex);
        if (valueMeta.getType() != ValueMetaGraph.TYPE_GRAPH) {
            throw new HopException("Please specify a Graph field to split");
        }
        data.typeField = null;
        if (StringUtils.isNotEmpty(meta.getTypeField())) {
            data.typeField = resolve(meta.getTypeField());
        }
        data.idField = null;
        if (StringUtils.isNotEmpty(meta.getIdField())) {
            data.idField = resolve(meta.getIdField());
        }
        data.propertySetField = null;
        if (StringUtils.isNotEmpty(meta.getPropertySetField())) {
            data.propertySetField = resolve(meta.getPropertySetField());
        }
    }
    ValueMetaGraph valueMeta = (ValueMetaGraph) getInputRowMeta().getValueMeta(data.graphFieldIndex);
    Object valueData = row[data.graphFieldIndex];
    GraphData graphData = valueMeta.getGraphData(valueData);
    for (GraphNodeData nodeData : graphData.getNodes()) {
        Object[] outputRowData = RowDataUtil.createResizedCopy(row, data.outputRowMeta.size());
        int index = getInputRowMeta().size();
        GraphData copy = graphData.createEmptyCopy();
        copy.getNodes().add(nodeData.clone());
        outputRowData[data.graphFieldIndex] = copy;
        if (data.typeField != null) {
            outputRowData[index++] = "Node";
        }
        if (data.idField != null) {
            outputRowData[index++] = nodeData.getId();
        }
        if (data.propertySetField != null) {
            outputRowData[index++] = nodeData.getPropertySetId();
        }
        putRow(data.outputRowMeta, outputRowData);
    }
    for (GraphRelationshipData relationshipData : graphData.getRelationships()) {
        Object[] outputRowData = RowDataUtil.createResizedCopy(row, data.outputRowMeta.size());
        int index = getInputRowMeta().size();
        GraphData copy = graphData.createEmptyCopy();
        copy.getRelationships().add(relationshipData.clone());
        outputRowData[data.graphFieldIndex] = copy;
        if (data.typeField != null) {
            outputRowData[index++] = "Relationship";
        }
        if (data.idField != null) {
            outputRowData[index++] = relationshipData.getId();
        }
        if (data.propertySetField != null) {
            outputRowData[index++] = relationshipData.getPropertySetId();
        }
        putRow(data.outputRowMeta, outputRowData);
    }
    return true;
}
Also used : IValueMeta(org.apache.hop.core.row.IValueMeta) ValueMetaGraph(org.apache.hop.neo4j.core.value.ValueMetaGraph) GraphRelationshipData(org.apache.hop.neo4j.core.data.GraphRelationshipData) HopException(org.apache.hop.core.exception.HopException) GraphNodeData(org.apache.hop.neo4j.core.data.GraphNodeData) GraphData(org.apache.hop.neo4j.core.data.GraphData)

Example 4 with ValueMetaGraph

use of org.apache.hop.neo4j.core.value.ValueMetaGraph in project hop by apache.

the class Neo4JOutputMeta method getFields.

@Override
public void getFields(IRowMeta inputRowMeta, String name, IRowMeta[] info, TransformMeta nextStep, IVariables space, IHopMetadataProvider metadataProvider) throws HopTransformException {
    if (returningGraph) {
        IValueMeta valueMetaGraph = new ValueMetaGraph(Const.NVL(returnGraphField, "graph"));
        valueMetaGraph.setOrigin(name);
        inputRowMeta.addValueMeta(valueMetaGraph);
    }
}
Also used : IValueMeta(org.apache.hop.core.row.IValueMeta) ValueMetaGraph(org.apache.hop.neo4j.core.value.ValueMetaGraph)

Example 5 with ValueMetaGraph

use of org.apache.hop.neo4j.core.value.ValueMetaGraph in project hop by apache.

the class GenerateCsv method addRowToBuffer.

protected void addRowToBuffer(IRowMeta inputRowMeta, Object[] row) throws HopException {
    try {
        ValueMetaGraph valueMetaGraph = (ValueMetaGraph) inputRowMeta.getValueMeta(data.graphFieldIndex);
        GraphData graphData = valueMetaGraph.getGraphData(row[data.graphFieldIndex]);
        // 
        for (GraphNodeData node : graphData.getNodes()) {
            // Copy the data and calculate a unique property set ID
            // 
            GraphNodeData nodeCopy = new GraphNodeData(node);
            nodeCopy.setPropertySetId(graphData.getSourcePipelineName() + "-" + graphData.getSourceTransformName() + "-" + node.getPropertySetId());
            data.indexedGraphData.addAndIndexNode(nodeCopy);
        }
        for (GraphRelationshipData relationship : graphData.getRelationships()) {
            // Copy the data and calculate a unique property set ID
            // 
            GraphRelationshipData relationshipCopy = new GraphRelationshipData(relationship);
            relationshipCopy.setPropertySetId(graphData.getSourcePipelineName() + "-" + graphData.getSourceTransformName() + "-" + relationship.getPropertySetId());
            data.indexedGraphData.addAndIndexRelationship(relationshipCopy);
        }
    } catch (Exception e) {
        throw new HopException("Error adding row to gencsv buffer", e);
    }
}
Also used : ValueMetaGraph(org.apache.hop.neo4j.core.value.ValueMetaGraph) HopException(org.apache.hop.core.exception.HopException) HopException(org.apache.hop.core.exception.HopException) IOException(java.io.IOException)

Aggregations

ValueMetaGraph (org.apache.hop.neo4j.core.value.ValueMetaGraph)6 IValueMeta (org.apache.hop.core.row.IValueMeta)4 HopException (org.apache.hop.core.exception.HopException)3 IOException (java.io.IOException)2 HopPluginException (org.apache.hop.core.exception.HopPluginException)1 HopTransformException (org.apache.hop.core.exception.HopTransformException)1 GraphData (org.apache.hop.neo4j.core.data.GraphData)1 GraphNodeData (org.apache.hop.neo4j.core.data.GraphNodeData)1 GraphRelationshipData (org.apache.hop.neo4j.core.data.GraphRelationshipData)1