Skip to content

Optimised DataBuilderMeta method calls #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: cpu_opt_v2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public DataSet getAccesibleDataSetFor(DataBuilder builder) {
* Merge data with current {@link com.flipkart.databuilderframework.model.DataSet}.
* Data will be added to the current data-set and override data with same type as identified by
* {@link com.flipkart.databuilderframework.model.Data#getData()}
*
* @param data {@link com.flipkart.databuilderframework.model.Data} to be merged.
*/
public void merge(Data data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,8 @@ private List<List<DataBuilderMeta>> buildHierarchy(
//Data is user-input data
continue;
}
DataBuilderMeta dataBuilderMeta = tmpDataBuilderMeta.deepCopy();
int rank = dependencyInfo.getValue().getRank();
dataBuilderMeta.setRank(rank);

DataBuilderMeta dataBuilderMeta = tmpDataBuilderMeta.deepCopy(rank);
//Set builder in the appropriate rank slots
if(null == dependencyHierarchy.get(rank)) {
dependencyHierarchy.set(rank, Lists.<DataBuilderMeta>newArrayList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
* The executor for a {@link com.flipkart.databuilderframework.model.DataFlow}.
Expand Down Expand Up @@ -39,7 +38,7 @@ protected DataExecutionResponse run(DataBuilderContext dataBuilderContext,
DataSet dataSet = dataFlowInstance.getDataSet().accessor().copy(); //Create own copy to work with
DataSetAccessor dataSetAccessor = DataSet.accessor(dataSet);
dataSetAccessor.merge(dataDelta);
Map<String, Data> responseData = Maps.newTreeMap();
Map<String, Data> responseData = Maps.newHashMap();
Set<String> activeDataSet = Sets.newHashSet();

for (Data deltaDeltaElement : dataDelta.getDelta()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.NotNull;
Expand All @@ -18,6 +19,7 @@
* execution.
*/
@lombok.Data
@EqualsAndHashCode(cacheStrategy = EqualsAndHashCode.CacheStrategy.LAZY)
public class DataBuilderMeta implements Comparable<DataBuilderMeta>, Serializable {
/**
* List of {@link com.flipkart.databuilderframework.model.Data} this {@link com.flipkart.databuilderframework.engine.DataBuilder}
Expand All @@ -26,25 +28,25 @@ public class DataBuilderMeta implements Comparable<DataBuilderMeta>, Serializabl
@NotNull
@NotEmpty
@JsonProperty
private Set<String> consumes;
private final Set<String> consumes;

/**
* {@link com.flipkart.databuilderframework.model.Data} this {@link com.flipkart.databuilderframework.engine.DataBuilder} generates.
*/
@NotNull
@NotEmpty
@JsonProperty
private String produces;
private final String produces;

/**
* Name for this builder
*/
@NotNull
@NotEmpty
@JsonProperty
private String name;
private final String name;

private int rank;
private final int rank;


/**
Expand All @@ -54,7 +56,7 @@ public class DataBuilderMeta implements Comparable<DataBuilderMeta>, Serializabl
* all consumes {@link com.flipkart.databuilderframework.model.Data} are present but its optional and not mandatory for {@link com.flipkart.databuilderframework.engine.DataBuilder} to run.
*/
@JsonProperty
private Set<String> optionals;
private final Set<String> optionals;

/**
* Set of {@link com.flipkart.databuilderframework.model.Data} this {@link com.flipkart.databuilderframework.engine.DataBuilder}
Expand All @@ -63,28 +65,37 @@ public class DataBuilderMeta implements Comparable<DataBuilderMeta>, Serializabl
@NotNull
@NotEmpty
@JsonProperty
private Set<String> access;
private final Set<String> access;

private final Set<String> accessibleDataSet;

private final Set<String> effectiveConsumes;

public DataBuilderMeta(Set<String> consumes, String produces, String name) {
this(consumes, produces, name, Collections.emptySet(), Collections.emptySet());
this(consumes, produces, name, 0, Collections.emptySet(), Collections.emptySet());
}

@Builder
public DataBuilderMeta(Set<String> consumes, String produces, String name,
public DataBuilderMeta(Set<String> consumes, String produces, String name,
Set<String> optionals, Set<String> access) {
this(consumes, produces, name, 0, optionals, access);
}

public DataBuilderMeta(Set<String> consumes, String produces, String name,
int rank,
Set<String> optionals, Set<String> access) {
this.consumes = consumes;
this.produces = produces;
this.name = name;
this.rank = rank;
this.optionals = optionals;
this.access = access;
}


public DataBuilderMeta() {
this.accessibleDataSet = constructAccessibleDataSet();
this.effectiveConsumes = constructEffectiveConsumes();
}

@JsonIgnore
public Set<String> getEffectiveConsumes(){
private Set<String> constructEffectiveConsumes(){
if(optionals != null && !optionals.isEmpty()){
return Sets.union(optionals, consumes);
}else{
Expand All @@ -93,9 +104,9 @@ public Set<String> getEffectiveConsumes(){
}

@JsonIgnore
public Set<String> getAccessibleDataSet(){
private Set<String> constructAccessibleDataSet(){
Set<String> output = consumes;
if(optionals != null && !optionals.isEmpty()){
if(optionals != null && !optionals.isEmpty()) {
output = Sets.union(optionals, output);
}
if(access != null && !access.isEmpty()){
Expand All @@ -109,8 +120,12 @@ public int compareTo(DataBuilderMeta rhs) {
}

public DataBuilderMeta deepCopy() {
Set<String> optionalCopy = (optionals != null) ? ImmutableSet.copyOf(optionals) : null;
Set<String> accessCopy = (access != null) ? ImmutableSet.copyOf(access) : null;
return new DataBuilderMeta(ImmutableSet.copyOf(consumes), produces, name, optionalCopy, accessCopy);
return deepCopy(0);
}

public DataBuilderMeta deepCopy(int rank) {
Set<String> optionalCopy = (optionals != null) ? ImmutableSet.copyOf(optionals) : null;
Set<String> accessCopy = (access != null) ? ImmutableSet.copyOf(access) : null;
return new DataBuilderMeta(ImmutableSet.copyOf(consumes), produces, name, rank, optionalCopy, accessCopy);
}
}