Skip to content

Commit

Permalink
fixed duration display
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Nov 6, 2023
1 parent 36dba7e commit 4ab2191
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ private ProposedImplementations prepareQueryList( AlgRoot logicalRoot, AlgDataTy

// Initialize result lists. They will all be with in the same ordering.
List<ProposedRoutingPlan> proposedRoutingPlans = null;
List<AlgNode> optimalNodeList = new ArrayList<>();
List<AlgRoot> parameterizedRootList = new ArrayList<>();
List<AlgNode> optimalNodes = new ArrayList<>();
List<AlgRoot> parameterizedRoots = new ArrayList<>();
List<PolyImplementation> results = new ArrayList<>();
List<String> generatedCodes = new ArrayList<>();

Expand Down Expand Up @@ -413,7 +413,7 @@ private ProposedImplementations prepareQueryList( AlgRoot logicalRoot, AlgDataTy
parameterizedRoot = routedRoot;
}

parameterizedRootList.add( parameterizedRoot );
parameterizedRoots.add( parameterizedRoot );
}

if ( isAnalyze ) {
Expand All @@ -429,9 +429,9 @@ private ProposedImplementations prepareQueryList( AlgRoot logicalRoot, AlgDataTy
for ( int i = 0; i < proposedRoutingPlans.size(); i++ ) {
AlgRoot routedRoot = proposedRoutingPlans.get( i ).getRoutedRoot();
if ( this.isImplementationCachingActive( statement, routedRoot ) ) {
AlgRoot parameterizedRoot = parameterizedRootList.get( i );
AlgRoot parameterizedRoot = parameterizedRoots.get( i );
PreparedResult<PolyValue> preparedResult = ImplementationCache.INSTANCE.getIfPresent( parameterizedRoot.alg );
AlgNode optimalNode = QueryPlanCache.INSTANCE.getIfPresent( parameterizedRootList.get( i ).alg );
AlgNode optimalNode = QueryPlanCache.INSTANCE.getIfPresent( parameterizedRoots.get( i ).alg );
if ( preparedResult != null ) {
PolyImplementation result = createPolyImplementation(
preparedResult,
Expand All @@ -443,16 +443,16 @@ private ProposedImplementations prepareQueryList( AlgRoot logicalRoot, AlgDataTy
Objects.requireNonNull( optimalNode.getTraitSet().getTrait( ModelTraitDef.INSTANCE ) ).getDataModel() );
results.add( result );
generatedCodes.add( preparedResult.getCode() );
optimalNodeList.add( optimalNode );
optimalNodes.add( optimalNode );
} else {
results.add( null );
generatedCodes.add( null );
optimalNodeList.add( null );
optimalNodes.add( null );
}
} else {
results.add( null );
generatedCodes.add( null );
optimalNodeList.add( null );
optimalNodes.add( null );
}
}

Expand All @@ -461,16 +461,16 @@ private ProposedImplementations prepareQueryList( AlgRoot logicalRoot, AlgDataTy
}

// Can we return earlier?
if ( results.stream().allMatch( Objects::nonNull ) && optimalNodeList.stream().allMatch( Objects::nonNull ) ) {
if ( results.stream().allMatch( Objects::nonNull ) && optimalNodes.stream().allMatch( Objects::nonNull ) ) {
return new ProposedImplementations(
proposedRoutingPlans,
optimalNodeList.stream().filter( Objects::nonNull ).collect( Collectors.toList() ),
optimalNodes.stream().filter( Objects::nonNull ).collect( Collectors.toList() ),
results.stream().filter( Objects::nonNull ).collect( Collectors.toList() ),
generatedCodes.stream().filter( Objects::nonNull ).collect( Collectors.toList() ),
logicalQueryInformation );
}

optimalNodeList = new ArrayList<>( Collections.nCopies( optimalNodeList.size(), null ) );
optimalNodes = new ArrayList<>( Collections.nCopies( optimalNodes.size(), null ) );

//
// Plan Caching
Expand All @@ -480,9 +480,9 @@ private ProposedImplementations prepareQueryList( AlgRoot logicalRoot, AlgDataTy
for ( int i = 0; i < proposedRoutingPlans.size(); i++ ) {
if ( this.isQueryPlanCachingActive( statement, proposedRoutingPlans.get( i ).getRoutedRoot() ) ) {
// Should always be the case
AlgNode cachedElem = QueryPlanCache.INSTANCE.getIfPresent( parameterizedRootList.get( i ).alg );
AlgNode cachedElem = QueryPlanCache.INSTANCE.getIfPresent( parameterizedRoots.get( i ).alg );
if ( cachedElem != null ) {
optimalNodeList.set( i, cachedElem );
optimalNodes.set( i, cachedElem );
}
}
}
Expand All @@ -495,16 +495,16 @@ private ProposedImplementations prepareQueryList( AlgRoot logicalRoot, AlgDataTy
}

// OptimalNode same size as routed, parametrized and result
for ( int i = 0; i < optimalNodeList.size(); i++ ) {
if ( optimalNodeList.get( i ) != null ) {
for ( int i = 0; i < optimalNodes.size(); i++ ) {
if ( optimalNodes.get( i ) != null ) {
continue;
}
AlgRoot parameterizedRoot = parameterizedRootList.get( i );
AlgRoot parameterizedRoot = parameterizedRoots.get( i );
AlgRoot routedRoot = proposedRoutingPlans.get( i ).getRoutedRoot();
optimalNodeList.set( i, optimize( parameterizedRoot, resultConvention ) );
optimalNodes.set( i, optimize( parameterizedRoot, resultConvention ) );

if ( this.isQueryPlanCachingActive( statement, routedRoot ) ) {
QueryPlanCache.INSTANCE.put( parameterizedRoot.alg, optimalNodeList.get( i ) );
QueryPlanCache.INSTANCE.put( parameterizedRoot.alg, optimalNodes.get( i ) );
}
}

Expand All @@ -515,13 +515,13 @@ private ProposedImplementations prepareQueryList( AlgRoot logicalRoot, AlgDataTy
statement.getProcessingDuration().start( "Implementation" );
}

for ( int i = 0; i < optimalNodeList.size(); i++ ) {
for ( int i = 0; i < optimalNodes.size(); i++ ) {
if ( results.get( i ) != null ) {
continue;
}

AlgNode optimalNode = optimalNodeList.get( i );
AlgRoot parameterizedRoot = parameterizedRootList.get( i );
AlgNode optimalNode = optimalNodes.get( i );
AlgRoot parameterizedRoot = parameterizedRoots.get( i );
AlgRoot routedRoot = proposedRoutingPlans.get( i ).getRoutedRoot();

final AlgDataType rowType = parameterizedRoot.alg.getRowType();
Expand Down Expand Up @@ -549,7 +549,7 @@ private ProposedImplementations prepareQueryList( AlgRoot logicalRoot, AlgDataTy
Objects.requireNonNull( optimalNode.getTraitSet().getTrait( ModelTraitDef.INSTANCE ) ).getDataModel() );
results.set( i, result );
generatedCodes.set( i, preparedResult.getCode() );
optimalNodeList.set( i, optimalRoot.alg );
optimalNodes.set( i, optimalRoot.alg );
}
if ( isAnalyze ) {
statement.getProcessingDuration().stop( "Implementation" );
Expand All @@ -563,7 +563,7 @@ private ProposedImplementations prepareQueryList( AlgRoot logicalRoot, AlgDataTy
// Finally, all optionals should be of certain values.
return new ProposedImplementations(
proposedRoutingPlans,
optimalNodeList.stream().filter( Objects::nonNull ).collect( Collectors.toList() ),
optimalNodes.stream().filter( Objects::nonNull ).collect( Collectors.toList() ),
results.stream().filter( Objects::nonNull ).collect( Collectors.toList() ),
generatedCodes.stream().filter( Objects::nonNull ).collect( Collectors.toList() ),
logicalQueryInformation );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
Expand All @@ -29,7 +30,7 @@

public class InformationDuration extends Information {

@JsonProperty

private final Map<String, Duration> children = new HashMap<>();


Expand All @@ -56,6 +57,11 @@ public InformationDuration( final InformationGroup group ) {
}


@JsonProperty("children")
public Collection<Duration> getDurationValues() {
return children.values();
}

public Duration start( final String name ) {
Duration d = new Duration( name );
this.children.put( name, d );
Expand Down Expand Up @@ -136,9 +142,10 @@ public static class Duration implements Comparable<Duration> {
@JsonProperty
private final long sequence;

@JsonProperty
@JsonPropertyOrder("sequence")

private final Map<String, Duration> children = new HashMap<>();


@JsonProperty
private final boolean isChild = true;
/**
Expand All @@ -165,6 +172,12 @@ private Duration( final String name ) {
}


@JsonPropertyOrder("sequence")
@JsonProperty("children")
public Collection<Duration> getDurationValues() {
return children.values();
}

private Duration( final String name, final long nanoDuration ) {
this.sequence = counter++;
this.name = name;
Expand Down

0 comments on commit 4ab2191

Please sign in to comment.