/** * Create a new result set with an additional final column. * * @param column the column being added * * @return the result set being constructed */ public ResultSetSchema withAddColumn(Column column) { LinkedHashSet<Column> columns = new LinkedHashSet<>(this.getColumns()); columns.add(column); return new ResultSetSchema(this.getGranularity(), columns); } }
/** * Extract schema components from ResultSet schema. * * @param schema Schema object from the ResultSet * * @return Schema components. */ private Map<String, Object> getSchemaComponents(ResultSetSchema schema) { Map<String, Object> schemaComponents = new HashMap<>(); schemaComponents.put(SCHEMA_TIMEZONE, DateTimeUtils.getTimeZone(schema.getGranularity()).getID()); schemaComponents.put(SCHEMA_GRANULARITY, schema.getGranularity().getName()); schemaComponents.put( SCHEMA_DIM_COLUMNS, schema.getColumns(DimensionColumn.class) .stream() .map(Column::getName) .collect(Collectors.toCollection(LinkedHashSet::new)) ); schemaComponents.put( SCHEMA_METRIC_COLUMNS, getMetricColumnNames(schema) ); return schemaComponents; }
/** * Remove result records which are missing and not marked as volatile. * Any bucket which is partially volatile is not removed. In the case of the All granularity, all data is * considered to be in a single bucket. * * @param result The result row being transformed * @param schema The schema for that result * @return Null if the bucket this result falls in is missing but not volatile */ @Override public Result map(Result result, ResultSetSchema schema) { Granularity grain = schema.getGranularity(); if (grain.equals(AllGranularity.INSTANCE)) { return ! volatileIntervalSupply.get().isEmpty() || missingIntervals.isEmpty() ? result : null; } // Currently any Granularity which isn't 'ALL' must currently be a TimeGrain Interval resultInterval = new Interval(result.getTimeStamp(), ((TimeGrain) grain).getPeriod()); return getMissingNotVolatile().stream().anyMatch((it) -> it.overlaps(resultInterval)) ? null : result; }