Skip to content

Commit

Permalink
gh-3166 ShallowCloneWithDeepOptions so options is not preserved in a …
Browse files Browse the repository at this point in the history
…join or while loop. Other information should be retained.
  • Loading branch information
GCHQDev404 committed Mar 12, 2024
1 parent c8a6197 commit f5d4b98
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package uk.gov.gchq.gaffer.store.operation.handler.join;

import uk.gov.gchq.gaffer.commonutil.exception.LimitExceededException;
import uk.gov.gchq.gaffer.operation.Operation;
import uk.gov.gchq.gaffer.operation.OperationException;
import uk.gov.gchq.gaffer.operation.impl.join.Join;
import uk.gov.gchq.gaffer.operation.impl.join.match.MatchKey;
Expand Down Expand Up @@ -63,9 +64,9 @@ public Iterable<? extends MapTuple> doOperation(final Join<I> operation, final C

JoinFunction joinFunction = operation.getJoinType().createInstance();

updateOperationInput(operation.getOperation(), null);
updateOperationInput(getOperationFromJoin(operation), null);
Iterable<I> rightIterable =
(Iterable<I>) getResultsOrNull(operation.getOperation(),
(Iterable<I>) getResultsOrNull(getOperationFromJoin(operation),
context,
store);

Expand All @@ -81,4 +82,8 @@ public Iterable<? extends MapTuple> doOperation(final Join<I> operation, final C
}

}

protected Operation getOperationFromJoin(final Join<I> operation) {
return operation.getOperation();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import uk.gov.gchq.gaffer.federatedstore.operation.RemoveGraph;
import uk.gov.gchq.gaffer.federatedstore.operation.RemoveGraphAndDeleteAllData;
import uk.gov.gchq.gaffer.federatedstore.operation.handler.FederatedDelegateToHandler;
import uk.gov.gchq.gaffer.federatedstore.operation.handler.FederatedStoreWhileHandler;
import uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedAddGraphHandler;
import uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedAddGraphWithHooksHandler;
import uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedChangeGraphAccessHandler;
Expand All @@ -53,20 +54,23 @@
import uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedOutputIterableHandler;
import uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedRemoveGraphAndDeleteAllDataHandler;
import uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedRemoveGraphHandler;
import uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedStoreJoinHandler;
import uk.gov.gchq.gaffer.federatedstore.schema.FederatedViewValidator;
import uk.gov.gchq.gaffer.federatedstore.util.ApplyViewToElementsFunction;
import uk.gov.gchq.gaffer.federatedstore.util.MergeSchema;
import uk.gov.gchq.gaffer.graph.GraphSerialisable;
import uk.gov.gchq.gaffer.operation.Operation;
import uk.gov.gchq.gaffer.operation.OperationException;
import uk.gov.gchq.gaffer.operation.impl.Validate;
import uk.gov.gchq.gaffer.operation.impl.While;
import uk.gov.gchq.gaffer.operation.impl.add.AddElements;
import uk.gov.gchq.gaffer.operation.impl.function.Aggregate;
import uk.gov.gchq.gaffer.operation.impl.function.Filter;
import uk.gov.gchq.gaffer.operation.impl.function.Transform;
import uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds;
import uk.gov.gchq.gaffer.operation.impl.get.GetAllElements;
import uk.gov.gchq.gaffer.operation.impl.get.GetElements;
import uk.gov.gchq.gaffer.operation.impl.join.Join;
import uk.gov.gchq.gaffer.operation.io.Output;
import uk.gov.gchq.gaffer.serialisation.Serialiser;
import uk.gov.gchq.gaffer.store.Context;
Expand Down Expand Up @@ -507,6 +511,10 @@ protected void addAdditionalOperationHandlers() {
addOperationHandler(Transform.class, new FederatedDelegateToHandler(new TransformHandler()));
addOperationHandler(Validate.class, new FederatedDelegateToHandler(new ValidateHandler()));

//override with Federated safe version.
addOperationHandler(While.class, new FederatedStoreWhileHandler());
addOperationHandler(Join.class, new FederatedStoreJoinHandler());

//FederationOperations
addOperationHandler(GetAllGraphIds.class, new FederatedGetAllGraphIDHandler());
addOperationHandler(AddGraph.class, new FederatedAddGraphHandler());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2024 Crown Copyright
*
* 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 uk.gov.gchq.gaffer.federatedstore.operation.handler;

import uk.gov.gchq.gaffer.operation.Operation;
import uk.gov.gchq.gaffer.operation.impl.While;
import uk.gov.gchq.gaffer.store.operation.handler.WhileHandler;

import static uk.gov.gchq.gaffer.federatedstore.util.FederatedStoreUtil.shallowCloneWithDeepOptions;

/**
* <p>
* An operation handler for {@link While} operations.
*
* @see WhileHandler
*/
public class FederatedStoreWhileHandler extends WhileHandler {

/**
* Gets an Operation from a While, but with a deep clone of the options field.
* This avoids a false looping error being detected by the FederatedStore.
*
* @param aWhile The while to get operation from
* @return The Operation with a deep clone of the options field.
*/
@Override
protected Operation getOperationFromWhile(final While aWhile) {
//TODO it is likely that other Option changes should be preserved.
return shallowCloneWithDeepOptions(super.getOperationFromWhile(aWhile));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package uk.gov.gchq.gaffer.federatedstore.operation.handler.impl;

import uk.gov.gchq.gaffer.federatedstore.util.FederatedStoreUtil;
import uk.gov.gchq.gaffer.operation.Operation;
import uk.gov.gchq.gaffer.operation.impl.join.Join;
import uk.gov.gchq.gaffer.store.operation.handler.join.JoinHandler;

public class FederatedStoreJoinHandler<I> extends JoinHandler<I> {

@Override
protected Operation getOperationFromJoin(final Join<I> join) {
//TODO it is likely that other Option changes should be preserved.
return FederatedStoreUtil.shallowCloneWithDeepOptions(super.getOperationFromJoin(join));
}
}

0 comments on commit f5d4b98

Please sign in to comment.