From 3ec3f47d6e02b4b5583c4494417615211303056b Mon Sep 17 00:00:00 2001 From: Steve Lord Date: Wed, 24 Feb 2021 12:21:45 -0800 Subject: [PATCH 1/4] Visitor for UpdateClause class hierarchy --- .../impl/condition/RemoveClause.java | 5 +++ .../versioned/impl/condition/SetClause.java | 5 +++ .../impl/condition/UpdateClause.java | 9 +++++ .../impl/condition/UpdateClauseVisitor.java | 36 +++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/UpdateClauseVisitor.java diff --git a/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/RemoveClause.java b/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/RemoveClause.java index b789602c079..6459c87578d 100644 --- a/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/RemoveClause.java +++ b/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/RemoveClause.java @@ -21,6 +21,11 @@ public abstract class RemoveClause implements UpdateClause { public abstract ExpressionPath getPath(); + @Override + public T accept(UpdateClauseVisitor visitor) { + return visitor.visit(this); + } + @Override public RemoveClause alias(AliasCollector c) { return ImmutableRemoveClause.builder().path(getPath().alias(c)).build(); diff --git a/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/SetClause.java b/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/SetClause.java index 05f840477ff..43e9cbf6a74 100644 --- a/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/SetClause.java +++ b/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/SetClause.java @@ -24,6 +24,11 @@ public abstract class SetClause implements UpdateClause { public abstract Value getValue(); + @Override + public T accept(UpdateClauseVisitor visitor) { + return visitor.visit(this); + } + public static SetClause equals(ExpressionPath path, Entity value) { return ImmutableSetClause.builder().path(path).value(Value.of(value)).build(); } diff --git a/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/UpdateClause.java b/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/UpdateClause.java index 9e5dedf5520..a54e49be01b 100644 --- a/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/UpdateClause.java +++ b/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/UpdateClause.java @@ -27,4 +27,13 @@ enum Type { String toClauseString(); + /** + * Default implementation for visitation. + * @param visitor the visitor that will be invoked. + * @param the type of the returned value. + * @return the possibly transformed value resulting from the visitation. + */ + default T accept(UpdateClauseVisitor visitor) { + throw new IllegalArgumentException(); + } } diff --git a/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/UpdateClauseVisitor.java b/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/UpdateClauseVisitor.java new file mode 100644 index 00000000000..14f64aa4e9c --- /dev/null +++ b/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/UpdateClauseVisitor.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2020 Dremio + * + * 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 org.projectnessie.versioned.impl.condition; + +/** + * Visitor for all classes in the UpdateClause hierarchy. + * @param The type to which the UpdateClause will be converted. + */ +public interface UpdateClauseVisitor { + /** + * Visit the passed in RemoveClause. + * @param clause the clause to visit. + * @return the possibly transformed value resulting from the visitation. + */ + T visit(RemoveClause clause); + + /** + * Visit the passed in SetClause. + * @param clause the clause to visit. + * @return the possibly transformed value resulting from the visitation. + */ + T visit(SetClause clause); +} From 33a00e7b946b0eb87f597fc6041985d5f3d35cfd Mon Sep 17 00:00:00 2001 From: Steve Lord Date: Wed, 24 Feb 2021 20:43:33 -0800 Subject: [PATCH 2/4] UpdateExpression visitor tests --- .../condition/TestUpdateClauseVisitor.java | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/TestUpdateClauseVisitor.java diff --git a/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/TestUpdateClauseVisitor.java b/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/TestUpdateClauseVisitor.java new file mode 100644 index 00000000000..a30622531cc --- /dev/null +++ b/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/TestUpdateClauseVisitor.java @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2020 Dremio + * + * 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 org.projectnessie.versioned.impl.condition; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.projectnessie.versioned.store.Entity; + +/** + * Test basic functionality and show usage of the UpdateClauseVisitor as pertains to UpdateExpression and the UpdateClause + * hierarchy (ValueOfEntity, ExpressionFunction, ExpressionPath). + */ +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class TestUpdateClauseVisitor { + + private static final Visitor VISITOR = new Visitor(); + private static final String ID_STR = "id"; + private static final Entity ENTITY_STR = Entity.ofString(ID_STR); + private static final String PATH_STR = "commits"; + private static final ExpressionPath PATH = ExpressionPath.builder(PATH_STR).build(); + + /** + * Sample interface or class into which UpdateClauses are converted. + */ + interface UpdateCommand { + /** + * An enum encapsulating. + */ + enum Operator { + // An operator to remove some part or all of an entity. + REMOVE, + + // An operator to set some part or all of an entity. + SET + } + + Operator getOperator(); + + ExpressionPath getPath(); + + class SetCommand implements UpdateCommand { + private final Entity entity; + private final ExpressionPath path; + + SetCommand(ExpressionPath path, Entity entity) { + this.path = path; + this.entity = entity; + } + + @Override + public Operator getOperator() { + return Operator.SET; + } + + @Override + public ExpressionPath getPath() { + return path; + } + + Entity getEntity() { + return entity; + } + } + + class RemoveCommand implements UpdateCommand { + private final ExpressionPath path; + + RemoveCommand(ExpressionPath path) { + this.path = path; + } + + @Override + public Operator getOperator() { + return Operator.REMOVE; + } + + @Override + public ExpressionPath getPath() { + return path; + } + } + } + + /** + * A test visitor which builds up an UpdateCommand representation of the passed in UpdateClause. + */ + static class Visitor implements UpdateClauseVisitor { + + @Override + public UpdateCommand visit(final RemoveClause clause) { + return new UpdateCommand.RemoveCommand(clause.getPath()); + } + + @Override + public UpdateCommand visit(final SetClause clause) { + switch (clause.getValue().getType()) { + case VALUE: + return new UpdateCommand.SetCommand(clause.getPath(), clause.getValue().getValue()); + case FUNCTION: + return new UpdateCommand.SetCommand(clause.getPath(), handleFunction(clause.getValue().getFunction())); + default: + throw new UnsupportedOperationException(String.format("Unsupported SetClause type: %s", clause.getValue().getType().name())); + } + } + + private Entity handleFunction(ExpressionFunction expressionFunction) { + if (ExpressionFunction.FunctionName.LIST_APPEND == expressionFunction.getName()) { + return expressionFunction.getArguments().get(1).getValue(); + } + throw new UnsupportedOperationException(String.format("Unsupported Set function: %s", expressionFunction.getName())); + } + } + + @Test + void testRemoveClause() { + final UpdateClause clause = RemoveClause.of(PATH); + final UpdateCommand command = clause.accept(VISITOR); + Assertions.assertEquals(UpdateCommand.Operator.REMOVE, command.getOperator()); + Assertions.assertEquals(PATH, command.getPath()); + } + + @Test + void testSetClauseEquals() { + testSetClause(SetClause.equals(PATH, ENTITY_STR), PATH, ENTITY_STR); + } + + @Test + void testSetClauseAppendToList() { + testSetClause(SetClause.appendToList(PATH, ENTITY_STR), PATH, ENTITY_STR); + } + + void testSetClause(UpdateClause clause, ExpressionPath path, Entity entity) { + final UpdateCommand command = clause.accept(VISITOR); + Assertions.assertEquals(UpdateCommand.Operator.SET, command.getOperator()); + Assertions.assertEquals(path, command.getPath()); + Assertions.assertEquals(entity, ((UpdateCommand.SetCommand)command).getEntity()); + } +} From 44d6e948e4f18b09d6aba1d63c89557eac10c311 Mon Sep 17 00:00:00 2001 From: Steve Lord Date: Fri, 26 Feb 2021 15:01:05 -0800 Subject: [PATCH 3/4] UpdateExpression PR updates --- .../versioned/impl/condition/AddClause.java | 5 ++ .../impl/condition/UpdateClause.java | 6 +- .../impl/condition/UpdateClauseVisitor.java | 7 ++ .../impl/condition/RemoveCommand.java | 26 ++++++ .../versioned/impl/condition/SetCommand.java | 29 +++++++ .../condition/TestUpdateClauseVisitor.java | 86 +++++-------------- .../impl/condition/UpdateCommand.java | 38 ++++++++ 7 files changed, 127 insertions(+), 70 deletions(-) create mode 100644 versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/RemoveCommand.java create mode 100644 versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/SetCommand.java create mode 100644 versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/UpdateCommand.java diff --git a/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/AddClause.java b/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/AddClause.java index db500cac159..eee46647f87 100644 --- a/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/AddClause.java +++ b/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/AddClause.java @@ -32,6 +32,11 @@ public static AddClause addToSetOrNumber(ExpressionPath path, Entity value) { return ImmutableAddClause.builder().path(path).value(Value.of(value)).build(); } + @Override + public T accept(UpdateClauseVisitor visitor) { + return visitor.visit(this); + } + @Override public UpdateClause alias(AliasCollector c) { return ImmutableAddClause.builder().path(getPath().alias(c)).value(getValue().alias(c)).build(); diff --git a/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/UpdateClause.java b/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/UpdateClause.java index a54e49be01b..bedec125e54 100644 --- a/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/UpdateClause.java +++ b/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/UpdateClause.java @@ -28,12 +28,10 @@ enum Type { String toClauseString(); /** - * Default implementation for visitation. + * Entry point for visitation. * @param visitor the visitor that will be invoked. * @param the type of the returned value. * @return the possibly transformed value resulting from the visitation. */ - default T accept(UpdateClauseVisitor visitor) { - throw new IllegalArgumentException(); - } + abstract T accept(UpdateClauseVisitor visitor); } diff --git a/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/UpdateClauseVisitor.java b/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/UpdateClauseVisitor.java index 14f64aa4e9c..d71362c2835 100644 --- a/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/UpdateClauseVisitor.java +++ b/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/condition/UpdateClauseVisitor.java @@ -20,6 +20,13 @@ * @param The type to which the UpdateClause will be converted. */ public interface UpdateClauseVisitor { + /** + * Visit the passed in AddClause. + * @param clause the clause to visit. + * @return the possibly transformed value resulting from the visitation. + */ + T visit(AddClause clause); + /** * Visit the passed in RemoveClause. * @param clause the clause to visit. diff --git a/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/RemoveCommand.java b/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/RemoveCommand.java new file mode 100644 index 00000000000..9d19c06f240 --- /dev/null +++ b/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/RemoveCommand.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2020 Dremio + * + * 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 org.projectnessie.versioned.impl.condition; + +import org.immutables.value.Value.Immutable; + +/** + * Sample of a specific type of update command into which UpdateClauses are converted. + */ +@Immutable +abstract class RemoveCommand implements UpdateCommand { +} diff --git a/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/SetCommand.java b/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/SetCommand.java new file mode 100644 index 00000000000..7ff7caccaed --- /dev/null +++ b/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/SetCommand.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2020 Dremio + * + * 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 org.projectnessie.versioned.impl.condition; + +import org.immutables.value.Value.Immutable; +import org.projectnessie.versioned.store.Entity; + +/** + * Sample of a specific type of update command into which UpdateClauses are converted. + */ +@Immutable +abstract class SetCommand implements UpdateCommand { + + abstract Entity getEntity(); +} diff --git a/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/TestUpdateClauseVisitor.java b/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/TestUpdateClauseVisitor.java index a30622531cc..b512dcb05f9 100644 --- a/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/TestUpdateClauseVisitor.java +++ b/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/TestUpdateClauseVisitor.java @@ -34,85 +34,39 @@ public class TestUpdateClauseVisitor { private static final String PATH_STR = "commits"; private static final ExpressionPath PATH = ExpressionPath.builder(PATH_STR).build(); - /** - * Sample interface or class into which UpdateClauses are converted. - */ - interface UpdateCommand { - /** - * An enum encapsulating. - */ - enum Operator { - // An operator to remove some part or all of an entity. - REMOVE, - - // An operator to set some part or all of an entity. - SET - } - - Operator getOperator(); - - ExpressionPath getPath(); - - class SetCommand implements UpdateCommand { - private final Entity entity; - private final ExpressionPath path; - - SetCommand(ExpressionPath path, Entity entity) { - this.path = path; - this.entity = entity; - } - - @Override - public Operator getOperator() { - return Operator.SET; - } - - @Override - public ExpressionPath getPath() { - return path; - } - - Entity getEntity() { - return entity; - } - } - - class RemoveCommand implements UpdateCommand { - private final ExpressionPath path; - - RemoveCommand(ExpressionPath path) { - this.path = path; - } - - @Override - public Operator getOperator() { - return Operator.REMOVE; - } - - @Override - public ExpressionPath getPath() { - return path; - } - } - } - /** * A test visitor which builds up an UpdateCommand representation of the passed in UpdateClause. */ static class Visitor implements UpdateClauseVisitor { + @Override + public UpdateCommand visit(final AddClause clause) { + throw new UnsupportedOperationException(); + } + @Override public UpdateCommand visit(final RemoveClause clause) { - return new UpdateCommand.RemoveCommand(clause.getPath()); + return ImmutableRemoveCommand.builder() + .operator(UpdateCommand.Operator.REMOVE) + .path(clause.getPath()) + .build(); } @Override public UpdateCommand visit(final SetClause clause) { switch (clause.getValue().getType()) { case VALUE: - return new UpdateCommand.SetCommand(clause.getPath(), clause.getValue().getValue()); + return ImmutableSetCommand.builder() + .operator(UpdateCommand.Operator.SET) + .path(clause.getPath()) + .entity(clause.getValue().getValue()) + .build(); case FUNCTION: - return new UpdateCommand.SetCommand(clause.getPath(), handleFunction(clause.getValue().getFunction())); + return ImmutableSetCommand.builder() + .operator(UpdateCommand.Operator.SET) + .path(clause.getPath()) + .entity(handleFunction(clause.getValue().getFunction())) + .build(); default: throw new UnsupportedOperationException(String.format("Unsupported SetClause type: %s", clause.getValue().getType().name())); } @@ -148,6 +102,6 @@ void testSetClause(UpdateClause clause, ExpressionPath path, Entity entity) { final UpdateCommand command = clause.accept(VISITOR); Assertions.assertEquals(UpdateCommand.Operator.SET, command.getOperator()); Assertions.assertEquals(path, command.getPath()); - Assertions.assertEquals(entity, ((UpdateCommand.SetCommand)command).getEntity()); + Assertions.assertEquals(entity, ((SetCommand)command).getEntity()); } } diff --git a/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/UpdateCommand.java b/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/UpdateCommand.java new file mode 100644 index 00000000000..7839cbaad67 --- /dev/null +++ b/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/UpdateCommand.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2020 Dremio + * + * 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 org.projectnessie.versioned.impl.condition; + +/** + * Sample interface or class into which UpdateClauses are converted. + */ +interface UpdateCommand { + /** + * An enum encapsulating. + */ + enum Operator { + // An operator to remove some part or all of an entity. + REMOVE, + + // An operator to set some part or all of an entity. + SET + } + + Operator getOperator(); + + ExpressionPath getPath(); + +} From 4ac8264645beb26b29cc5ea2e2fa28297568d5bc Mon Sep 17 00:00:00 2001 From: Steve Lord Date: Wed, 3 Mar 2021 09:18:37 -0800 Subject: [PATCH 4/4] PR updates --- .../impl/condition/RemoveCommand.java | 26 --------- .../versioned/impl/condition/SetCommand.java | 29 ---------- .../condition/TestUpdateClauseVisitor.java | 53 ++++++++++++++++--- .../impl/condition/UpdateCommand.java | 38 ------------- 4 files changed, 45 insertions(+), 101 deletions(-) delete mode 100644 versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/RemoveCommand.java delete mode 100644 versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/SetCommand.java delete mode 100644 versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/UpdateCommand.java diff --git a/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/RemoveCommand.java b/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/RemoveCommand.java deleted file mode 100644 index 9d19c06f240..00000000000 --- a/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/RemoveCommand.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2020 Dremio - * - * 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 org.projectnessie.versioned.impl.condition; - -import org.immutables.value.Value.Immutable; - -/** - * Sample of a specific type of update command into which UpdateClauses are converted. - */ -@Immutable -abstract class RemoveCommand implements UpdateCommand { -} diff --git a/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/SetCommand.java b/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/SetCommand.java deleted file mode 100644 index 7ff7caccaed..00000000000 --- a/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/SetCommand.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2020 Dremio - * - * 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 org.projectnessie.versioned.impl.condition; - -import org.immutables.value.Value.Immutable; -import org.projectnessie.versioned.store.Entity; - -/** - * Sample of a specific type of update command into which UpdateClauses are converted. - */ -@Immutable -abstract class SetCommand implements UpdateCommand { - - abstract Entity getEntity(); -} diff --git a/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/TestUpdateClauseVisitor.java b/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/TestUpdateClauseVisitor.java index b512dcb05f9..d55474fa2f8 100644 --- a/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/TestUpdateClauseVisitor.java +++ b/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/TestUpdateClauseVisitor.java @@ -16,6 +16,7 @@ package org.projectnessie.versioned.impl.condition; +import org.immutables.value.Value.Immutable; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -83,25 +84,61 @@ private Entity handleFunction(ExpressionFunction expressionFunction) { @Test void testRemoveClause() { final UpdateClause clause = RemoveClause.of(PATH); - final UpdateCommand command = clause.accept(VISITOR); - Assertions.assertEquals(UpdateCommand.Operator.REMOVE, command.getOperator()); - Assertions.assertEquals(PATH, command.getPath()); + testClause(RemoveClause.of(PATH), UpdateCommand.Operator.REMOVE, PATH); } @Test void testSetClauseEquals() { - testSetClause(SetClause.equals(PATH, ENTITY_STR), PATH, ENTITY_STR); + final UpdateCommand command = testClause(SetClause.equals(PATH, ENTITY_STR), UpdateCommand.Operator.SET, PATH); + Assertions.assertEquals(ENTITY_STR, ((UpdateCommand.SetCommand)command).getEntity()); } @Test void testSetClauseAppendToList() { - testSetClause(SetClause.appendToList(PATH, ENTITY_STR), PATH, ENTITY_STR); + final UpdateCommand command = testClause(SetClause.appendToList(PATH, ENTITY_STR), UpdateCommand.Operator.SET, PATH); + Assertions.assertEquals(ENTITY_STR, ((UpdateCommand.SetCommand)command).getEntity()); } - void testSetClause(UpdateClause clause, ExpressionPath path, Entity entity) { + UpdateCommand testClause(UpdateClause clause, UpdateCommand.Operator operator, ExpressionPath path) { final UpdateCommand command = clause.accept(VISITOR); - Assertions.assertEquals(UpdateCommand.Operator.SET, command.getOperator()); + Assertions.assertEquals(operator, command.getOperator()); Assertions.assertEquals(path, command.getPath()); - Assertions.assertEquals(entity, ((SetCommand)command).getEntity()); + return command; + } + + /** + * Sample interface or class into which UpdateClauses are converted. + */ + static interface UpdateCommand { + /** + * An enum encapsulating the type of update. + */ + enum Operator { + // An operator to remove some part or all of an entity. + REMOVE, + + // An operator to set some part or all of an entity. + SET + } + + Operator getOperator(); + + ExpressionPath getPath(); + + /** + * Sample of a specific type of update command into which UpdateClauses are converted. + */ + @Immutable + abstract class RemoveCommand implements UpdateCommand { + } + + /** + * Sample of a specific type of update command into which UpdateClauses are converted. + */ + @Immutable + abstract class SetCommand implements UpdateCommand { + + abstract Entity getEntity(); + } } } diff --git a/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/UpdateCommand.java b/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/UpdateCommand.java deleted file mode 100644 index 7839cbaad67..00000000000 --- a/versioned/tiered/tiered-impl/src/test/java/org/projectnessie/versioned/impl/condition/UpdateCommand.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2020 Dremio - * - * 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 org.projectnessie.versioned.impl.condition; - -/** - * Sample interface or class into which UpdateClauses are converted. - */ -interface UpdateCommand { - /** - * An enum encapsulating. - */ - enum Operator { - // An operator to remove some part or all of an entity. - REMOVE, - - // An operator to set some part or all of an entity. - SET - } - - Operator getOperator(); - - ExpressionPath getPath(); - -}