Search in sources :

Example 1 with ValidateNode

use of org.apache.hudi.integ.testsuite.dag.nodes.ValidateNode in project hudi by apache.

the class ComplexDagGenerator method build.

@Override
public WorkflowDag build() {
    // root node
    DagNode root = new InsertNode(Config.newBuilder().withNumRecordsToInsert(1000).withNumInsertPartitions(3).withRecordSize(1000).build());
    // child node1
    DagNode child1 = new UpsertNode(Config.newBuilder().withNumRecordsToUpdate(999).withNumRecordsToInsert(1000).withNumUpsertFiles(1).withNumUpsertPartitions(1).withNumInsertPartitions(1).withRecordSize(10000).build());
    // function used to build ValidateNode
    Function<List<DagNode<JavaRDD<WriteStatus>>>, Boolean> function = (dagNodes) -> {
        DagNode<JavaRDD<WriteStatus>> parent1 = dagNodes.get(0);
        List<WriteStatus> statuses = parent1.getResult().collect();
        long totalRecordsTouched = statuses.stream().map(st -> st.getStat().getNumUpdateWrites() + st.getStat().getNumInserts()).reduce((a, b) -> a + b).get();
        boolean b1 = totalRecordsTouched == parent1.getConfig().getNumRecordsInsert() + parent1.getConfig().getNumRecordsUpsert();
        boolean b2 = statuses.size() > parent1.getConfig().getNumUpsertFiles();
        DagNode<JavaRDD<WriteStatus>> parent2 = parent1.getParentNodes().get(0);
        statuses = parent2.getResult().collect();
        totalRecordsTouched = statuses.stream().map(st -> st.getStat().getNumUpdateWrites() + st.getStat().getNumInserts()).reduce((a, b) -> a + b).get();
        boolean b3 = totalRecordsTouched == parent2.getConfig().getNumRecordsInsert() * parent2.getConfig().getNumInsertPartitions() + parent2.getConfig().getNumRecordsUpsert();
        return b1 & b2 & b3;
    };
    // child node2
    DagNode child2 = new ValidateNode(Config.newBuilder().build(), function);
    // create relationship between nodes
    root.addChildNode(child1);
    // child1.addParentNode(root);
    child1.addChildNode(child2);
    // child2.addParentNode(child1);
    List<DagNode> rootNodes = new ArrayList<>();
    rootNodes.add(root);
    return new WorkflowDag(rootNodes);
}
Also used : UpsertNode(org.apache.hudi.integ.testsuite.dag.nodes.UpsertNode) WriteStatus(org.apache.hudi.client.WriteStatus) DagNode(org.apache.hudi.integ.testsuite.dag.nodes.DagNode) List(java.util.List) InsertNode(org.apache.hudi.integ.testsuite.dag.nodes.InsertNode) Config(org.apache.hudi.integ.testsuite.configuration.DeltaConfig.Config) Function(java.util.function.Function) JavaRDD(org.apache.spark.api.java.JavaRDD) ArrayList(java.util.ArrayList) ValidateNode(org.apache.hudi.integ.testsuite.dag.nodes.ValidateNode) ValidateNode(org.apache.hudi.integ.testsuite.dag.nodes.ValidateNode) ArrayList(java.util.ArrayList) UpsertNode(org.apache.hudi.integ.testsuite.dag.nodes.UpsertNode) JavaRDD(org.apache.spark.api.java.JavaRDD) DagNode(org.apache.hudi.integ.testsuite.dag.nodes.DagNode) List(java.util.List) ArrayList(java.util.ArrayList) InsertNode(org.apache.hudi.integ.testsuite.dag.nodes.InsertNode) WriteStatus(org.apache.hudi.client.WriteStatus)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Function (java.util.function.Function)1 WriteStatus (org.apache.hudi.client.WriteStatus)1 Config (org.apache.hudi.integ.testsuite.configuration.DeltaConfig.Config)1 DagNode (org.apache.hudi.integ.testsuite.dag.nodes.DagNode)1 InsertNode (org.apache.hudi.integ.testsuite.dag.nodes.InsertNode)1 UpsertNode (org.apache.hudi.integ.testsuite.dag.nodes.UpsertNode)1 ValidateNode (org.apache.hudi.integ.testsuite.dag.nodes.ValidateNode)1 JavaRDD (org.apache.spark.api.java.JavaRDD)1