### Question:
DistinctStage implements TranslationStage { @Override public void perform(TranslatorContext context) { if(context.getMetadata().isSuppressingDistinct()) { context.setDistinctSuppression(true); return; } if(!context.getQuery().isDistinct() && context.getTableTree().getNodeCount() <= 1) { return; } for(ResultNodeDescriptor node : context.getResultNodeList()) { if(isUnsupportedForDistinct(node.getJdbcType())) { context.setDistinctSuppression(true); return; } } context.getSelectBuilder().distinct(); }  @Override void perform(TranslatorContext context);  }### Answer:
@Test public void noSuppression() { TranslatableQueryWrapper wrapper = new MockQueryWrapperBuilder().withDistinct(true).build(); TranslatorContext context = new MockTranslatorContext(wrapper); assertFalse(context.isDistinctSuppression()); DistinctStage stage = new DistinctStage(); stage.perform(context); assertFalse(context.isDistinctSuppression()); }
@Test public void explicitSuppression() { TranslatableQueryWrapper wrapper = new MockQueryWrapperBuilder() .withDistinct(true) .withMetaData(new MockQueryMetadataBuilder() .withSuppressDistinct() .build()) .build(); TranslatorContext context = new MockTranslatorContext(wrapper); assertFalse(context.isDistinctSuppression()); DistinctStage stage = new DistinctStage(); stage.perform(context); assertTrue(context.isDistinctSuppression()); }
@Test public void suppressionByType() { TranslatableQueryWrapper wrapper = new MockQueryWrapperBuilder() .withDistinct(true) .withMetaData(new MockQueryMetadataBuilder().build()) .build(); TranslatorContext context = new MockTranslatorContext(wrapper); DbAttribute attribute = new DbAttribute(); attribute.setType(Types.LONGVARBINARY); Node node = new ColumnNode("t0", "attr", null, attribute); context.addResultNode(node); assertFalse(context.isDistinctSuppression()); DistinctStage stage = new DistinctStage(); stage.perform(context); assertTrue(context.isDistinctSuppression()); }