SchemaElementDefinition implements ElementDefinition { @JsonIgnore public ElementAggregator getQueryAggregator(final Set<String> viewGroupBy, final ElementAggregator viewAggregator) { if (null == viewAggregator) { return getQueryAggregatorForNullViewAggregator(viewGroupBy); } return getQueryAggregatorForNonNullViewAggregator(viewGroupBy, viewAggregator); } SchemaElementDefinition(); ValidationResult validate(); @JsonIgnore Set<String> getProperties(); boolean containsProperty(final String propertyName); @JsonGetter("properties") Map<String, String> getPropertyMap(); @JsonIgnore Collection<IdentifierType> getIdentifiers(); @JsonIgnore Map<IdentifierType, String> getIdentifierMap(); boolean containsIdentifier(final IdentifierType identifierType); String getPropertyTypeName(final String propertyName); String getIdentifierTypeName(final IdentifierType idType); @JsonIgnore Collection<String> getPropertyTypeNames(); @JsonIgnore Collection<String> getIdentifierTypeNames(); Class<?> getClass(final String key); @JsonIgnore ElementAggregator getOriginalAggregator(); @JsonGetter("aggregateFunctions") List<TupleAdaptedBinaryOperator<String, ?>> getOriginalAggregateFunctions(); @JsonIgnore ElementAggregator getFullAggregator(); @JsonIgnore ElementAggregator getIngestAggregator(); @JsonIgnore ElementAggregator getQueryAggregator(final Set<String> viewGroupBy, final ElementAggregator viewAggregator); @JsonIgnore ElementFilter getValidator(); @JsonIgnore ElementFilter getOriginalValidator(); boolean hasValidation(); ElementFilter getValidator(final boolean includeIsA); @SuppressFBWarnings(value = "PZLA_PREFER_ZERO_LENGTH_ARRAYS", justification = "null is only returned when the validator is null") @JsonGetter("validateFunctions") TupleAdaptedPredicate[] getOriginalValidateFunctions(); @JsonIgnore Iterable<TypeDefinition> getPropertyTypeDefs(); TypeDefinition getPropertyTypeDef(final String property); Class<?> getPropertyClass(final String propertyName); Class<?> getIdentifierClass(final IdentifierType idType); Set<String> getGroupBy(); String getDescription(); @JsonIgnore abstract SchemaElementDefinition getExpandedDefinition(); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString(); @Override void lock(); boolean isAggregate(); void setAggregate(final boolean aggregate);  }
@Test public void shouldReturnQueryAggregator() { final T elementDef = createBuilder() .property("property1", PROPERTY_STRING_TYPE) .property("property2", PROPERTY_STRING_TYPE) .property("property3", PROPERTY_STRING_TYPE) .property("visibility", PROPERTY_STRING_TYPE) .property("timestamp", PROPERTY_STRING_TYPE) .groupBy("property1", "property2") .build(); setupSchema(elementDef); final ElementAggregator aggregator = elementDef.getQueryAggregator(Sets.newHashSet("property1"), null); assertEquals(4, aggregator.getComponents().size()); assertTrue(aggregator.getComponents().get(0).getBinaryOperator() instanceof ExampleAggregateFunction); assertArrayEquals(new String[]{"property2"}, aggregator.getComponents().get(0).getSelection()); assertTrue(aggregator.getComponents().get(1).getBinaryOperator() instanceof ExampleAggregateFunction); assertArrayEquals(new String[]{"property3"}, aggregator.getComponents().get(1).getSelection()); assertTrue(aggregator.getComponents().get(2).getBinaryOperator() instanceof ExampleAggregateFunction); assertArrayEquals(new String[]{"visibility"}, aggregator.getComponents().get(2).getSelection()); assertTrue(aggregator.getComponents().get(3).getBinaryOperator() instanceof ExampleAggregateFunction); assertArrayEquals(new String[]{"timestamp"}, aggregator.getComponents().get(3).getSelection()); try { aggregator.getComponents().add(null); fail("Exception expected"); } catch (final UnsupportedOperationException e) { assertNotNull(e); } assertSame(aggregator, elementDef.getQueryAggregator(Sets.newHashSet("property1"), null)); assertNotSame(aggregator, elementDef.getQueryAggregator(Sets.newHashSet(), null)); }
@Test public void shouldReturnQueryAggregatorWithMultiPropertyAggregator() { final T elementDef = createBuilder() .property("property1", PROPERTY_STRING_TYPE) .property("property2", PROPERTY_STRING_TYPE) .property("property3", PROPERTY_STRING_TYPE) .property("property4", PROPERTY_STRING_TYPE) .property("property5", PROPERTY_STRING_TYPE) .property("visibility", PROPERTY_STRING_TYPE) .property("timestamp", PROPERTY_STRING_TYPE) .groupBy("property1", "property2") .aggregator(new ElementAggregator.Builder() .select("property1", "property2") .execute(new ExampleTuple2BinaryOperator()) .select("property3", "property4") .execute(new ExampleTuple2BinaryOperator()) .build()) .build(); setupSchema(elementDef); final ElementAggregator aggregator = elementDef.getQueryAggregator(Sets.newHashSet(), null); assertEquals(5, aggregator.getComponents().size()); assertTrue(aggregator.getComponents().get(0).getBinaryOperator() instanceof ExampleTuple2BinaryOperator); assertArrayEquals(new String[]{"property1", "property2"}, aggregator.getComponents().get(0).getSelection()); assertTrue(aggregator.getComponents().get(1).getBinaryOperator() instanceof ExampleTuple2BinaryOperator); assertArrayEquals(new String[]{"property3", "property4"}, aggregator.getComponents().get(1).getSelection()); assertTrue(aggregator.getComponents().get(2).getBinaryOperator() instanceof ExampleAggregateFunction); assertArrayEquals(new String[]{"property5"}, aggregator.getComponents().get(2).getSelection()); assertTrue(aggregator.getComponents().get(3).getBinaryOperator() instanceof ExampleAggregateFunction); assertArrayEquals(new String[]{"visibility"}, aggregator.getComponents().get(3).getSelection()); assertTrue(aggregator.getComponents().get(4).getBinaryOperator() instanceof ExampleAggregateFunction); assertArrayEquals(new String[]{"timestamp"}, aggregator.getComponents().get(4).getSelection()); try { aggregator.getComponents().add(null); fail("Exception expected"); } catch (final UnsupportedOperationException e) { assertNotNull(e); } assertSame(aggregator, elementDef.getQueryAggregator(Sets.newHashSet(), null)); }
@Test public void shouldReturnQueryAggregatorWithViewAggregator() { final T elementDef = createBuilder() .property("property1", PROPERTY_STRING_TYPE) .property("property2", PROPERTY_STRING_TYPE) .property("property3", PROPERTY_STRING_TYPE) .property("property4", PROPERTY_STRING_TYPE) .property("property5", PROPERTY_STRING_TYPE) .property("visibility", PROPERTY_STRING_TYPE) .property("timestamp", PROPERTY_STRING_TYPE) .groupBy("property1", "property2") .aggregator(new ElementAggregator.Builder() .select("property3", "property4") .execute(new ExampleTuple2BinaryOperator()) .build()) .build(); setupSchema(elementDef); final ElementAggregator viewAggregator = new ElementAggregator.Builder() .select("property1") .execute(new StringConcat()) .build(); final ElementAggregator aggregator = elementDef.getQueryAggregator(Sets.newHashSet(), viewAggregator); int i = 0; assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof StringConcat); assertArrayEquals(new String[]{"property1"}, aggregator.getComponents().get(i).getSelection()); i++; assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleTuple2BinaryOperator); assertArrayEquals(new String[]{"property3", "property4"}, aggregator.getComponents().get(i).getSelection()); i++; assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction); assertArrayEquals(new String[]{"property2"}, aggregator.getComponents().get(i).getSelection()); i++; assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction); assertArrayEquals(new String[]{"property5"}, aggregator.getComponents().get(i).getSelection()); i++; assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction); assertArrayEquals(new String[]{"visibility"}, aggregator.getComponents().get(i).getSelection()); i++; assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction); assertArrayEquals(new String[]{"timestamp"}, aggregator.getComponents().get(i).getSelection()); i++; assertEquals(i, aggregator.getComponents().size()); try { aggregator.getComponents().add(null); fail("Exception expected"); } catch (final UnsupportedOperationException e) { assertNotNull(e); } assertNotSame(aggregator, elementDef.getQueryAggregator(Sets.newHashSet(), viewAggregator)); }
@Test public void shouldReturnQueryAggregatorWithViewAggregatorAndMultipleAgg() { final T elementDef = createBuilder() .property("property1", PROPERTY_STRING_TYPE) .property("property2", PROPERTY_STRING_TYPE) .property("property3", PROPERTY_STRING_TYPE) .property("property4", PROPERTY_STRING_TYPE) .property("property5", PROPERTY_STRING_TYPE) .property("visibility", PROPERTY_STRING_TYPE) .property("timestamp", PROPERTY_STRING_TYPE) .groupBy("property1", "property2") .aggregator(new ElementAggregator.Builder() .select("property1", "property2") .execute(new ExampleTuple2BinaryOperator()) .select("property3", "property4") .execute(new ExampleTuple2BinaryOperator()) .build()) .build(); setupSchema(elementDef); final ElementAggregator viewAggregator = new ElementAggregator.Builder() .select("property1") .execute(new StringConcat()) .build(); final ElementAggregator aggregator = elementDef.getQueryAggregator(Sets.newHashSet(), viewAggregator); int i = 0; assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof StringConcat); assertArrayEquals(new String[]{"property1"}, aggregator.getComponents().get(i).getSelection()); i++; assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleTuple2BinaryOperator); assertArrayEquals(new String[]{"property1", "property2"}, aggregator.getComponents().get(i).getSelection()); i++; assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleTuple2BinaryOperator); assertArrayEquals(new String[]{"property3", "property4"}, aggregator.getComponents().get(i).getSelection()); i++; assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction); assertArrayEquals(new String[]{"property5"}, aggregator.getComponents().get(i).getSelection()); i++; assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction); assertArrayEquals(new String[]{"visibility"}, aggregator.getComponents().get(i).getSelection()); i++; assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction); assertArrayEquals(new String[]{"timestamp"}, aggregator.getComponents().get(i).getSelection()); i++; assertEquals(i, aggregator.getComponents().size()); try { aggregator.getComponents().add(null); fail("Exception expected"); } catch (final UnsupportedOperationException e) { assertNotNull(e); } assertNotSame(aggregator, elementDef.getQueryAggregator(Sets.newHashSet(), viewAggregator)); }
@Test public void shouldReturnQueryAggregatorWithMultiPropertyAggregatorWithSingleGroupBy() { final T elementDef = createBuilder() .property("property1", PROPERTY_STRING_TYPE) .property("property2", PROPERTY_STRING_TYPE) .property("property3", PROPERTY_STRING_TYPE) .property("property4", PROPERTY_STRING_TYPE) .property("property5", PROPERTY_STRING_TYPE) .property("visibility", PROPERTY_STRING_TYPE) .property("timestamp", PROPERTY_STRING_TYPE) .groupBy("property1") .aggregator(new ElementAggregator.Builder() .select("property1", "property2") .execute(new ExampleTuple2BinaryOperator()) .select("property3", "property4") .execute(new ExampleTuple2BinaryOperator()) .build()) .build(); setupSchema(elementDef); final ElementAggregator aggregator = elementDef.getQueryAggregator(Sets.newHashSet(), null); assertEquals(5, aggregator.getComponents().size()); assertTrue(aggregator.getComponents().get(0).getBinaryOperator() instanceof ExampleTuple2BinaryOperator); assertArrayEquals(new String[]{"property1", "property2"}, aggregator.getComponents().get(0).getSelection()); assertTrue(aggregator.getComponents().get(1).getBinaryOperator() instanceof ExampleTuple2BinaryOperator); assertArrayEquals(new String[]{"property3", "property4"}, aggregator.getComponents().get(1).getSelection()); assertTrue(aggregator.getComponents().get(2).getBinaryOperator() instanceof ExampleAggregateFunction); assertArrayEquals(new String[]{"property5"}, aggregator.getComponents().get(2).getSelection()); assertTrue(aggregator.getComponents().get(3).getBinaryOperator() instanceof ExampleAggregateFunction); assertArrayEquals(new String[]{"visibility"}, aggregator.getComponents().get(3).getSelection()); assertTrue(aggregator.getComponents().get(4).getBinaryOperator() instanceof ExampleAggregateFunction); assertArrayEquals(new String[]{"timestamp"}, aggregator.getComponents().get(4).getSelection()); try { aggregator.getComponents().add(null); fail("Exception expected"); } catch (final UnsupportedOperationException e) { assertNotNull(e); } assertSame(aggregator, elementDef.getQueryAggregator(Sets.newHashSet(), null)); }