All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.hollow.tools.diff.specific.HollowSpecificDiff Maven / Gradle / Ivy

There is a newer version: 7.14.3
Show newest version
/*
 *  Copyright 2016-2019 Netflix, Inc.
 *
 *     Licensed under the Apache License, Version 2.0 (the "License");
 *     you may not use this file except in compliance with the License.
 *     You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *     Unless required by applicable law or agreed to in writing, software
 *     distributed under the License is distributed on an "AS IS" BASIS,
 *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *     See the License for the specific language governing permissions and
 *     limitations under the License.
 *
 */
package com.netflix.hollow.tools.diff.specific;

import com.netflix.hollow.core.index.traversal.HollowIndexerValueTraverser;
import com.netflix.hollow.core.read.engine.HollowReadStateEngine;
import com.netflix.hollow.core.read.engine.object.HollowObjectTypeReadState;
import com.netflix.hollow.core.util.SimultaneousExecutor;
import com.netflix.hollow.tools.diff.HollowDiffMatcher;
import java.util.Arrays;
import java.util.BitSet;
import java.util.concurrent.atomic.AtomicLong;

/**
 * The HollowSpecificDiff allows for the investigation of diffs among specific fields for matched records in two states.
 */
public class HollowSpecificDiff {

    private final HollowReadStateEngine from;
    private final HollowReadStateEngine to;
    private final HollowDiffMatcher matcher;
    private final String type;

    private BitSet elementKeyPaths;
    private BitSet elementNonKeyPaths;
    private String elementPaths[];

    private final AtomicLong totalUnmatchedFromElements;
    private final AtomicLong totalUnmatchedToElements;
    private final AtomicLong totalModifiedElements;
    private final AtomicLong totalMatchedEqualElements;

    /**
     * @param from the from state
     * @param to the to state
     * @param type the type to diff
     */
    public HollowSpecificDiff(HollowReadStateEngine from, HollowReadStateEngine to, String type) {
        this.from = from;
        this.to = to;
        this.matcher = new HollowDiffMatcher((HollowObjectTypeReadState)from.getTypeState(type), (HollowObjectTypeReadState)to.getTypeState(type));
        this.type = type;
        this.totalUnmatchedFromElements = new AtomicLong();
        this.totalUnmatchedToElements = new AtomicLong();
        this.totalMatchedEqualElements = new AtomicLong();
        this.totalModifiedElements = new AtomicLong();
    }

    /**
     * Set the primary key paths which will be used to find matching records across the two states
     *
     * @param paths the key paths
     */
    public void setRecordMatchPaths(String... paths) {
        for(String path : paths)
            matcher.addMatchPath(path);
    }

    /**
     * Set the paths for which we will inspect differences across the two states
     *
     * @param paths the paths for inspection
     */
    public void setElementMatchPaths(String... paths) {
        resetResults();
        this.elementPaths = paths;
        this.elementKeyPaths = null;
        this.elementNonKeyPaths = null;
    }

    /**
     * Optionally specify paths for which we will match records within an individual type's hierarchy
     *
     * @param paths the paths for matching
     */
    public void setElementKeyPaths(String... paths) {
        resetResults();
        elementKeyPaths = new BitSet(elementPaths.length);
        for(int i=0;i>> 32);
                        int toOrdinal = (int)ordinalPair;

                        fromTraverser.traverse(fromOrdinal);
                        toTraverser.traverse(toOrdinal);

                        if(fromTraverser.getNumMatches() * 2 > hashedResults.length)
                            hashedResults = new int[hashTableSize(fromTraverser.getNumMatches())];

                        populateHashTable(fromTraverser, hashedResults);

                        countMatches(fromTraverser, toTraverser, hashedResults);
                    }

                    for(int i=threadNumber;i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy